KiCad PCB EDA Suite
WRL2TRANSFORM Class Reference

#include <vrml2_transform.h>

Inheritance diagram for WRL2TRANSFORM:
WRL2NODE

Public Member Functions

 WRL2TRANSFORM ()
 
 WRL2TRANSFORM (WRL2NODE *aNode)
 
virtual ~WRL2TRANSFORM ()
 
bool Read (WRLPROC &proc, WRL2BASE *aTopNode) override
 
bool AddRefNode (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 isDangling (void) override
 Determine whether an object should be moved to a different parent during the VRML to SG* translation. 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...
 
virtual bool AddChildNode (WRL2NODE *aNode)
 
std::string GetError (void)
 
WRL2NODES getNodeTypeID (const std::string &aNodeName)
 
virtual void unlinkChildNode (const WRL2NODE *aNode)
 Remove references to an owned child. More...
 
virtual void unlinkRefNode (const WRL2NODE *aNode)
 Remove pointers to a referenced node. More...
 
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 readChildren (WRLPROC &proc, WRL2BASE *aTopNode)
 

Private Attributes

WRLVEC3F center
 
WRLVEC3F scale
 
WRLVEC3F translation
 
WRLROTATION rotation
 
WRLROTATION scaleOrientation
 
WRLVEC3F bboxCenter
 
WRLVEC3F bboxSize
 

Detailed Description

Definition at line 39 of file vrml2_transform.h.

Constructor & Destructor Documentation

◆ WRL2TRANSFORM() [1/2]

WRL2TRANSFORM::WRL2TRANSFORM ( )

Definition at line 34 of file vrml2_transform.cpp.

34 : WRL2NODE()
35{
37}
WRL2NODES m_Type
Definition: vrml2_node.h:170

References WRL2NODE::m_Type, and WRL2_TRANSFORM.

◆ WRL2TRANSFORM() [2/2]

WRL2TRANSFORM::WRL2TRANSFORM ( WRL2NODE aNode)

Definition at line 40 of file vrml2_transform.cpp.

40 : WRL2NODE()
41{
43 m_Parent = aParent;
44
45 if( nullptr != m_Parent )
46 m_Parent->AddChildNode( this );
47}
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, and WRL2_TRANSFORM.

◆ ~WRL2TRANSFORM()

WRL2TRANSFORM::~WRL2TRANSFORM ( )
virtual

Definition at line 50 of file vrml2_transform.cpp.

51{
52 wxLogTrace( traceVrmlPlugin,
53 wxT( " * [INFO] Destroying Transform node with %zu children, %zu"
54 "references, and %zu back pointers." ),
55 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
56}
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 WRL2NODE::AddChildNode ( WRL2NODE aNode)
virtualinherited

Reimplemented in WRL2APPEARANCE, WRL2BOX, WRL2COLOR, WRL2COORDS, WRL2FACESET, WRL2INLINE, WRL2LINESET, WRL2MATERIAL, WRL2NORMS, WRL2POINTSET, and WRL2SHAPE.

Definition at line 356 of file vrml2_node.cpp.

357{
358 wxCHECK_MSG( aNode, false, wxT( "Invalid node pointer." ) );
359 wxCHECK_MSG( aNode->GetNodeType() != WRL2NODES::WRL2_BASE, false,
360 wxT( "Attempting to add a base node to another node." ) );
361
362
363 std::list< WRL2NODE* >::iterator sC = m_Children.begin();
364 std::list< WRL2NODE* >::iterator eC = m_Children.end();
365
366 while( sC != eC )
367 {
368 if( *sC == aNode )
369 return false;
370
371 ++sC;
372 }
373
374 m_Children.push_back( aNode );
375
376 if( aNode->GetParent() != this )
377 aNode->SetParent( this );
378
379 return true;
380}
WRL2NODE * GetParent(void) const
Definition: vrml2_node.cpp:210
virtual bool SetParent(WRL2NODE *aParent, bool doUnlink=true)
Set the parent WRL2NODE of this object.
Definition: vrml2_node.cpp:339
WRL2NODES GetNodeType(void) const
Definition: vrml2_node.cpp:204

References WRL2NODE::GetNodeType(), WRL2NODE::GetParent(), WRL2NODE::m_Children, WRL2NODE::SetParent(), and WRL2_BASE.

Referenced by WRL2APPEARANCE::AddChildNode(), WRL2FACESET::AddChildNode(), WRL2LINESET::AddChildNode(), WRL2POINTSET::AddChildNode(), WRL2SHAPE::AddChildNode(), WRL2SWITCH::AddRefNode(), AddRefNode(), WRL2NODE::SetParent(), WRL2APPEARANCE::WRL2APPEARANCE(), WRL2BOX::WRL2BOX(), WRL2COLOR::WRL2COLOR(), WRL2COORDS::WRL2COORDS(), WRL2FACESET::WRL2FACESET(), WRL2INLINE::WRL2INLINE(), WRL2LINESET::WRL2LINESET(), WRL2MATERIAL::WRL2MATERIAL(), WRL2NORMS::WRL2NORMS(), WRL2POINTSET::WRL2POINTSET(), WRL2SHAPE::WRL2SHAPE(), WRL2SWITCH::WRL2SWITCH(), and WRL2TRANSFORM().

◆ 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 WRL2TRANSFORM::AddRefNode ( WRL2NODE aNode)
overridevirtual

Reimplemented from WRL2NODE.

Definition at line 259 of file vrml2_transform.cpp.

260{
261 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
262
263 // take possession if the node is dangling WRL2_SHAPE
264
265 if( WRL2NODES::WRL2_SHAPE == aNode->GetNodeType() && aNode->isDangling() )
266 {
267 WRL2NODE* np = aNode->GetParent();
268
269 if( nullptr != np )
270 aNode->SetParent( this );
271
272
273 if( !WRL2NODE::AddChildNode( aNode ) )
274 {
275 aNode->SetParent( nullptr );
276 return false;
277 }
278 }
279
280 if( !WRL2NODE::AddRefNode( aNode ) )
281 return false;
282
283 return true;
284}
virtual bool isDangling(void)=0
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
virtual bool AddRefNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:383

References WRL2NODE::AddChildNode(), WRL2NODE::AddRefNode(), WRL2NODE::GetNodeType(), WRL2NODE::GetParent(), WRL2NODE::isDangling(), WRL2NODE::SetParent(), and WRL2_SHAPE.

◆ 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(), WRL2FACESET::AddChildNode(), WRL2LINESET::AddChildNode(), WRL2POINTSET::AddChildNode(), WRL2SHAPE::AddChildNode(), WRL2APPEARANCE::AddRefNode(), WRL2FACESET::AddRefNode(), WRL2LINESET::AddRefNode(), WRL2POINTSET::AddRefNode(), and WRL2SHAPE::AddRefNode().

◆ GetParent()

WRL2NODE * WRL2NODE::GetParent ( void  ) const
inherited

◆ isDangling()

bool WRL2TRANSFORM::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 59 of file vrml2_transform.cpp.

60{
61 // a Transform node is never dangling
62 return false;
63}

◆ Read()

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

Implements WRL2NODE.

Definition at line 66 of file vrml2_transform.cpp.

67{
68 /*
69 * Structure of a Transform node (p.120):
70 *
71 * Transform {
72 * eventIn MFNode addChildren
73 * eventIn MFNode removeChildren
74 * exposedField SFVec3f center 0 0 0
75 * exposedField MFNode children []
76 * exposedField SFRotation rotation 0 0 1 0
77 * exposedField SFVec3f scale 1 1 1
78 * exposedField SFRotation scaleOrientation 0 0 1 0
79 * exposedField SFVec3f translation 0 0 0
80 * field SFVec3f bboxCenter 0 0 0
81 * field SFVec3f bboxSize 0 0 0
82 * }
83 */
84
85 wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
86
87 center.x = 0.0;
88 center.y = 0.0;
89 center.z = 0.0;
90
94
95 rotation.x = 0.0;
96 rotation.y = 0.0;
97 rotation.z = 1.0;
98 rotation.w = 0.0;
99
101
102 scale.x = 1.0;
103 scale.y = 1.0;
104 scale.z = 1.0;
105
106 size_t line, column;
107 proc.GetFilePosData( line, column );
108
109 char tok = proc.Peek();
110
111 if( proc.eof() )
112 {
113 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
114 " * [INFO] bad file format; unexpected eof %s." ),
115 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
116
117 return false;
118 }
119
120 if( '{' != tok )
121 {
122 wxLogTrace( traceVrmlPlugin,
123 wxT( "%s:%s:%d\n"
124 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
125 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
126
127 return false;
128 }
129
130 proc.Pop();
131 std::string glob;
132
133 while( true )
134 {
135 if( proc.Peek() == '}' )
136 {
137 proc.Pop();
138 break;
139 }
140
141 if( !proc.ReadName( glob ) )
142 {
143 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
144 "%s" ),
145 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
146
147 return false;
148 }
149
150 // expecting one of:
151 // center
152 // children
153 // rotation
154 // scale
155 // ScaleOrientation
156 // translation
157 if( !glob.compare( "center" ) )
158 {
159 if( !proc.ReadSFVec3f( center ) )
160 {
161 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
162 " * [INFO] invalid center %s\n"
163 " * [INFO] file: '%s'\n"
164 "%s" ),
165 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
166 proc.GetFileName(), proc.GetError() );
167
168 return false;
169 }
170
171 // convert from 1 VRML Unit = 0.1 inch to 1 VRML Unit = 1 mm
172 center.x *= 2.54f;
173 center.y *= 2.54f;
174 center.z *= 2.54f;
175 }
176 else if( !glob.compare( "rotation" ) )
177 {
178 if( !proc.ReadSFRotation( rotation ) )
179 {
180 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
181 " * [INFO] invalid rotation %s\n"
182 " * [INFO] file: '%s'\n"
183 "%s" ),
184 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
185 proc.GetFileName(), proc.GetError() );
186
187 return false;
188 }
189 }
190 else if( !glob.compare( "scale" ) )
191 {
192 if( !proc.ReadSFVec3f( scale ) )
193 {
194 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
195 " * [INFO] invalid scale %s\n"
196 " * [INFO] file: '%s'\n"
197 "%s" ),
198 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
199 proc.GetFileName(), proc.GetError() );
200
201 return false;
202 }
203 }
204 else if( !glob.compare( "scaleOrientation" ) )
205 {
206 if( !proc.ReadSFRotation( scaleOrientation ) )
207 {
208 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
209 " * [INFO] invalid scaleOrientation %s\n"
210 " * [INFO] file: '%s'\n"
211 "%s" ),
212 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
213 proc.GetFileName(), proc.GetError() );
214
215 return false;
216 }
217 }
218 else if( !glob.compare( "translation" ) )
219 {
220 if( !proc.ReadSFVec3f( translation ) )
221 {
222 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
223 " * [INFO] invalid translation %s\n"
224 " * [INFO] file: '%s'\n"
225 "%s" ),
226 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
227 proc.GetFileName(), proc.GetError() );
228
229 return false;
230 }
231
232 // convert from 1 VRML Unit = 0.1 inch to 1 VRML Unit = 1 mm
233 translation.x *= 2.54f;
234 translation.y *= 2.54f;
235 translation.z *= 2.54f;
236 }
237 else if( !glob.compare( "children" ) )
238 {
239 if( !readChildren( proc, aTopNode ) )
240 return false;
241 }
242 else
243 {
244 wxLogTrace( traceVrmlPlugin,
245 wxT( "%s:%s:%d\n"
246 " * [INFO] invalid Transform %s.\n"
247 " * [INFO] file: '%s'\n" ),
248 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
249 proc.GetFileName() );
250
251 return false;
252 }
253 } // while( true ) -- reading contents of Transform{}
254
255 return true;
256}
WRLROTATION scaleOrientation
WRLVEC3F translation
bool readChildren(WRLPROC &proc, WRL2BASE *aTopNode)
WRLVEC3F bboxCenter
WRLROTATION rotation
WRLVEC3F bboxSize
void Pop(void)
Definition: wrlproc.cpp:2035
char Peek(void)
Definition: wrlproc.cpp:2007
std::string GetFileName(void)
Definition: wrlproc.cpp:1995
bool GetFilePosData(size_t &line, size_t &column)
Definition: wrlproc.cpp:1966
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool eof(void)
Definition: wrlproc.cpp:1954
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982
bool ReadSFRotation(WRLROTATION &aSFRotation)
Definition: wrlproc.cpp:937
bool ReadSFVec3f(WRLVEC3F &aSFVec3f)
Definition: wrlproc.cpp:1082

References bboxCenter, bboxSize, center, WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFileName(), WRLPROC::GetFilePosData(), WRLPROC::GetFilePosition(), WRLPROC::Peek(), WRLPROC::Pop(), readChildren(), WRLPROC::ReadName(), WRLPROC::ReadSFRotation(), WRLPROC::ReadSFVec3f(), rotation, scale, scaleOrientation, traceVrmlPlugin, and translation.

Referenced by WRL2BASE::readTransform().

◆ readChildren()

bool WRL2TRANSFORM::readChildren ( WRLPROC proc,
WRL2BASE aTopNode 
)
private

Definition at line 287 of file vrml2_transform.cpp.

288{
289 char tok = proc.Peek();
290
291 if( proc.eof() )
292 {
293 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
294 " * [INFO] bad file format; unexpected eof %s." ),
295 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
296
297 return false;
298 }
299
300 if( '[' != tok )
301 {
302 // since there are no delimiters we expect a single child
303 if( !aTopNode->ReadNode( proc, this, nullptr ) )
304 return false;
305
306 if( proc.Peek() == ',' )
307 proc.Pop();
308
309 return true;
310 }
311
312 proc.Pop();
313
314 while( true )
315 {
316 if( proc.Peek() == ']' )
317 {
318 proc.Pop();
319 break;
320 }
321
322 if( !aTopNode->ReadNode( proc, this, nullptr ) )
323 return false;
324
325 if( proc.Peek() == ',' )
326 proc.Pop();
327 }
328
329 return true;
330}
bool ReadNode(WRLPROC &proc, WRL2NODE *aParent, WRL2NODE **aNode)
Definition: vrml2_base.cpp:277

References WRLPROC::eof(), WRLPROC::GetFilePosition(), WRLPROC::Peek(), WRLPROC::Pop(), WRL2BASE::ReadNode(), and traceVrmlPlugin.

Referenced by Read().

◆ 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 AddRefNode().

◆ TranslateToSG()

SGNODE * WRL2TRANSFORM::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 333 of file vrml2_transform.cpp.

334{
335 wxLogTrace( traceVrmlPlugin,
336 wxT( " * [INFO] Translating Switch with %zu children, %zu references, and"
337 "%zu back pointers." ),
338 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
339
340 if( m_Children.empty() && m_Refs.empty() )
341 return nullptr;
342
343 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
344
345 wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_TRANSFORM ), nullptr,
346 wxString::Format( wxT( "Transform does not have a Transform parent (parent "
347 "ID: %d)." ), ptype ) );
348
349 if( m_sgNode )
350 {
351 if( nullptr != aParent )
352 {
353 if( nullptr == S3D::GetSGNodeParent( m_sgNode )
354 && !S3D::AddSGNodeChild( aParent, m_sgNode ) )
355 {
356 return nullptr;
357 }
358 else if( aParent != S3D::GetSGNodeParent( m_sgNode )
359 && !S3D::AddSGNodeRef( aParent, m_sgNode ) )
360 {
361 return nullptr;
362 }
363 }
364
365 return m_sgNode;
366 }
367
368 IFSG_TRANSFORM txNode( aParent );
369
370 std::list< WRL2NODE* >::iterator sC = m_Children.begin();
371 std::list< WRL2NODE* >::iterator eC = m_Children.end();
372 WRL2NODES type;
373
374 // Include only the following in a Transform node:
375 // Shape
376 // Switch
377 // Transform
378 // Inline
379 bool test = false; // set to true if there are any subnodes for display
380
381 for( int i = 0; i < 2; ++i )
382 {
383 while( sC != eC )
384 {
385 type = (*sC)->GetNodeType();
386
387 switch( type )
388 {
393
394 if( nullptr != (*sC)->TranslateToSG( txNode.GetRawPtr() ) )
395 test = true;
396
397 break;
398
399 default:
400 break;
401 }
402
403 ++ sC;
404 }
405
406 sC = m_Refs.begin();
407 eC = m_Refs.end();
408 }
409
410 if( false == test )
411 {
412 txNode.Destroy();
413 return nullptr;
414 }
415
416 txNode.SetScale( SGPOINT( scale.x, scale.y, scale.z ) );
417 txNode.SetCenter( SGPOINT( center.x, center.y, center.z ) );
418 txNode.SetTranslation( SGPOINT( translation.x, translation.y, translation.z ) );
419 txNode.SetScaleOrientation( SGVECTOR( scaleOrientation.x, scaleOrientation.y,
421 txNode.SetRotation( SGVECTOR( rotation.x, rotation.y, rotation.z), rotation.w );
422
423 m_sgNode = txNode.GetRawPtr();
424
425 return m_sgNode;
426}
IFSG_TRANSFORM is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH.
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_TRANSFORM
Definition: sg_types.h:36
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
WRL2NODES
Definition: wrltypes.h:125

References S3D::AddSGNodeChild(), S3D::AddSGNodeRef(), center, IFSG_NODE::Destroy(), Format(), IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), S3D::GetSGNodeType(), WRL2NODE::m_BackPointers, WRL2NODE::m_Children, WRL2NODE::m_Refs, WRL2NODE::m_sgNode, rotation, scale, scaleOrientation, IFSG_TRANSFORM::SetCenter(), IFSG_TRANSFORM::SetRotation(), IFSG_TRANSFORM::SetScale(), IFSG_TRANSFORM::SetScaleOrientation(), IFSG_TRANSFORM::SetTranslation(), S3D::SGTYPE_TRANSFORM, traceVrmlPlugin, translation, WRL2_INLINE, WRL2_SHAPE, WRL2_SWITCH, and WRL2_TRANSFORM.

◆ unlinkChildNode()

void WRL2NODE::unlinkChildNode ( const WRL2NODE 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.

Reimplemented in WRL2APPEARANCE, WRL2FACESET, WRL2LINESET, WRL2POINTSET, and WRL2SHAPE.

Definition at line 407 of file vrml2_node.cpp.

408{
409 std::list< WRL2NODE* >::iterator sL = m_Children.begin();
410 std::list< WRL2NODE* >::iterator eL = m_Children.end();
411
412 while( sL != eL )
413 {
414 if( *sL == aNode )
415 {
416 m_Children.erase( sL );
417 return;
418 }
419
420 ++sL;
421 }
422}

References WRL2NODE::m_Children.

Referenced by WRL2NODE::SetParent(), WRL2APPEARANCE::unlinkChildNode(), WRL2FACESET::unlinkChildNode(), WRL2LINESET::unlinkChildNode(), WRL2POINTSET::unlinkChildNode(), WRL2SHAPE::unlinkChildNode(), and WRL2NODE::~WRL2NODE().

◆ unlinkRefNode()

void WRL2NODE::unlinkRefNode ( const WRL2NODE 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.

Reimplemented in WRL2APPEARANCE, WRL2FACESET, WRL2LINESET, WRL2POINTSET, and WRL2SHAPE.

Definition at line 425 of file vrml2_node.cpp.

426{
427 std::list< WRL2NODE* >::iterator sL = m_Refs.begin();
428 std::list< WRL2NODE* >::iterator eL = m_Refs.end();
429
430 while( sL != eL )
431 {
432 if( *sL == aNode )
433 {
434 m_Refs.erase( sL );
435 return;
436 }
437
438 ++sL;
439 }
440}

References WRL2NODE::m_Refs.

Referenced by WRL2APPEARANCE::unlinkRefNode(), WRL2FACESET::unlinkRefNode(), WRL2LINESET::unlinkRefNode(), WRL2POINTSET::unlinkRefNode(), and WRL2SHAPE::unlinkRefNode().

Member Data Documentation

◆ bboxCenter

WRLVEC3F WRL2TRANSFORM::bboxCenter
private

Definition at line 60 of file vrml2_transform.h.

Referenced by Read().

◆ bboxSize

WRLVEC3F WRL2TRANSFORM::bboxSize
private

Definition at line 61 of file vrml2_transform.h.

Referenced by Read().

◆ center

WRLVEC3F WRL2TRANSFORM::center
private

Definition at line 55 of file vrml2_transform.h.

Referenced by Read(), 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

◆ rotation

WRLROTATION WRL2TRANSFORM::rotation
private

Definition at line 58 of file vrml2_transform.h.

Referenced by Read(), and TranslateToSG().

◆ scale

WRLVEC3F WRL2TRANSFORM::scale
private

Definition at line 56 of file vrml2_transform.h.

Referenced by Read(), and TranslateToSG().

◆ scaleOrientation

WRLROTATION WRL2TRANSFORM::scaleOrientation
private

Definition at line 59 of file vrml2_transform.h.

Referenced by Read(), and TranslateToSG().

◆ translation

WRLVEC3F WRL2TRANSFORM::translation
private

Definition at line 57 of file vrml2_transform.h.

Referenced by Read(), and TranslateToSG().


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