/*****************************************************************************
*
* Copyright (c) 2000 - 2017, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

#include <PySubsetAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <snprintf.h>
#include <ColorAttribute.h>
#include <PyColorAttributeList.h>
#include <GlyphTypes.h>

// ****************************************************************************
// Module: PySubsetAttributes
//
// Purpose: 
//   This class contains the plot attributes for the subset boundary plot.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a SubsetAttributes.
//
struct SubsetAttributesObject
{
    PyObject_HEAD
    SubsetAttributes *data;
    bool        owns;
    PyObject   *parent;
};

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

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

    const char *colorType_names = "ColorBySingleColor, ColorByMultipleColors, ColorByColorTable";
    switch (atts->GetColorType())
    {
      case SubsetAttributes::ColorBySingleColor:
          SNPRINTF(tmpStr, 1000, "%scolorType = %sColorBySingleColor  # %s\n", prefix, prefix, colorType_names);
          str += tmpStr;
          break;
      case SubsetAttributes::ColorByMultipleColors:
          SNPRINTF(tmpStr, 1000, "%scolorType = %sColorByMultipleColors  # %s\n", prefix, prefix, colorType_names);
          str += tmpStr;
          break;
      case SubsetAttributes::ColorByColorTable:
          SNPRINTF(tmpStr, 1000, "%scolorType = %sColorByColorTable  # %s\n", prefix, prefix, colorType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    SNPRINTF(tmpStr, 1000, "%scolorTableName = \"%s\"\n", prefix, atts->GetColorTableName().c_str());
    str += tmpStr;
    if(atts->GetInvertColorTable())
        SNPRINTF(tmpStr, 1000, "%sinvertColorTable = 1\n", prefix);
    else
        SNPRINTF(tmpStr, 1000, "%sinvertColorTable = 0\n", prefix);
    str += tmpStr;
    if(atts->GetLegendFlag())
        SNPRINTF(tmpStr, 1000, "%slegendFlag = 1\n", prefix);
    else
        SNPRINTF(tmpStr, 1000, "%slegendFlag = 0\n", prefix);
    str += tmpStr;
    const char *lineStyle_values[] = {"SOLID", "DASH", "DOT", "DOTDASH"};
    SNPRINTF(tmpStr, 1000, "%slineStyle = %s%s  # SOLID, DASH, DOT, DOTDASH\n", prefix, prefix, lineStyle_values[atts->GetLineStyle()]);
    str += tmpStr;
    SNPRINTF(tmpStr, 1000, "%slineWidth = %d\n", prefix, atts->GetLineWidth());
    str += tmpStr;
    const unsigned char *singleColor = atts->GetSingleColor().GetColor();
    SNPRINTF(tmpStr, 1000, "%ssingleColor = (%d, %d, %d, %d)\n", prefix, int(singleColor[0]), int(singleColor[1]), int(singleColor[2]), int(singleColor[3]));
    str += tmpStr;
    { const ColorAttributeList &cL = atts->GetMultiColor();
        const char *comment = (prefix==0 || strcmp(prefix,"")==0) ? "# " : "";
        for(int i = 0; i < cL.GetNumColors(); ++i)
        {
            const unsigned char *c = cL[i].GetColor();
            SNPRINTF(tmpStr, 1000, "%s%sSetMultiColor(%d, (%d, %d, %d, %d))\n",
                     comment, prefix, i, int(c[0]), int(c[1]), int(c[2]), int(c[3]));
            str += tmpStr;
        }
    }
    {   const stringVector &subsetNames = atts->GetSubsetNames();
        SNPRINTF(tmpStr, 1000, "%ssubsetNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < subsetNames.size(); ++i)
        {
            SNPRINTF(tmpStr, 1000, "\"%s\"", subsetNames[i].c_str());
            str += tmpStr;
            if(i < subsetNames.size() - 1)
            {
                SNPRINTF(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        SNPRINTF(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    SNPRINTF(tmpStr, 1000, "%sopacity = %g\n", prefix, atts->GetOpacity());
    str += tmpStr;
    if(atts->GetWireframe())
        SNPRINTF(tmpStr, 1000, "%swireframe = 1\n", prefix);
    else
        SNPRINTF(tmpStr, 1000, "%swireframe = 0\n", prefix);
    str += tmpStr;
    if(atts->GetDrawInternal())
        SNPRINTF(tmpStr, 1000, "%sdrawInternal = 1\n", prefix);
    else
        SNPRINTF(tmpStr, 1000, "%sdrawInternal = 0\n", prefix);
    str += tmpStr;
    SNPRINTF(tmpStr, 1000, "%ssmoothingLevel = %d\n", prefix, atts->GetSmoothingLevel());
    str += tmpStr;
    SNPRINTF(tmpStr, 1000, "%spointSize = %g\n", prefix, atts->GetPointSize());
    str += tmpStr;
    const char *pointType_names = "Box, Axis, Icosahedron, Octahedron, Tetrahedron, "
        "SphereGeometry, Point, Sphere";
    switch (atts->GetPointType())
    {
      case Box:
          SNPRINTF(tmpStr, 1000, "%spointType = %sBox  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Axis:
          SNPRINTF(tmpStr, 1000, "%spointType = %sAxis  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Icosahedron:
          SNPRINTF(tmpStr, 1000, "%spointType = %sIcosahedron  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Octahedron:
          SNPRINTF(tmpStr, 1000, "%spointType = %sOctahedron  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Tetrahedron:
          SNPRINTF(tmpStr, 1000, "%spointType = %sTetrahedron  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case SphereGeometry:
          SNPRINTF(tmpStr, 1000, "%spointType = %sSphereGeometry  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Point:
          SNPRINTF(tmpStr, 1000, "%spointType = %sPoint  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Sphere:
          SNPRINTF(tmpStr, 1000, "%spointType = %sSphere  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetPointSizeVarEnabled())
        SNPRINTF(tmpStr, 1000, "%spointSizeVarEnabled = 1\n", prefix);
    else
        SNPRINTF(tmpStr, 1000, "%spointSizeVarEnabled = 0\n", prefix);
    str += tmpStr;
    SNPRINTF(tmpStr, 1000, "%spointSizeVar = \"%s\"\n", prefix, atts->GetPointSizeVar().c_str());
    str += tmpStr;
    SNPRINTF(tmpStr, 1000, "%spointSizePixels = %d\n", prefix, atts->GetPointSizePixels());
    str += tmpStr;
    return str;
}

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

/*static*/ PyObject *
SubsetAttributes_SetColorType(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the colorType in the object.
    if(ival >= 0 && ival < 3)
        obj->data->SetColorType(SubsetAttributes::ColoringMethod(ival));
    else
    {
        fprintf(stderr, "An invalid colorType value was given. "
                        "Valid values are in the range of [0,2]. "
                        "You can also use the following names: "
                        "ColorBySingleColor, ColorByMultipleColors, ColorByColorTable.");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetColorType(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetColorType()));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetColorTableName(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    char *str;
    if(!PyArg_ParseTuple(args, "s", &str))
        return NULL;

    // Set the colorTableName in the object.
    obj->data->SetColorTableName(std::string(str));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetColorTableName(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetColorTableName().c_str());
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetInvertColorTable(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the invertColorTable in the object.
    obj->data->SetInvertColorTable(ival != 0);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetInvertColorTable(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetInvertColorTable()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetLegendFlag(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the legendFlag in the object.
    obj->data->SetLegendFlag(ival != 0);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetLegendFlag(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetLegendFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetLineStyle(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the lineStyle in the object.
    if(ival >= 0 && ival <= 3)
        obj->data->SetLineStyle(ival);
    else
    {
        fprintf(stderr, "An invalid  value was given. "
                        "Valid values are in the range of [0,3]. "
                        "You can also use the following names: "
                        "\"SOLID\", \"DASH\", \"DOT\", \"DOTDASH\"\n");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetLineStyle(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetLineStyle()));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetLineWidth(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the lineWidth in the object.
    obj->data->SetLineWidth(ival);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetLineWidth(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetLineWidth()));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetSingleColor(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int c[4];
    if(!PyArg_ParseTuple(args, "iiii", &c[0], &c[1], &c[2], &c[3]))
    {
        c[3] = 255;
        if(!PyArg_ParseTuple(args, "iii", &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "dddd", &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "ddd", &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                PyObject *tuple = NULL;
                if(!PyArg_ParseTuple(args, "O", &tuple))
                    return NULL;

                if(!PyTuple_Check(tuple))
                    return NULL;

                // Make sure that the tuple is the right size.
                if(PyTuple_Size(tuple) < 3 || PyTuple_Size(tuple) > 4)
                    return NULL;

                // Make sure that all elements in the tuple are ints.
                for(int i = 0; i < PyTuple_Size(tuple); ++i)
                {
                    PyObject *item = PyTuple_GET_ITEM(tuple, i);
                    if(PyInt_Check(item))
                        c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
                    else if(PyFloat_Check(item))
                        c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
                    else
                        return NULL;
                }
            }
        }
        PyErr_Clear();
    }

    // Set the singleColor in the object.
    ColorAttribute ca(c[0], c[1], c[2], c[3]);
    obj->data->SetSingleColor(ca);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetSingleColor(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the singleColor.
    PyObject *retval = PyTuple_New(4);
    const unsigned char *singleColor = obj->data->GetSingleColor().GetColor();
    PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(singleColor[0])));
    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(singleColor[1])));
    PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(singleColor[2])));
    PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(singleColor[3])));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetMultiColor(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    PyObject *pyobj = NULL;
    ColorAttributeList &cL = obj->data->GetMultiColor();
    int index = 0;
    int c[4] = {0,0,0,255};
    bool setTheColor = true;

    if(!PyArg_ParseTuple(args, "iiiii", &index, &c[0], &c[1], &c[2], &c[3]))
    {
        if(!PyArg_ParseTuple(args, "iiii", &index, &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "idddd", &index, &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "iddd", &index, &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                if(!PyArg_ParseTuple(args, "iO", &index, &pyobj))
                {
                    if(PyArg_ParseTuple(args, "O", &pyobj))
                    {
                        setTheColor = false;
                        if(PyTuple_Check(pyobj))
                        {
                            // Make sure that the tuple is the right size.
                            if(PyTuple_Size(pyobj) < cL.GetNumColors())
                                return NULL;

                            // Make sure that the tuple is the right size.
                            bool badInput = false;
                            int *C = new int[4 * cL.GetNumColors()];
                            for(int i = 0; i < PyTuple_Size(pyobj) && !badInput; ++i)
                            {
                                PyObject *item = PyTuple_GET_ITEM(pyobj, i);
                                if(PyTuple_Check(item) &&
                                   (PyTuple_Size(item) == 3 || PyTuple_Size(item) == 4))
                                {
                                    C[i*4] = 0;
                                    C[i*4+1] = 0;
                                    C[i*4+2] = 0;
                                    C[i*4+3] = 255;
                                    for(int j = 0; j < PyTuple_Size(item) && !badInput; ++j)
                                    {
                                        PyObject *colorcomp = PyTuple_GET_ITEM(item, j);
                                        if(PyInt_Check(colorcomp))
                                           C[i*4+j] = int(PyInt_AS_LONG(colorcomp));
                                        else if(PyFloat_Check(colorcomp))
                                           C[i*4+j] = int(PyFloat_AS_DOUBLE(colorcomp));
                                        else
                                           badInput = true;
                                    }
                                }
                                else
                                    badInput = true;
                            }

                            if(badInput)
                            {
                                delete [] C;
                                return NULL;
                            }

                            for(int i = 0; i < cL.GetNumColors(); ++i)
                                cL[i].SetRgba(C[i*4], C[i*4+1], C[i*4+2], C[i*4+3]);
                            delete [] C;
                        }
                        else if(PyList_Check(pyobj))
                        {
                            // Make sure that the list is the right size.
                            if(PyList_Size(pyobj) < cL.GetNumColors())
                                return NULL;

                            // Make sure that the tuple is the right size.
                            bool badInput = false;
                            int *C = new int[4 * cL.GetNumColors()];
                            for(int i = 0; i < PyList_Size(pyobj) && !badInput; ++i)
                            {
                                PyObject *item = PyList_GET_ITEM(pyobj, i);
                                if(PyTuple_Check(item) &&
                                   (PyTuple_Size(item) == 3 || PyTuple_Size(item) == 4))
                                {
                                    C[i*4] = 0;
                                    C[i*4+1] = 0;
                                    C[i*4+2] = 0;
                                    C[i*4+3] = 255;
                                    for(int j = 0; j < PyTuple_Size(item) && !badInput; ++j)
                                    {
                                        PyObject *colorcomp = PyTuple_GET_ITEM(item, j);
                                        if(PyInt_Check(colorcomp))
                                           C[i*4+j] = int(PyInt_AS_LONG(colorcomp));
                                        else if(PyFloat_Check(colorcomp))
                                           C[i*4+j] = int(PyFloat_AS_DOUBLE(colorcomp));
                                        else
                                           badInput = true;
                                    }
                                }
                                else
                                    badInput = true;
                            }

                            if(badInput)
                            {
                                delete [] C;
                                return NULL;
                            }

                            for(int i = 0; i < cL.GetNumColors(); ++i)
                                cL[i].SetRgba(C[i*4], C[i*4+1], C[i*4+2], C[i*4+3]);

                            delete [] C;
                        }
                        else
                            return NULL;
                    }
                }
                else
                {
                    if(!PyTuple_Check(pyobj))
                        return NULL;

                    // Make sure that the tuple is the right size.
                    if(PyTuple_Size(pyobj) < 3 || PyTuple_Size(pyobj) > 4)
                        return NULL;

                    // Make sure that all elements in the tuple are ints.
                    for(int i = 0; i < PyTuple_Size(pyobj); ++i)
                    {
                        PyObject *item = PyTuple_GET_ITEM(pyobj, i);
                        if(PyInt_Check(item))
                            c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(pyobj, i)));
                        else if(PyFloat_Check(item))
                            c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(pyobj, i)));
                        else
                            return NULL;
                    }
                }
            }
        }
        PyErr_Clear();
    }

    if(index < 0 || index >= cL.GetNumColors())
        return NULL;

    // Set the color in the object.
    if(setTheColor)
        cL[index] = ColorAttribute(c[0], c[1], c[2], c[3]);
    cL.SelectColors();
    obj->data->SelectMultiColor();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetMultiColor(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = NULL;
    ColorAttributeList &cL = obj->data->GetMultiColor();

    int index = 0;
    if(PyArg_ParseTuple(args, "i", &index))
    {
        if(index < 0 || index >= cL.GetNumColors())
            return NULL;

        // Allocate a tuple the with enough entries to hold the singleColor.
        retval = PyTuple_New(4);
        const unsigned char *c = cL.GetColors(index).GetColor();
        PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(c[0])));
        PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(c[1])));
        PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(c[2])));
        PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(c[3])));
    }
    else
    {
        PyErr_Clear();

        // Return the whole thing.
        retval = PyList_New(cL.GetNumColors());
        for(int i = 0; i < cL.GetNumColors(); ++i)
        {
            const unsigned char *c = cL.GetColors(i).GetColor();

            PyObject *t = PyTuple_New(4);
            PyTuple_SET_ITEM(t, 0, PyInt_FromLong(long(c[0])));
            PyTuple_SET_ITEM(t, 1, PyInt_FromLong(long(c[1])));
            PyTuple_SET_ITEM(t, 2, PyInt_FromLong(long(c[2])));
            PyTuple_SET_ITEM(t, 3, PyInt_FromLong(long(c[3])));

            PyList_SET_ITEM(retval, i, t);
        }
    }
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetSubsetNames(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    stringVector  &vec = obj->data->GetSubsetNames();
    PyObject     *tuple;
    if(!PyArg_ParseTuple(args, "O", &tuple))
        return NULL;

    if(PyTuple_Check(tuple))
    {
        vec.resize(PyTuple_Size(tuple));
        for(int i = 0; i < PyTuple_Size(tuple); ++i)
        {
            PyObject *item = PyTuple_GET_ITEM(tuple, i);
            if(PyString_Check(item))
                vec[i] = std::string(PyString_AS_STRING(item));
            else
                vec[i] = std::string("");
        }
    }
    else if(PyString_Check(tuple))
    {
        vec.resize(1);
        vec[0] = std::string(PyString_AS_STRING(tuple));
    }
    else
        return NULL;

    // Mark the subsetNames in the object as modified.
    obj->data->SelectSubsetNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetSubsetNames(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the subsetNames.
    const stringVector &subsetNames = obj->data->GetSubsetNames();
    PyObject *retval = PyTuple_New(subsetNames.size());
    for(size_t i = 0; i < subsetNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(subsetNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetOpacity(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    double dval;
    if(!PyArg_ParseTuple(args, "d", &dval))
        return NULL;

    // Set the opacity in the object.
    obj->data->SetOpacity(dval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetOpacity(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetOpacity());
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetWireframe(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the wireframe in the object.
    obj->data->SetWireframe(ival != 0);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetWireframe(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetWireframe()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetDrawInternal(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the drawInternal in the object.
    obj->data->SetDrawInternal(ival != 0);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetDrawInternal(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetDrawInternal()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetSmoothingLevel(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the smoothingLevel in the object.
    obj->data->SetSmoothingLevel((int)ival);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetSmoothingLevel(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetSmoothingLevel()));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetPointSize(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    double dval;
    if(!PyArg_ParseTuple(args, "d", &dval))
        return NULL;

    // Set the pointSize in the object.
    obj->data->SetPointSize(dval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetPointSize(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetPointSize());
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetPointType(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    if(ival >= 0 && ival < 8)
    {
        obj->data->SetPointType(GlyphType(ival));
    }
    else
    {
        fprintf(stderr, "An invalid pointType value was given. "
                        "Valid values are in the range of [0,7]. "
                        "You can also use the following names: "
                        "Box, Axis, Icosahedron, Octahedron, Tetrahedron, "
                        "SphereGeometry, Point, Sphere.");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetPointType(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetPointType()));
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetPointSizeVarEnabled(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the pointSizeVarEnabled in the object.
    obj->data->SetPointSizeVarEnabled(ival != 0);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetPointSizeVarEnabled(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetPointSizeVarEnabled()?1L:0L);
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetPointSizeVar(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    char *str;
    if(!PyArg_ParseTuple(args, "s", &str))
        return NULL;

    // Set the pointSizeVar in the object.
    obj->data->SetPointSizeVar(std::string(str));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetPointSizeVar(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetPointSizeVar().c_str());
    return retval;
}

/*static*/ PyObject *
SubsetAttributes_SetPointSizePixels(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;

    int ival;
    if(!PyArg_ParseTuple(args, "i", &ival))
        return NULL;

    // Set the pointSizePixels in the object.
    obj->data->SetPointSizePixels((int)ival);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
SubsetAttributes_GetPointSizePixels(PyObject *self, PyObject *args)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetPointSizePixels()));
    return retval;
}



PyMethodDef PySubsetAttributes_methods[SUBSETATTRIBUTES_NMETH] = {
    {"Notify", SubsetAttributes_Notify, METH_VARARGS},
    {"SetColorType", SubsetAttributes_SetColorType, METH_VARARGS},
    {"GetColorType", SubsetAttributes_GetColorType, METH_VARARGS},
    {"SetColorTableName", SubsetAttributes_SetColorTableName, METH_VARARGS},
    {"GetColorTableName", SubsetAttributes_GetColorTableName, METH_VARARGS},
    {"SetInvertColorTable", SubsetAttributes_SetInvertColorTable, METH_VARARGS},
    {"GetInvertColorTable", SubsetAttributes_GetInvertColorTable, METH_VARARGS},
    {"SetLegendFlag", SubsetAttributes_SetLegendFlag, METH_VARARGS},
    {"GetLegendFlag", SubsetAttributes_GetLegendFlag, METH_VARARGS},
    {"SetLineStyle", SubsetAttributes_SetLineStyle, METH_VARARGS},
    {"GetLineStyle", SubsetAttributes_GetLineStyle, METH_VARARGS},
    {"SetLineWidth", SubsetAttributes_SetLineWidth, METH_VARARGS},
    {"GetLineWidth", SubsetAttributes_GetLineWidth, METH_VARARGS},
    {"SetSingleColor", SubsetAttributes_SetSingleColor, METH_VARARGS},
    {"GetSingleColor", SubsetAttributes_GetSingleColor, METH_VARARGS},
    {"SetMultiColor", SubsetAttributes_SetMultiColor, METH_VARARGS},
    {"GetMultiColor", SubsetAttributes_GetMultiColor, METH_VARARGS},
    {"SetSubsetNames", SubsetAttributes_SetSubsetNames, METH_VARARGS},
    {"GetSubsetNames", SubsetAttributes_GetSubsetNames, METH_VARARGS},
    {"SetOpacity", SubsetAttributes_SetOpacity, METH_VARARGS},
    {"GetOpacity", SubsetAttributes_GetOpacity, METH_VARARGS},
    {"SetWireframe", SubsetAttributes_SetWireframe, METH_VARARGS},
    {"GetWireframe", SubsetAttributes_GetWireframe, METH_VARARGS},
    {"SetDrawInternal", SubsetAttributes_SetDrawInternal, METH_VARARGS},
    {"GetDrawInternal", SubsetAttributes_GetDrawInternal, METH_VARARGS},
    {"SetSmoothingLevel", SubsetAttributes_SetSmoothingLevel, METH_VARARGS},
    {"GetSmoothingLevel", SubsetAttributes_GetSmoothingLevel, METH_VARARGS},
    {"SetPointSize", SubsetAttributes_SetPointSize, METH_VARARGS},
    {"GetPointSize", SubsetAttributes_GetPointSize, METH_VARARGS},
    {"SetPointType", SubsetAttributes_SetPointType, METH_VARARGS},
    {"GetPointType", SubsetAttributes_GetPointType, METH_VARARGS},
    {"SetPointSizeVarEnabled", SubsetAttributes_SetPointSizeVarEnabled, METH_VARARGS},
    {"GetPointSizeVarEnabled", SubsetAttributes_GetPointSizeVarEnabled, METH_VARARGS},
    {"SetPointSizeVar", SubsetAttributes_SetPointSizeVar, METH_VARARGS},
    {"GetPointSizeVar", SubsetAttributes_GetPointSizeVar, METH_VARARGS},
    {"SetPointSizePixels", SubsetAttributes_SetPointSizePixels, METH_VARARGS},
    {"GetPointSizePixels", SubsetAttributes_GetPointSizePixels, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
SubsetAttributes_dealloc(PyObject *v)
{
   SubsetAttributesObject *obj = (SubsetAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static int
SubsetAttributes_compare(PyObject *v, PyObject *w)
{
    SubsetAttributes *a = ((SubsetAttributesObject *)v)->data;
    SubsetAttributes *b = ((SubsetAttributesObject *)w)->data;
    return (*a == *b) ? 0 : -1;
}

PyObject *
PySubsetAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "colorType") == 0)
        return SubsetAttributes_GetColorType(self, NULL);
    if(strcmp(name, "ColorBySingleColor") == 0)
        return PyInt_FromLong(long(SubsetAttributes::ColorBySingleColor));
    if(strcmp(name, "ColorByMultipleColors") == 0)
        return PyInt_FromLong(long(SubsetAttributes::ColorByMultipleColors));
    if(strcmp(name, "ColorByColorTable") == 0)
        return PyInt_FromLong(long(SubsetAttributes::ColorByColorTable));

    if(strcmp(name, "colorTableName") == 0)
        return SubsetAttributes_GetColorTableName(self, NULL);
    if(strcmp(name, "invertColorTable") == 0)
        return SubsetAttributes_GetInvertColorTable(self, NULL);
    if(strcmp(name, "legendFlag") == 0)
        return SubsetAttributes_GetLegendFlag(self, NULL);
    if(strcmp(name, "lineStyle") == 0)
        return SubsetAttributes_GetLineStyle(self, NULL);
    if(strcmp(name, "SOLID") == 0)
        return PyInt_FromLong(long(0));
    else if(strcmp(name, "DASH") == 0)
        return PyInt_FromLong(long(1));
    else if(strcmp(name, "DOT") == 0)
        return PyInt_FromLong(long(2));
    else if(strcmp(name, "DOTDASH") == 0)
        return PyInt_FromLong(long(3));

    if(strcmp(name, "lineWidth") == 0)
        return SubsetAttributes_GetLineWidth(self, NULL);
    if(strcmp(name, "singleColor") == 0)
        return SubsetAttributes_GetSingleColor(self, NULL);
    if(strcmp(name, "multiColor") == 0)
        return SubsetAttributes_GetMultiColor(self, NULL);
    if(strcmp(name, "subsetNames") == 0)
        return SubsetAttributes_GetSubsetNames(self, NULL);
    if(strcmp(name, "opacity") == 0)
        return SubsetAttributes_GetOpacity(self, NULL);
    if(strcmp(name, "wireframe") == 0)
        return SubsetAttributes_GetWireframe(self, NULL);
    if(strcmp(name, "drawInternal") == 0)
        return SubsetAttributes_GetDrawInternal(self, NULL);
    if(strcmp(name, "smoothingLevel") == 0)
        return SubsetAttributes_GetSmoothingLevel(self, NULL);
    if(strcmp(name, "pointSize") == 0)
        return SubsetAttributes_GetPointSize(self, NULL);
    if(strcmp(name, "pointType") == 0)
        return SubsetAttributes_GetPointType(self, NULL);
    if(strcmp(name, "Box") == 0)
        return PyInt_FromLong(long(Box));
    if(strcmp(name, "Axis") == 0)
        return PyInt_FromLong(long(Axis));
    if(strcmp(name, "Icosahedron") == 0)
        return PyInt_FromLong(long(Icosahedron));
    if(strcmp(name, "Octahedron") == 0)
        return PyInt_FromLong(long(Octahedron));
    if(strcmp(name, "Tetrahedron") == 0)
        return PyInt_FromLong(long(Tetrahedron));
    if(strcmp(name, "SphereGeometry") == 0)
        return PyInt_FromLong(long(SphereGeometry));
    if(strcmp(name, "Point") == 0)
        return PyInt_FromLong(long(Point));
    if(strcmp(name, "Sphere") == 0)
        return PyInt_FromLong(long(Sphere));

    if(strcmp(name, "pointSizeVarEnabled") == 0)
        return SubsetAttributes_GetPointSizeVarEnabled(self, NULL);
    if(strcmp(name, "pointSizeVar") == 0)
        return SubsetAttributes_GetPointSizeVar(self, NULL);
    if(strcmp(name, "pointSizePixels") == 0)
        return SubsetAttributes_GetPointSizePixels(self, NULL);

    // Try and handle legacy fields

    // subsetType and it's possible enumerations
    // these should have been internal all along ...
    if (strcmp(name, "subsetType") == 0)
    {
        return PyInt_FromLong(0L);
    }
    else if (strcmp(name, "Domain") == 0)
    {
        return PyInt_FromLong(0L);
    }
    else if (strcmp(name, "Group") == 0)
    {
        return PyInt_FromLong(0L);
    }
    else if (strcmp(name, "Material") == 0)
    {
        return PyInt_FromLong(0L);
    }
    else if (strcmp(name, "Unknown") == 0)
    {
        return PyInt_FromLong(0L);
    }
    // filledFlag -- hasn't been used in a LONG time
    else if (strcmp(name, "filledFlag") == 0)
    {
        return PyInt_FromLong(0L);
    }
    return Py_FindMethod(PySubsetAttributes_methods, self, name);
}

int
PySubsetAttributes_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);
    PyObject *obj = NULL;

    if(strcmp(name, "colorType") == 0)
        obj = SubsetAttributes_SetColorType(self, tuple);
    else if(strcmp(name, "colorTableName") == 0)
        obj = SubsetAttributes_SetColorTableName(self, tuple);
    else if(strcmp(name, "invertColorTable") == 0)
        obj = SubsetAttributes_SetInvertColorTable(self, tuple);
    else if(strcmp(name, "legendFlag") == 0)
        obj = SubsetAttributes_SetLegendFlag(self, tuple);
    else if(strcmp(name, "lineStyle") == 0)
        obj = SubsetAttributes_SetLineStyle(self, tuple);
    else if(strcmp(name, "lineWidth") == 0)
        obj = SubsetAttributes_SetLineWidth(self, tuple);
    else if(strcmp(name, "singleColor") == 0)
        obj = SubsetAttributes_SetSingleColor(self, tuple);
    else if(strcmp(name, "multiColor") == 0)
        obj = SubsetAttributes_SetMultiColor(self, tuple);
    else if(strcmp(name, "subsetNames") == 0)
        obj = SubsetAttributes_SetSubsetNames(self, tuple);
    else if(strcmp(name, "opacity") == 0)
        obj = SubsetAttributes_SetOpacity(self, tuple);
    else if(strcmp(name, "wireframe") == 0)
        obj = SubsetAttributes_SetWireframe(self, tuple);
    else if(strcmp(name, "drawInternal") == 0)
        obj = SubsetAttributes_SetDrawInternal(self, tuple);
    else if(strcmp(name, "smoothingLevel") == 0)
        obj = SubsetAttributes_SetSmoothingLevel(self, tuple);
    else if(strcmp(name, "pointSize") == 0)
        obj = SubsetAttributes_SetPointSize(self, tuple);
    else if(strcmp(name, "pointType") == 0)
        obj = SubsetAttributes_SetPointType(self, tuple);
    else if(strcmp(name, "pointSizeVarEnabled") == 0)
        obj = SubsetAttributes_SetPointSizeVarEnabled(self, tuple);
    else if(strcmp(name, "pointSizeVar") == 0)
        obj = SubsetAttributes_SetPointSizeVar(self, tuple);
    else if(strcmp(name, "pointSizePixels") == 0)
        obj = SubsetAttributes_SetPointSizePixels(self, tuple);

    // Try and handle legacy fields
    if(obj == NULL)
    {
        if(strcmp(name, "filledFlag") == 0)
        {
            Py_INCREF(Py_None);
            obj = Py_None;
        }
        // internal only, shouldn't be set by scripts
        else if(strcmp(name, "subsetType") == 0)
        {
            Py_INCREF(Py_None);
            obj = Py_None;
        }
    }
    if(obj != NULL)
        Py_DECREF(obj);

    Py_DECREF(tuple);
    if( obj == NULL)
        PyErr_Format(PyExc_RuntimeError, "Unable to set unknown attribute: '%s'", name);
    return (obj != NULL) ? 0 : -1;
}

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

PyObject *
SubsetAttributes_str(PyObject *v)
{
    SubsetAttributesObject *obj = (SubsetAttributesObject *)v;
    return PyString_FromString(PySubsetAttributes_ToString(obj->data,"").c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *SubsetAttributes_Purpose = "This class contains the plot attributes for the subset boundary plot.";
#else
static char *SubsetAttributes_Purpose = "This class contains the plot attributes for the subset boundary plot.";
#endif

//
// The type description structure
//
static PyTypeObject SubsetAttributesType =
{
    //
    // Type header
    //
    PyObject_HEAD_INIT(&PyType_Type)
    0,                                   // ob_size
    "SubsetAttributes",                    // tp_name
    sizeof(SubsetAttributesObject),        // tp_basicsize
    0,                                   // tp_itemsize
    //
    // Standard methods
    //
    (destructor)SubsetAttributes_dealloc,  // tp_dealloc
    (printfunc)SubsetAttributes_print,     // tp_print
    (getattrfunc)PySubsetAttributes_getattr, // tp_getattr
    (setattrfunc)PySubsetAttributes_setattr, // tp_setattr
    (cmpfunc)SubsetAttributes_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)SubsetAttributes_str,        // tp_str
    0,                                   // tp_getattro
    0,                                   // tp_setattro
    0,                                   // tp_as_buffer
    Py_TPFLAGS_CHECKTYPES,               // tp_flags
    SubsetAttributes_Purpose,              // tp_doc
    0,                                   // tp_traverse
    0,                                   // tp_clear
    0,                                   // tp_richcompare
    0                                    // tp_weaklistoffset
};

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

static SubsetAttributes *defaultAtts = 0;
static SubsetAttributes *currentAtts = 0;

static PyObject *
NewSubsetAttributes(int useCurrent)
{
    SubsetAttributesObject *newObject;
    newObject = PyObject_NEW(SubsetAttributesObject, &SubsetAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new SubsetAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new SubsetAttributes(*defaultAtts);
    else
        newObject->data = new SubsetAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapSubsetAttributes(const SubsetAttributes *attr)
{
    SubsetAttributesObject *newObject;
    newObject = PyObject_NEW(SubsetAttributesObject, &SubsetAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (SubsetAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

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

PyObject *
SubsetAttributes_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 *)NewSubsetAttributes(useCurrent);
}

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

static Observer *SubsetAttributesObserver = 0;

std::string
PySubsetAttributes_GetLogString()
{
    std::string s("SubsetAtts = SubsetAttributes()\n");
    if(currentAtts != 0)
        s += PySubsetAttributes_ToString(currentAtts, "SubsetAtts.");
    return s;
}

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

    if(cb != 0)
    {
        std::string s("SubsetAtts = SubsetAttributes()\n");
        s += PySubsetAttributes_ToString(currentAtts, "SubsetAtts.");
        cb(s);
    }
}

void
PySubsetAttributes_StartUp(SubsetAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PySubsetAttributes_SetDefaults(subj);

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

}

void
PySubsetAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete SubsetAttributesObserver;
    SubsetAttributesObserver = 0;
}

PyMethodDef *
PySubsetAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return SubsetAttributesMethods;
}

bool
PySubsetAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &SubsetAttributesType);
}

SubsetAttributes *
PySubsetAttributes_FromPyObject(PyObject *obj)
{
    SubsetAttributesObject *obj2 = (SubsetAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PySubsetAttributes_New()
{
    return NewSubsetAttributes(0);
}

PyObject *
PySubsetAttributes_Wrap(const SubsetAttributes *attr)
{
    return WrapSubsetAttributes(attr);
}

void
PySubsetAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    SubsetAttributesObject *obj2 = (SubsetAttributesObject *)obj;
    obj2->parent = parent;
}

// ****************************************************************************
//  Modifications:
//    Kathleen Bonnell, Mon Dec  2 18:06:04 PST 2002
//    Make defaultAtts point to the passed atts directly.
//
// ****************************************************************************
void
PySubsetAttributes_SetDefaults(const SubsetAttributes *atts)
{
    defaultAtts = const_cast<SubsetAttributes*>(atts);
}

