KiCad PCB EDA Suite
WRL1COORDS Class Reference

#include <vrml1_coords.h>

Inheritance diagram for WRL1COORDS:
WRL1NODE

Public Member Functions

 WRL1COORDS (NAMEREGISTER *aDictionary)
 
 WRL1COORDS (NAMEREGISTER *aDictionary, WRL1NODE *aParent)
 
virtual ~WRL1COORDS ()
 
bool Read (WRLPROC &proc, WRL1BASE *aTopNode) override
 
bool AddRefNode (WRL1NODE *aNode) override
 
bool AddChildNode (WRL1NODE *aNode) override
 
SGNODETranslateToSG (SGNODE *aParent, WRL1STATUS *sp) override
 Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library. More...
 
void GetCoords (WRLVEC3F *&aCoordList, size_t &aListSize)
 
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...
 
virtual bool SetParent (WRL1NODE *aParent, bool doUnlink=true)
 Set the parent WRL1NODE of this object. More...
 
virtual std::string GetName (void)
 
virtual bool SetName (const std::string &aName)
 
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...
 
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

void addItem (WRL1NODE *aNode)
 
void delItem (const WRL1NODE *aNode)
 

Private Attributes

std::vector< WRLVEC3Fpoints
 

Detailed Description

Definition at line 41 of file vrml1_coords.h.

Constructor & Destructor Documentation

◆ WRL1COORDS() [1/2]

WRL1COORDS::WRL1COORDS ( NAMEREGISTER aDictionary)

Definition at line 34 of file vrml1_coords.cpp.

34 : WRL1NODE( aDictionary )
35{
37}
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:91
WRL1NODES m_Type
Definition: vrml1_node.h:227
@ WRL1_COORDINATE3

References WRL1NODE::m_Type, and WRL1_COORDINATE3.

◆ WRL1COORDS() [2/2]

WRL1COORDS::WRL1COORDS ( NAMEREGISTER aDictionary,
WRL1NODE aParent 
)

Definition at line 40 of file vrml1_coords.cpp.

40 :
41 WRL1NODE( aDictionary )
42{
44 m_Parent = aParent;
45
46 if( nullptr != m_Parent )
47 m_Parent->AddChildNode( this );
48}
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::AddChildNode(), WRL1NODE::m_Parent, WRL1NODE::m_Type, and WRL1_COORDINATE3.

◆ ~WRL1COORDS()

WRL1COORDS::~WRL1COORDS ( )
virtual

Definition at line 51 of file vrml1_coords.cpp.

52{
53 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Coordinate3 node." ) );
54}
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool WRL1COORDS::AddChildNode ( WRL1NODE aNode)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 64 of file vrml1_coords.cpp.

65{
66 // this node may not own or reference any other node
67 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
68}

◆ 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

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

Referenced by WRL1NODE::AddRefNode().

◆ AddRefNode()

bool WRL1COORDS::AddRefNode ( WRL1NODE aNode)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 57 of file vrml1_coords.cpp.

58{
59 // this node may not own or reference any other node
60 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
61}

◆ 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}
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:231

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

Referenced by WRL1BASE::~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 WRL1BASE::implementUse().

◆ GetCoords()

void WRL1COORDS::GetCoords ( WRLVEC3F *&  aCoordList,
size_t &  aListSize 
)

Definition at line 166 of file vrml1_coords.cpp.

167{
168 if( points.size() < 3 )
169 {
170 aCoordList = nullptr;
171 aListSize = 0;
172 return;
173 }
174
175 aCoordList = &points[0];
176 aListSize = points.size();
177}
std::vector< WRLVEC3F > points
Definition: vrml1_coords.h:56

References points.

Referenced by WRL1FACESET::TranslateToSG().

◆ 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 WRL1NODE::GetName ( void  )
virtualinherited

Reimplemented in WRL1BASE.

Definition at line 266 of file vrml1_node.cpp.

267{
268 return m_Name;
269}
std::string m_Name
Definition: vrml1_node.h:228

References WRL1NODE::m_Name.

◆ 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(), WRL1BASE::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 WRL1BASE::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 WRL1BASE::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().

◆ Read()

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

Implements WRL1NODE.

Definition at line 71 of file vrml1_coords.cpp.

72{
73 char tok = proc.Peek();
74
75 if( proc.eof() )
76 {
77 wxLogTrace( traceVrmlPlugin,
78 wxT( "%s:%s:%d\n"
79 " * [INFO] bad file format; unexpected eof %s." ),
80 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
81
82 return false;
83 }
84
85 if( '{' != tok )
86 {
87 wxLogTrace( traceVrmlPlugin,
88 wxT( "%s:%s:%d\n"
89 " * [INFO] bad file format; expecting '{' but got '%s' %s" ),
90 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
91
92 return false;
93 }
94
95 proc.Pop();
96 std::string glob;
97
98 if( proc.Peek() == '}' )
99 {
100 proc.Pop();
101 return true;
102 }
103
104 if( !proc.ReadName( glob ) )
105 {
106 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
107 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
108
109 return false;
110 }
111
112 // expecting 'point'
113 if( !glob.compare( "point" ) )
114 {
115 if( !proc.ReadMFVec3f( points ) )
116 {
117 wxLogTrace( traceVrmlPlugin,
118 wxT( "%s:%s:%d\n"
119 " * [INFO] invalid point set %s\n"
120 " * [INFO] file: '%s'\n"
121 "%s" ),
122 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
123 proc.GetFileName(), proc.GetError() );
124
125 return false;
126 }
127 }
128 else
129 {
130 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
131 "* [INFO] bad Coordinate %s.\n"
132 "* [INFO] file: '%s'." ),
133 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
134
135 return false;
136 }
137
138 // assuming legacy KiCad expectation of 1U = 0.1 inch,
139 // convert to mm to meet the expectations of the SG structure
140 std::vector< WRLVEC3F >::iterator sP = points.begin();
141 std::vector< WRLVEC3F >::iterator eP = points.end();
142
143 while( sP != eP )
144 {
145 sP->x *= 2.54f;
146 sP->y *= 2.54f;
147 sP->z *= 2.54f;
148 ++sP;
149 }
150
151 if( proc.Peek() == '}' )
152 {
153 proc.Pop();
154 return true;
155 }
156
157 wxLogTrace( traceVrmlPlugin,
158 wxT( "%s:%s:%d\n"
159 " * [INFO] bad Coordinate %s (no closing brace)." ),
160 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
161
162 return false;
163}
void Pop(void)
Definition: wrlproc.cpp:2035
char Peek(void)
Definition: wrlproc.cpp:2007
std::string GetFileName(void)
Definition: wrlproc.cpp:1995
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool eof(void)
Definition: wrlproc.cpp:1954
bool ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition: wrlproc.cpp:1839
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982

References WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFileName(), WRLPROC::GetFilePosition(), WRLPROC::Peek(), points, WRLPROC::Pop(), WRLPROC::ReadMFVec3f(), WRLPROC::ReadName(), and traceVrmlPlugin.

Referenced by WRL1BASE::readCoords().

◆ SetName()

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

Reimplemented in WRL1BASE.

Definition at line 272 of file vrml1_node.cpp.

273{
274 if( aName.empty() )
275 return false;
276
277 if( isdigit( aName[0] ) )
278 {
279 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
280 " * [INFO] invalid node name '%s' (begins with digit)" ),
281 __FILE__, __FUNCTION__, __LINE__, aName );
282
283 return false;
284 }
285
286 // The character '+' is not allowed in names as per the VRML1 specification;
287 // however many parsers accept them and many bad generators use them so the rules
288 // have been relaxed here.
289 #define BAD_CHARS1 "\"\'#,.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F"
290 #define BAD_CHARS2 "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
291
292 if( std::string::npos != aName.find_first_of( BAD_CHARS1 )
293 || std::string::npos != aName.find_first_of( BAD_CHARS2 ) )
294 {
295 wxLogTrace( traceVrmlPlugin,
296 wxT( "%s:%s:%d\n"
297 " * [INFO] invalid node name '%s' (contains invalid character)" ),
298 __FILE__, __FUNCTION__, __LINE__, aName );
299
300 return false;
301 }
302
303 m_Name = aName;
304
305 if( m_dictionary )
306 m_dictionary->AddName( aName, this );
307
308 return true;
309}
bool AddName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:39
#define BAD_CHARS2
#define BAD_CHARS1

References NAMEREGISTER::AddName(), BAD_CHARS1, BAD_CHARS2, WRL1NODE::m_dictionary, WRL1NODE::m_Name, and traceVrmlPlugin.

Referenced by WRL1BASE::implementDef().

◆ SetParent()

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

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 in WRL1BASE.

Definition at line 359 of file vrml1_node.cpp.

360{
361 if( aParent == m_Parent )
362 return true;
363
364 if( nullptr != m_Parent && doUnlink )
365 m_Parent->unlinkChildNode( this );
366
367 m_Parent = aParent;
368
369 if( nullptr != m_Parent )
370 m_Parent->AddChildNode( this );
371
372 return true;
373}
virtual void unlinkChildNode(const WRL1NODE *aNode)
Remove references to an owned child; it is invoked by the child upon destruction to ensure that the p...
Definition: vrml1_node.cpp:420

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

Referenced by WRL1NODE::AddChildNode().

◆ TranslateToSG()

SGNODE * WRL1COORDS::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 180 of file vrml1_coords.cpp.

181{
182 wxCHECK_MSG( sp, nullptr, wxT( "Invalid base data." ) );
183
184 sp->coord = this;
185
186 return nullptr;
187}
WRL1COORDS * coord
Definition: vrml1_node.h:94

References WRL1STATUS::coord.

◆ 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}
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:232

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

◆ points

std::vector< WRLVEC3F > WRL1COORDS::points
private

Definition at line 56 of file vrml1_coords.h.

Referenced by GetCoords(), and Read().


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