Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

IndexedLineSet.cpp

Go to the documentation of this file.
00001 #include "IndexedLineSet.h"
00002 #include "RenderingNodes.h"
00003 
00004 #include <iostream>
00005 
00006 using namespace X3DTK;
00007 using namespace std;
00008 
00009 IndexedLineSet::IndexedLineSet()
00010 : X3DGeometryNode(), color_(0), coord_(0), colorPerVertex_(true), lineWidth_(1.0f)
00011 {
00012   defineTagName("IndexedLineSet", "Rendering");
00013 }
00014 
00015 IndexedLineSet::IndexedLineSet(const X3DColorNode *color, const X3DCoordinateNode *coord, const MFInt32 &colorIndex, SFBool colorPerVertex, const MFInt32 &coordIndex, SFFloat lineWidth)
00016 : X3DGeometryNode(), color_((SFNode)color), coord_((SFNode)coord), colorIndex_(colorIndex), colorPerVertex_(colorPerVertex), coordIndex_(coordIndex), lineWidth_(lineWidth)
00017 {
00018   defineTagName("IndexedLineSet", "Rendering");
00019 }
00020 
00021 IndexedLineSet::IndexedLineSet(const IndexedLineSet &I)
00022 : X3DGeometryNode(), color_(I.color_), coord_(I.coord_), colorIndex_(I.colorIndex_), colorPerVertex_(I.colorPerVertex_), coordIndex_(I.coordIndex_), lineWidth_(I.lineWidth_)
00023 {
00024   defineTagName("IndexedLineSet", "Rendering");
00025 }  
00026 
00027 SFNode IndexedLineSet::clone() const
00028 {
00029   return new IndexedLineSet(*this);
00030 }
00031 
00032 IndexedLineSet::~IndexedLineSet()
00033 {
00034 }  
00035   
00036 //modifiers
00037 void IndexedLineSet::setColor(const X3DColorNode *color)
00038 {
00039   removeLink(this, color_);
00040   color_ = (SFNode)color;
00041   addLink(this, color_);
00042 }
00043 
00044 void IndexedLineSet::setCoord(const X3DCoordinateNode *coord)
00045 {
00046   removeLink(this, coord_);  
00047   coord_ = (SFNode)coord;
00048   addLink(this, coord_);
00049 }
00050 
00051 void IndexedLineSet::setColorIndex(const MFInt32 &colorIndex)
00052 {
00053   colorIndex_ = colorIndex;
00054 }
00055 
00056 void IndexedLineSet::setColorPerVertex(SFBool colorPerVertex)
00057 {
00058   colorPerVertex_ = colorPerVertex;
00059 }
00060 
00061 void IndexedLineSet::setCoordIndex(const MFInt32 &coordIndex)
00062 {
00063   coordIndex_ = coordIndex;
00064   if ((!coordIndex_.empty()) && (coordIndex_.back() != -1))
00065     coordIndex_.push_back(-1);
00066 }
00067 
00068 void IndexedLineSet::setLineWidth(SFFloat lineWidth)
00069 {
00070   lineWidth_ = lineWidth;
00071 }
00072   
00073 bool IndexedLineSet::addChild(const SFNode &N)
00074 {
00075   if (dynamic_cast<X3DColorNode *>(N) != 0)
00076   {
00077     if (color_ != 0)
00078       return false;
00079       
00080     setColor(static_cast<X3DColorNode *>(N));
00081     return true;
00082   }
00083   
00084   if (dynamic_cast<X3DCoordinateNode *>(N) != 0)
00085   {
00086     if (coord_ != 0)
00087       return false;
00088       
00089     setCoord(static_cast<X3DCoordinateNode *>(N));
00090     return true;    
00091   }
00092   
00093   cerr << "IndexedLineSet::addChild : a node of type " << N->getTypeName() << " cannot be a child!" << endl;
00094   return false;
00095 }
00096 
00097 bool IndexedLineSet::setChild(const SFNode &N)
00098 {
00099   if (dynamic_cast<X3DColorNode *>(N) != 0)
00100   {
00101     setColor(static_cast<X3DColorNode *>(N));
00102     return true;
00103   }
00104   
00105   if (dynamic_cast<X3DCoordinateNode *>(N) != 0)
00106   {
00107     setCoord(static_cast<X3DCoordinateNode *>(N));
00108     return true;    
00109   }
00110   
00111   cerr << "IndexedLineSet::setChild : a node of type " << N->getTypeName() << " cannot be a child!" << endl;
00112   return false;
00113 }
00114 
00115 bool IndexedLineSet::removeChild(const SFNode &N)
00116 {
00117   if (color_ == N)
00118   {
00119     setColor(0);
00120     return true;
00121   } 
00122    
00123   if (coord_ == N)
00124   {
00125     setCoord(0);
00126     return true;
00127   } 
00128   
00129   return false;
00130 }
00131 
00132 void IndexedLineSet::loadAttributes(const X3DFileElement *element)
00133 { 
00134   int index;
00135   index = element->getIndexAttribute("colorIndex");
00136   if (index != -1)
00137     colorIndex_ = MFInt32(element->getAttribute(index));  
00138   
00139   index = element->getIndexAttribute("colorPerVertex");
00140   if (index != -1)
00141     colorPerVertex_ = (element->getAttribute(index).upper() == "TRUE");
00142   
00143   index = element->getIndexAttribute("coordIndex");  
00144   if (index != -1)
00145     coordIndex_ = MFInt32(element->getAttribute(index));
00146     
00147   index = element->getIndexAttribute("lineWidth");    
00148   if (index != -1)
00149     lineWidth_ = element->getAttribute(index).toFloat();
00150 }
00151 
00152 SFString IndexedLineSet::writeAttributes() const
00153 {
00154   SFString attr;
00155   if (!colorIndex_.empty())
00156     attr += " colorIndex=\"" + toSFString(colorIndex_) + "\"";
00157   if (!colorPerVertex_)
00158     attr += " colorPerVertex=\"FALSE\"";
00159   if (!coordIndex_.empty())  
00160     attr += " coordIndex=\"" + toSFString(coordIndex_) + "\"";
00161   if (lineWidth_ != 1.0f)
00162     attr += " lineWidth=\"" + toSFString(lineWidth_) + "\"";
00163     
00164   return attr;
00165 }
00166 
00167 void IndexedLineSet::removeScenesToChildren(const MFScene &sceneList)
00168 {
00169   removeScenes(color_, sceneList);
00170   removeScenes(coord_, sceneList);
00171 }
00172 
00173 void IndexedLineSet::addScenesToChildren(const MFScene &sceneList)
00174 {
00175   addScenes(color_, sceneList);
00176   addScenes(coord_, sceneList);
00177 }

Generated on Wed May 14 10:03:10 2003 for X3DToolKit by doxygen1.3