KiCad PCB EDA Suite
WRL1BASE Class Reference

Represent the top node of a VRML1 model. More...

#include <vrml1_base.h>

Inheritance diagram for WRL1BASE:
WRL1NODE

Public Member Functions

 WRL1BASE ()
 
virtual ~WRL1BASE ()
 
bool Read (WRLPROC &proc)
 
bool ReadNode (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
virtual std::string GetName (void) override
 
virtual bool SetName (const std::string &aName) override
 
bool Read (WRLPROC &proc, WRL1BASE *aTopNode) override
 
bool SetParent (WRL1NODE *aParent, bool doUnlink=true) override
 Set the parent WRL1NODE of this object. More...
 
SGNODETranslateToSG (SGNODE *aParent, WRL1STATUS *sp) override
 Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library. More...
 
void cancelDict (void)
 
WRL1NODES getNodeTypeID (const std::string &aNodeName)
 Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists. More...
 
virtual void unlinkChildNode (const WRL1NODE *aNode)
 Remove references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
virtual void unlinkRefNode (const WRL1NODE *aNode)
 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. More...
 
void addNodeRef (WRL1NODE *aNode)
 Add a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (WRL1NODE *aNode)
 Remove a pointer to a node which references, but does not own, this node. More...
 
WRL1NODES GetNodeType (void) const
 Return the type of this node instance. More...
 
WRL1NODEGetParent (void) const
 Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
const char * GetNodeTypeName (WRL1NODES aNodeType) const
 
size_t GetNItems (void) const
 
virtual WRL1NODEFindNode (const std::string &aNodeName)
 Search the tree of linked nodes and returns a reference to the current node with the given name. More...
 
virtual bool AddChildNode (WRL1NODE *aNode)
 
virtual bool AddRefNode (WRL1NODE *aNode)
 
std::string GetError (void)
 

Protected Attributes

WRL1NODEm_Parent
 
WRL1NODES m_Type
 
std::string m_Name
 
std::list< WRL1NODE * > m_BackPointers
 
std::list< WRL1NODE * > m_Children
 
std::list< WRL1NODE * > m_Refs
 
std::list< WRL1NODE * > m_Items
 
std::string m_error
 
WRL1STATUS m_current
 
SGNODEm_sgNode
 
NAMEREGISTERm_dictionary
 

Private Member Functions

bool implementUse (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool implementDef (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readGroup (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readSeparator (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readSwitch (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readMaterial (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readMatBinding (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readCoords (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readFaceSet (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readTransform (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
bool readShapeHints (WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
 
void addItem (WRL1NODE *aNode)
 
void delItem (const WRL1NODE *aNode)
 

Detailed Description

Represent the top node of a VRML1 model.

Definition at line 45 of file vrml1_base.h.

Constructor & Destructor Documentation

◆ WRL1BASE()

WRL1BASE::WRL1BASE ( )

Definition at line 42 of file vrml1_base.cpp.

42 : WRL1NODE( nullptr )
43{
46 return;
47}
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:91
WRL1NODES m_Type
Definition: vrml1_node.h:227
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246

References WRL1NODE::m_dictionary, WRL1NODE::m_Type, and WRL1_BASE.

◆ ~WRL1BASE()

WRL1BASE::~WRL1BASE ( )
virtual

Definition at line 50 of file vrml1_base.cpp.

51{
52 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying virtual base node." ) );
53
54 cancelDict();
55}
void cancelDict(void)
Definition: vrml1_node.cpp:198
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References WRL1NODE::cancelDict(), and traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool WRL1NODE::AddChildNode ( WRL1NODE aNode)
virtualinherited

Reimplemented in WRL1COORDS, WRL1FACESET, WRL1MATBINDING, WRL1MATERIAL, WRL1SHAPEHINTS, and WRL1TRANSFORM.

Definition at line 376 of file vrml1_node.cpp.

377{
378 wxCHECK_MSG( aNode, false, wxT( "Invalid node pointer." ) );
379 wxCHECK_MSG( aNode->GetNodeType() != WRL1NODES::WRL1_BASE, false,
380 wxT( "Attempting to add a base node to another node." ) );
381
382 std::list< WRL1NODE* >::iterator sC = m_Children.begin();
383 std::list< WRL1NODE* >::iterator eC = m_Children.end();
384
385 while( sC != eC )
386 {
387 if( *sC == aNode )
388 return false;
389
390 ++sC;
391 }
392
393 m_Children.push_back( aNode );
394 addItem( aNode );
395
396 if( aNode->GetParent() != this )
397 aNode->SetParent( this );
398
399 return true;
400}
WRL1NODE * GetParent(void) const
Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition: vrml1_node.cpp:260
virtual bool SetParent(WRL1NODE *aParent, bool doUnlink=true)
Set the parent WRL1NODE of this object.
Definition: vrml1_node.cpp:359
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:231
void addItem(WRL1NODE *aNode)
Definition: vrml1_node.cpp:458
WRL1NODES GetNodeType(void) const
Return the type of this node instance.
Definition: vrml1_node.cpp:254

References WRL1NODE::addItem(), WRL1NODE::GetNodeType(), WRL1NODE::GetParent(), WRL1NODE::m_Children, WRL1NODE::SetParent(), and WRL1_BASE.

Referenced by WRL1NODE::SetParent(), WRL1COORDS::WRL1COORDS(), WRL1FACESET::WRL1FACESET(), WRL1GROUP::WRL1GROUP(), WRL1MATBINDING::WRL1MATBINDING(), WRL1MATERIAL::WRL1MATERIAL(), WRL1SEPARATOR::WRL1SEPARATOR(), WRL1SHAPEHINTS::WRL1SHAPEHINTS(), WRL1SWITCH::WRL1SWITCH(), and WRL1TRANSFORM::WRL1TRANSFORM().

◆ addItem()

void WRL1NODE::addItem ( WRL1NODE aNode)
privateinherited

Definition at line 458 of file vrml1_node.cpp.

459{
460 m_Items.push_back( aNode );
461}
std::list< WRL1NODE * > m_Items
Definition: vrml1_node.h:233

References WRL1NODE::m_Items.

Referenced by WRL1NODE::AddChildNode(), and WRL1NODE::AddRefNode().

◆ addNodeRef()

void WRL1NODE::addNodeRef ( WRL1NODE 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 216 of file vrml1_node.cpp.

217{
218 // the parent node must never be added as a backpointer
219 if( aNode == m_Parent )
220 return;
221
222 std::list< WRL1NODE* >::iterator sR = m_BackPointers.begin();
223 std::list< WRL1NODE* >::iterator eR = m_BackPointers.end();
224
225 while( sR != eR )
226 {
227 if( *sR == aNode )
228 return;
229
230 ++sR;
231 }
232
233 m_BackPointers.push_back( aNode );
234}
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::m_BackPointers, and WRL1NODE::m_Parent.

Referenced by WRL1NODE::AddRefNode().

◆ AddRefNode()

bool WRL1NODE::AddRefNode ( WRL1NODE aNode)
virtualinherited

Reimplemented in WRL1COORDS, WRL1FACESET, WRL1MATBINDING, WRL1MATERIAL, WRL1SHAPEHINTS, and WRL1TRANSFORM.

Definition at line 403 of file vrml1_node.cpp.

404{
405 wxCHECK_MSG( aNode, false, wxT( "Invalid node pointer." ) );
406 wxCHECK_MSG( aNode->GetNodeType() != WRL1NODES::WRL1_BASE, false,
407 wxT( "Attempt to add a base node reference to another base node" ) );
408
409 // note: the VRML1 spec does not prevent the reuse of a node at
410 // the same level; for example a Coordinate3 node can be recalled
411 // at any time to set the current coordinate set.
412 m_Refs.push_back( aNode );
413 aNode->addNodeRef( this );
414 addItem( aNode );
415
416 return true;
417}
void addNodeRef(WRL1NODE *aNode)
Add a pointer to a node which references, but does not own, this node.
Definition: vrml1_node.cpp:216
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:232

References WRL1NODE::addItem(), WRL1NODE::addNodeRef(), WRL1NODE::GetNodeType(), WRL1NODE::m_Refs, and WRL1_BASE.

Referenced by implementUse().

◆ cancelDict()

void WRL1NODE::cancelDict ( void  )
inherited

Definition at line 198 of file vrml1_node.cpp.

199{
200 std::list< WRL1NODE* >::iterator sC = m_Children.begin();
201 std::list< WRL1NODE* >::iterator eC = m_Children.end();
202
203 while( sC != eC )
204 {
205 (*sC)->cancelDict();
206 ++sC;
207 }
208
209 if( m_Type == WRL1NODES::WRL1_BASE && nullptr != m_dictionary )
210 delete m_dictionary;
211
212 m_dictionary = nullptr;
213}

References WRL1NODE::m_Children, WRL1NODE::m_dictionary, WRL1NODE::m_Type, and WRL1_BASE.

Referenced by ~WRL1BASE().

◆ delItem()

void WRL1NODE::delItem ( const WRL1NODE aNode)
privateinherited

Definition at line 464 of file vrml1_node.cpp.

465{
466 std::list< WRL1NODE* >::iterator sL = m_Items.begin();
467 std::list< WRL1NODE* >::iterator eL = m_Items.end();
468
469 while( sL != eL )
470 {
471 if( *sL == aNode )
472 {
473 m_Items.erase( sL );
474 return;
475 }
476
477 ++sL;
478 }
479}

References WRL1NODE::m_Items.

Referenced by WRL1NODE::unlinkChildNode(), and WRL1NODE::unlinkRefNode().

◆ delNodeRef()

void WRL1NODE::delNodeRef ( WRL1NODE 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 237 of file vrml1_node.cpp.

238{
239 std::list< WRL1NODE* >::iterator np = std::find( m_BackPointers.begin(),
240 m_BackPointers.end(), aNode );
241
242 if( np != m_BackPointers.end() )
243 {
244 m_BackPointers.erase( np );
245 return;
246 }
247
248 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
249 " * [BUG] delNodeRef() did not find its target." ),
250 __FILE__, __FUNCTION__, __LINE__ );
251}

References WRL1NODE::m_BackPointers, and traceVrmlPlugin.

◆ FindNode()

WRL1NODE * WRL1NODE::FindNode ( const std::string &  aNodeName)
virtualinherited

Search the tree of linked nodes and returns a reference to the current node 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.
Returns
is a valid node pointer on success, otherwise NULL.

Definition at line 350 of file vrml1_node.cpp.

351{
352 if( nullptr == m_dictionary )
353 return nullptr;
354
355 return m_dictionary->FindName( aNodeName );
356}
WRL1NODE * FindName(const std::string &aName)
Definition: vrml1_node.cpp:72

References NAMEREGISTER::FindName(), and WRL1NODE::m_dictionary.

Referenced by implementUse().

◆ GetError()

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

Definition at line 344 of file vrml1_node.cpp.

345{
346 return m_error;
347}
std::string m_error
Definition: vrml1_node.h:234

References WRL1NODE::m_error.

◆ GetName()

std::string WRL1BASE::GetName ( void  )
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 64 of file vrml1_base.cpp.

65{
66 wxCHECK_MSG( false, std::string( "" ),
67 wxT( "Attempt to extract name from virtual base node." ) );
68}

◆ GetNItems()

size_t WRL1NODE::GetNItems ( void  ) const
inherited

Definition at line 338 of file vrml1_node.cpp.

339{
340 return m_Items.size();
341}

References WRL1NODE::m_Items.

◆ GetNodeType()

WRL1NODES WRL1NODE::GetNodeType ( void  ) const
inherited

Return the type of this node instance.

Definition at line 254 of file vrml1_node.cpp.

255{
256 return m_Type;
257}

References WRL1NODE::m_Type.

Referenced by WRL1NODE::AddChildNode(), WRL1NODE::AddRefNode(), implementUse(), WRL1GROUP::TranslateToSG(), and WRL1TRANSFORM::TranslateToSG().

◆ getNodeTypeID()

WRL1NODES WRL1NODE::getNodeTypeID ( const std::string &  aNodeName)
inherited

Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists.

Definition at line 327 of file vrml1_node.cpp.

328{
329 NODEMAP::iterator it = nodenames.find( aNodeName );
330
331 if( nodenames.end() != it )
332 return it->second;
333
335}
static NODEMAP nodenames
Definition: vrml1_node.cpp:88

References nodenames, and WRL1_INVALID.

Referenced by ReadNode().

◆ GetNodeTypeName()

const char * WRL1NODE::GetNodeTypeName ( WRL1NODES  aNodeType) const
inherited

Definition at line 312 of file vrml1_node.cpp.

313{
314 if( aNodeType < WRL1NODES::WRL1_BASE || aNodeType >= WRL1NODES::WRL1_END )
315 return "*INVALID_TYPE*";
316
317 if( aNodeType == WRL1NODES::WRL1_BASE )
318 return "*VIRTUAL_BASE*";
319
320 NODEMAP::iterator it = nodenames.begin();
321 advance( it, ( static_cast<int>( aNodeType ) - static_cast<int>( WRL1NODES::WRL1_BEGIN ) ) );
322
323 return it->first.c_str();
324}

References nodenames, WRL1_BASE, WRL1_BEGIN, and WRL1_END.

Referenced by implementUse().

◆ GetParent()

WRL1NODE * WRL1NODE::GetParent ( void  ) const
inherited

Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.

top level transform).

Definition at line 260 of file vrml1_node.cpp.

261{
262 return m_Parent;
263}

References WRL1NODE::m_Parent.

Referenced by WRL1NODE::AddChildNode().

◆ implementDef()

bool WRL1BASE::implementDef ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 156 of file vrml1_base.cpp.

157{
158 if( nullptr != aNode )
159 *aNode = nullptr;
160
161 wxCHECK_MSG( nullptr != aParent, false, wxT( "Invalid parent pointer." ) );
162
163 std::string glob;
164 WRL1NODE* lnode = nullptr;
165
166 if( !proc.ReadName( glob ) )
167 {
168 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
169 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
170
171 return false;
172 }
173
174 if( ReadNode( proc, aParent, &lnode ) )
175 {
176 if( nullptr != aNode )
177 *aNode = lnode;
178
179 if( lnode && !lnode->SetName( glob ) )
180 {
181 wxLogTrace( traceVrmlPlugin,
182 wxT( "%s:%s:%d\n * [INFO] bad formatting (invalid name) %s." ),
183 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
184
185 return false;
186 }
187
188 if( !m_dictionary )
189 return false;
190
191 m_dictionary->AddName( glob, lnode );
192
193 return true;
194 }
195
196 return false;
197}
bool AddName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:39
bool ReadNode(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:200
The base class of all VRML1 nodes.
Definition: vrml1_node.h:117
virtual bool SetName(const std::string &aName)
Definition: vrml1_node.cpp:272
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982

References NAMEREGISTER::AddName(), WRLPROC::GetError(), WRLPROC::GetFilePosition(), WRL1NODE::m_dictionary, WRLPROC::ReadName(), ReadNode(), WRL1NODE::SetName(), and traceVrmlPlugin.

Referenced by ReadNode().

◆ implementUse()

bool WRL1BASE::implementUse ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 111 of file vrml1_base.cpp.

112{
113 if( nullptr != aNode )
114 *aNode = nullptr;
115
116 wxCHECK_MSG( aParent, false, wxT( "Invoked with invalid parent." ) );
117
118 std::string glob;
119
120 if( !proc.ReadName( glob ) )
121 {
122 wxLogTrace( traceVrmlPlugin, wxT( "%s" ), proc.GetError() );
123
124 return false;
125 }
126
127 WRL1NODE* ref = aParent->FindNode( glob );
128
129 // return 'true' - the file may be defective but it may still be somewhat OK
130 if( nullptr == ref )
131 {
132 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n * [INFO] node '%s' not found." ),
133 __FILE__, __FUNCTION__, __LINE__, glob );
134
135 return true;
136 }
137
138 if( !aParent->AddRefNode( ref ) )
139 {
140 wxLogTrace( traceVrmlPlugin,
141 wxT( "%s:%s:%d\n * [INFO] failed to add node '%s' (%s) to parent of type %s." ),
142 __FILE__, __FUNCTION__, __LINE__, glob,
143 ref->GetNodeTypeName( ref->GetNodeType() ),
144 aParent->GetNodeTypeName( aParent->GetNodeType() ) );
145
146 return false;
147 }
148
149 if( nullptr != aNode )
150 *aNode = ref;
151
152 return true;
153}
virtual WRL1NODE * FindNode(const std::string &aNodeName)
Search the tree of linked nodes and returns a reference to the current node with the given name.
Definition: vrml1_node.cpp:350
virtual bool AddRefNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:403
const char * GetNodeTypeName(WRL1NODES aNodeType) const
Definition: vrml1_node.cpp:312

References WRL1NODE::AddRefNode(), WRL1NODE::FindNode(), WRLPROC::GetError(), WRL1NODE::GetNodeType(), WRL1NODE::GetNodeTypeName(), WRLPROC::ReadName(), and traceVrmlPlugin.

Referenced by ReadNode().

◆ Read() [1/2]

bool WRL1BASE::Read ( WRLPROC proc)

Definition at line 77 of file vrml1_base.cpp.

78{
79 wxCHECK_MSG( proc.GetVRMLType() == WRLVERSION::VRML_V1, false,
80 wxT( "No open file or file is not a VRML1 file" ) );
81
82 // Note: according to the VRML1 specification, a file may contain
83 // only one grouping node at the top level. The following code
84 // supports non-conformant VRML1 files by processing all top level
85 // nodes as if the vrml1_base were the equivalent of a vrml1_separator
86
87 while( proc.Peek() )
88 {
89 if( !ReadNode( proc, this, nullptr ) )
90 {
91 wxLogTrace( traceVrmlPlugin,
92 wxT( "%s:%s:%d\n * [INFO] bad file format; unexpected eof %s" ),
93 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
94
95 return false;
96 }
97 }
98
99 if( !proc.eof() )
100 {
101 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
102 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
103
104 return false;
105 }
106
107 return true;
108}
char Peek(void)
Definition: wrlproc.cpp:2007
WRLVERSION GetVRMLType(void)
Definition: wrlproc.cpp:230
bool eof(void)
Definition: wrlproc.cpp:1954

References WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFilePosition(), WRLPROC::GetVRMLType(), WRLPROC::Peek(), ReadNode(), traceVrmlPlugin, and VRML_V1.

Referenced by LoadVRML().

◆ Read() [2/2]

bool WRL1BASE::Read ( WRLPROC proc,
WRL1BASE aTopNode 
)
overridevirtual

Implements WRL1NODE.

Definition at line 346 of file vrml1_base.cpp.

347{
348 wxCHECK_MSG( false, false, wxT( "This method must never be invoked on a WRL1BASE object" ) );
349}

◆ readCoords()

bool WRL1BASE::readCoords ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 449 of file vrml1_base.cpp.

450{
451 if( nullptr != aNode )
452 *aNode = nullptr;
453
454 WRL1COORDS* np = new WRL1COORDS( m_dictionary, aParent );
455
456 if( !np->Read( proc, this ) )
457 {
458 delete np;
459 return false;
460 }
461
462 if( nullptr != aNode )
463 *aNode = (WRL1NODE*) np;
464
465 return true;
466}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1COORDS::Read().

Referenced by ReadNode().

◆ readFaceSet()

bool WRL1BASE::readFaceSet ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 469 of file vrml1_base.cpp.

470{
471 if( nullptr != aNode )
472 *aNode = nullptr;
473
474 WRL1FACESET* np = new WRL1FACESET( m_dictionary, aParent );
475
476 if( !np->Read( proc, this ) )
477 {
478 delete np;
479 return false;
480 }
481
482 if( nullptr != aNode )
483 *aNode = (WRL1NODE*) np;
484
485 return true;
486}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1FACESET::Read().

Referenced by ReadNode().

◆ readGroup()

bool WRL1BASE::readGroup ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 352 of file vrml1_base.cpp.

353{
354 if( nullptr != aNode )
355 *aNode = nullptr;
356
357 WRL1GROUP* np = new WRL1GROUP( m_dictionary, aParent );
358
359 if( !np->Read( proc, this ) )
360 {
361 delete np;
362 return false;
363 }
364
365 if( nullptr != aNode )
366 *aNode = (WRL1NODE*) np;
367
368 return true;
369}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override
Definition: vrml1_group.cpp:66

References WRL1NODE::m_dictionary, and WRL1GROUP::Read().

Referenced by ReadNode().

◆ readMatBinding()

bool WRL1BASE::readMatBinding ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 429 of file vrml1_base.cpp.

430{
431 if( nullptr != aNode )
432 *aNode = nullptr;
433
434 WRL1MATBINDING* np = new WRL1MATBINDING( m_dictionary, aParent );
435
436 if( !np->Read( proc, this ) )
437 {
438 delete np;
439 return false;
440 }
441
442 if( nullptr != aNode )
443 *aNode = (WRL1NODE*) np;
444
445 return true;
446}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1MATBINDING::Read().

Referenced by ReadNode().

◆ readMaterial()

bool WRL1BASE::readMaterial ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 409 of file vrml1_base.cpp.

410{
411 if( nullptr != aNode )
412 *aNode = nullptr;
413
414 WRL1MATERIAL* np = new WRL1MATERIAL( m_dictionary, aParent );
415
416 if( !np->Read( proc, this ) )
417 {
418 delete np;
419 return false;
420 }
421
422 if( nullptr != aNode )
423 *aNode = (WRL1NODE*) np;
424
425 return true;
426}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1MATERIAL::Read().

Referenced by ReadNode().

◆ ReadNode()

bool WRL1BASE::ReadNode ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)

Definition at line 200 of file vrml1_base.cpp.

201{
202 // This function reads a node and stores a pointer to it in aNode.
203 // A value 'true' is returned if a node is successfully read or,
204 // if the node is not supported, successfully discarded. Callers
205 // must always check the value of aNode when the function returns
206 // 'true' since it will be NULL if the node type is not supported.
207
208 if( nullptr != aNode )
209 *aNode = nullptr;
210
211 wxCHECK_MSG( aParent, false, wxT( "Invalid parent pointer." ) );
212
213 std::string glob;
214 WRL1NODES ntype;
215
216 if( !proc.ReadName( glob ) )
217 {
218 if( !proc.eof() )
219 {
220 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
221 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
222 }
223
224 return false;
225 }
226
227 // Process node name:
228 // the names encountered at this point should be one of the
229 // built-in node names or one of:
230 // DEF, USE
231 if( !glob.compare( "USE" ) )
232 {
233 if( !implementUse( proc, aParent, aNode ) )
234 return false;
235
236 return true;
237 }
238
239 if( !glob.compare( "DEF" ) )
240 {
241 if( !implementDef( proc, aParent, aNode ) )
242 return false;
243
244 return true;
245 }
246
247 ntype = getNodeTypeID( glob );
248
249 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Processing node '%s' ID: %d." ), glob, ntype );
250
251 switch( ntype )
252 {
254
255 if( !readGroup( proc, aParent, aNode ) )
256 return false;
257
258 break;
259
261
262 if( !readSeparator( proc, aParent, aNode ) )
263 return false;
264
265 break;
266
268
269 if( !readSwitch( proc, aParent, aNode ) )
270 return false;
271
272 break;
273
275
276 if( !readMaterial( proc, aParent, aNode ) )
277 return false;
278
279 break;
280
282
283 if( !readMatBinding( proc, aParent, aNode ) )
284 return false;
285
286 break;
287
289
290 if( !readCoords( proc, aParent, aNode ) )
291 return false;
292
293 break;
294
296
297 if( !readFaceSet( proc, aParent, aNode ) )
298 return false;
299
300 break;
301
306
307 if( !readTransform( proc, aParent, aNode ) )
308 return false;
309
310 break;
311
313
314 if( !readShapeHints( proc, aParent, aNode ) )
315 return false;
316
317 break;
318
319 //
320 // items not implemented or for optional future implementation:
321 //
322 default:
323
324 if( !proc.DiscardNode() )
325 {
326 wxLogTrace( traceVrmlPlugin,
327 wxT( "%s:%s:%d\n * [INFO] could not discard node %s." ),
328 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
329
330 return false;
331 }
332 else
333 {
334 wxLogTrace( traceVrmlPlugin,
335 wxT( " * [INFO] discarded node '%s' %s (currently unsupported)." ),
336 glob, proc.GetFilePosition() );
337 }
338
339 break;
340 }
341
342 return true;
343}
bool readMaterial(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:409
bool implementUse(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:111
bool readMatBinding(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:429
bool readFaceSet(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:469
bool readCoords(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:449
bool readTransform(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:489
bool readShapeHints(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:509
bool readGroup(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:352
bool readSwitch(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:392
bool implementDef(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:156
bool readSeparator(WRLPROC &proc, WRL1NODE *aParent, WRL1NODE **aNode)
Definition: vrml1_base.cpp:372
WRL1NODES getNodeTypeID(const std::string &aNodeName)
Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists.
Definition: vrml1_node.cpp:327
bool DiscardNode(void)
Definition: wrlproc.cpp:368
WRL1NODES
Definition: wrltypes.h:56
@ WRL1_INDEXEDFACESET
@ WRL1_COORDINATE3
@ WRL1_TRANSLATION
@ WRL1_MATERIALBINDING

References WRLPROC::DiscardNode(), WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFilePosition(), WRL1NODE::getNodeTypeID(), implementDef(), implementUse(), readCoords(), readFaceSet(), readGroup(), readMatBinding(), readMaterial(), WRLPROC::ReadName(), readSeparator(), readShapeHints(), readSwitch(), readTransform(), traceVrmlPlugin, WRL1_COORDINATE3, WRL1_GROUP, WRL1_INDEXEDFACESET, WRL1_MATERIAL, WRL1_MATERIALBINDING, WRL1_ROTATION, WRL1_SCALE, WRL1_SEPARATOR, WRL1_SHAPEHINTS, WRL1_SWITCH, WRL1_TRANSFORM, and WRL1_TRANSLATION.

Referenced by implementDef(), Read(), WRL1GROUP::Read(), WRL1SEPARATOR::Read(), and WRL1SWITCH::Read().

◆ readSeparator()

bool WRL1BASE::readSeparator ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 372 of file vrml1_base.cpp.

373{
374 if( nullptr != aNode )
375 *aNode = nullptr;
376
377 WRL1SEPARATOR* np = new WRL1SEPARATOR( m_dictionary, aParent );
378
379 if( !np->Read( proc, this ) )
380 {
381 delete np;
382 return false;
383 }
384
385 if( nullptr != aNode )
386 *aNode = (WRL1NODE*) np;
387
388 return true;
389}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1SEPARATOR::Read().

Referenced by ReadNode().

◆ readShapeHints()

bool WRL1BASE::readShapeHints ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 509 of file vrml1_base.cpp.

510{
511 if( nullptr != aNode )
512 *aNode = nullptr;
513
514 WRL1SHAPEHINTS* np = new WRL1SHAPEHINTS( m_dictionary, aParent );
515
516 if( !np->Read( proc, this ) )
517 {
518 delete np;
519 return false;
520 }
521
522 if( nullptr != aNode )
523 *aNode = (WRL1NODE*) np;
524
525 return true;
526}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1SHAPEHINTS::Read().

Referenced by ReadNode().

◆ readSwitch()

bool WRL1BASE::readSwitch ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 392 of file vrml1_base.cpp.

393{
394 WRL1SWITCH* np = new WRL1SWITCH( m_dictionary, aParent );
395
396 if( !np->Read( proc, this ) )
397 {
398 delete np;
399 return false;
400 }
401
402 if( nullptr != aNode )
403 *aNode = (WRL1NODE*) np;
404
405 return true;
406}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1SWITCH::Read().

Referenced by ReadNode().

◆ readTransform()

bool WRL1BASE::readTransform ( WRLPROC proc,
WRL1NODE aParent,
WRL1NODE **  aNode 
)
private

Definition at line 489 of file vrml1_base.cpp.

490{
491 if( nullptr != aNode )
492 *aNode = nullptr;
493
494 WRL1TRANSFORM* np = new WRL1TRANSFORM( m_dictionary, aParent );
495
496 if( !np->Read( proc, this ) )
497 {
498 delete np;
499 return false;
500 }
501
502 if( nullptr != aNode )
503 *aNode = (WRL1NODE*) np;
504
505 return true;
506}
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override

References WRL1NODE::m_dictionary, and WRL1TRANSFORM::Read().

Referenced by ReadNode().

◆ SetName()

bool WRL1BASE::SetName ( const std::string &  aName)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 71 of file vrml1_base.cpp.

72{
73 wxCHECK_MSG( false, false, wxT( "Attempt to set name on virtual base node." ) );
74}

◆ SetParent()

bool WRL1BASE::SetParent ( WRL1NODE aParent,
bool  doUnlink = true 
)
overridevirtual

Set the parent WRL1NODE 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; false if the given node is not allowed to be a parent to the derived object.

Reimplemented from WRL1NODE.

Definition at line 58 of file vrml1_base.cpp.

59{
60 wxCHECK_MSG( false, false, wxT( "Attempt to set parent on WRL1BASE node." ) );
61}

◆ TranslateToSG()

SGNODE * WRL1BASE::TranslateToSG ( SGNODE aParent,
WRL1STATUS sp 
)
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 WRL1NODE.

Definition at line 529 of file vrml1_base.cpp.

530{
531 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Translating VRML1 Base with %zu items." ),
532 m_Items.size() );
533
534 if( m_Items.empty() )
535 return nullptr;
536
537 if( m_Items.size() == 1 )
538 return ( *m_Items.begin() )->TranslateToSG( nullptr, nullptr );
539
540 // Note: according to the VRML1 specification, a file may contain
541 // only one grouping node at the top level. The following code
542 // supports non-conformant VRML1 files.
543
544 m_current.Init();
545
546 IFSG_TRANSFORM txNode( true );
547 bool hasContent = false;
548
549 std::list< WRL1NODE* >::iterator sI = m_Items.begin();
550 std::list< WRL1NODE* >::iterator eI = m_Items.end();
551
552 SGNODE* node = txNode.GetRawPtr();
553
554 while( sI != eI )
555 {
556 if( nullptr != (*sI)->TranslateToSG( node, &m_current ) )
557 hasContent = true;
558
559 ++sI;
560 }
561
562 if( !hasContent )
563 {
564 txNode.Destroy();
565 return nullptr;
566 }
567
568 return node;
569}
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
WRL1STATUS m_current
Definition: vrml1_node.h:236
void Init()
Definition: vrml1_node.h:74

References IFSG_NODE::Destroy(), IFSG_NODE::GetRawPtr(), WRL1STATUS::Init(), WRL1NODE::m_current, WRL1NODE::m_Items, and traceVrmlPlugin.

Referenced by LoadVRML().

◆ unlinkChildNode()

void WRL1NODE::unlinkChildNode ( const WRL1NODE aNode)
virtualinherited

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.

Definition at line 420 of file vrml1_node.cpp.

421{
422 std::list< WRL1NODE* >::iterator sL = m_Children.begin();
423 std::list< WRL1NODE* >::iterator eL = m_Children.end();
424
425 while( sL != eL )
426 {
427 if( *sL == aNode )
428 {
429 m_Children.erase( sL );
430 delItem( aNode );
431 return;
432 }
433
434 ++sL;
435 }
436}
void delItem(const WRL1NODE *aNode)
Definition: vrml1_node.cpp:464

References WRL1NODE::delItem(), and WRL1NODE::m_Children.

Referenced by WRL1NODE::SetParent(), and WRL1NODE::~WRL1NODE().

◆ unlinkRefNode()

void WRL1NODE::unlinkRefNode ( const WRL1NODE aNode)
virtualinherited

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.

Definition at line 439 of file vrml1_node.cpp.

440{
441 std::list< WRL1NODE* >::iterator sL = m_Refs.begin();
442 std::list< WRL1NODE* >::iterator eL = m_Refs.end();
443
444 while( sL != eL )
445 {
446 if( *sL == aNode )
447 {
448 m_Refs.erase( sL );
449 delItem( aNode );
450 return;
451 }
452
453 ++sL;
454 }
455}

References WRL1NODE::delItem(), and WRL1NODE::m_Refs.

Member Data Documentation

◆ m_BackPointers

◆ m_Children

◆ m_current

◆ m_dictionary

◆ m_error

std::string WRL1NODE::m_error
protectedinherited

Definition at line 234 of file vrml1_node.h.

Referenced by WRL1NODE::GetError().

◆ m_Items

◆ m_Name

std::string WRL1NODE::m_Name
protectedinherited

Definition at line 228 of file vrml1_node.h.

Referenced by WRL1NODE::GetName(), WRL1NODE::SetName(), and WRL1NODE::~WRL1NODE().

◆ m_Parent

◆ m_Refs

◆ m_sgNode

SGNODE* WRL1NODE::m_sgNode
protectedinherited

Definition at line 237 of file vrml1_node.h.

Referenced by WRL1NODE::WRL1NODE().

◆ m_Type


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