KiCad PCB EDA Suite
SGCOORDS Class Reference

#include <sg_coords.h>

Inheritance diagram for SGCOORDS:
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...
 
 SGCOORDS (SGNODE *aParent)
 
virtual ~SGCOORDS ()
 
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 GetCoordsList (size_t &aListSize, SGPOINT *&aCoordsList)
 
void SetCoordsList (size_t aListSize, const SGPOINT *aCoordsList)
 
void AddCoord (double aXValue, double aYValue, double aZValue)
 
void AddCoord (const SGPOINT &aPoint)
 
bool CalcNormals (SGFACESET *callingNode, SGNODE **aPtr=NULL)
 Function CalcNormals calculates normals for this coordinate list and sets the normals list in the parent SGFACESET. More...
 
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< SGPOINTcoords
 

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 37 of file sg_coords.h.

Constructor & Destructor Documentation

SGCOORDS::SGCOORDS ( SGNODE aParent)

Definition at line 34 of file sg_coords.cpp.

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

34  : SGNODE( aParent )
35 {
37 
38  if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
39  {
40  m_Parent = NULL;
41 
42 #ifdef DEBUG
43  std::ostringstream ostr;
44  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
45  ostr << " * [BUG] inappropriate parent to SGCOORDS (type ";
46  ostr << aParent->GetNodeType() << ")";
47  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
48 #endif
49  }
50  else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
51  {
52  m_Parent->AddChildNode( this );
53  }
54 
55  return;
56 }
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
SGCOORDS::~SGCOORDS ( )
virtual

Definition at line 59 of file sg_coords.cpp.

References coords.

60 {
61  coords.clear();
62  return;
63 }
std::vector< SGPOINT > coords
Definition: sg_coords.h:40

Member Function Documentation

bool SGCOORDS::AddChildNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 147 of file sg_coords.cpp.

148 {
149  #ifdef DEBUG
150  std::ostringstream ostr;
151  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
152  ostr << " * [BUG] this node does not accept children or refs";
153  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
154  #endif
155 
156  return false;
157 }
void SGCOORDS::AddCoord ( double  aXValue,
double  aYValue,
double  aZValue 
)

Definition at line 189 of file sg_coords.cpp.

References coords.

190 {
191  coords.push_back( SGPOINT( aXValue, aYValue, aZValue ) );
192  return;
193 }
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
void SGCOORDS::AddCoord ( const SGPOINT aPoint)

Definition at line 196 of file sg_coords.cpp.

References coords.

197 {
198  coords.push_back( aPoint );
199  return;
200 }
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
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 SGCOORDS::AddRefNode ( SGNODE aNode)
overridevirtual

Implements SGNODE.

Definition at line 134 of file sg_coords.cpp.

135 {
136  #ifdef DEBUG
137  std::ostringstream ostr;
138  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
139  ostr << " * [BUG] this node does not accept children or refs";
140  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
141  #endif
142 
143  return false;
144 }
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_NORMALS::Attach(), IFSG_SHAPE::Attach(), IFSG_COORDINDEX::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_NORMALS::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDINDEX::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
bool SGCOORDS::CalcNormals ( SGFACESET callingNode,
SGNODE **  aPtr = NULL 
)

Function CalcNormals calculates normals for this coordinate list and sets the normals list in the parent SGFACESET.

Definition at line 377 of file sg_coords.cpp.

References S3D::CalcTriangleNormals(), coords, SGFACESET::GatherCoordIndices(), SGNODE::m_BackPointers, SGFACESET::m_Normals, SGNODE::m_Parent, and SGNORMALS::norms.

Referenced by SGFACESET::CalcNormals().

378 {
379  if( aPtr )
380  *aPtr = NULL;
381 
382  if( NULL == m_Parent || NULL == callingNode )
383  return false;
384 
385  // the parent and all references must have indices; collect all
386  // indices into one std::vector<>
387  std::vector< int > ilist;
388  SGNORMALS* np = NULL;
389 
390  if( callingNode == m_Parent )
391  {
392  ((SGFACESET*)m_Parent)->GatherCoordIndices( ilist );
393 
394  std::list< SGNODE* >::iterator sB = m_BackPointers.begin();
395  std::list< SGNODE* >::iterator eB = m_BackPointers.end();
396 
397  while( sB != eB )
398  {
399  SGFACESET* fp = (SGFACESET*)(*sB);
400  fp->GatherCoordIndices( ilist );
401  ++sB;
402  }
403 
404  np = ((SGFACESET*)m_Parent)->m_Normals;
405 
406  if( !np )
407  np = new SGNORMALS( m_Parent );
408 
409  }
410  else
411  {
412  callingNode->GatherCoordIndices( ilist );
413  np = callingNode->m_Normals;
414 
415  if( !np )
416  np = new SGNORMALS( callingNode );
417 
418  }
419 
420  if( S3D::CalcTriangleNormals( coords, ilist, np->norms ) )
421  {
422  if( aPtr )
423  *aPtr = np;
424 
425  return true;
426  }
427 
428  delete np;
429 
430  return false;
431 }
SGNODE * m_Parent
Definition: sg_node.h:83
bool CalcTriangleNormals(std::vector< SGPOINT > coords, std::vector< int > &index, std::vector< SGVECTOR > &norms)
Definition: sg_helpers.cpp:384
std::vector< SGVECTOR > norms
Definition: sg_normals.h:38
void GatherCoordIndices(std::vector< int > &aIndexList)
Function GatherCoordIndices adds all internal coordinate indices to the given list in preparation for...
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
SGNORMALS * m_Normals
Definition: sg_faceset.h:56
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_COORDS::Attach(), IFSG_NORMALS::Attach(), IFSG_FACESET::Attach(), IFSG_SHAPE::Attach(), IFSG_COLORS::Attach(), IFSG_TRANSFORM::Attach(), IFSG_NODE::Destroy(), IFSG_APPEARANCE::NewNode(), IFSG_SHAPE::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_NORMALS::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 * SGCOORDS::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 96 of file sg_coords.cpp.

References SGNODE::m_Name.

Referenced by SGFACESET::FindNode().

97 {
98  if( NULL == aNodeName || 0 == aNodeName[0] )
99  return NULL;
100 
101  if( !m_Name.compare( aNodeName ) )
102  return this;
103 
104  return NULL;
105 }
std::string m_Name
Definition: sg_node.h:85
bool SGCOORDS::GetCoordsList ( size_t &  aListSize,
SGPOINT *&  aCoordsList 
)

Definition at line 160 of file sg_coords.cpp.

References coords.

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

161 {
162  if( coords.empty() )
163  {
164  aListSize = 0;
165  aCoordsList = NULL;
166  return false;
167  }
168 
169  aListSize = coords.size();
170  aCoordsList = &coords[0];
171  return true;
172 }
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
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_NORMALS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_SHAPE::NewNode(), IFSG_FACESET::NewNode(), IFSG_COORDS::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 SGCOORDS::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 344 of file sg_coords.cpp.

References coords, and S3D::ReadPoint().

Referenced by SGFACESET::ReadCache().

345 {
346  if( !coords.empty() )
347  {
348  #ifdef DEBUG
349  std::ostringstream ostr;
350  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
351  ostr << " * [BUG] non-empty node";
352  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
353  #endif
354 
355  return false;
356  }
357 
358  size_t npts;
359  aFile.read( (char*)&npts, sizeof(size_t) );
360  SGPOINT tmp;
361 
362  if( aFile.fail() )
363  return false;
364 
365  for( size_t i = 0; i < npts; ++i )
366  {
367  if( !S3D::ReadPoint( aFile, tmp ) || aFile.fail() )
368  return false;
369 
370  coords.push_back( tmp );
371  }
372 
373  return true;
374 }
bool ReadPoint(std::istream &aFile, SGPOINT &aPoint)
Definition: sg_helpers.cpp:296
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
void SGCOORDS::ReNameNodes ( void  )
overridevirtual

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

Implements SGNODE.

Definition at line 203 of file sg_coords.cpp.

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

Referenced by SGFACESET::ReNameNodes().

204 {
205  m_written = false;
206 
207  // rename this node
208  m_Name.clear();
209  GetName();
210 }
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 SGCOORDS::SetCoordsList ( size_t  aListSize,
const SGPOINT aCoordsList 
)

Definition at line 175 of file sg_coords.cpp.

References coords.

176 {
177  coords.clear();
178 
179  if( 0 == aListSize || NULL == aCoordsList )
180  return;
181 
182  for( size_t i = 0; i < aListSize; ++i )
183  coords.push_back( aCoordsList[i] );
184 
185  return;
186 }
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
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 SGCOORDS::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 66 of file sg_coords.cpp.

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

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

67 {
68  if( NULL != m_Parent )
69  {
70  if( aParent == m_Parent )
71  return true;
72 
73  // handle the change in parents
74  if( notify )
75  m_Parent->unlinkChildNode( this );
76 
77  m_Parent = NULL;
78 
79  if( NULL == aParent )
80  return true;
81  }
82 
83  // only a SGFACESET may be parent to a SGCOORDS
84  if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
85  return false;
86 
87  m_Parent = aParent;
88 
89  if( m_Parent )
90  m_Parent->AddChildNode( this );
91 
92  return true;
93 }
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 SGCOORDS::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 108 of file sg_coords.cpp.

109 {
110  #ifdef DEBUG
111  std::ostringstream ostr;
112  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
113  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
114  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
115  #endif
116 
117  return;
118 }
void SGCOORDS::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 121 of file sg_coords.cpp.

122 {
123  #ifdef DEBUG
124  std::ostringstream ostr;
125  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
126  ostr << " * [BUG] unexpected code branch; node should have no children or refs";
127  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
128  #endif
129 
130  return;
131 }
bool SGCOORDS::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 275 of file sg_coords.cpp.

References coords, SGNODE::GetName(), SGNODE::GetParent(), SGNODE::m_Parent, SGNODE::m_written, SGNODE::WriteCache(), and S3D::WritePoint().

Referenced by SGFACESET::WriteCache().

276 {
277  if( NULL == parentNode )
278  {
279  if( NULL == m_Parent )
280  {
281  #ifdef DEBUG
282  std::ostringstream ostr;
283  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
284  ostr << " * [BUG] corrupt data; m_aParent is NULL";
285  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
286  #endif
287 
288  return false;
289  }
290 
291  SGNODE* np = m_Parent;
292 
293  while( NULL != np->GetParent() )
294  np = np->GetParent();
295 
296  if( np->WriteCache( aFile, NULL ) )
297  {
298  m_written = true;
299  return true;
300  }
301 
302  return false;
303  }
304 
305  if( parentNode != m_Parent )
306  {
307  #ifdef DEBUG
308  std::ostringstream ostr;
309  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
310  ostr << " * [BUG] corrupt data; parentNode != m_aParent";
311  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
312  #endif
313 
314  return false;
315  }
316 
317  if( !aFile.good() )
318  {
319  #ifdef DEBUG
320  std::ostringstream ostr;
321  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
322  ostr << " * [INFO] bad stream";
323  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
324  #endif
325 
326  return false;
327  }
328 
329  aFile << "[" << GetName() << "]";
330  size_t npts = coords.size();
331  aFile.write( (char*)&npts, sizeof(size_t) );
332 
333  for( size_t i = 0; i < npts; ++i )
334  S3D::WritePoint( aFile, coords[i] );
335 
336  if( aFile.fail() )
337  return false;
338 
339  m_written = true;
340  return true;
341 }
SGNODE * m_Parent
Definition: sg_node.h:83
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
bool WritePoint(std::ostream &aFile, const SGPOINT &aPoint)
Definition: sg_helpers.cpp:165
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...
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
bool SGCOORDS::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 213 of file sg_coords.cpp.

References coords, S3D::FormatPoint(), SGNODE::GetName(), SGNODE::m_written, SGPOINT::x, SGPOINT::y, and SGPOINT::z.

Referenced by SGFACESET::WriteVRML().

214 {
215  if( coords.empty() )
216  return false;
217 
218  if( aReuseFlag )
219  {
220  if( !m_written )
221  {
222  aFile << " coord DEF " << GetName() << " Coordinate { point [\n ";
223  m_written = true;
224  }
225  else
226  {
227  aFile << " coord USE " << GetName() << "\n";
228  return true;
229  }
230  }
231  else
232  {
233  aFile << " coord Coordinate { point [\n ";
234  }
235 
236  std::string tmp;
237  size_t n = coords.size();
238  bool nline = false;
239  SGPOINT pt;
240 
241  for( size_t i = 0; i < n; )
242  {
243  // ensure VRML output has 1U = 0.1 inch as per legacy kicad expectations
244  pt = coords[i];
245  pt.x /= 2.54;
246  pt.y /= 2.54;
247  pt.z /= 2.54;
248  S3D::FormatPoint( tmp, pt );
249  aFile << tmp ;
250  ++i;
251 
252  if( i < n )
253  {
254  aFile << ",";
255 
256  if( nline )
257  {
258  aFile << "\n ";
259  nline = false;
260  }
261  else
262  {
263  nline = true;
264  }
265 
266  }
267  }
268 
269  aFile << "] }\n";
270 
271  return true;
272 }
double x
Definition: sg_base.h:70
void FormatPoint(std::string &result, const SGPOINT &point)
Definition: sg_helpers.cpp:108
double y
Definition: sg_base.h:71
const char * GetName(void)
Definition: sg_node.cpp:150
bool m_written
Definition: sg_node.h:86
std::vector< SGPOINT > coords
Definition: sg_coords.h:40
double z
Definition: sg_base.h:72

Member Data Documentation

std::vector< SGPOINT > SGCOORDS::coords
std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited

Definition at line 82 of file sg_node.h.

Referenced by SGNODE::addNodeRef(), CalcNormals(), SGNODE::delNodeRef(), and SGNODE::~SGNODE().


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