KiCad PCB EDA Suite
WRL2APPEARANCE Class Reference

#include <vrml2_appearance.h>

Inheritance diagram for WRL2APPEARANCE:
WRL2NODE

Public Member Functions

 WRL2APPEARANCE ()
 
 WRL2APPEARANCE (WRL2NODE *aParent)
 
virtual ~WRL2APPEARANCE ()
 
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 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...
 
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)
 Return true if the node type is a material description class. 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...
 

Private Attributes

WRL2NODEmaterial
 
WRL2NODEtexture
 
WRL2NODEtextureTransform
 

Detailed Description

Definition at line 38 of file vrml2_appearance.h.

Constructor & Destructor Documentation

◆ WRL2APPEARANCE() [1/2]

WRL2APPEARANCE::WRL2APPEARANCE ( )

Definition at line 35 of file vrml2_appearance.cpp.

35 : WRL2NODE()
36{
37 material = nullptr;
38 texture = nullptr;
39 textureTransform = nullptr;
41}
WRL2NODE * textureTransform
WRL2NODE * material
WRL2NODE * texture
WRL2NODES m_Type
Definition: vrml2_node.h:170

References WRL2NODE::m_Type, material, texture, textureTransform, and WRL2_APPEARANCE.

◆ WRL2APPEARANCE() [2/2]

WRL2APPEARANCE::WRL2APPEARANCE ( WRL2NODE aParent)

Definition at line 44 of file vrml2_appearance.cpp.

44 : WRL2NODE()
45{
46 material = nullptr;
47 texture = nullptr;
48 textureTransform = nullptr;
50 m_Parent = aParent;
51
52 if( nullptr != m_Parent )
53 m_Parent->AddChildNode( this );
54}
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, material, texture, textureTransform, and WRL2_APPEARANCE.

◆ ~WRL2APPEARANCE()

WRL2APPEARANCE::~WRL2APPEARANCE ( )
virtual

Definition at line 57 of file vrml2_appearance.cpp.

58{
59 wxLogTrace( traceVrmlPlugin,
60 wxT( " * [INFO] Destroying Appearance node with %zu children, %zu"
61 "references, and %zu back pointers." ),
62 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
63}
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 WRL2APPEARANCE::AddChildNode ( WRL2NODE aNode)
overridevirtual

Reimplemented from WRL2NODE.

Definition at line 159 of file vrml2_appearance.cpp.

160{
161 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
162
163 WRL2NODES type = aNode->GetNodeType();
164
165 if( !checkNodeType( type ) )
166 {
167 wxLogTrace( traceVrmlPlugin,
168 wxT( "%s:%s:%d\n"
169 " * [INFO] bad file format; unexpected child node '%s'." ),
170 __FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
171
172 return false;
173 }
174
175 if( WRL2NODES::WRL2_MATERIAL == type )
176 {
177 if( nullptr != material )
178 {
179 wxLogTrace( traceVrmlPlugin,
180 wxT( "%s:%s:%d\n"
181 " * [INFO] bad file format; multiple material nodes." ),
182 __FILE__, __FUNCTION__, __LINE__ );
183
184 return false;
185 }
186
187 material = aNode;
188 return WRL2NODE::AddChildNode( aNode );
189 }
190
192 {
193 if( nullptr != textureTransform )
194 {
195 wxLogTrace( traceVrmlPlugin,
196 wxT( "%s:%s:%d\n"
197 " * [INFO] bad file format; multiple textureTransform nodes." ),
198 __FILE__, __FUNCTION__, __LINE__ );
199
200 return false;
201 }
202
203 textureTransform = aNode;
204 return WRL2NODE::AddChildNode( aNode );
205 }
206
207 if( nullptr != texture )
208 {
209 wxLogTrace( traceVrmlPlugin,
210 wxT( "%s:%s:%d\n"
211 " * [INFO] bad file format; multiple texture nodes." ),
212 __FILE__, __FUNCTION__, __LINE__ );
213
214 return false;
215 }
216
217 texture = aNode;
218 return WRL2NODE::AddChildNode( aNode );
219}
bool checkNodeType(WRL2NODES aType)
Return true if the node type is a material description class.
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_TEXTURETRANSFORM

References WRL2NODE::AddChildNode(), checkNodeType(), WRL2NODE::GetNodeType(), WRL2NODE::GetNodeTypeName(), material, texture, textureTransform, traceVrmlPlugin, WRL2_MATERIAL, and WRL2_TEXTURETRANSFORM.

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

Reimplemented from WRL2NODE.

Definition at line 96 of file vrml2_appearance.cpp.

97{
98 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
99
100 WRL2NODES type = aNode->GetNodeType();
101
102 if( !checkNodeType( type ) )
103 {
104 wxLogTrace( traceVrmlPlugin,
105 wxT( "%s:%s:%d\n"
106 " * [INFO] bad file format; unexpected child node '%s'." ),
107 __FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
108
109 return false;
110 }
111
112 if( WRL2NODES::WRL2_MATERIAL == type )
113 {
114 if( nullptr != material )
115 {
116 wxLogTrace( traceVrmlPlugin,
117 wxT( "%s:%s:%d\n"
118 " * [INFO] bad file format; multiple material nodes." ),
119 __FILE__, __FUNCTION__, __LINE__ );
120
121 return false;
122 }
123
124 material = aNode;
125 return WRL2NODE::AddRefNode( aNode );
126 }
127
129 {
130 if( nullptr != textureTransform )
131 {
132 wxLogTrace( traceVrmlPlugin,
133 wxT( "%s:%s:%d\n"
134 " * [INFO] bad file format; multiple textureTransform nodes." ),
135 __FILE__, __FUNCTION__, __LINE__ );
136
137 return false;
138 }
139
140 textureTransform = aNode;
141 return WRL2NODE::AddRefNode( aNode );
142 }
143
144 if( nullptr != texture )
145 {
146 wxLogTrace( traceVrmlPlugin,
147 wxT( "%s:%s:%d\n"
148 " * [INFO] bad file format; multiple texture nodes." ),
149 __FILE__, __FUNCTION__, __LINE__ );
150
151 return false;
152 }
153
154 texture = aNode;
155 return WRL2NODE::AddRefNode( aNode );
156}
virtual bool AddRefNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:383

References WRL2NODE::AddRefNode(), checkNodeType(), WRL2NODE::GetNodeType(), WRL2NODE::GetNodeTypeName(), material, texture, textureTransform, traceVrmlPlugin, WRL2_MATERIAL, and WRL2_TEXTURETRANSFORM.

◆ checkNodeType()

bool WRL2APPEARANCE::checkNodeType ( WRL2NODES  aType)
private

Return true if the node type is a material description class.

Definition at line 66 of file vrml2_appearance.cpp.

67{
68 switch( aType )
69 {
75 break;
76
77 default:
78 return false;
79 break;
80 }
81
82 return true;
83}
@ WRL2_MOVIETEXTURE
@ WRL2_PIXELTEXTURE
@ WRL2_IMAGETEXTURE

References WRL2_IMAGETEXTURE, WRL2_MATERIAL, WRL2_MOVIETEXTURE, WRL2_PIXELTEXTURE, and WRL2_TEXTURETRANSFORM.

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

◆ GetParent()

WRL2NODE * WRL2NODE::GetParent ( void  ) const
inherited

◆ isDangling()

bool WRL2APPEARANCE::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 86 of file vrml2_appearance.cpp.

87{
88 // this node is dangling unless it has a parent of type WRL2_SHAPE
89 if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_SHAPE )
90 return true;
91
92 return false;
93}

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

◆ Read()

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

Implements WRL2NODE.

Definition at line 222 of file vrml2_appearance.cpp.

223{
224 wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
225
226 char tok = proc.Peek();
227
228 if( proc.eof() )
229 {
230 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
231 " * [INFO] bad file format; unexpected eof %s." ),
232 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
233
234 return false;
235 }
236
237 if( '{' != tok )
238 {
239 wxLogTrace( traceVrmlPlugin,
240 wxT( "%s:%s:%d\n"
241 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
242 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
243
244 return false;
245 }
246
247 proc.Pop();
248 std::string glob;
249
250 while( true )
251 {
252 if( proc.Peek() == '}' )
253 {
254 proc.Pop();
255 break;
256 }
257
258 if( !proc.ReadName( glob ) )
259 {
260 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
261 "%s" ),
262 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
263
264 return false;
265 }
266
267 // expecting one of:
268 // material
269 // texture
270 // textureTransform
271
272 if( !glob.compare( "material" ) )
273 {
274 if( !aTopNode->ReadNode( proc, this, nullptr ) )
275 {
276 wxLogTrace( traceVrmlPlugin,
277 wxT( "%s:%s:%d\n"
278 " * [INFO] could not read material information." ),
279 __FILE__, __FUNCTION__, __LINE__ );
280
281 return false;
282 }
283 }
284 else if( !glob.compare( "texture" ) )
285 {
286 if( !aTopNode->ReadNode( proc, this, nullptr ) )
287 {
288 wxLogTrace( traceVrmlPlugin,
289 wxT( "%s:%s:%d\n"
290 " * [INFO] could not read texture information." ),
291 __FILE__, __FUNCTION__, __LINE__ );
292
293 return false;
294 }
295 }
296 else if( !glob.compare( "textureTransform" ) )
297 {
298 if( !aTopNode->ReadNode( proc, this, nullptr ) )
299 {
300 wxLogTrace( traceVrmlPlugin,
301 wxT( "%s:%s:%d\n"
302 " * [INFO] could not read textureTransform information." ),
303 __FILE__, __FUNCTION__, __LINE__ );
304
305 return false;
306 }
307 }
308 else
309 {
310 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
311 " * [INFO] bad Appearance %s.\n"
312 " * [INFO] file: '%s'" ),
313 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
314 proc.GetFileName() );
315
316 return false;
317 }
318 } // while( true ) -- reading contents of Appearance{}
319
320 return true;
321}
bool ReadNode(WRLPROC &proc, WRL2NODE *aParent, WRL2NODE **aNode)
Definition: vrml2_base.cpp:277
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 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(), WRLPROC::Pop(), WRLPROC::ReadName(), WRL2BASE::ReadNode(), and traceVrmlPlugin.

Referenced by WRL2BASE::readAppearance().

◆ 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 * WRL2APPEARANCE::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 324 of file vrml2_appearance.cpp.

325{
326 if( nullptr == material && nullptr == texture )
327 return nullptr;
328
329 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
330
331 wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_SHAPE ), nullptr,
332 wxString::Format( wxT( " * [BUG] Appearance does not have a Shape parent "
333 "(parent ID: %d)." ), ptype ) );
334
335 wxLogTrace( traceVrmlPlugin,
336 wxT( " * [INFO] Translating Appearance node with %zu children, %zu"
337 "references, and %zu back pointers." ),
338 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
339
340 if( m_sgNode )
341 {
342 if( nullptr != aParent )
343 {
344 if( nullptr == S3D::GetSGNodeParent( m_sgNode )
345 && !S3D::AddSGNodeChild( aParent, m_sgNode ) )
346 {
347 return nullptr;
348 }
349 else if( aParent != S3D::GetSGNodeParent( m_sgNode )
350 && !S3D::AddSGNodeRef( aParent, m_sgNode ) )
351 {
352 return nullptr;
353 }
354 }
355
356 return m_sgNode;
357 }
358
359 if( nullptr != texture )
360 {
361 // use a default gray appearance
362 IFSG_APPEARANCE matNode( aParent );
363 matNode.SetEmissive( 0.0f, 0.0f, 0.0f );
364 matNode.SetSpecular( 0.65f, 0.65f, 0.65f );
365 matNode.SetDiffuse( 0.65f, 0.65f, 0.65f );
366
367 // default ambient
368 matNode.SetShininess( 0.2f );
369 matNode.SetTransparency( 0.0f );
370 m_sgNode = matNode.GetRawPtr();
371
372 return m_sgNode;
373 }
374
375 m_sgNode = material->TranslateToSG( aParent );
376
377 return m_sgNode;
378}
SGNODE * m_sgNode
Definition: vrml2_node.h:178
virtual SGNODE * TranslateToSG(SGNODE *aParent)=0
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
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

References S3D::AddSGNodeChild(), S3D::AddSGNodeRef(), Format(), IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), S3D::GetSGNodeType(), WRL2NODE::m_BackPointers, WRL2NODE::m_Children, WRL2NODE::m_Refs, WRL2NODE::m_sgNode, material, IFSG_APPEARANCE::SetDiffuse(), IFSG_APPEARANCE::SetEmissive(), IFSG_APPEARANCE::SetShininess(), IFSG_APPEARANCE::SetSpecular(), IFSG_APPEARANCE::SetTransparency(), S3D::SGTYPE_SHAPE, texture, traceVrmlPlugin, and WRL2NODE::TranslateToSG().

◆ unlinkChildNode()

void WRL2APPEARANCE::unlinkChildNode ( const WRL2NODE aNode)
overrideprivatevirtual

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 381 of file vrml2_appearance.cpp.

382{
383 if( nullptr == aNode )
384 return;
385
386 if( aNode->GetParent() == this )
387 {
388 if( aNode == material )
389 material = nullptr;
390 else if( aNode == texture )
391 texture = nullptr;
392 else if( aNode == textureTransform )
393 textureTransform = nullptr;
394
395 }
396
398}
WRL2NODE * GetParent(void) const
Definition: vrml2_node.cpp:210

References WRL2NODE::GetParent(), material, texture, textureTransform, and WRL2NODE::unlinkChildNode().

◆ unlinkRefNode()

void WRL2APPEARANCE::unlinkRefNode ( const WRL2NODE aNode)
overrideprivatevirtual

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 401 of file vrml2_appearance.cpp.

402{
403 if( nullptr == aNode )
404 return;
405
406 if( aNode->GetParent() != this )
407 {
408 if( aNode == material )
409 material = nullptr;
410 else if( aNode == texture )
411 texture = nullptr;
412 else if( aNode == textureTransform )
413 textureTransform = nullptr;
414 }
415
417}
virtual void unlinkRefNode(const WRL2NODE *aNode)
Remove pointers to a referenced node.
Definition: vrml2_node.cpp:425

References WRL2NODE::GetParent(), material, texture, textureTransform, and WRL2NODE::unlinkRefNode().

Member Data Documentation

◆ 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

◆ material

WRL2NODE* WRL2APPEARANCE::material
private

◆ texture

WRL2NODE* WRL2APPEARANCE::texture
private

◆ textureTransform

WRL2NODE* WRL2APPEARANCE::textureTransform
private

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