KiCad PCB EDA Suite
WRL2APPEARANCE Class Reference

WRL2APPEARANCE. More...

#include <vrml2_appearance.h>

Inheritance diagram for WRL2APPEARANCE:
WRL2NODE

Public Member Functions

bool isDangling (void) override
 Function isDangling 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. More...
 
 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
 Function TranslateToSG produces a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library. More...
 
WRL2NODES getNodeTypeID (const std::string &aNodeName)
 Function getNodeTypeID returns the ID based on the given aNodeName or WRL2_INVALID (WRL2_END) if no such node name exists. More...
 
void addNodeRef (WRL2NODE *aNode)
 Function addNodeRef adds a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (WRL2NODE *aNode)
 Function delNodeRef removes a pointer to a node which references, but does not own, this node. More...
 
WRL2NODES GetNodeType (void) const
 Function GetNodeType returns the type of this node instance. More...
 
WRL2NODEGetParent (void) const
 Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
virtual bool SetParent (WRL2NODE *aParent, bool doUnlink=true)
 Function SetParent sets 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)
 Function FindNode searches the tree of linked nodes and returns a reference to the first node found with the given name. More...
 
std::string GetError (void)
 

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)
 Function checkNodeType returns true if the node type is a material description class. More...
 
void unlinkChildNode (const WRL2NODE *aNode) override
 Function unlinkChild removes references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
void unlinkRefNode (const WRL2NODE *aNode) override
 Function unlinkRef removes 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...
 

Private Attributes

WRL2NODEmaterial
 
WRL2NODEtexture
 
WRL2NODEtextureTransform
 

Detailed Description

WRL2APPEARANCE.

Definition at line 40 of file vrml2_appearance.h.

Constructor & Destructor Documentation

◆ WRL2APPEARANCE() [1/2]

WRL2APPEARANCE::WRL2APPEARANCE ( )

Definition at line 34 of file vrml2_appearance.cpp.

34  : WRL2NODE()
35 {
36  material = NULL;
37  texture = NULL;
40  return;
41 }
WRL2NODE * material
WRL2NODES m_Type
Definition: vrml2_node.h:62
#define NULL
WRL2NODE * texture
WRL2NODE * textureTransform

References WRL2NODE::m_Type, material, NULL, 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 = NULL;
47  texture = NULL;
50  m_Parent = aParent;
51 
52  if( NULL != m_Parent )
53  m_Parent->AddChildNode( this );
54 
55  return;
56 }
WRL2NODE * material
WRL2NODES m_Type
Definition: vrml2_node.h:62
#define NULL
WRL2NODE * m_Parent
Definition: vrml2_node.h:61
WRL2NODE * texture
WRL2NODE * textureTransform
virtual bool AddChildNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:377

References WRL2NODE::AddChildNode(), WRL2NODE::m_Parent, WRL2NODE::m_Type, material, NULL, texture, textureTransform, and WRL2_APPEARANCE.

◆ ~WRL2APPEARANCE()

WRL2APPEARANCE::~WRL2APPEARANCE ( )
virtual

Definition at line 59 of file vrml2_appearance.cpp.

60 {
61  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 2 )
62  do {
63  std::ostringstream ostr;
64  ostr << " * [INFO] Destroying Appearance with " << m_Children.size();
65  ostr << " children, " << m_Refs.size() << " references and ";
66  ostr << m_BackPointers.size() << " backpointers";
67  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
68  } while( 0 );
69  #endif
70 }
std::list< WRL2NODE * > m_Children
Definition: vrml2_node.h:66
#define MASK_VRML
Definition: wrltypes.h:37
std::list< WRL2NODE * > m_Refs
Definition: vrml2_node.h:67
std::list< WRL2NODE * > m_BackPointers
Definition: vrml2_node.h:65

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

Member Function Documentation

◆ AddChildNode()

bool WRL2APPEARANCE::AddChildNode ( WRL2NODE aNode)
overridevirtual

Reimplemented from WRL2NODE.

Definition at line 196 of file vrml2_appearance.cpp.

197 {
198  if( NULL == aNode )
199  {
200  #ifdef DEBUG_VRML2
201  do {
202  std::ostringstream ostr;
203  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
204  ostr << " * [BUG] NULL passed for aNode";
205  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
206  } while( 0 );
207  #endif
208 
209  return false;
210  }
211 
212  WRL2NODES type = aNode->GetNodeType();
213 
214  if( !checkNodeType( type ) )
215  {
216  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
217  do {
218  std::ostringstream ostr;
219  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
220  ostr << " * [INFO] bad file format; unexpected child node '";
221  ostr << aNode->GetNodeTypeName( type ) << "'";
222  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
223  } while( 0 );
224  #endif
225 
226  return false;
227  }
228 
229  if( WRL2_MATERIAL == type )
230  {
231  if( NULL != material )
232  {
233  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
234  do {
235  std::ostringstream ostr;
236  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
237  ostr << " * [INFO] bad file format; multiple material nodes";
238  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
239  } while( 0 );
240  #endif
241 
242  return false;
243  }
244 
245  material = aNode;
246  return WRL2NODE::AddChildNode( aNode );
247  }
248 
249  if( WRL2_TEXTURETRANSFORM == type )
250  {
251  if( NULL != textureTransform )
252  {
253  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
254  do {
255  std::ostringstream ostr;
256  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
257  ostr << " * [INFO] bad file format; multiple textureTransform nodes";
258  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
259  } while( 0 );
260  #endif
261 
262  return false;
263  }
264 
265  textureTransform = aNode;
266  return WRL2NODE::AddChildNode( aNode );
267  }
268 
269  if( NULL != texture )
270  {
271  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
272  do {
273  std::ostringstream ostr;
274  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
275  ostr << " * [INFO] bad file format; multiple texture nodes";
276  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
277  } while( 0 );
278  #endif
279 
280  return false;
281  }
282 
283  texture = aNode;
284  return WRL2NODE::AddChildNode( aNode );
285 }
WRL2NODE * material
bool checkNodeType(WRL2NODES aType)
Function checkNodeType returns true if the node type is a material description class.
#define MASK_VRML
Definition: wrltypes.h:37
#define NULL
WRL2NODES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: vrml2_node.cpp:212
WRL2NODE * texture
const char * GetNodeTypeName(WRL2NODES aNodeType) const
Definition: vrml2_node.cpp:295
WRL2NODE * textureTransform
virtual bool AddChildNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:377
WRL2NODES
Definition: wrltypes.h:121

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

◆ addNodeRef()

void WRL2NODE::addNodeRef ( WRL2NODE aNode)
inherited

Function addNodeRef adds 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 170 of file vrml2_node.cpp.

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

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

105 {
106  if( NULL == aNode )
107  {
108  #ifdef DEBUG_VRML2
109  do {
110  std::ostringstream ostr;
111  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
112  ostr << " * [BUG] NULL passed for aNode";
113  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
114  } while( 0 );
115  #endif
116 
117  return false;
118  }
119 
120  WRL2NODES type = aNode->GetNodeType();
121 
122  if( !checkNodeType( type ) )
123  {
124  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
125  do {
126  std::ostringstream ostr;
127  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
128  ostr << " * [INFO] bad file format; unexpected child node '";
129  ostr << aNode->GetNodeTypeName( type ) << "'";
130  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
131  } while( 0 );
132  #endif
133 
134  return false;
135  }
136 
137  if( WRL2_MATERIAL == type )
138  {
139  if( NULL != material )
140  {
141  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
142  do {
143  std::ostringstream ostr;
144  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
145  ostr << " * [INFO] bad file format; multiple material nodes";
146  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
147  } while( 0 );
148  #endif
149 
150  return false;
151  }
152 
153  material = aNode;
154  return WRL2NODE::AddRefNode( aNode );
155  }
156 
157  if( WRL2_TEXTURETRANSFORM == type )
158  {
159  if( NULL != textureTransform )
160  {
161  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
162  do {
163  std::ostringstream ostr;
164  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
165  ostr << " * [INFO] bad file format; multiple textureTransform nodes";
166  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
167  } while( 0 );
168  #endif
169 
170  return false;
171  }
172 
173  textureTransform = aNode;
174  return WRL2NODE::AddRefNode( aNode );
175  }
176 
177  if( NULL != texture )
178  {
179  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
180  do {
181  std::ostringstream ostr;
182  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
183  ostr << " * [INFO] bad file format; multiple texture nodes";
184  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
185  } while( 0 );
186  #endif
187 
188  return false;
189  }
190 
191  texture = aNode;
192  return WRL2NODE::AddRefNode( aNode );
193 }
WRL2NODE * material
bool checkNodeType(WRL2NODES aType)
Function checkNodeType returns true if the node type is a material description class.
#define MASK_VRML
Definition: wrltypes.h:37
#define NULL
WRL2NODES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: vrml2_node.cpp:212
WRL2NODE * texture
const char * GetNodeTypeName(WRL2NODES aNodeType) const
Definition: vrml2_node.cpp:295
WRL2NODE * textureTransform
WRL2NODES
Definition: wrltypes.h:121
virtual bool AddRefNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:416

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

◆ checkNodeType()

bool WRL2APPEARANCE::checkNodeType ( WRL2NODES  aType)
private

Function checkNodeType returns true if the node type is a material description class.

Definition at line 73 of file vrml2_appearance.cpp.

74 {
75  switch( aType )
76  {
77  case WRL2_MATERIAL:
78  case WRL2_IMAGETEXTURE:
79  case WRL2_PIXELTEXTURE:
80  case WRL2_MOVIETEXTURE:
82  break;
83 
84  default:
85  return false;
86  break;
87  }
88 
89  return true;
90 }

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

Referenced by AddChildNode(), and AddRefNode().

◆ delNodeRef()

void WRL2NODE::delNodeRef ( WRL2NODE aNode)
inherited

Function delNodeRef removes 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 188 of file vrml2_node.cpp.

189 {
190  std::list< WRL2NODE* >::iterator np =
191  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
192 
193  if( np != m_BackPointers.end() )
194  {
195  m_BackPointers.erase( np );
196  return;
197  }
198 
199  #ifdef DEBUG_VRML2
200  do {
201  std::ostringstream ostr;
202  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
203  ostr << " * [BUG] delNodeRef() did not find its target";
204  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
205  } while( 0 );
206  #endif
207 
208  return;
209 }
#define MASK_VRML
Definition: wrltypes.h:37
std::list< WRL2NODE * > m_BackPointers
Definition: vrml2_node.h:65

References WRL2NODE::m_BackPointers, and MASK_VRML.

◆ FindNode()

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

Function FindNode searches 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, otherwise NULL

Definition at line 327 of file vrml2_node.cpp.

328 {
329  if( aNodeName.empty() )
330  return NULL;
331 
332  if( !m_Name.compare( aNodeName ) )
333  return this;
334 
335  std::list< WRL2NODE* >::iterator sLA = m_Children.begin();
336  std::list< WRL2NODE* >::iterator eLA = m_Children.end();
337 
338  WRL2NODE* psg = NULL;
339 
340  while( sLA != eLA )
341  {
342  if( *sLA != aCaller )
343  {
344  psg = (*sLA)->FindNode( aNodeName, this );
345 
346  if( NULL != psg)
347  return psg;
348 
349  }
350  ++sLA;
351  }
352 
353  if( NULL != m_Parent && aCaller != m_Parent )
354  return m_Parent->FindNode( aNodeName, this );
355 
356  return NULL;
357 }
WRL2NODE represents the base class of all VRML2 nodes.
Definition: vrml2_node.h:58
std::list< WRL2NODE * > m_Children
Definition: vrml2_node.h:66
std::string m_Name
Definition: vrml2_node.h:63
#define NULL
WRL2NODE * m_Parent
Definition: vrml2_node.h:61
virtual WRL2NODE * FindNode(const std::string &aNodeName, const WRL2NODE *aCaller)
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
Definition: vrml2_node.cpp:327

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

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

◆ GetError()

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

Definition at line 321 of file vrml2_node.cpp.

322 {
323  return m_error;
324 }
std::string m_error
Definition: vrml2_node.h:68

References WRL2NODE::m_error.

◆ GetName()

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

Reimplemented in WRL2BASE.

Definition at line 224 of file vrml2_node.cpp.

225 {
226  return m_Name;
227 }
std::string m_Name
Definition: vrml2_node.h:63

References WRL2NODE::m_Name.

◆ GetNodeType()

◆ getNodeTypeID()

WRL2NODES WRL2NODE::getNodeTypeID ( const std::string &  aNodeName)
inherited

Function getNodeTypeID returns the ID based on the given aNodeName or WRL2_INVALID (WRL2_END) if no such node name exists.

Definition at line 310 of file vrml2_node.cpp.

311 {
312  NODEMAP::iterator it = nodenames.find( aNodeName );
313 
314  if( nodenames.end() != it )
315  return it->second;
316 
317  return WRL2_INVALID;
318 }
static NODEMAP nodenames
Definition: vrml2_node.cpp:42

References nodenames, and WRL2_INVALID.

Referenced by WRL2BASE::ReadNode().

◆ GetNodeTypeName()

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

Definition at line 295 of file vrml2_node.cpp.

296 {
297  if( aNodeType < WRL2_BASE || aNodeType >= WRL2_END )
298  return "*INVALID_TYPE*";
299 
300  if( aNodeType == WRL2_BASE )
301  return "*VIRTUAL_BASE*";
302 
303  NODEMAP::iterator it = nodenames.begin();
304  advance( it, (aNodeType - WRL2_BEGIN) );
305 
306  return it->first.c_str();
307 }
static NODEMAP nodenames
Definition: vrml2_node.cpp:42

References nodenames, WRL2_BASE, WRL2_BEGIN, and WRL2_END.

Referenced by WRL2SHAPE::AddChildNode(), AddChildNode(), WRL2POINTSET::AddChildNode(), WRL2LINESET::AddChildNode(), WRL2FACESET::AddChildNode(), WRL2SHAPE::AddRefNode(), AddRefNode(), WRL2POINTSET::AddRefNode(), WRL2LINESET::AddRefNode(), WRL2FACESET::AddRefNode(), and WRL2BASE::implementUse().

◆ GetParent()

WRL2NODE * WRL2NODE::GetParent ( void  ) const
inherited

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

top level transform)

Definition at line 218 of file vrml2_node.cpp.

219 {
220  return m_Parent;
221 }
WRL2NODE * m_Parent
Definition: vrml2_node.h:61

References WRL2NODE::m_Parent.

Referenced by WRL2NODE::AddChildNode(), WRL2SWITCH::AddRefNode(), WRL2TRANSFORM::AddRefNode(), unlinkChildNode(), WRL2POINTSET::unlinkChildNode(), WRL2LINESET::unlinkChildNode(), WRL2FACESET::unlinkChildNode(), unlinkRefNode(), WRL2POINTSET::unlinkRefNode(), WRL2LINESET::unlinkRefNode(), and WRL2FACESET::unlinkRefNode().

◆ isDangling()

bool WRL2APPEARANCE::isDangling ( void  )
overridevirtual

Function isDangling 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.

This function is used to determine whether an object should be moved to a different parent during the VRML to SG* translation.

Implements WRL2NODE.

Definition at line 93 of file vrml2_appearance.cpp.

94 {
95  // this node is dangling unless it has a parent of type WRL2_SHAPE
96 
97  if( NULL == m_Parent || m_Parent->GetNodeType() != WRL2_SHAPE )
98  return true;
99 
100  return false;
101 }
#define NULL
WRL2NODE * m_Parent
Definition: vrml2_node.h:61
WRL2NODES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: vrml2_node.cpp:212

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

◆ Read()

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

Implements WRL2NODE.

Definition at line 288 of file vrml2_appearance.cpp.

289 {
290  if( NULL == aTopNode )
291  {
292  #ifdef DEBUG_VRML2
293  do {
294  std::ostringstream ostr;
295  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
296  ostr << " * [BUG] aTopNode is NULL";
297  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
298  } while( 0 );
299  #endif
300 
301  return false;
302  }
303 
304  size_t line, column;
305  proc.GetFilePosData( line, column );
306 
307  char tok = proc.Peek();
308 
309  if( proc.eof() )
310  {
311  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
312  do {
313  std::ostringstream ostr;
314  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
315  ostr << " * [INFO] bad file format; unexpected eof at line ";
316  ostr << line << ", column " << column;
317  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
318  } while( 0 );
319  #endif
320 
321  return false;
322  }
323 
324  if( '{' != tok )
325  {
326  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
327  do {
328  std::ostringstream ostr;
329  ostr << proc.GetError() << "\n";
330  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
331  ostr << " * [INFO] bad file format; expecting '{' but got '" << tok;
332  ostr << "' at line " << line << ", column " << column;
333  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
334  } while( 0 );
335  #endif
336 
337  return false;
338  }
339 
340  proc.Pop();
341  std::string glob;
342 
343  while( true )
344  {
345  if( proc.Peek() == '}' )
346  {
347  proc.Pop();
348  break;
349  }
350 
351  if( !proc.ReadName( glob ) )
352  {
353  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
354  do {
355  std::ostringstream ostr;
356  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
357  ostr << proc.GetError();
358  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
359  } while( 0 );
360  #endif
361 
362  return false;
363  }
364 
365  // expecting one of:
366  // material
367  // texture
368  // textureTransform
369 
370  proc.GetFilePosData( line, column );
371 
372  if( !glob.compare( "material" ) )
373  {
374  if( !aTopNode->ReadNode( proc, this, NULL ) )
375  {
376  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
377  do {
378  std::ostringstream ostr;
379  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
380  ostr << " * [INFO] could not read material information";
381  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
382  } while( 0 );
383  #endif
384 
385  return false;
386  }
387  }
388  else if( !glob.compare( "texture" ) )
389  {
390  if( !aTopNode->ReadNode( proc, this, NULL ) )
391  {
392  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
393  do {
394  std::ostringstream ostr;
395  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
396  ostr << " * [INFO] could not read texture information";
397  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
398  } while( 0 );
399  #endif
400 
401  return false;
402  }
403  }
404  else if( !glob.compare( "textureTransform" ) )
405  {
406  if( !aTopNode->ReadNode( proc, this, NULL ) )
407  {
408  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
409  do {
410  std::ostringstream ostr;
411  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
412  ostr << " * [INFO] could not read textureTransform information";
413  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
414  } while( 0 );
415  #endif
416 
417  return false;
418  }
419  }
420  else
421  {
422  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
423  do {
424  std::ostringstream ostr;
425  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
426  ostr << " * [INFO] bad Appearance at line " << line << ", column ";
427  ostr << column << "\n";
428  ostr << " * [INFO] file: '" << proc.GetFileName() << "'";
429  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
430  } while( 0 );
431  #endif
432 
433  return false;
434  }
435  } // while( true ) -- reading contents of Appearance{}
436 
437  return true;
438 }
void Pop(void)
Definition: wrlproc.cpp:2007
bool GetFilePosData(size_t &line, size_t &column)
Definition: wrlproc.cpp:1951
#define MASK_VRML
Definition: wrltypes.h:37
bool ReadNode(WRLPROC &proc, WRL2NODE *aParent, WRL2NODE **aNode)
Definition: vrml2_base.cpp:371
#define NULL
char Peek(void)
Definition: wrlproc.cpp:1979
std::string GetFileName(void)
Definition: wrlproc.cpp:1967
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:280
std::string GetError(void)
Definition: wrlproc.cpp:1945
bool eof(void)
Definition: wrlproc.cpp:1939

References WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFileName(), WRLPROC::GetFilePosData(), MASK_VRML, NULL, WRLPROC::Peek(), WRLPROC::Pop(), WRLPROC::ReadName(), and WRL2BASE::ReadNode().

Referenced by WRL2BASE::readAppearance().

◆ SetName()

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

Reimplemented in WRL2BASE.

Definition at line 230 of file vrml2_node.cpp.

231 {
232  if( aName.empty() )
233  return false;
234 
235  std::set< std::string >::iterator item = badNames.find( aName );
236 
237  if( item != badNames.end() )
238  {
239  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
240  do {
241  std::ostringstream ostr;
242  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
243  ostr << " * [INFO] invalid node name '" << *item << "' (matches restricted word)";
244  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
245  } while( 0 );
246  #endif
247 
248  return false;
249  }
250 
251 
252  if( isdigit( aName[0] ) )
253  {
254  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
255  do {
256  std::ostringstream ostr;
257  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
258  ostr << " * [INFO] invalid node name '" << *item << "' (begins with digit)";
259  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
260  } while( 0 );
261  #endif
262 
263  return false;
264  }
265 
266  // The characters '+' and '-' are not allowed in names as per the VRML2 specification;
267  // however many parsers accept them and many bad generators use them so the rules
268  // have been relaxed here.
269  // #define BAD_CHARS1 "\"\'#+,-.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F"
270  #define BAD_CHARS1 "\"\'#,.\\[]{}\x00\x01\x02\x03\x04\x05\x06\x09\x0A\x0B\x0C\x0D\x0E\x0F"
271  #define BAD_CHARS2 "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
272 
273  if( std::string::npos != aName.find_first_of( BAD_CHARS1 )
274  || std::string::npos != aName.find_first_of( BAD_CHARS2 ) )
275  {
276  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 1 )
277  do {
278  std::ostringstream ostr;
279  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
280  ostr << " * [INFO] invalid node name '" << aName;
281  ostr << "' (contains invalid character)";
282  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
283  } while( 0 );
284  #endif
285 
286  return false;
287  }
288 
289  m_Name = aName;
290 
291  return true;
292 }
#define BAD_CHARS1
#define BAD_CHARS2
std::string m_Name
Definition: vrml2_node.h:63
#define MASK_VRML
Definition: wrltypes.h:37
static std::set< std::string > badNames
Definition: vrml2_node.cpp:38

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

Referenced by WRL2BASE::implementDef().

◆ SetParent()

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

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

Reimplemented in WRL2BASE.

Definition at line 360 of file vrml2_node.cpp.

361 {
362  if( aParent == m_Parent )
363  return true;
364 
365  if( NULL != m_Parent && doUnlink )
366  m_Parent->unlinkChildNode( this );
367 
368  m_Parent = aParent;
369 
370  if( NULL != m_Parent )
371  m_Parent->AddChildNode( this );
372 
373  return true;
374 }
#define NULL
WRL2NODE * m_Parent
Definition: vrml2_node.h:61
virtual bool AddChildNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:377
virtual void unlinkChildNode(const WRL2NODE *aNode)
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
Definition: vrml2_node.cpp:464

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

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

◆ TranslateToSG()

SGNODE * WRL2APPEARANCE::TranslateToSG ( SGNODE aParent)
overridevirtual

Function TranslateToSG produces 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 441 of file vrml2_appearance.cpp.

442 {
443  if( NULL == material && NULL == texture )
444  return NULL;
445 
446  S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
447 
448  if( NULL != aParent && ptype != S3D::SGTYPE_SHAPE )
449  {
450  #ifdef DEBUG_VRML2
451  do {
452  std::ostringstream ostr;
453  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
454  ostr << " * [BUG] Appearance does not have a Shape parent (parent ID: ";
455  ostr << ptype << ")";
456  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
457  } while( 0 );
458  #endif
459 
460  return NULL;
461  }
462 
463  #if defined( DEBUG_VRML2 ) && ( DEBUG_VRML2 > 2 )
464  do {
465  std::ostringstream ostr;
466  ostr << " * [INFO] Translating Appearance with " << m_Children.size();
467  ostr << " children, " << m_Refs.size() << " references and ";
468  ostr << m_BackPointers.size() << " backpointers";
469  wxLogTrace( MASK_VRML, "%s\n", ostr.str().c_str() );
470  } while( 0 );
471  #endif
472 
473  if( m_sgNode )
474  {
475  if( NULL != aParent )
476  {
478  && !S3D::AddSGNodeChild( aParent, m_sgNode ) )
479  {
480  return NULL;
481  }
482  else if( aParent != S3D::GetSGNodeParent( m_sgNode )
483  && !S3D::AddSGNodeRef( aParent, m_sgNode ) )
484  {
485  return NULL;
486  }
487  }
488 
489  return m_sgNode;
490  }
491 
492  if( NULL != texture )
493  {
494  // use a default gray appearance
495  IFSG_APPEARANCE matNode( aParent );
496  matNode.SetEmissive( 0.0f, 0.0f, 0.0f );
497  matNode.SetSpecular( 0.65f, 0.65f, 0.65f );
498  matNode.SetDiffuse( 0.65f, 0.65f, 0.65f );
499  // default ambient
500  matNode.SetShininess( 0.2f );
501  matNode.SetTransparency( 0.0f );
502  m_sgNode = matNode.GetRawPtr();
503 
504  return m_sgNode;
505  }
506 
507  m_sgNode = material->TranslateToSG( aParent );
508 
509  return m_sgNode;
510 }
WRL2NODE * material
virtual SGNODE * TranslateToSG(SGNODE *aParent)=0
Function TranslateToSG produces a representation of the data using the intermediate scenegraph struct...
std::list< WRL2NODE * > m_Children
Definition: vrml2_node.h:66
#define MASK_VRML
Definition: wrltypes.h:37
std::list< WRL2NODE * > m_Refs
Definition: vrml2_node.h:67
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:636
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:645
#define NULL
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:654
SGNODE * m_sgNode
Definition: vrml2_node.h:70
std::list< WRL2NODE * > m_BackPointers
Definition: vrml2_node.h:65
WRL2NODE * texture
SGTYPES
Definition: sg_types.h:34
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition: ifsg_api.cpp:627

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

◆ unlinkChildNode()

void WRL2APPEARANCE::unlinkChildNode ( const WRL2NODE aNode)
overrideprivatevirtual

Function unlinkChild removes 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 513 of file vrml2_appearance.cpp.

514 {
515  if( NULL == aNode )
516  return;
517 
518  if( aNode->GetParent() == this )
519  {
520  if( aNode == material )
521  material = NULL;
522  else if( aNode == texture )
523  texture = NULL;
524  else if( aNode == textureTransform )
526 
527  }
528 
529  WRL2NODE::unlinkChildNode( aNode );
530  return;
531 }
WRL2NODE * material
#define NULL
WRL2NODE * texture
WRL2NODE * textureTransform
WRL2NODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: vrml2_node.cpp:218
virtual void unlinkChildNode(const WRL2NODE *aNode)
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
Definition: vrml2_node.cpp:464

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

◆ unlinkRefNode()

void WRL2APPEARANCE::unlinkRefNode ( const WRL2NODE aNode)
overrideprivatevirtual

Function unlinkRef removes 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 534 of file vrml2_appearance.cpp.

535 {
536  if( NULL == aNode )
537  return;
538 
539  if( aNode->GetParent() != this )
540  {
541  if( aNode == material )
542  material = NULL;
543  else if( aNode == texture )
544  texture = NULL;
545  else if( aNode == textureTransform )
547 
548  }
549 
550  WRL2NODE::unlinkRefNode( aNode );
551  return;
552 }
WRL2NODE * material
#define NULL
WRL2NODE * texture
WRL2NODE * textureTransform
virtual void unlinkRefNode(const WRL2NODE *aNode)
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
Definition: vrml2_node.cpp:484
WRL2NODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: vrml2_node.cpp:218

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

Member Data Documentation

◆ m_BackPointers

◆ m_Children

◆ m_error

std::string WRL2NODE::m_error
protectedinherited

Definition at line 68 of file vrml2_node.h.

Referenced by WRL2NODE::GetError().

◆ m_Name

std::string WRL2NODE::m_Name
protectedinherited

Definition at line 63 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: