#include <PyH5PartRandomSampleAttributes.h>
#include <ObserverToCallback.h>
#include <ColorAttribute.h>
#include <snprintf.h>

// ****************************************************************************
// Module: PyH5PartRandomSampleAttributes
//
// Purpose: 
//   Randomly reduce an H5Part point mesh
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   Thu Mar 16 10:26:56 PDT 2006
//
// ****************************************************************************

//
// This struct contains the Python type information and a H5PartRandomSampleAttributes.
//
struct H5PartRandomSampleAttributesObject
{
    PyObject_HEAD
    H5PartRandomSampleAttributes *data;
    bool owns;
};

//
// Internal prototypes
//
static PyObject *NewH5PartRandomSampleAttributes(int);

std::string
PyH5PartRandomSampleAttributes_ToString(const H5PartRandomSampleAttributes *atts, const char *prefix)
{
    std::string str; 
    char tmpStr[1000]; 

    SNPRINTF(tmpStr, 1000, "%sfactor = %g\n", prefix, atts->GetFactor());
    str += tmpStr;
    return str;
}

static PyObject *
H5PartRandomSampleAttributes_Notify(PyObject *self, PyObject *args)
{
    H5PartRandomSampleAttributesObject *obj = (H5PartRandomSampleAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
H5PartRandomSampleAttributes_SetFactor(PyObject *self, PyObject *args)
{
    H5PartRandomSampleAttributesObject *obj = (H5PartRandomSampleAttributesObject *)self;

    float fval;
    if(!PyArg_ParseTuple(args, "f", &fval))
        return NULL;

    // Set the factor in the object.
    obj->data->SetFactor(fval);

    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
H5PartRandomSampleAttributes_GetFactor(PyObject *self, PyObject *args)
{
    H5PartRandomSampleAttributesObject *obj = (H5PartRandomSampleAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(double(obj->data->GetFactor()));
    return retval;
}



static struct PyMethodDef H5PartRandomSampleAttributes_methods[] = {
    {"Notify", H5PartRandomSampleAttributes_Notify, METH_VARARGS},
    {"SetFactor", H5PartRandomSampleAttributes_SetFactor, METH_VARARGS},
    {"GetFactor", H5PartRandomSampleAttributes_GetFactor, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
H5PartRandomSampleAttributes_dealloc(PyObject *v)
{
   H5PartRandomSampleAttributesObject *obj = (H5PartRandomSampleAttributesObject *)v;
   if(obj->owns)
       delete obj->data;
}

static int
H5PartRandomSampleAttributes_compare(PyObject *v, PyObject *w)
{
    H5PartRandomSampleAttributes *a = ((H5PartRandomSampleAttributesObject *)v)->data;
    H5PartRandomSampleAttributes *b = ((H5PartRandomSampleAttributesObject *)w)->data;
    return (*a == *b) ? 0 : -1;
}

static PyObject *
H5PartRandomSampleAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "factor") == 0)
        return H5PartRandomSampleAttributes_GetFactor(self, NULL);

    return Py_FindMethod(H5PartRandomSampleAttributes_methods, self, name);
}

static int
H5PartRandomSampleAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    // Create a tuple to contain the arguments since all of the Set
    // functions expect a tuple.
    PyObject *tuple = PyTuple_New(1);
    PyTuple_SET_ITEM(tuple, 0, args);
    Py_INCREF(args);
    bool retval = false;

    if(strcmp(name, "factor") == 0)
        retval = (H5PartRandomSampleAttributes_SetFactor(self, tuple) != NULL);

    Py_DECREF(tuple);
    return retval ? 0 : -1;
}

static int
H5PartRandomSampleAttributes_print(PyObject *v, FILE *fp, int flags)
{
    H5PartRandomSampleAttributesObject *obj = (H5PartRandomSampleAttributesObject *)v;
    fprintf(fp, "%s", PyH5PartRandomSampleAttributes_ToString(obj->data, "").c_str());
    return 0;
}

PyObject *
H5PartRandomSampleAttributes_str(PyObject *v)
{
    H5PartRandomSampleAttributesObject *obj = (H5PartRandomSampleAttributesObject *)v;
    return PyString_FromString(PyH5PartRandomSampleAttributes_ToString(obj->data,"").c_str());
}

//
// The doc string for the class.
//
static char *H5PartRandomSampleAttributes_Purpose = "Randomly reduce an H5Part point mesh";

//
// The type description structure
//
static PyTypeObject H5PartRandomSampleAttributesType =
{
    //
    // Type header
    //
    PyObject_HEAD_INIT(&PyType_Type)
    0,                                   // ob_size
    "H5PartRandomSampleAttributes",                    // tp_name
    sizeof(H5PartRandomSampleAttributesObject),        // tp_basicsize
    0,                                   // tp_itemsize
    //
    // Standard methods
    //
    (destructor)H5PartRandomSampleAttributes_dealloc,  // tp_dealloc
    (printfunc)H5PartRandomSampleAttributes_print,     // tp_print
    (getattrfunc)H5PartRandomSampleAttributes_getattr, // tp_getattr
    (setattrfunc)H5PartRandomSampleAttributes_setattr, // tp_setattr
    (cmpfunc)H5PartRandomSampleAttributes_compare,     // tp_compare
    (reprfunc)0,                         // tp_repr
    //
    // Type categories
    //
    0,                                   // tp_as_number
    0,                                   // tp_as_sequence
    0,                                   // tp_as_mapping
    //
    // More methods
    //
    0,                                   // tp_hash
    0,                                   // tp_call
    (reprfunc)H5PartRandomSampleAttributes_str,        // tp_str
    0,                                   // tp_getattro
    0,                                   // tp_setattro
    0,                                   // tp_as_buffer
    Py_TPFLAGS_CHECKTYPES,               // tp_flags
    H5PartRandomSampleAttributes_Purpose,              // tp_doc
    0,                                   // tp_traverse
    0,                                   // tp_clear
    0,                                   // tp_richcompare
    0                                    // tp_weaklistoffset
};

//
// Helper functions for object allocation.
//

static H5PartRandomSampleAttributes *defaultAtts = 0;
static H5PartRandomSampleAttributes *currentAtts = 0;

static PyObject *
NewH5PartRandomSampleAttributes(int useCurrent)
{
    H5PartRandomSampleAttributesObject *newObject;
    newObject = PyObject_NEW(H5PartRandomSampleAttributesObject, &H5PartRandomSampleAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new H5PartRandomSampleAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new H5PartRandomSampleAttributes(*defaultAtts);
    else
        newObject->data = new H5PartRandomSampleAttributes;
    newObject->owns = true;
    return (PyObject *)newObject;
}

static PyObject *
WrapH5PartRandomSampleAttributes(const H5PartRandomSampleAttributes *attr)
{
    H5PartRandomSampleAttributesObject *newObject;
    newObject = PyObject_NEW(H5PartRandomSampleAttributesObject, &H5PartRandomSampleAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (H5PartRandomSampleAttributes *)attr;
    newObject->owns = false;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
H5PartRandomSampleAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewH5PartRandomSampleAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef H5PartRandomSampleAttributesMethods[] = {
    {"H5PartRandomSampleAttributes", H5PartRandomSampleAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *H5PartRandomSampleAttributesObserver = 0;

std::string
PyH5PartRandomSampleAttributes_GetLogString()
{
    std::string s("H5PartRandomSampleAtts = H5PartRandomSampleAttributes()\n");
    if(currentAtts != 0)
        s += PyH5PartRandomSampleAttributes_ToString(currentAtts, "H5PartRandomSampleAtts.");
    return s;
}

static void
PyH5PartRandomSampleAttributes_CallLogRoutine(Subject *subj, void *data)
{
    H5PartRandomSampleAttributes *atts = (H5PartRandomSampleAttributes *)subj;
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("H5PartRandomSampleAtts = H5PartRandomSampleAttributes()\n");
        s += PyH5PartRandomSampleAttributes_ToString(currentAtts, "H5PartRandomSampleAtts.");
        cb(s);
    }
}

void
PyH5PartRandomSampleAttributes_StartUp(H5PartRandomSampleAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyH5PartRandomSampleAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(H5PartRandomSampleAttributesObserver == 0)
    {
        H5PartRandomSampleAttributesObserver = new ObserverToCallback(subj,
            PyH5PartRandomSampleAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyH5PartRandomSampleAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete H5PartRandomSampleAttributesObserver;
    H5PartRandomSampleAttributesObserver = 0;
}

PyMethodDef *
PyH5PartRandomSampleAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return H5PartRandomSampleAttributesMethods;
}

bool
PyH5PartRandomSampleAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &H5PartRandomSampleAttributesType);
}

H5PartRandomSampleAttributes *
PyH5PartRandomSampleAttributes_FromPyObject(PyObject *obj)
{
    H5PartRandomSampleAttributesObject *obj2 = (H5PartRandomSampleAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyH5PartRandomSampleAttributes_NewPyObject()
{
    return NewH5PartRandomSampleAttributes(0);
}

PyObject *
PyH5PartRandomSampleAttributes_WrapPyObject(const H5PartRandomSampleAttributes *attr)
{
    return WrapH5PartRandomSampleAttributes(attr);
}

void
PyH5PartRandomSampleAttributes_SetDefaults(const H5PartRandomSampleAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new H5PartRandomSampleAttributes(*atts);
}

