KiCad PCB EDA Suite
SGCOLORS Class Reference

#include <sg_colors.h>

Inheritance diagram for SGCOLORS:
SGNODE

Public Member Functions

void unlinkChildNode (const SGNODE *aNode) override
 Function unlinkChild removes references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
void unlinkRefNode (const SGNODE *aNode) override
 Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references. More...
 
 SGCOLORS (SGNODE *aParent)
 
virtual ~SGCOLORS ()
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Function SetParent sets the parent SGNODE of this object. More...
 
SGNODEFindNode (const char *aNodeName, const SGNODE *aCaller) override
 Function FindNode searches the tree of linked nodes and returns a reference to the first node found with the given name. More...
 
bool AddRefNode (SGNODE *aNode) override
 
bool AddChildNode (SGNODE *aNode) override
 
bool GetColorList (size_t &aListSize, SGCOLOR *&aColorList)
 
void SetColorList (size_t aListSize, const SGCOLOR *aColorList)
 
void AddColor (double aRedValue, double aGreenValue, double aBlueValue)
 
void AddColor (const SGCOLOR &aColor)
 
void ReNameNodes (void) override
 Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations. More...
 
bool WriteVRML (std::ostream &aFile, bool aReuseFlag) override
 Function WriteVRML writes this node's data to a VRML file; this includes all data of child and referenced nodes. More...
 
bool WriteCache (std::ostream &aFile, SGNODE *parentNode) override
 Function WriteCache write's this node's data to a binary cache file; the data includes all data of children and references to children. More...
 
bool ReadCache (std::istream &aFile, SGNODE *parentNode) override
 Function ReadCache Reads binary format data from a cache file. More...
 
void addNodeRef (SGNODE *aNode)
 Function addNodeRef adds a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (const SGNODE *aNode)
 Function delNodeRef removes a pointer to a node which references, but does not own, this node. More...
 
bool isWritten (void)
 Function IsWritten returns true if the object had already been written to a cache file or VRML file; for internal use only. More...
 
S3D::SGTYPES GetNodeType (void) const
 Function GetNodeType returns the type of this node instance. More...
 
SGNODEGetParent (void) const
 Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
bool SwapParent (SGNODE *aNewParent)
 Function SwapParent swaps the ownership with the given parent. More...
 
const char * GetName (void)
 
void SetName (const char *aName)
 
const char * GetNodeTypeName (S3D::SGTYPES aNodeType) const
 
void AssociateWrapper (SGNODE **aWrapperRef)
 Function AssociateWrapper associates this object with a handle to itself; this handle is typically held by an IFSG* wrapper and the pointer which it refers to is set to NULL upon destruction of this object. More...
 
void DisassociateWrapper (SGNODE **aWrapperRef)
 Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object. More...
 
void ResetNodeIndex (void)
 Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations. More...
 

Public Attributes

std::vector< SGCOLORcolors
 

Protected Attributes

std::list< SGNODE * > m_BackPointers
 
SGNODEm_Parent
 
S3D::SGTYPES m_SGtype
 
std::string m_Name
 
bool m_written
 

Detailed Description

Definition at line 35 of file sg_colors.h.

Constructor & Destructor Documentation

SGCOLORS::SGCOLORS ( SGNODE aParent)

Definition at line 31 of file sg_colors.cpp.

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::m_SGtype, S3D::SGTYPE_COLORS, and S3D::SGTYPE_FACESET.

31  : SGNODE( aParent )
32 {
34 
35  if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
36  {
37  m_Parent = NULL;
38 
39 #ifdef DEBUG
40  std::ostringstream ostr;
41  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
42  ostr << " * [BUG] inappropriate parent to SGCOLORS (type ";
43  ostr << aParent->GetNodeType() << ")";
44  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
45 #endif
46  }
47  else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
48  {
49  m_Parent->AddChildNode( this );
50  }
51 
52  return;
53 }
SGNODE * m_Parent
Definition: sg_node.h:83
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
virtual bool AddChildNode(SGNODE *aNode)=0
SGCOLORS::~SGCOLORS ( )
virtual

Definition at line 56 of file sg_colors.cpp.

References colors.

57 {
58  colors.clear();
59  return;
60 }
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38

Member Function Documentation

bool SGCOLORS::AddChildNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 144 of file sg_colors.cpp.

145 {
146  #ifdef DEBUG
147  std::ostringstream ostr;
148  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
149  ostr << " * [BUG] this node does not accept children or refs";
150  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
151  #endif
152 
153  return false;
154 }
void SGCOLORS::AddColor ( double  aRedValue,
double  aGreenValue,
double  aBlueValue 
)

Definition at line 186 of file sg_colors.cpp.

References colors.

187 {
188  colors.push_back( SGCOLOR( aRedValue, aGreenValue, aBlueValue ) );
189  return;
190 }
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38
void SGCOLORS::AddColor ( const SGCOLOR aColor)

Definition at line 193 of file sg_colors.cpp.

References colors.

194 {
195  colors.push_back( aColor );
196  return;
197 }
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38
void SGNODE::addNodeRef ( SGNODE aNode)
inherited

Function addNodeRef adds a pointer to a node which references, but does not own, this node.

Such back-pointers are required to ensure that invalidated references are removed when a node is deleted

Parameters
aNodeis the node holding a reference to this object

Definition at line 176 of file sg_node.cpp.

References SGNODE::m_BackPointers.

Referenced by SGSHAPE::addNode(), SGFACESET::addNode(), SGSHAPE::ReadCache(), and SGFACESET::ReadCache().

177 {
178  if( NULL == aNode )
179  return;
180 
181  std::list< SGNODE* >::iterator np =
182  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
183 
184  if( np != m_BackPointers.end() )
185  return;
186 
187  m_BackPointers.push_back( aNode );
188  return;
189 }
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
bool SGCOLORS::AddRefNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 131 of file sg_colors.cpp.

132 {
133  #ifdef DEBUG
134  std::ostringstream ostr;
135  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
136  ostr << " * [BUG] this node does not accept children or refs";
137  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
138  #endif
139 
140  return false;
141 }
void SGNODE::AssociateWrapper ( SGNODE **  aWrapperRef)
inherited

Function AssociateWrapper associates this object with a handle to itself; this handle is typically held by an IFSG* wrapper and the pointer which it refers to is set to NULL upon destruction of this object.

This mechanism provides a scheme by which a wrapper can be notified of the destruction of the object which it wraps.

Definition at line 219 of file sg_node.cpp.

References SGNODE::m_Association.

Referenced by S3D::AssociateSGNodeWrapper(), IFSG_APPEARANCE::Attach(), IFSG_SHAPE::Attach(), IFSG_COORDINDEX::Attach(), IFSG_NORMALS::Attach(), IFSG_COORDS::Attach(), IFSG_FACESET::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_APPEARANCE::IFSG_APPEARANCE(), IFSG_COLORS::IFSG_COLORS(), IFSG_COORDINDEX::IFSG_COORDINDEX(), IFSG_COORDS::IFSG_COORDS(), IFSG_FACESET::IFSG_FACESET(), IFSG_NORMALS::IFSG_NORMALS(), IFSG_SHAPE::IFSG_SHAPE(), IFSG_TRANSFORM::IFSG_TRANSFORM(), IFSG_APPEARANCE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

220 {
221  if( NULL == aWrapperRef )
222  {
223  #ifdef DEBUG
224  std::ostringstream ostr;
225  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
226  ostr << " * [BUG] NULL handle";
227  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
228  #endif
229 
230  return;
231  }
232 
233  if( *aWrapperRef != this )
234  {
235  #ifdef DEBUG
236  std::ostringstream ostr;
237  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
238  ostr << " * [BUG] handle value does not match this object's pointer";
239  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
240  #endif
241 
242  return;
243  }
244 
245  // if there is an existing association then break it and emit a warning
246  // just in case the behavior is undesired
247  if( m_Association )
248  {
249  *m_Association = NULL;
250 
251  #ifdef DEBUG
252  std::ostringstream ostr;
253  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
254  ostr << " * [WARNING] association being broken with previous wrapper";
255  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
256  #endif
257  }
258 
259  m_Association = aWrapperRef;
260 
261  return;
262 }
SGNODE ** m_Association
Definition: sg_node.h:79
void SGNODE::delNodeRef ( const SGNODE aNode)
inherited

Function delNodeRef removes a pointer to a node which references, but does not own, this node.

Parameters
aNodeis the node holding a reference to this object

Definition at line 192 of file sg_node.cpp.

References SGNODE::GetNodeType(), SGNODE::m_BackPointers, and SGNODE::m_SGtype.

Referenced by SGSHAPE::unlinkNode(), SGFACESET::unlinkNode(), SGFACESET::~SGFACESET(), and SGSHAPE::~SGSHAPE().

193 {
194  if( NULL == aNode )
195  return;
196 
197  std::list< SGNODE* >::iterator np =
198  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
199 
200  if( np != m_BackPointers.end() )
201  {
202  m_BackPointers.erase( np );
203  return;
204  }
205 
206  #ifdef DEBUG
207  std::ostringstream ostr;
208  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
209  ostr << " * [BUG] delNodeRef() did not find its target\n";
210  ostr << " * This Node Type: " << m_SGtype << ", Referenced node type: ";
211  ostr << aNode->GetNodeType() << "\n";
212  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
213  #endif
214 
215  return;
216 }
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
void SGNODE::DisassociateWrapper ( SGNODE **  aWrapperRef)
inherited

Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object.

Definition at line 264 of file sg_node.cpp.

References SGNODE::GetName(), SGNODE::m_Association, SGNODE::m_SGtype, and node_names.

Referenced by IFSG_APPEARANCE::Attach(), IFSG_COORDINDEX::Attach(), IFSG_NORMALS::Attach(), IFSG_FACESET::Attach(), IFSG_COORDS::Attach(), IFSG_SHAPE::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_NODE::Destroy(), IFSG_APPEARANCE::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_NORMALS::NewNode(), IFSG_FACESET::NewNode(), IFSG_COLORS::NewNode(), IFSG_TRANSFORM::NewNode(), and IFSG_NODE::~IFSG_NODE().

265 {
266  if( !m_Association )
267  return;
268 
269  if( !aWrapperRef )
270  {
271  #ifdef DEBUG
272  std::ostringstream ostr;
273  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
274  ostr << " * [BUG] invalid handle value aWrapperRef";
275  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
276  #endif
277 
278  return;
279  }
280 
281  if( *aWrapperRef != *m_Association || aWrapperRef != m_Association )
282  {
283  #ifdef DEBUG
284  std::ostringstream ostr;
285  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
286  ostr << " * [BUG] *aWrapperRef (" << *aWrapperRef;
287  ostr << ") does not match *m_Association (" << *m_Association << ") in type ";
288  ostr << node_names[ m_SGtype] << "\n";
289  ostr << " * [INFO] OR aWrapperRef(" << aWrapperRef << ") != m_Association(";
290  ostr << m_Association << ")\n";
291  ostr << " * [INFO] node name: " << GetName();
292  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
293  #endif
294 
295  return;
296  }
297 
298  m_Association = NULL;
299 
300  return;
301 }
SGNODE ** m_Association
Definition: sg_node.h:79
const char * GetName(void)
Definition: sg_node.cpp:150
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
SGNODE * SGCOLORS::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtual

Function FindNode searches the tree of linked nodes and returns a reference to the first node found with the given name.

The reference is then typically added to another node via AddRefNode().

Parameters
aNodeNameis the name of the node to search for
aCalleris a pointer to the node invoking this function
Returns
is a valid node pointer on success, otherwise NULL

Implements SGNODE.

Definition at line 93 of file sg_colors.cpp.

References SGNODE::m_Name.

Referenced by SGFACESET::FindNode().

94 {
95  if( NULL == aNodeName || 0 == aNodeName[0] )
96  return NULL;
97 
98  if( !m_Name.compare( aNodeName ) )
99  return this;
100 
101  return NULL;
102 }
std::string m_Name
Definition: sg_node.h:85
bool SGCOLORS::GetColorList ( size_t &  aListSize,
SGCOLOR *&  aColorList 
)

Definition at line 157 of file sg_colors.cpp.

References colors.

Referenced by SGSHAPE::Prepare(), and SGFACESET::validate().

158 {
159  if( colors.empty() )
160  {
161  aListSize = 0;
162  aColorList = NULL;
163  return false;
164  }
165 
166  aListSize = colors.size();
167  aColorList = &colors[0];
168  return true;
169 }
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38
const char * SGNODE::GetNodeTypeName ( S3D::SGTYPES  aNodeType) const
inherited

Definition at line 170 of file sg_node.cpp.

References node_names.

Referenced by IFSG_NODE::GetNodeTypeName(), IFSG_APPEARANCE::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_SHAPE::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_COLORS::NewNode(), and IFSG_TRANSFORM::NewNode().

171 {
172  return node_names[aNodeType].c_str();
173 }
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:34
SGNODE * SGNODE::GetParent ( void  ) const
inherited
bool SGNODE::isWritten ( void  )
inlineinherited

Function IsWritten returns true if the object had already been written to a cache file or VRML file; for internal use only.

Definition at line 130 of file sg_node.h.

References SGNODE::m_written.

Referenced by SGSHAPE::WriteCache(), SGFACESET::WriteCache(), and SCENEGRAPH::WriteCache().

131  {
132  return m_written;
133  }
bool m_written
Definition: sg_node.h:86
bool SGCOLORS::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtual

Function ReadCache Reads binary format data from a cache file.

To read a cache file, open the file for reading and invoke this function from a new SCENEGRAPH node.

Implements SGNODE.

Definition at line 337 of file sg_colors.cpp.

References colors, and S3D::ReadColor().

Referenced by SGFACESET::ReadCache().

338 {
339  if( !colors.empty() )
340  {
341  #ifdef DEBUG
342  std::ostringstream ostr;
343  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
344  ostr << " * [BUG] non-empty node";
345  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
346  #endif
347 
348  return false;
349  }
350 
351  size_t ncolors;
352  aFile.read( (char*)&ncolors, sizeof(size_t) );
353  SGCOLOR tmp;
354 
355  if( aFile.fail() )
356  return false;
357 
358  for( size_t i = 0; i < ncolors; ++i )
359  {
360  if( !S3D::ReadColor( aFile, tmp ) || aFile.fail() )
361  return false;
362 
363  colors.push_back( tmp );
364  }
365 
366  return true;
367 }
bool ReadColor(std::istream &aFile, SGCOLOR &aColor)
Definition: sg_helpers.cpp:324
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38
void SGCOLORS::ReNameNodes ( void  )
overridevirtual

Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations.

Implements SGNODE.

Definition at line 200 of file sg_colors.cpp.

References SGNODE::GetName(), SGNODE::m_Name, and SGNODE::m_written.

Referenced by SGFACESET::ReNameNodes().

201 {
202  m_written = false;
203 
204  // rename this node
205  m_Name.clear();
206  GetName();
207 }
const char * GetName(void)
Definition: sg_node.cpp:150
bool m_written
Definition: sg_node.h:86
std::string m_Name
Definition: sg_node.h:85
void SGNODE::ResetNodeIndex ( void  )
inherited

Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations.

Definition at line 304 of file sg_node.cpp.

References node_counts, and S3D::SGTYPE_END.

Referenced by S3D::ResetNodeIndex(), SCENEGRAPH::WriteCache(), and S3D::WriteVRML().

305 {
306  for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
307  node_counts[i] = 1;
308 
309  return;
310 }
static unsigned int node_counts[S3D::SGTYPE_END]
Definition: sg_node.cpp:48
void SGCOLORS::SetColorList ( size_t  aListSize,
const SGCOLOR aColorList 
)

Definition at line 172 of file sg_colors.cpp.

References colors.

173 {
174  colors.clear();
175 
176  if( 0 == aListSize || NULL == aColorList )
177  return;
178 
179  for( size_t i = 0; i < aListSize; ++i )
180  colors.push_back( aColorList[i] );
181 
182  return;
183 }
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38
void SGNODE::SetName ( const char *  aName)
inherited

Definition at line 159 of file sg_node.cpp.

References getNodeName(), SGNODE::m_Name, and SGNODE::m_SGtype.

Referenced by SGSHAPE::ReadCache(), SGFACESET::ReadCache(), SCENEGRAPH::ReadCache(), and IFSG_NODE::SetName().

160 {
161  if( NULL == aName || 0 == aName[0] )
163  else
164  m_Name = aName;
165 
166  return;
167 }
std::string m_Name
Definition: sg_node.h:85
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
static void getNodeName(S3D::SGTYPES nodeType, std::string &aName)
Definition: sg_node.cpp:57
bool SGCOLORS::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtual

Function SetParent sets the parent SGNODE of this object.

Parameters
aParent[in] is the desired parent node
Returns
true if the operation succeeds; false if the given node is not allowed to be a parent to the derived object.

Implements SGNODE.

Definition at line 63 of file sg_colors.cpp.

References SGNODE::AddChildNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, S3D::SGTYPE_FACESET, and SGNODE::unlinkChildNode().

Referenced by SGFACESET::addNode(), and SGFACESET::~SGFACESET().

64 {
65  if( NULL != m_Parent )
66  {
67  if( aParent == m_Parent )
68  return true;
69 
70  // handle the change in parents
71  if( notify )
72  m_Parent->unlinkChildNode( this );
73 
74  m_Parent = NULL;
75 
76  if( NULL == aParent )
77  return true;
78  }
79 
80  // only a SGFACESET may be parent to a SGCOLORS
81  if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
82  return false;
83 
84  m_Parent = aParent;
85 
86  if( m_Parent )
87  m_Parent->AddChildNode( this );
88 
89  return true;
90 }
SGNODE * m_Parent
Definition: sg_node.h:83
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
virtual bool AddChildNode(SGNODE *aNode)=0
bool SGNODE::SwapParent ( SGNODE aNewParent)
inherited

Function SwapParent swaps the ownership with the given parent.

This operation may be required when reordering nodes for optimization.

Parameters
aNewParent[in] will become the new parent to the object; it must be the same type as the parent of this instance.

Definition at line 120 of file sg_node.cpp.

References SGNODE::AddChildNode(), SGNODE::AddRefNode(), SGNODE::GetNodeType(), SGNODE::m_Parent, SGNODE::unlinkChildNode(), and SGNODE::unlinkRefNode().

Referenced by SGSHAPE::WriteCache(), and SGFACESET::WriteCache().

121 {
122  if( aNewParent == m_Parent )
123  return true;
124 
125  if( NULL == aNewParent )
126  return false;
127 
128  if( NULL == m_Parent )
129  {
130  if( aNewParent->AddChildNode( this ) )
131  return true;
132 
133  return false;
134  }
135 
136  if( aNewParent->GetNodeType() != m_Parent->GetNodeType() )
137  return false;
138 
139  SGNODE* oldParent = m_Parent;
140  m_Parent->unlinkChildNode( this );
141  m_Parent = NULL;
142  aNewParent->unlinkRefNode( this );
143  aNewParent->AddChildNode( this );
144  oldParent->AddRefNode( this );
145 
146  return true;
147 }
virtual bool AddRefNode(SGNODE *aNode)=0
SGNODE * m_Parent
Definition: sg_node.h:83
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
virtual void unlinkRefNode(const SGNODE *aNode)=0
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
virtual bool AddChildNode(SGNODE *aNode)=0
void SGCOLORS::unlinkChildNode ( const SGNODE aNode)
overridevirtual

Function unlinkChild removes references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references.

Parameters
aNodeis the child which is being deleted

Implements SGNODE.

Definition at line 105 of file sg_colors.cpp.

106 {
107  #ifdef DEBUG
108  std::ostringstream ostr;
109  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
110  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
111  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
112  #endif
113 
114  return;
115 }
void SGCOLORS::unlinkRefNode ( const SGNODE aNode)
overridevirtual

Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references.

Parameters
aNodeis the node which is being deleted

Implements SGNODE.

Definition at line 118 of file sg_colors.cpp.

119 {
120  #ifdef DEBUG
121  std::ostringstream ostr;
122  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
123  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
124  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
125  #endif
126 
127  return;
128 }
bool SGCOLORS::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtual

Function WriteCache write's this node's data to a binary cache file; the data includes all data of children and references to children.

If this function is invoked by the user, parentNode must be set to NULL in order to ensure coherent data.

Implements SGNODE.

Definition at line 268 of file sg_colors.cpp.

References colors, SGNODE::GetName(), SGNODE::GetParent(), SGNODE::m_Parent, SGNODE::m_written, SGNODE::WriteCache(), and S3D::WriteColor().

Referenced by SGFACESET::WriteCache().

269 {
270  if( NULL == parentNode )
271  {
272  if( NULL == m_Parent )
273  {
274  #ifdef DEBUG
275  std::ostringstream ostr;
276  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
277  ostr << " * [BUG] corrupt data; m_aParent is NULL";
278  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
279  #endif
280 
281  return false;
282  }
283 
284  SGNODE* np = m_Parent;
285 
286  while( NULL != np->GetParent() )
287  np = np->GetParent();
288 
289  if( np->WriteCache( aFile, NULL ) )
290  {
291  m_written = true;
292  return true;
293  }
294 
295  return false;
296  }
297 
298  if( parentNode != m_Parent )
299  {
300  #ifdef DEBUG
301  std::ostringstream ostr;
302  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
303  ostr << " * [BUG] corrupt data; parentNode != m_aParent";
304  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
305  #endif
306 
307  return false;
308  }
309 
310  if( !aFile.good() )
311  {
312  #ifdef DEBUG
313  std::ostringstream ostr;
314  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
315  ostr << " * [INFO] bad stream";
316  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
317  #endif
318 
319  return false;
320  }
321 
322  aFile << "[" << GetName() << "]";
323  size_t ncolors = colors.size();
324  aFile.write( (char*)&ncolors, sizeof(size_t) );
325 
326  for( size_t i = 0; i < ncolors; ++i )
327  S3D::WriteColor( aFile, colors[i] );
328 
329  if( aFile.fail() )
330  return false;
331 
332  m_written = true;
333  return true;
334 }
SGNODE * m_Parent
Definition: sg_node.h:83
bool WriteColor(std::ostream &aFile, const SGCOLOR &aColor)
Definition: sg_helpers.cpp:193
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
const char * GetName(void)
Definition: sg_node.cpp:150
bool m_written
Definition: sg_node.h:86
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
bool SGCOLORS::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtual

Function WriteVRML writes this node's data to a VRML file; this includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 210 of file sg_colors.cpp.

References colors, S3D::FormatColor(), SGNODE::GetName(), and SGNODE::m_written.

Referenced by SGFACESET::WriteVRML().

211 {
212  if( colors.empty() )
213  return false;
214 
215  if( aReuseFlag )
216  {
217  if( !m_written )
218  {
219  aFile << "color DEF " << GetName() << " Color { color [\n ";
220  m_written = true;
221  }
222  else
223  {
224  aFile << "color USE " << GetName() << "\n";
225  return true;
226  }
227  }
228  else
229  {
230  aFile << "color Color { color [\n ";
231  }
232 
233  std::string tmp;
234  size_t n = colors.size();
235  bool nline = false;
236 
237  for( size_t i = 0; i < n; )
238  {
239  S3D::FormatColor( tmp, colors[i] );
240  float r,g,b;
241  colors[i].GetColor(r, g, b);
242  aFile << tmp ;
243  ++i;
244 
245  if( i < n )
246  {
247  aFile << ",";
248 
249  if( nline )
250  {
251  aFile << "\n ";
252  nline = false;
253  }
254  else
255  {
256  nline = true;
257  }
258 
259  }
260  }
261 
262  aFile << "] }\n";
263 
264  return true;
265 }
void FormatColor(std::string &result, const SGCOLOR &aColor)
Definition: sg_helpers.cpp:146
const char * GetName(void)
Definition: sg_node.cpp:150
bool m_written
Definition: sg_node.h:86
std::vector< SGCOLOR > colors
Definition: sg_colors.h:38

Member Data Documentation

std::vector< SGCOLOR > SGCOLORS::colors
std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited

The documentation for this class was generated from the following files: