KiCad PCB EDA Suite
SGCOORDS Class Reference

Define a vertex coordinate set for a scenegraph object. More...

#include <sg_coords.h>

Inheritance diagram for SGCOORDS:
SGNODE

Public Member Functions

 SGCOORDS (SGNODE *aParent)
 
virtual ~SGCOORDS ()
 
void unlinkChildNode (const SGNODE *aNode) noexcept override
 Remove references to an owned child. More...
 
void unlinkRefNode (const SGNODE *aNode) noexcept override
 Remove pointers to a referenced node. More...
 
virtual bool SetParent (SGNODE *aParent, bool notify=true) override
 Set the parent SGNODE of this object. More...
 
SGNODEFindNode (const char *aNodeName, const SGNODE *aCaller) noexcept override
 Search the tree of linked nodes and return a reference to the first node found with the given name. More...
 
bool AddRefNode (SGNODE *aNode) noexcept override
 
bool AddChildNode (SGNODE *aNode) noexcept 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=nullptr)
 Calculate normals for this coordinate list and sets the normals list in the parent SGFACESET. More...
 
void ReNameNodes (void) override
 Rename a node and all its child nodes in preparation for write operations. More...
 
bool WriteVRML (std::ostream &aFile, bool aReuseFlag) override
 Writes this node's data to a VRML file. More...
 
bool WriteCache (std::ostream &aFile, SGNODE *parentNode) override
 Write this node's data to a binary cache file. More...
 
bool ReadCache (std::istream &aFile, SGNODE *parentNode) override
 Reads binary format data from a cache file. More...
 
S3D::SGTYPES GetNodeType (void) const noexcept
 Return the type of this node instance. More...
 
SGNODEGetParent (void) const noexcept
 Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
bool SwapParent (SGNODE *aNewParent)
 Swap the ownership with the given parent. More...
 
const char * GetName (void)
 
void SetName (const char *aName)
 
const char * GetNodeTypeName (S3D::SGTYPES aNodeType) const noexcept
 
void AssociateWrapper (SGNODE **aWrapperRef) noexcept
 Associate this object with a handle to itself. More...
 
void DisassociateWrapper (SGNODE **aWrapperRef) noexcept
 Remove the association between an IFSG* wrapper object and this object. More...
 
void ResetNodeIndex (void) noexcept
 Reset the global SG* node indices in preparation for write operations. More...
 
void addNodeRef (SGNODE *aNode)
 Add a pointer to a node which references this node, but does not own. More...
 
void delNodeRef (const SGNODE *aNode)
 Remove a pointer to a node which references this node, but does not own. More...
 
bool isWritten (void) noexcept
 Return true if the object had already been written to a cache file or VRML file. More...
 

Public Attributes

std::vector< SGPOINTcoords
 

Protected Attributes

std::list< SGNODE * > m_BackPointers
 nodes which hold a reference to this. More...
 
SGNODEm_Parent
 Pointer to parent node; may be NULL for top level transform. More...
 
S3D::SGTYPES m_SGtype
 Type of Scene Graph node. More...
 
std::string m_Name
 name to use for referencing the entity by name. More...
 
bool m_written
 Set to true when the object has been written after a ReNameNodes(). More...
 

Private Attributes

SGNODE ** m_Association
 Handle to the instance held by a wrapper. More...
 

Detailed Description

Define a vertex coordinate set for a scenegraph object.

Definition at line 40 of file sg_coords.h.

Constructor & Destructor Documentation

◆ SGCOORDS()

SGCOORDS::SGCOORDS ( SGNODE aParent)

Definition at line 35 of file sg_coords.cpp.

35 : SGNODE( aParent )
36{
38
39 if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
40 {
41 m_Parent = nullptr;
42
43 wxLogTrace( MASK_3D_SG,
44 wxT( "%s:%s:%d * [BUG] inappropriate parent to SGCOORDS (type %s)" ),
45 __FILE__, __FUNCTION__, __LINE__, aParent->GetNodeType() );
46 }
47 else if( nullptr != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() )
48 {
49 m_Parent->AddChildNode( this );
50 }
51}
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104
virtual bool AddChildNode(SGNODE *aNode)=0
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
@ SGTYPE_FACESET
Definition: sg_types.h:40
@ SGTYPE_COORDS
Definition: sg_types.h:41

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

◆ ~SGCOORDS()

SGCOORDS::~SGCOORDS ( )
virtual

Definition at line 54 of file sg_coords.cpp.

55{
56 coords.clear();
57}
std::vector< SGPOINT > coords
Definition: sg_coords.h:72

References coords.

Member Function Documentation

◆ AddChildNode()

bool SGCOORDS::AddChildNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 122 of file sg_coords.cpp.

123{
124 wxCHECK( aNode, false );
125
126 return false;
127}

◆ AddCoord() [1/2]

void SGCOORDS::AddCoord ( const SGPOINT aPoint)

Definition at line 163 of file sg_coords.cpp.

164{
165 coords.push_back( aPoint );
166}

References coords.

◆ AddCoord() [2/2]

void SGCOORDS::AddCoord ( double  aXValue,
double  aYValue,
double  aZValue 
)

Definition at line 157 of file sg_coords.cpp.

158{
159 coords.emplace_back( aXValue, aYValue, aZValue );
160}

References coords.

◆ addNodeRef()

void SGNODE::addNodeRef ( SGNODE aNode)
inherited

Add a pointer to a node which references this node, but does not own.

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 170 of file sg_node.cpp.

171{
172 if( nullptr == aNode )
173 return;
174
175 std::list< SGNODE* >::iterator np =
176 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
177
178 if( np != m_BackPointers.end() )
179 return;
180
181 m_BackPointers.push_back( aNode );
182}
std::list< SGNODE * > m_BackPointers
nodes which hold a reference to this.
Definition: sg_node.h:226

References SGNODE::m_BackPointers.

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

◆ AddRefNode()

bool SGCOORDS::AddRefNode ( SGNODE aNode)
overridevirtualnoexcept

Implements SGNODE.

Definition at line 114 of file sg_coords.cpp.

115{
116 wxCHECK( aNode, false );
117
118 return false;
119}

◆ AssociateWrapper()

void SGNODE::AssociateWrapper ( SGNODE **  aWrapperRef)
noexceptinherited

Associate this object with a handle to itself.

The 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 207 of file sg_node.cpp.

208{
209 wxCHECK( aWrapperRef && *aWrapperRef == this, /* void */ );
210
211 // if there is an existing association then break it and emit a warning
212 // just in case the behavior is undesired
213 if( m_Association )
214 {
215 *m_Association = nullptr;
216
217 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [WARNING] association being broken with "
218 "previous wrapper" ),
219 __FILE__, __FUNCTION__, __LINE__ );
220 }
221
222 m_Association = aWrapperRef;
223}
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition: sg_node.h:233

Referenced by S3D::AssociateSGNodeWrapper(), IFSG_APPEARANCE::Attach(), IFSG_COLORS::Attach(), IFSG_COORDINDEX::Attach(), IFSG_COORDS::Attach(), IFSG_FACESET::Attach(), IFSG_NORMALS::Attach(), IFSG_SHAPE::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_COLORS::NewNode(), IFSG_COORDINDEX::NewNode(), IFSG_COORDS::NewNode(), IFSG_FACESET::NewNode(), IFSG_NORMALS::NewNode(), IFSG_SHAPE::NewNode(), and IFSG_TRANSFORM::NewNode().

◆ CalcNormals()

bool SGCOORDS::CalcNormals ( SGFACESET callingNode,
SGNODE **  aPtr = nullptr 
)

Calculate normals for this coordinate list and sets the normals list in the parent SGFACESET.

Definition at line 309 of file sg_coords.cpp.

310{
311 if( aPtr )
312 *aPtr = nullptr;
313
314 if( nullptr == m_Parent || nullptr == callingNode )
315 return false;
316
317 // the parent and all references must have indices; collect all
318 // indices into one std::vector<>
319 std::vector< int > ilist;
320 SGNORMALS* np = nullptr;
321
322 if( callingNode == m_Parent )
323 {
324 ((SGFACESET*)m_Parent)->GatherCoordIndices( ilist );
325
326 std::list< SGNODE* >::iterator sB = m_BackPointers.begin();
327 std::list< SGNODE* >::iterator eB = m_BackPointers.end();
328
329 while( sB != eB )
330 {
331 SGFACESET* fp = (SGFACESET*)(*sB);
332 fp->GatherCoordIndices( ilist );
333 ++sB;
334 }
335
336 np = ( (SGFACESET*) m_Parent )->m_Normals;
337
338 if( !np )
339 np = new SGNORMALS( m_Parent );
340
341 }
342 else
343 {
344 callingNode->GatherCoordIndices( ilist );
345 np = callingNode->m_Normals;
346
347 if( !np )
348 np = new SGNORMALS( callingNode );
349
350 }
351
352 if( S3D::CalcTriangleNormals( coords, ilist, np->norms ) )
353 {
354 if( aPtr )
355 *aPtr = np;
356
357 return true;
358 }
359
360 delete np;
361
362 return false;
363}
Define an indexed face set for a scenegraph.
Definition: sg_faceset.h:47
void GatherCoordIndices(std::vector< int > &aIndexList)
Add all internal coordinate indices to the given list in preparation for a normals calculation.
Definition: sg_faceset.cpp:968
SGNORMALS * m_Normals
Definition: sg_faceset.h:82
Define a set of vertex normals for a scene graph object.
Definition: sg_normals.h:39
std::vector< SGVECTOR > norms
Definition: sg_normals.h:64
bool CalcTriangleNormals(std::vector< SGPOINT > coords, std::vector< int > &index, std::vector< SGVECTOR > &norms)
Definition: sg_helpers.cpp:353

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

Referenced by SGFACESET::CalcNormals().

◆ delNodeRef()

void SGNODE::delNodeRef ( const SGNODE aNode)
inherited

Remove a pointer to a node which references this node, but does not own.

Parameters
aNodeis the node holding a reference to this object.

Definition at line 185 of file sg_node.cpp.

186{
187 if( nullptr == aNode )
188 return;
189
190 std::list< SGNODE* >::iterator np =
191 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
192
193 if( np != m_BackPointers.end() )
194 {
195 m_BackPointers.erase( np );
196 return;
197 }
198
199 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] delNodeRef() did not find its target, this "
200 "node type %d, referenced node type %d" ),
201 __FILE__, __FUNCTION__, __LINE__,
202 m_SGtype,
203 aNode->GetNodeType() );
204}

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

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

◆ DisassociateWrapper()

void SGNODE::DisassociateWrapper ( SGNODE **  aWrapperRef)
noexceptinherited

Remove the association between an IFSG* wrapper object and this object.

Definition at line 225 of file sg_node.cpp.

226{
227 if( !m_Association )
228 return;
229
230 wxCHECK( aWrapperRef, /* void */ );
231
232 wxCHECK( *aWrapperRef == *m_Association && aWrapperRef == m_Association, /* void */ );
233
234 m_Association = nullptr;
235}

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

◆ FindNode()

SGNODE * SGCOORDS::FindNode ( const char *  aNodeName,
const SGNODE aCaller 
)
overridevirtualnoexcept

Search the tree of linked nodes and return 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 90 of file sg_coords.cpp.

91{
92 if( nullptr == aNodeName || 0 == aNodeName[0] )
93 return nullptr;
94
95 if( !m_Name.compare( aNodeName ) )
96 return this;
97
98 return nullptr;
99}
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229

Referenced by SGFACESET::FindNode().

◆ GetCoordsList()

bool SGCOORDS::GetCoordsList ( size_t &  aListSize,
SGPOINT *&  aCoordsList 
)

Definition at line 130 of file sg_coords.cpp.

131{
132 if( coords.empty() )
133 {
134 aListSize = 0;
135 aCoordsList = nullptr;
136 return false;
137 }
138
139 aListSize = coords.size();
140 aCoordsList = &coords[0];
141 return true;
142}

References coords.

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

◆ GetName()

◆ GetNodeType()

◆ GetNodeTypeName()

const char * SGNODE::GetNodeTypeName ( S3D::SGTYPES  aNodeType) const
noexceptinherited

Definition at line 164 of file sg_node.cpp.

165{
166 return node_names[aNodeType].c_str();
167}
static const std::string node_names[S3D::SGTYPE_END+1]
Definition: sg_node.cpp:36

References node_names.

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

◆ GetParent()

◆ isWritten()

bool SGNODE::isWritten ( void  )
inlinenoexceptinherited

Return true if the object had already been written to a cache file or VRML file.

For internal use only.

Definition at line 220 of file sg_node.h.

221 {
222 return m_written;
223 }
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230

References SGNODE::m_written.

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

◆ ReadCache()

bool SGCOORDS::ReadCache ( std::istream &  aFile,
SGNODE parentNode 
)
overridevirtual

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 286 of file sg_coords.cpp.

287{
288 wxCHECK( coords.empty(), false );
289
290 size_t npts;
291 aFile.read( (char*) &npts, sizeof( size_t ) );
292 SGPOINT tmp;
293
294 if( aFile.fail() )
295 return false;
296
297 for( size_t i = 0; i < npts; ++i )
298 {
299 if( !S3D::ReadPoint( aFile, tmp ) || aFile.fail() )
300 return false;
301
302 coords.push_back( tmp );
303 }
304
305 return true;
306}
bool ReadPoint(std::istream &aFile, SGPOINT &aPoint)
Definition: sg_helpers.cpp:267

References coords, and S3D::ReadPoint().

Referenced by SGFACESET::ReadCache().

◆ ReNameNodes()

void SGCOORDS::ReNameNodes ( void  )
overridevirtual

Rename a node and all its child nodes in preparation for write operations.

Implements SGNODE.

Definition at line 169 of file sg_coords.cpp.

170{
171 m_written = false;
172
173 // rename this node
174 m_Name.clear();
175 GetName();
176}
const char * GetName(void)
Definition: sg_node.cpp:146

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

Referenced by SGFACESET::ReNameNodes().

◆ ResetNodeIndex()

void SGNODE::ResetNodeIndex ( void  )
noexceptinherited

Reset the global SG* node indices in preparation for write operations.

Definition at line 238 of file sg_node.cpp.

239{
240 for( int i = 0; i < (int)S3D::SGTYPE_END; ++i )
241 node_counts[i] = 1;
242}
@ SGTYPE_END
Definition: sg_types.h:45
static unsigned int node_counts[S3D::SGTYPE_END]
Definition: sg_node.cpp:50

References node_counts, and S3D::SGTYPE_END.

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

◆ SetCoordsList()

void SGCOORDS::SetCoordsList ( size_t  aListSize,
const SGPOINT aCoordsList 
)

Definition at line 145 of file sg_coords.cpp.

146{
147 coords.clear();
148
149 if( 0 == aListSize || nullptr == aCoordsList )
150 return;
151
152 for( size_t i = 0; i < aListSize; ++i )
153 coords.push_back( aCoordsList[i] );
154}

References coords.

◆ SetName()

void SGNODE::SetName ( const char *  aName)
inherited

Definition at line 155 of file sg_node.cpp.

156{
157 if( nullptr == aName || 0 == aName[0] )
159 else
160 m_Name = aName;
161}

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

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

◆ SetParent()

bool SGCOORDS::SetParent ( SGNODE aParent,
bool  notify = true 
)
overridevirtual

Set 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 60 of file sg_coords.cpp.

61{
62 if( nullptr != m_Parent )
63 {
64 if( aParent == m_Parent )
65 return true;
66
67 // handle the change in parents
68 if( notify )
70
71 m_Parent = nullptr;
72
73 if( nullptr == aParent )
74 return true;
75 }
76
77 // only a SGFACESET may be parent to a SGCOORDS
78 if( nullptr != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() )
79 return false;
80
81 m_Parent = aParent;
82
83 if( m_Parent )
84 m_Parent->AddChildNode( this );
85
86 return true;
87}
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.

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

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

◆ SwapParent()

bool SGNODE::SwapParent ( SGNODE aNewParent)
inherited

Swap the ownership with the given parent.

This operation may be required when reordering nodes for optimization.

Parameters
aNewParentwill become the new parent to the object; it must be the same type as the parent of this instance.

Definition at line 116 of file sg_node.cpp.

117{
118 if( aNewParent == m_Parent )
119 return true;
120
121 if( nullptr == aNewParent )
122 return false;
123
124 if( nullptr == m_Parent )
125 {
126 if( aNewParent->AddChildNode( this ) )
127 return true;
128
129 return false;
130 }
131
132 if( aNewParent->GetNodeType() != m_Parent->GetNodeType() )
133 return false;
134
135 SGNODE* oldParent = m_Parent;
136 m_Parent->unlinkChildNode( this );
137 m_Parent = nullptr;
138 aNewParent->unlinkRefNode( this );
139 aNewParent->AddChildNode( this );
140 oldParent->AddRefNode( this );
141
142 return true;
143}
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
virtual bool AddRefNode(SGNODE *aNode)=0
virtual void unlinkRefNode(const SGNODE *aNode)=0
Remove pointers to a referenced node.

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

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

◆ unlinkChildNode()

void SGCOORDS::unlinkChildNode ( const SGNODE aNode)
overridevirtualnoexcept

Remove references to an owned child.

This 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 102 of file sg_coords.cpp.

103{
104 wxCHECK( aCaller, /* void */ );
105}

◆ unlinkRefNode()

void SGCOORDS::unlinkRefNode ( const SGNODE aNode)
overridevirtualnoexcept

Remove pointers to a referenced node.

This 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 108 of file sg_coords.cpp.

109{
110 wxCHECK( aCaller, /* void */ );
111}

◆ WriteCache()

bool SGCOORDS::WriteCache ( std::ostream &  aFile,
SGNODE parentNode 
)
overridevirtual

Write 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 241 of file sg_coords.cpp.

242{
243 if( nullptr == parentNode )
244 {
245 wxCHECK( m_Parent, false );
246
247 SGNODE* np = m_Parent;
248
249 while( nullptr != np->GetParent() )
250 np = np->GetParent();
251
252 if( np->WriteCache( aFile, nullptr ) )
253 {
254 m_written = true;
255 return true;
256 }
257
258 return false;
259 }
260
261 wxCHECK( parentNode == m_Parent, false );
262
263 if( !aFile.good() )
264 {
265 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [INFO] bad stream" ),
266 __FILE__, __FUNCTION__, __LINE__ );
267
268 return false;
269 }
270
271 aFile << "[" << GetName() << "]";
272 size_t npts = coords.size();
273 aFile.write( (char*)&npts, sizeof(size_t) );
274
275 for( size_t i = 0; i < npts; ++i )
276 S3D::WritePoint( aFile, coords[i] );
277
278 if( aFile.fail() )
279 return false;
280
281 m_written = true;
282 return true;
283}
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition: sg_node.cpp:110
bool WritePoint(std::ostream &aFile, const SGPOINT &aPoint)
Definition: sg_helpers.cpp:152

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

Referenced by SGFACESET::WriteCache().

◆ WriteVRML()

bool SGCOORDS::WriteVRML ( std::ostream &  aFile,
bool  aReuseFlag 
)
overridevirtual

Writes this node's data to a VRML file.

This includes all data of child and referenced nodes.

Implements SGNODE.

Definition at line 179 of file sg_coords.cpp.

180{
181 if( coords.empty() )
182 return false;
183
184 if( aReuseFlag )
185 {
186 if( !m_written )
187 {
188 aFile << " coord DEF " << GetName() << " Coordinate { point [\n ";
189 m_written = true;
190 }
191 else
192 {
193 aFile << " coord USE " << GetName() << "\n";
194 return true;
195 }
196 }
197 else
198 {
199 aFile << " coord Coordinate { point [\n ";
200 }
201
202 std::string tmp;
203 size_t n = coords.size();
204 bool nline = false;
205 SGPOINT pt;
206
207 for( size_t i = 0; i < n; )
208 {
209 // ensure VRML output has 1U = 0.1 inch as per legacy kicad expectations
210 pt = coords[i];
211 pt.x /= 2.54;
212 pt.y /= 2.54;
213 pt.z /= 2.54;
214 S3D::FormatPoint( tmp, pt );
215 aFile << tmp ;
216 ++i;
217
218 if( i < n )
219 {
220 aFile << ",";
221
222 if( nline )
223 {
224 aFile << "\n ";
225 nline = false;
226 }
227 else
228 {
229 nline = true;
230 }
231
232 }
233 }
234
235 aFile << "] }\n";
236
237 return true;
238}
double z
Definition: sg_base.h:72
double x
Definition: sg_base.h:70
double y
Definition: sg_base.h:71
void FormatPoint(std::string &result, const SGPOINT &point)
Definition: sg_helpers.cpp:103

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

Referenced by SGFACESET::WriteVRML().

Member Data Documentation

◆ coords

std::vector< SGPOINT > SGCOORDS::coords

◆ m_Association

SGNODE** SGNODE::m_Association
privateinherited

Handle to the instance held by a wrapper.

Definition at line 233 of file sg_node.h.

Referenced by SGNODE::SGNODE(), and SGNODE::~SGNODE().

◆ m_BackPointers

std::list< SGNODE* > SGNODE::m_BackPointers
protectedinherited

nodes which hold a reference to this.

Definition at line 226 of file sg_node.h.

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

◆ m_Name

◆ m_Parent

◆ m_SGtype

◆ m_written


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