KiCad PCB EDA Suite
WRL2FACESET Class Reference

#include <vrml2_faceset.h>

Inheritance diagram for WRL2FACESET:
WRL2NODE

Public Member Functions

 WRL2FACESET ()
 
 WRL2FACESET (WRL2NODE *aParent)
 
virtual ~WRL2FACESET ()
 
bool Read (WRLPROC &proc, WRL2BASE *aTopNode) override
 
bool AddRefNode (WRL2NODE *aNode) override
 
bool AddChildNode (WRL2NODE *aNode) override
 
SGNODETranslateToSG (SGNODE *aParent) override
 Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library. More...
 
bool HasColors (void)
 
bool isDangling (void) override
 Determine whether an object should be moved to a different parent during the VRML to SG* translation. More...
 
void unlinkChildNode (const WRL2NODE *aNode) override
 Remove references to an owned child. More...
 
void unlinkRefNode (const WRL2NODE *aNode) override
 Remove pointers to a referenced node. More...
 
WRL2NODES GetNodeType (void) const
 
WRL2NODEGetParent (void) const
 
virtual bool SetParent (WRL2NODE *aParent, bool doUnlink=true)
 Set the parent WRL2NODE of this object. More...
 
virtual std::string GetName (void)
 
virtual bool SetName (const std::string &aName)
 
const char * GetNodeTypeName (WRL2NODES aNodeType) const
 
virtual WRL2NODEFindNode (const std::string &aNodeName, const WRL2NODE *aCaller)
 Search the tree of linked nodes and returns a reference to the first node found with the given name. More...
 
std::string GetError (void)
 
WRL2NODES getNodeTypeID (const std::string &aNodeName)
 
void addNodeRef (WRL2NODE *aNode)
 Add a pointer to a node which references but does not own this node. More...
 
void delNodeRef (WRL2NODE *aNode)
 Remove a pointer to a node which references but does not own this node. More...
 

Protected Attributes

WRL2NODEm_Parent
 
WRL2NODES m_Type
 
std::string m_Name
 
std::list< WRL2NODE * > m_BackPointers
 
std::list< WRL2NODE * > m_Children
 
std::list< WRL2NODE * > m_Refs
 
std::string m_error
 
SGNODEm_sgNode
 

Private Member Functions

bool checkNodeType (WRL2NODES aType)
 
void setDefaults (void)
 

Private Attributes

WRL2NODEcolor
 
WRL2NODEcoord
 
WRL2NODEnormal
 
WRL2NODEtexCoord
 
bool ccw
 
bool colorPerVertex
 
bool convex
 
bool normalPerVertex
 
bool solid
 
std::vector< int > colorIndex
 
std::vector< int > coordIndex
 
std::vector< int > normalIndex
 
float creaseAngle
 
float creaseLimit
 

Detailed Description

Definition at line 40 of file vrml2_faceset.h.

Constructor & Destructor Documentation

◆ WRL2FACESET() [1/2]

WRL2FACESET::WRL2FACESET ( )

Definition at line 38 of file vrml2_faceset.cpp.

38 : WRL2NODE()
39{
42}
void setDefaults(void)
WRL2NODES m_Type
Definition: vrml2_node.h:170
@ WRL2_INDEXEDFACESET

References WRL2NODE::m_Type, setDefaults(), and WRL2_INDEXEDFACESET.

◆ WRL2FACESET() [2/2]

WRL2FACESET::WRL2FACESET ( WRL2NODE aParent)

Definition at line 45 of file vrml2_faceset.cpp.

45 : WRL2NODE()
46{
49 m_Parent = aParent;
50
51 if( nullptr != m_Parent )
52 m_Parent->AddChildNode( this );
53}
WRL2NODE * m_Parent
Definition: vrml2_node.h:169
virtual bool AddChildNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:356

References WRL2NODE::AddChildNode(), WRL2NODE::m_Parent, WRL2NODE::m_Type, setDefaults(), and WRL2_INDEXEDFACESET.

◆ ~WRL2FACESET()

WRL2FACESET::~WRL2FACESET ( )
virtual

Definition at line 56 of file vrml2_faceset.cpp.

57{
58 wxLogTrace( traceVrmlPlugin,
59 wxT( " * [INFO] Destroying IndexedFaceSet node with %zu children, %zu"
60 "references, and %zu back pointers." ),
61 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
62}
std::list< WRL2NODE * > m_BackPointers
Definition: vrml2_node.h:173
std::list< WRL2NODE * > m_Children
Definition: vrml2_node.h:174
std::list< WRL2NODE * > m_Refs
Definition: vrml2_node.h:175
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References WRL2NODE::m_BackPointers, WRL2NODE::m_Children, WRL2NODE::m_Refs, and traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool WRL2FACESET::AddChildNode ( WRL2NODE aNode)
overridevirtual

Reimplemented from WRL2NODE.

Definition at line 201 of file vrml2_faceset.cpp.

202{
203 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
204
205 WRL2NODES type = aNode->GetNodeType();
206
207 if( !checkNodeType( type ) )
208 {
209 wxLogTrace( traceVrmlPlugin,
210 wxT( "%s:%s:%d\n"
211 " * [INFO] bad file format; unexpected child node '%s'." ),
212 __FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
213
214 return false;
215 }
216
217 if( WRL2NODES::WRL2_COLOR == type )
218 {
219 if( nullptr != color )
220 {
221 wxLogTrace( traceVrmlPlugin,
222 wxT( "%s:%s:%d\n"
223 " * [INFO] bad file format; multiple color nodes." ),
224 __FILE__, __FUNCTION__, __LINE__ );
225
226 return false;
227 }
228
229 color = aNode;
230 return WRL2NODE::AddChildNode( aNode );
231 }
232
233 if( WRL2NODES::WRL2_COORDINATE == type )
234 {
235 if( nullptr != coord )
236 {
237 wxLogTrace( traceVrmlPlugin,
238 wxT( "%s:%s:%d\n"
239 " * [INFO] bad file format; multiple coord nodes." ),
240 __FILE__, __FUNCTION__, __LINE__ );
241
242 return false;
243 }
244
245 coord = aNode;
246 return WRL2NODE::AddChildNode( aNode );
247 }
248
249 if( WRL2NODES::WRL2_NORMAL == type )
250 {
251 if( nullptr != normal )
252 {
253 wxLogTrace( traceVrmlPlugin,
254 wxT( "%s:%s:%d\n"
255 " * [INFO] bad file format; multiple normal nodes." ),
256 __FILE__, __FUNCTION__, __LINE__ );
257
258 return false;
259 }
260
261 normal = aNode;
262 return WRL2NODE::AddChildNode( aNode );
263 }
264
265 wxCHECK_MSG( WRL2NODES::WRL2_TEXTURECOORDINATE == type, false,
266 wxT( "Unexpected code branch." ) );
267
268 if( nullptr != texCoord )
269 {
270 wxLogTrace( traceVrmlPlugin,
271 wxT( "%s:%s:%d\n"
272 " * [INFO] bad file format; multiple texCoord nodes." ),
273 __FILE__, __FUNCTION__, __LINE__ );
274
275 return false;
276 }
277
278 texCoord = aNode;
279 return WRL2NODE::AddChildNode( aNode );
280}
WRL2NODE * normal
Definition: vrml2_faceset.h:72
WRL2NODE * coord
Definition: vrml2_faceset.h:71
bool checkNodeType(WRL2NODES aType)
WRL2NODE * color
Definition: vrml2_faceset.h:70
WRL2NODE * texCoord
Definition: vrml2_faceset.h:73
const char * GetNodeTypeName(WRL2NODES aNodeType) const
Definition: vrml2_node.cpp:273
WRL2NODES GetNodeType(void) const
Definition: vrml2_node.cpp:204
WRL2NODES
Definition: wrltypes.h:125
@ WRL2_TEXTURECOORDINATE

References WRL2NODE::AddChildNode(), checkNodeType(), color, coord, WRL2NODE::GetNodeType(), WRL2NODE::GetNodeTypeName(), normal, texCoord, traceVrmlPlugin, WRL2_COLOR, WRL2_COORDINATE, WRL2_NORMAL, and WRL2_TEXTURECOORDINATE.

◆ addNodeRef()

void WRL2NODE::addNodeRef ( WRL2NODE aNode)
inherited

Add 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 171 of file vrml2_node.cpp.

172{
173 // the parent node must never be added as a backpointer
174 if( aNode == m_Parent )
175 return;
176
177 std::list< WRL2NODE* >::iterator np =
178 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
179
180 if( np != m_BackPointers.end() )
181 return;
182
183 m_BackPointers.push_back( aNode );
184}

References WRL2NODE::m_BackPointers, and WRL2NODE::m_Parent.

Referenced by WRL2NODE::AddRefNode().

◆ AddRefNode()

bool WRL2FACESET::AddRefNode ( WRL2NODE aNode)
overridevirtual

Reimplemented from WRL2NODE.

Definition at line 119 of file vrml2_faceset.cpp.

120{
121 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
122
123 WRL2NODES type = aNode->GetNodeType();
124
125 if( !checkNodeType( type ) )
126 {
127 wxLogTrace( traceVrmlPlugin,
128 wxT( "%s:%s:%d\n"
129 " * [INFO] bad file format; unexpected child node '%s'." ),
130 __FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
131
132 return false;
133 }
134
135 if( WRL2NODES::WRL2_COLOR == type )
136 {
137 if( nullptr != color )
138 {
139 wxLogTrace( traceVrmlPlugin,
140 wxT( "%s:%s:%d\n"
141 " * [INFO] bad file format; multiple color nodes." ),
142 __FILE__, __FUNCTION__, __LINE__ );
143
144 return false;
145 }
146
147 color = aNode;
148 return WRL2NODE::AddRefNode( aNode );
149 }
150
151 if( WRL2NODES::WRL2_COORDINATE == type )
152 {
153 if( nullptr != coord )
154 {
155 wxLogTrace( traceVrmlPlugin,
156 wxT( "%s:%s:%d\n"
157 " * [INFO] bad file format; multiple coord nodes." ),
158 __FILE__, __FUNCTION__, __LINE__ );
159
160 return false;
161 }
162
163 coord = aNode;
164 return WRL2NODE::AddRefNode( aNode );
165 }
166
167 if( WRL2NODES::WRL2_NORMAL == type )
168 {
169 if( nullptr != normal )
170 {
171 wxLogTrace( traceVrmlPlugin,
172 wxT( "%s:%s:%d\n"
173 " * [INFO] bad file format; multiple normal nodes." ),
174 __FILE__, __FUNCTION__, __LINE__ );
175
176 return false;
177 }
178
179 normal = aNode;
180 return WRL2NODE::AddRefNode( aNode );
181 }
182
183 wxCHECK_MSG( WRL2NODES::WRL2_TEXTURECOORDINATE == type, false,
184 wxT( "Unexpected code branch." ) );
185
186 if( nullptr != texCoord )
187 {
188 wxLogTrace( traceVrmlPlugin,
189 wxT( "%s:%s:%d\n"
190 " * [INFO] bad file format; multiple texCoord nodes." ),
191 __FILE__, __FUNCTION__, __LINE__ );
192
193 return false;
194 }
195
196 texCoord = aNode;
197 return WRL2NODE::AddRefNode( aNode );
198}
virtual bool AddRefNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:383

References WRL2NODE::AddRefNode(), checkNodeType(), color, coord, WRL2NODE::GetNodeType(), WRL2NODE::GetNodeTypeName(), normal, texCoord, traceVrmlPlugin, WRL2_COLOR, WRL2_COORDINATE, WRL2_NORMAL, and WRL2_TEXTURECOORDINATE.

◆ checkNodeType()

bool WRL2FACESET::checkNodeType ( WRL2NODES  aType)
private
Returns
true if the node type is a valid subnode of FaceSet.

Definition at line 83 of file vrml2_faceset.cpp.

84{
85 // nodes must be one of:
86 // Color
87 // Coordinate
88 // Normal
89 // TextureCoordinate
90
91 switch( aType )
92 {
97 break;
98
99 default:
100 return false;
101 break;
102 }
103
104 return true;
105}

References WRL2_COLOR, WRL2_COORDINATE, WRL2_NORMAL, and WRL2_TEXTURECOORDINATE.

Referenced by AddChildNode(), and AddRefNode().

◆ delNodeRef()

void WRL2NODE::delNodeRef ( WRL2NODE aNode)
inherited

Remove 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 187 of file vrml2_node.cpp.

188{
189 std::list< WRL2NODE* >::iterator np =
190 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
191
192 if( np != m_BackPointers.end() )
193 {
194 m_BackPointers.erase( np );
195 return;
196 }
197
198 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
199 " * [BUG] delNodeRef() did not find its target." ),
200 __FILE__, __FUNCTION__, __LINE__ );
201}

References WRL2NODE::m_BackPointers, and traceVrmlPlugin.

◆ FindNode()

WRL2NODE * WRL2NODE::FindNode ( const std::string &  aNodeName,
const WRL2NODE aCaller 
)
virtualinherited

Search 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 or NULL.

Definition at line 305 of file vrml2_node.cpp.

306{
307 if( aNodeName.empty() )
308 return nullptr;
309
310 if( !m_Name.compare( aNodeName ) )
311 return this;
312
313 std::list< WRL2NODE* >::iterator sLA = m_Children.begin();
314 std::list< WRL2NODE* >::iterator eLA = m_Children.end();
315
316 WRL2NODE* psg = nullptr;
317
318 while( sLA != eLA )
319 {
320 if( *sLA != aCaller )
321 {
322 psg = (*sLA)->FindNode( aNodeName, this );
323
324 if( nullptr != psg )
325 return psg;
326
327 }
328
329 ++sLA;
330 }
331
332 if( nullptr != m_Parent && aCaller != m_Parent )
333 return m_Parent->FindNode( aNodeName, this );
334
335 return nullptr;
336}
std::string m_Name
Definition: vrml2_node.h:171
virtual WRL2NODE * FindNode(const std::string &aNodeName, const WRL2NODE *aCaller)
Search the tree of linked nodes and returns a reference to the first node found with the given name.
Definition: vrml2_node.cpp:305

References WRL2NODE::FindNode(), WRL2NODE::m_Children, WRL2NODE::m_Name, and WRL2NODE::m_Parent.

Referenced by WRL2NODE::FindNode(), and WRL2BASE::implementUse().

◆ GetError()

std::string WRL2NODE::GetError ( void  )
inherited

Definition at line 299 of file vrml2_node.cpp.

300{
301 return m_error;
302}
std::string m_error
Definition: vrml2_node.h:176

References WRL2NODE::m_error.

◆ GetName()

std::string WRL2NODE::GetName ( void  )
virtualinherited

Reimplemented in WRL2BASE.

Definition at line 216 of file vrml2_node.cpp.

217{
218 return m_Name;
219}

References WRL2NODE::m_Name.

◆ GetNodeType()

◆ getNodeTypeID()

WRL2NODES WRL2NODE::getNodeTypeID ( const std::string &  aNodeName)
inherited
Returns
The ID based on the given aNodeName or WRL2_INVALID (WRL2_END) if no such node name exists.

Definition at line 288 of file vrml2_node.cpp.

289{
290 NODEMAP::iterator it = nodenames.find( aNodeName );
291
292 if( nodenames.end() != it )
293 return it->second;
294
296}
static NODEMAP nodenames
Definition: vrml2_node.cpp:43

References nodenames, and WRL2_INVALID.

Referenced by WRL2BASE::ReadNode().

◆ GetNodeTypeName()

const char * WRL2NODE::GetNodeTypeName ( WRL2NODES  aNodeType) const
inherited

Definition at line 273 of file vrml2_node.cpp.

274{
275 if( aNodeType < WRL2NODES::WRL2_BASE || aNodeType >= WRL2NODES::WRL2_END )
276 return "*INVALID_TYPE*";
277
278 if( aNodeType == WRL2NODES::WRL2_BASE )
279 return "*VIRTUAL_BASE*";
280
281 NODEMAP::iterator it = nodenames.begin();
282 advance( it, (static_cast<int>( aNodeType ) - static_cast<int>( WRL2NODES::WRL2_BEGIN ) ) );
283
284 return it->first.c_str();
285}

References nodenames, WRL2_BASE, WRL2_BEGIN, and WRL2_END.

Referenced by WRL2APPEARANCE::AddChildNode(), AddChildNode(), WRL2LINESET::AddChildNode(), WRL2POINTSET::AddChildNode(), WRL2SHAPE::AddChildNode(), WRL2APPEARANCE::AddRefNode(), AddRefNode(), WRL2LINESET::AddRefNode(), WRL2POINTSET::AddRefNode(), and WRL2SHAPE::AddRefNode().

◆ GetParent()

WRL2NODE * WRL2NODE::GetParent ( void  ) const
inherited

◆ HasColors()

bool WRL2FACESET::HasColors ( void  )
Returns
true if the face set has a color node.

Definition at line 766 of file vrml2_faceset.cpp.

767{
768 if( nullptr == color )
769 return false;
770
771 return ( (WRL2COLOR*) color )->HasColors();
772}

References color.

◆ isDangling()

bool WRL2FACESET::isDangling ( void  )
overridevirtual

Determine whether an object should be moved to a different parent during the VRML to SG* translation.

Returns
true if the object does not have a parent which is a logical container for the object for example if a Shape has a parent which is a Base node.

Implements WRL2NODE.

Definition at line 108 of file vrml2_faceset.cpp.

109{
110 // this node is dangling unless it has a parent of type WRL2_SHAPE
111
112 if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_SHAPE )
113 return true;
114
115 return false;
116}

References WRL2NODE::GetNodeType(), WRL2NODE::m_Parent, and WRL2_SHAPE.

◆ Read()

bool WRL2FACESET::Read ( WRLPROC proc,
WRL2BASE aTopNode 
)
overridevirtual

Implements WRL2NODE.

Definition at line 284 of file vrml2_faceset.cpp.

285{
286 char tok = proc.Peek();
287
288 if( proc.eof() )
289 {
290 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
291 " * [INFO] bad file format; unexpected eof %s." ),
292 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
293
294 return false;
295 }
296
297 if( '{' != tok )
298 {
299 wxLogTrace( traceVrmlPlugin,
300 wxT( "%s:%s:%d\n"
301 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
302 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
303
304 return false;
305 }
306
307 proc.Pop();
308 std::string glob;
309
310 while( true )
311 {
312 if( proc.Peek() == '}' )
313 {
314 proc.Pop();
315 break;
316 }
317
318 if( !proc.ReadName( glob ) )
319 {
320 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
321 "%s" ),
322 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
323
324 return false;
325 }
326
327 // expecting one of:
328 // [node]
329 // color
330 // coord
331 // normal
332 // texCoord
333 // [bool]
334 // ccw
335 // colorPerVertex
336 // convex
337 // normalPerVertex
338 // solid
339 // [ vector<int> ]
340 // colorIndex
341 // coordIndex
342 // normalIndex;
343 // [float]
344 // creaseAngle
345
346 if( !glob.compare( "ccw" ) )
347 {
348 if( !proc.ReadSFBool( ccw ) )
349 {
350 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
351 " * [INFO] invalid ccw %s\n"
352 " * [INFO] file: '%s'\n"
353 "%s" ),
354 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
355 proc.GetFileName(), proc.GetError() );
356
357 return false;
358 }
359 }
360 else if( !glob.compare( "colorPerVertex" ) )
361 {
362 if( !proc.ReadSFBool( colorPerVertex ) )
363 {
364 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
365 " * [INFO] invalid colorPerVertex %s\n"
366 " * [INFO] file: '%s'\n"
367 "%s" ),
368 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
369 proc.GetFileName(), proc.GetError() );
370
371 return false;
372 }
373 }
374 else if( !glob.compare( "convex" ) )
375 {
376 if( !proc.ReadSFBool( convex ) )
377 {
378 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
379 " * [INFO] invalid convex %s\n"
380 " * [INFO] file: '%s'\n"
381 "%s" ),
382 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
383 proc.GetFileName(), proc.GetError() );
384
385 return false;
386 }
387 }
388 else if( !glob.compare( "normalPerVertex" ) )
389 {
390 if( !proc.ReadSFBool( normalPerVertex ) )
391 {
392 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
393 " * [INFO] invalid normalPerVertex %s\n"
394 " * [INFO] file: '%s'\n"
395 "%s" ),
396 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
397 proc.GetFileName(), proc.GetError() );
398
399 return false;
400 }
401 }
402 else if( !glob.compare( "solid" ) )
403 {
404 if( !proc.ReadSFBool( solid ) )
405 {
406 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
407 " * [INFO] invalid solid %s\n"
408 " * [INFO] file: '%s'\n"
409 "%s" ),
410 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
411 proc.GetFileName(), proc.GetError() );
412
413 return false;
414 }
415 }
416 else if( !glob.compare( "creaseAngle" ) )
417 {
418 if( !proc.ReadSFFloat( creaseAngle ) )
419 {
420 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
421 " * [INFO] invalid creaseAngle %s\n"
422 " * [INFO] file: '%s'\n"
423 "%s" ),
424 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
425 proc.GetFileName(), proc.GetError() );
426
427 return false;
428 }
429
430 if( creaseAngle < 0.0 )
431 creaseAngle = 0.0f;
432 else if( creaseAngle > M_PI_2 )
433 creaseAngle = static_cast<float>( M_PI_2 );
434
435 creaseLimit = cosf( creaseAngle );
436 }
437 else if( !glob.compare( "colorIndex" ) )
438 {
439 if( !proc.ReadMFInt( colorIndex ) )
440 {
441 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
442 " * [INFO] invalid colorIndex %s\n"
443 " * [INFO] file: '%s'\n"
444 "%s" ),
445 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
446 proc.GetFileName(), proc.GetError() );
447
448 return false;
449 }
450 }
451 else if( !glob.compare( "coordIndex" ) )
452 {
453 if( !proc.ReadMFInt( coordIndex ) )
454 {
455 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
456 " * [INFO] invalid coordIndex %s\n"
457 " * [INFO] file: '%s'\n"
458 "%s" ),
459 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
460 proc.GetFileName(), proc.GetError() );
461
462 return false;
463 }
464 }
465 else if( !glob.compare( "normalIndex" ) )
466 {
467 if( !proc.ReadMFInt( normalIndex ) )
468 {
469 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
470 " * [INFO] invalid normalIndex %s\n"
471 " * [INFO] file: '%s'\n"
472 "%s" ),
473 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
474 proc.GetFileName(), proc.GetError() );
475
476 return false;
477 }
478 }
479 else if( !glob.compare( "color" ) )
480 {
481 if( !aTopNode->ReadNode( proc, this, nullptr ) )
482 {
483 wxLogTrace( traceVrmlPlugin,
484 wxT( "%s:%s:%d\n"
485 " * [INFO] could not read color node information." ),
486 __FILE__, __FUNCTION__, __LINE__ );
487
488 return false;
489 }
490 }
491 else if( !glob.compare( "coord" ) )
492 {
493 if( !aTopNode->ReadNode( proc, this, nullptr ) )
494 {
495 wxLogTrace( traceVrmlPlugin,
496 wxT( "%s:%s:%d\n"
497 " * [INFO] could not read coord node information." ),
498 __FILE__, __FUNCTION__, __LINE__ );
499
500 return false;
501 }
502 }
503 else if( !glob.compare( "normal" ) )
504 {
505 if( !aTopNode->ReadNode( proc, this, nullptr ) )
506 {
507 wxLogTrace( traceVrmlPlugin,
508 wxT( "%s:%s:%d\n"
509 " * [INFO] could not read normal node information." ),
510 __FILE__, __FUNCTION__, __LINE__ );
511
512 return false;
513 }
514 }
515 else if( !glob.compare( "texCoord" ) )
516 {
517 if( !aTopNode->ReadNode( proc, this, nullptr ) )
518 {
519 wxLogTrace( traceVrmlPlugin,
520 wxT( "%s:%s:%d\n"
521 " * [INFO] could not read texCoord node information." ),
522 __FILE__, __FUNCTION__, __LINE__ );
523
524 return false;
525 }
526 }
527 else
528 {
529 wxLogTrace( traceVrmlPlugin,
530 wxT( "%s:%s:%d\n"
531 " * [INFO] invalid IndexedFaceSet %s (no closing brace)\n"
532 " * [INFO] file: '%s'\n" ),
533 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
534 proc.GetFileName() );
535
536 return false;
537 }
538 } // while( true ) -- reading contents of IndexedFaceSet{}
539
540 return true;
541}
bool ReadNode(WRLPROC &proc, WRL2NODE *aParent, WRL2NODE **aNode)
Definition: vrml2_base.cpp:277
std::vector< int > normalIndex
Definition: vrml2_faceset.h:83
float creaseAngle
Definition: vrml2_faceset.h:85
std::vector< int > coordIndex
Definition: vrml2_faceset.h:82
float creaseLimit
Definition: vrml2_faceset.h:86
bool normalPerVertex
Definition: vrml2_faceset.h:78
std::vector< int > colorIndex
Definition: vrml2_faceset.h:81
bool colorPerVertex
Definition: vrml2_faceset.h:76
void Pop(void)
Definition: wrlproc.cpp:2035
bool ReadSFFloat(float &aSFFloat)
Definition: wrlproc.cpp:806
char Peek(void)
Definition: wrlproc.cpp:2007
std::string GetFileName(void)
Definition: wrlproc.cpp:1995
bool ReadMFInt(std::vector< int > &aMFInt32)
Definition: wrlproc.cpp:1504
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool ReadSFBool(bool &aSFBool)
Definition: wrlproc.cpp:729
bool eof(void)
Definition: wrlproc.cpp:1954
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982
#define M_PI_2
Definition: transline.cpp:40

References ccw, colorIndex, colorPerVertex, convex, coordIndex, creaseAngle, creaseLimit, WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFileName(), WRLPROC::GetFilePosition(), M_PI_2, normalIndex, normalPerVertex, WRLPROC::Peek(), WRLPROC::Pop(), WRLPROC::ReadMFInt(), WRLPROC::ReadName(), WRL2BASE::ReadNode(), WRLPROC::ReadSFBool(), WRLPROC::ReadSFFloat(), solid, and traceVrmlPlugin.

Referenced by WRL2BASE::readFaceSet().

◆ setDefaults()

void WRL2FACESET::setDefaults ( void  )
private

Definition at line 65 of file vrml2_faceset.cpp.

66{
67 color = nullptr;
68 coord = nullptr;
69 normal = nullptr;
70 texCoord = nullptr;
71
72 ccw = true;
73 colorPerVertex = true;
74 convex = true;
75 normalPerVertex = true;
76 solid = true;
77
78 creaseAngle = 0.733f; // approx 42 degrees; this is larger than VRML spec.
79 creaseLimit = 0.74317f; // cos( 0.733 )
80}

References ccw, color, colorPerVertex, convex, coord, creaseAngle, creaseLimit, normal, normalPerVertex, solid, and texCoord.

Referenced by WRL2FACESET().

◆ SetName()

bool WRL2NODE::SetName ( const std::string &  aName)
virtualinherited

Reimplemented in WRL2BASE.

Definition at line 222 of file vrml2_node.cpp.

223{
224 if( aName.empty() )
225 return false;
226
227 std::set< std::string >::iterator item = badNames.find( aName );
228
229 if( item != badNames.end() )
230 {
231 wxLogTrace( traceVrmlPlugin,
232 wxT( "%s:%s:%d\n"
233 " * [INFO] invalid node name '%s' (matches restricted word)" ),
234 __FILE__, __FUNCTION__, __LINE__, *item );
235
236 return false;
237 }
238
239
240 if( isdigit( aName[0] ) )
241 {
242 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
243 " * [INFO] invalid node name '%s' (begins with digit)" ),
244 __FILE__, __FUNCTION__, __LINE__, aName );
245
246 return false;
247 }
248
249 // The characters '+' and '-' are not allowed in names as per the VRML2 specification;
250 // however many parsers accept them and many bad generators use them so the rules
251 // have been relaxed here.
252 // #define BAD_CHARS1 "\"\'#+,-.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F"
253 #define BAD_CHARS1 "\"\'#,.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F"
254 #define BAD_CHARS2 "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
255
256 if( std::string::npos != aName.find_first_of( BAD_CHARS1 )
257 || std::string::npos != aName.find_first_of( BAD_CHARS2 ) )
258 {
259 wxLogTrace( traceVrmlPlugin,
260 wxT( "%s:%s:%d\n"
261 " * [INFO] invalid node name '%s' (contains invalid character)" ),
262 __FILE__, __FUNCTION__, __LINE__, aName );
263
264 return false;
265 }
266
267 m_Name = aName;
268
269 return true;
270}
#define BAD_CHARS2
#define BAD_CHARS1
static std::set< std::string > badNames
Definition: vrml2_node.cpp:39

References BAD_CHARS1, BAD_CHARS2, badNames, WRL2NODE::m_Name, and traceVrmlPlugin.

Referenced by WRL2BASE::implementDef().

◆ SetParent()

bool WRL2NODE::SetParent ( WRL2NODE aParent,
bool  doUnlink = true 
)
virtualinherited

Set the parent WRL2NODE of this object.

Parameters
aParent[in] is the desired parent node.
doUnlinkindicates that the child must be unlinked from the parent
Returns
true if the operation succeeds of false if the given node is not allowed to be a parent to the derived object.

Reimplemented in WRL2BASE.

Definition at line 339 of file vrml2_node.cpp.

340{
341 if( aParent == m_Parent )
342 return true;
343
344 if( nullptr != m_Parent && doUnlink )
345 m_Parent->unlinkChildNode( this );
346
347 m_Parent = aParent;
348
349 if( nullptr != m_Parent )
350 m_Parent->AddChildNode( this );
351
352 return true;
353}
virtual void unlinkChildNode(const WRL2NODE *aNode)
Remove references to an owned child.
Definition: vrml2_node.cpp:407

References WRL2NODE::AddChildNode(), WRL2NODE::m_Parent, and WRL2NODE::unlinkChildNode().

Referenced by WRL2NODE::AddChildNode(), WRL2SWITCH::AddRefNode(), and WRL2TRANSFORM::AddRefNode().

◆ TranslateToSG()

SGNODE * WRL2FACESET::TranslateToSG ( SGNODE aParent)
overridevirtual

Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library.

Parameters
aParentis a pointer to the parent SG node.
Returns
is non-NULL on success.

Implements WRL2NODE.

Definition at line 544 of file vrml2_faceset.cpp.

545{
546 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
547
548 wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_SHAPE ), nullptr,
549 wxString::Format( wxT( "IndexedFaceSet does not have a Shape parent (parent "
550 "ID: %d)." ), ptype ) );
551
552 wxLogTrace( traceVrmlPlugin,
553 wxT( " * [INFO] Translating IndexedFaceSet with %zu children, %zu references, "
554 "%zu back pointers, and %zu coord indices." ),
555 m_Children.size(), m_Refs.size(), m_BackPointers.size(), coordIndex.size() );
556
557 if( m_sgNode )
558 {
559 if( nullptr != aParent )
560 {
561 if( nullptr == S3D::GetSGNodeParent( m_sgNode )
562 && !S3D::AddSGNodeChild( aParent, m_sgNode ) )
563 {
564 return nullptr;
565 }
566 else if( aParent != S3D::GetSGNodeParent( m_sgNode )
567 && !S3D::AddSGNodeRef( aParent, m_sgNode ) )
568 {
569 return nullptr;
570 }
571 }
572
573 return m_sgNode;
574 }
575
576 size_t vsize = coordIndex.size();
577
578 if( nullptr == coord || vsize < 3 )
579 return nullptr;
580
581 WRLVEC3F* pcoords;
582 size_t coordsize;
583 ((WRL2COORDS*) coord)->GetCoords( pcoords, coordsize );
584
585 if( coordsize < 3 )
586 return nullptr;
587
588 // check that all indices are valid
589 for( size_t idx = 0; idx < vsize; ++idx )
590 {
591 if( coordIndex[idx] < 0 )
592 continue;
593
594 if( coordIndex[idx] >= (int)coordsize )
595 return nullptr;
596 }
597
598 SHAPE lShape;
599 FACET* fp = nullptr;
600 size_t iCoord;
601 int idx; // coordinate index
602 size_t cidx = 0; // color index
603 SGCOLOR pc1;
604
605 if( nullptr == color )
606 {
607 // no per-vertex colors; we can save a few CPU cycles
608 for( iCoord = 0; iCoord < vsize; ++iCoord )
609 {
610 idx = coordIndex[iCoord];
611
612 if( idx < 0 )
613 {
614 if( nullptr != fp )
615 {
616 if( fp->HasMinPoints() )
617 fp = nullptr;
618 else
619 fp->Init();
620 }
621
622 continue;
623 }
624
625 // if the coordinate is bad then skip it
626 if( idx >= (int)coordsize )
627 continue;
628
629 if( nullptr == fp )
630 fp = lShape.NewFacet();
631
632 // push the vertex value and index
633 fp->AddVertex( pcoords[idx], idx );
634 }
635 }
636 else
637 {
638 WRL2COLOR* cn = (WRL2COLOR*) color;
639 WRLVEC3F tc;
640
641 for( iCoord = 0; iCoord < vsize; ++iCoord )
642 {
643 idx = coordIndex[iCoord];
644
645 if( idx < 0 )
646 {
647 if( nullptr != fp )
648 {
649 if( fp->HasMinPoints() )
650 fp = nullptr;
651 else
652 fp->Init();
653 }
654
655 if( !colorPerVertex )
656 ++cidx;
657
658 continue;
659 }
660
661 // if the coordinate is bad then skip it
662 if( idx >= (int)coordsize )
663 continue;
664
665 if( nullptr == fp )
666 fp = lShape.NewFacet();
667
668 // push the vertex value and index
669 fp->AddVertex( pcoords[idx], idx );
670
671 // push the color if appropriate
672 if( !colorPerVertex )
673 {
674 if( colorIndex.empty() )
675 {
676 cn->GetColor( cidx, tc.x, tc.y, tc.z );
677 pc1.SetColor( tc.x, tc.y, tc.z );
678 fp->AddColor( pc1 );
679 }
680 else
681 {
682 if( cidx < colorIndex.size() )
683 cn->GetColor( colorIndex[cidx], tc.x, tc.y, tc.z );
684 else
685 cn->GetColor( colorIndex.back(), tc.x, tc.y, tc.z );
686
687 pc1.SetColor( tc.x, tc.y, tc.z );
688 fp->AddColor( pc1 );
689 }
690 }
691 else
692 {
693 if( colorIndex.empty() )
694 {
695 cn->GetColor( idx, tc.x, tc.y, tc.z );
696 pc1.SetColor( tc.x, tc.y, tc.z );
697 fp->AddColor( pc1 );
698 }
699 else
700 {
701 if( iCoord < colorIndex.size() )
702 cn->GetColor( colorIndex[iCoord], tc.x, tc.y, tc.z );
703 else
704 cn->GetColor( colorIndex.back(), tc.x, tc.y, tc.z );
705
706 pc1.SetColor( tc.x, tc.y, tc.z );
707 fp->AddColor( pc1 );
708 }
709 }
710 }
711 }
712
713 SGNODE* np = nullptr;
714
715 if( ccw )
716 np = lShape.CalcShape( aParent, nullptr, WRL1_ORDER::ORD_CCW, creaseLimit, true );
717 else
718 np = lShape.CalcShape( aParent, nullptr, WRL1_ORDER::ORD_CLOCKWISE, creaseLimit, true );
719
720 return np;
721}
Definition: wrlfacet.h:43
bool HasMinPoints()
Definition: wrlfacet.cpp:173
void AddVertex(WRLVEC3F &aVertex, int aIndex)
Add the vertex and its associated index to the internal list of polygon vertices.
Definition: wrlfacet.cpp:191
void AddColor(const SGCOLOR &aColor)
Add the given RGB color to the internal list.
Definition: wrlfacet.cpp:204
void Init()
Definition: wrlfacet.cpp:158
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
An abstract shape on 2D plane.
Definition: shape.h:124
FACET * NewFacet()
Definition: wrlfacet.cpp:695
SGNODE * CalcShape(SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
Definition: wrlfacet.cpp:703
void GetColor(int aIndex, float &red, float &green, float &blue)
Retrieve the given color (or default 0.8, 0.8, 0.8 if index is invalid).
SGNODE * m_sgNode
Definition: vrml2_node.h:178
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition: ifsg_api.cpp:485
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:494
SGTYPES
Definition: sg_types.h:35
@ SGTYPE_SHAPE
Definition: sg_types.h:44
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:512
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:503
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188

References FACET::AddColor(), S3D::AddSGNodeChild(), S3D::AddSGNodeRef(), FACET::AddVertex(), SHAPE::CalcShape(), ccw, color, colorIndex, colorPerVertex, coord, coordIndex, creaseLimit, Format(), WRL2COLOR::GetColor(), S3D::GetSGNodeParent(), S3D::GetSGNodeType(), FACET::HasMinPoints(), FACET::Init(), WRL2NODE::m_BackPointers, WRL2NODE::m_Children, WRL2NODE::m_Refs, WRL2NODE::m_sgNode, SHAPE::NewFacet(), ORD_CCW, ORD_CLOCKWISE, SGCOLOR::SetColor(), S3D::SGTYPE_SHAPE, and traceVrmlPlugin.

◆ unlinkChildNode()

void WRL2FACESET::unlinkChildNode ( const WRL2NODE aNode)
overridevirtual

Remove 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.

Reimplemented from WRL2NODE.

Definition at line 724 of file vrml2_faceset.cpp.

725{
726 if( nullptr == aNode )
727 return;
728
729 if( aNode->GetParent() == this )
730 {
731 if( aNode == color )
732 color = nullptr;
733 else if( aNode == coord )
734 coord = nullptr;
735 else if( aNode == normal )
736 normal = nullptr;
737 else if( aNode == texCoord )
738 texCoord = nullptr;
739 }
740
742}
WRL2NODE * GetParent(void) const
Definition: vrml2_node.cpp:210

References color, coord, WRL2NODE::GetParent(), normal, texCoord, and WRL2NODE::unlinkChildNode().

◆ unlinkRefNode()

void WRL2FACESET::unlinkRefNode ( const WRL2NODE aNode)
overridevirtual

Remove 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.

Reimplemented from WRL2NODE.

Definition at line 745 of file vrml2_faceset.cpp.

746{
747 if( nullptr == aNode )
748 return;
749
750 if( aNode->GetParent() != this )
751 {
752 if( aNode == color )
753 color = nullptr;
754 else if( aNode == coord )
755 coord = nullptr;
756 else if( aNode == normal )
757 normal = nullptr;
758 else if( aNode == texCoord )
759 texCoord = nullptr;
760 }
761
763}
virtual void unlinkRefNode(const WRL2NODE *aNode)
Remove pointers to a referenced node.
Definition: vrml2_node.cpp:425

References color, coord, WRL2NODE::GetParent(), normal, texCoord, and WRL2NODE::unlinkRefNode().

Member Data Documentation

◆ ccw

bool WRL2FACESET::ccw
private

Definition at line 75 of file vrml2_faceset.h.

Referenced by Read(), setDefaults(), and TranslateToSG().

◆ color

WRL2NODE* WRL2FACESET::color
private

◆ colorIndex

std::vector< int > WRL2FACESET::colorIndex
private

Definition at line 81 of file vrml2_faceset.h.

Referenced by Read(), and TranslateToSG().

◆ colorPerVertex

bool WRL2FACESET::colorPerVertex
private

Definition at line 76 of file vrml2_faceset.h.

Referenced by Read(), setDefaults(), and TranslateToSG().

◆ convex

bool WRL2FACESET::convex
private

Definition at line 77 of file vrml2_faceset.h.

Referenced by Read(), and setDefaults().

◆ coord

WRL2NODE* WRL2FACESET::coord
private

◆ coordIndex

std::vector< int > WRL2FACESET::coordIndex
private

Definition at line 82 of file vrml2_faceset.h.

Referenced by Read(), and TranslateToSG().

◆ creaseAngle

float WRL2FACESET::creaseAngle
private

Definition at line 85 of file vrml2_faceset.h.

Referenced by Read(), and setDefaults().

◆ creaseLimit

float WRL2FACESET::creaseLimit
private

Definition at line 86 of file vrml2_faceset.h.

Referenced by Read(), setDefaults(), and TranslateToSG().

◆ m_BackPointers

◆ m_Children

◆ m_error

std::string WRL2NODE::m_error
protectedinherited

Definition at line 176 of file vrml2_node.h.

Referenced by WRL2NODE::GetError().

◆ m_Name

std::string WRL2NODE::m_Name
protectedinherited

Definition at line 171 of file vrml2_node.h.

Referenced by WRL2NODE::FindNode(), WRL2NODE::GetName(), and WRL2NODE::SetName().

◆ m_Parent

◆ m_Refs

◆ m_sgNode

◆ m_Type

◆ normal

WRL2NODE* WRL2FACESET::normal
private

Definition at line 72 of file vrml2_faceset.h.

Referenced by AddChildNode(), AddRefNode(), setDefaults(), unlinkChildNode(), and unlinkRefNode().

◆ normalIndex

std::vector< int > WRL2FACESET::normalIndex
private

Definition at line 83 of file vrml2_faceset.h.

Referenced by Read().

◆ normalPerVertex

bool WRL2FACESET::normalPerVertex
private

Definition at line 78 of file vrml2_faceset.h.

Referenced by Read(), and setDefaults().

◆ solid

bool WRL2FACESET::solid
private

Definition at line 79 of file vrml2_faceset.h.

Referenced by Read(), and setDefaults().

◆ texCoord

WRL2NODE* WRL2FACESET::texCoord
private

Definition at line 73 of file vrml2_faceset.h.

Referenced by AddChildNode(), AddRefNode(), setDefaults(), unlinkChildNode(), and unlinkRefNode().


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