/*****************************************************************************
*
* Copyright (c) 2000 - 2018, 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 <CylinderAttributes.h>
#include <DataNode.h>

// ****************************************************************************
// Method: CylinderAttributes::CylinderAttributes
//
// Purpose: 
//   Init utility for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

void CylinderAttributes::Init()
{
    point1[0] = 0;
    point1[1] = 0;
    point1[2] = 0;
    point2[0] = 1;
    point2[1] = 0;
    point2[2] = 0;
    radius = 1;
    inverse = false;

    CylinderAttributes::SelectAll();
}

// ****************************************************************************
// Method: CylinderAttributes::CylinderAttributes
//
// Purpose: 
//   Copy utility for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

void CylinderAttributes::Copy(const CylinderAttributes &obj)
{
    point1[0] = obj.point1[0];
    point1[1] = obj.point1[1];
    point1[2] = obj.point1[2];

    point2[0] = obj.point2[0];
    point2[1] = obj.point2[1];
    point2[2] = obj.point2[2];

    radius = obj.radius;
    inverse = obj.inverse;

    CylinderAttributes::SelectAll();
}

// Type map format string
const char *CylinderAttributes::TypeMapFormatString = CYLINDERATTRIBUTES_TMFS;
const AttributeGroup::private_tmfs_t CylinderAttributes::TmfsStruct = {CYLINDERATTRIBUTES_TMFS};


// ****************************************************************************
// Method: CylinderAttributes::CylinderAttributes
//
// Purpose: 
//   Default constructor for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

CylinderAttributes::CylinderAttributes() : 
    AttributeSubject(CylinderAttributes::TypeMapFormatString)
{
    CylinderAttributes::Init();
}

// ****************************************************************************
// Method: CylinderAttributes::CylinderAttributes
//
// Purpose: 
//   Constructor for the derived classes of CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

CylinderAttributes::CylinderAttributes(private_tmfs_t tmfs) : 
    AttributeSubject(tmfs.tmfs)
{
    CylinderAttributes::Init();
}

// ****************************************************************************
// Method: CylinderAttributes::CylinderAttributes
//
// Purpose: 
//   Copy constructor for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

CylinderAttributes::CylinderAttributes(const CylinderAttributes &obj) : 
    AttributeSubject(CylinderAttributes::TypeMapFormatString)
{
    CylinderAttributes::Copy(obj);
}

// ****************************************************************************
// Method: CylinderAttributes::CylinderAttributes
//
// Purpose: 
//   Copy constructor for derived classes of the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

CylinderAttributes::CylinderAttributes(const CylinderAttributes &obj, private_tmfs_t tmfs) : 
    AttributeSubject(tmfs.tmfs)
{
    CylinderAttributes::Copy(obj);
}

// ****************************************************************************
// Method: CylinderAttributes::~CylinderAttributes
//
// Purpose: 
//   Destructor for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

CylinderAttributes::~CylinderAttributes()
{
    // nothing here
}

// ****************************************************************************
// Method: CylinderAttributes::operator = 
//
// Purpose: 
//   Assignment operator for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

CylinderAttributes& 
CylinderAttributes::operator = (const CylinderAttributes &obj)
{
    if (this == &obj) return *this;

    CylinderAttributes::Copy(obj);

    return *this;
}

// ****************************************************************************
// Method: CylinderAttributes::operator == 
//
// Purpose: 
//   Comparison operator == for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

bool
CylinderAttributes::operator == (const CylinderAttributes &obj) const
{
    // Compare the point1 arrays.
    bool point1_equal = true;
    for(int i = 0; i < 3 && point1_equal; ++i)
        point1_equal = (point1[i] == obj.point1[i]);

    // Compare the point2 arrays.
    bool point2_equal = true;
    for(int i = 0; i < 3 && point2_equal; ++i)
        point2_equal = (point2[i] == obj.point2[i]);

    // Create the return value
    return (point1_equal &&
            point2_equal &&
            (radius == obj.radius) &&
            (inverse == obj.inverse));
}

// ****************************************************************************
// Method: CylinderAttributes::operator != 
//
// Purpose: 
//   Comparison operator != for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

bool
CylinderAttributes::operator != (const CylinderAttributes &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: CylinderAttributes::TypeName
//
// Purpose: 
//   Type name method for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

const std::string
CylinderAttributes::TypeName() const
{
    return "CylinderAttributes";
}

bool
CylinderAttributes::CopyAttributes(const AttributeGroup *atts)
{
    bool retval = false;

    if(TypeName() == atts->TypeName())
    {
        // Call assignment operator.
        const CylinderAttributes *tmp = (const CylinderAttributes *)atts;
        *this = *tmp;
        retval = true;
    }
    else if(atts->TypeName() == "Line")
    {
        const Line *tmp = (const Line*)atts;
        SetPoint1(tmp->GetPoint1());
        SetPoint2(tmp->GetPoint2());
        retval = true;
    }

    return retval;
}

AttributeSubject *
CylinderAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;

    if(TypeName() == tname)
    {
        retval = new CylinderAttributes(*this);
    }
    else if(tname == "Line")
    {
        Line *line = new Line;

        line->SetPoint1(GetPoint1());
        line->SetPoint2(GetPoint2());
        retval = line;
    }

    return retval;
}

// ****************************************************************************
// Method: CylinderAttributes::NewInstance
//
// Purpose: 
//   NewInstance method for the CylinderAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

AttributeSubject *
CylinderAttributes::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new CylinderAttributes(*this);
    else
        retval = new CylinderAttributes;

    return retval;
}

// ****************************************************************************
// Method: CylinderAttributes::SelectAll
//
// Purpose: 
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

void
CylinderAttributes::SelectAll()
{
    Select(ID_point1,  (void *)point1, 3);
    Select(ID_point2,  (void *)point2, 3);
    Select(ID_radius,  (void *)&radius);
    Select(ID_inverse, (void *)&inverse);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: CylinderAttributes::CreateNode
//
// Purpose: 
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

bool
CylinderAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    CylinderAttributes defaultObject;
    bool addToParent = false;
    // Create a node for CylinderAttributes.
    DataNode *node = new DataNode("CylinderAttributes");

    if(completeSave || !FieldsEqual(ID_point1, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("point1", point1, 3));
    }

    if(completeSave || !FieldsEqual(ID_point2, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("point2", point2, 3));
    }

    if(completeSave || !FieldsEqual(ID_radius, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("radius", radius));
    }

    if(completeSave || !FieldsEqual(ID_inverse, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("inverse", inverse));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: CylinderAttributes::SetFromNode
//
// Purpose: 
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

void
CylinderAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("CylinderAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("point1")) != 0)
        SetPoint1(node->AsDoubleArray());
    if((node = searchNode->GetNode("point2")) != 0)
        SetPoint2(node->AsDoubleArray());
    if((node = searchNode->GetNode("radius")) != 0)
        SetRadius(node->AsDouble());
    if((node = searchNode->GetNode("inverse")) != 0)
        SetInverse(node->AsBool());
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
CylinderAttributes::SetPoint1(const double *point1_)
{
    point1[0] = point1_[0];
    point1[1] = point1_[1];
    point1[2] = point1_[2];
    Select(ID_point1, (void *)point1, 3);
}

void
CylinderAttributes::SetPoint2(const double *point2_)
{
    point2[0] = point2_[0];
    point2[1] = point2_[1];
    point2[2] = point2_[2];
    Select(ID_point2, (void *)point2, 3);
}

void
CylinderAttributes::SetRadius(double radius_)
{
    radius = radius_;
    Select(ID_radius, (void *)&radius);
}

void
CylinderAttributes::SetInverse(bool inverse_)
{
    inverse = inverse_;
    Select(ID_inverse, (void *)&inverse);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

const double *
CylinderAttributes::GetPoint1() const
{
    return point1;
}

double *
CylinderAttributes::GetPoint1()
{
    return point1;
}

const double *
CylinderAttributes::GetPoint2() const
{
    return point2;
}

double *
CylinderAttributes::GetPoint2()
{
    return point2;
}

double
CylinderAttributes::GetRadius() const
{
    return radius;
}

bool
CylinderAttributes::GetInverse() const
{
    return inverse;
}

///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////

void
CylinderAttributes::SelectPoint1()
{
    Select(ID_point1, (void *)point1, 3);
}

void
CylinderAttributes::SelectPoint2()
{
    Select(ID_point2, (void *)point2, 3);
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: CylinderAttributes::GetFieldName
//
// Purpose: 
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

std::string
CylinderAttributes::GetFieldName(int index) const
{
    switch (index)
    {
    case ID_point1:  return "point1";
    case ID_point2:  return "point2";
    case ID_radius:  return "radius";
    case ID_inverse: return "inverse";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: CylinderAttributes::GetFieldType
//
// Purpose: 
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

AttributeGroup::FieldType
CylinderAttributes::GetFieldType(int index) const
{
    switch (index)
    {
    case ID_point1:  return FieldType_doubleArray;
    case ID_point2:  return FieldType_doubleArray;
    case ID_radius:  return FieldType_double;
    case ID_inverse: return FieldType_bool;
    default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: CylinderAttributes::GetFieldTypeName
//
// Purpose: 
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

std::string
CylinderAttributes::GetFieldTypeName(int index) const
{
    switch (index)
    {
    case ID_point1:  return "doubleArray";
    case ID_point2:  return "doubleArray";
    case ID_radius:  return "double";
    case ID_inverse: return "bool";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: CylinderAttributes::FieldsEqual
//
// Purpose: 
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//   
// ****************************************************************************

bool
CylinderAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const CylinderAttributes &obj = *((const CylinderAttributes*)rhs);
    bool retval = false;
    switch (index_)
    {
    case ID_point1:
        {  // new scope
        // Compare the point1 arrays.
        bool point1_equal = true;
        for(int i = 0; i < 3 && point1_equal; ++i)
            point1_equal = (point1[i] == obj.point1[i]);

        retval = point1_equal;
        }
        break;
    case ID_point2:
        {  // new scope
        // Compare the point2 arrays.
        bool point2_equal = true;
        for(int i = 0; i < 3 && point2_equal; ++i)
            point2_equal = (point2[i] == obj.point2[i]);

        retval = point2_equal;
        }
        break;
    case ID_radius:
        {  // new scope
        retval = (radius == obj.radius);
        }
        break;
    case ID_inverse:
        {  // new scope
        retval = (inverse == obj.inverse);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

