KiCad PCB EDA Suite
WRL1MATERIAL Class Reference

#include <vrml1_material.h>

Inheritance diagram for WRL1MATERIAL:
WRL1NODE

Public Member Functions

 WRL1MATERIAL (NAMEREGISTER *aDictionary)
 
 WRL1MATERIAL (NAMEREGISTER *aDictionary, WRL1NODE *aParent)
 
virtual ~WRL1MATERIAL ()
 
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...
 
SGNODEGetAppearance (int aIndex)
 Return an SGAPPEARANCE node representing the appearance for an IndexedFaceSet. More...
 
void GetColor (SGCOLOR *aColor, int aIndex)
 Compute an SGCOLOR representing the appearance of a vertex or face. More...
 
void Reclaim (SGNODE *aColor)
 Destroy the given color node if it does not have a parent. More...
 
void cancelDict (void)
 
WRL1NODES getNodeTypeID (const std::string &aNodeName)
 Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists. More...
 
virtual void unlinkChildNode (const WRL1NODE *aNode)
 Remove references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references. More...
 
virtual void unlinkRefNode (const WRL1NODE *aNode)
 Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references. More...
 
void addNodeRef (WRL1NODE *aNode)
 Add a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (WRL1NODE *aNode)
 Remove a pointer to a node which references, but does not own, this node. More...
 
WRL1NODES GetNodeType (void) const
 Return the type of this node instance. More...
 
WRL1NODEGetParent (void) const
 Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie. More...
 
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 checkRange (float &aValue)
 

Private Attributes

std::vector< WRLVEC3FdiffuseColor
 
std::vector< WRLVEC3FemissiveColor
 
std::vector< WRLVEC3FspecularColor
 
std::vector< WRLVEC3FambientColor
 
std::vector< float > shininess
 
std::vector< float > transparency
 
SGNODEcolors [2]
 

Detailed Description

Definition at line 41 of file vrml1_material.h.

Constructor & Destructor Documentation

◆ WRL1MATERIAL() [1/2]

WRL1MATERIAL::WRL1MATERIAL ( NAMEREGISTER aDictionary)

Definition at line 35 of file vrml1_material.cpp.

35  : WRL1NODE( aDictionary )
36 {
37  colors[0] = nullptr;
38  colors[1] = nullptr;
40 }
SGNODE * colors[2]
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:91
WRL1NODES m_Type
Definition: vrml1_node.h:227

References colors, WRL1NODE::m_Type, and WRL1_MATERIAL.

◆ WRL1MATERIAL() [2/2]

WRL1MATERIAL::WRL1MATERIAL ( NAMEREGISTER aDictionary,
WRL1NODE aParent 
)

Definition at line 43 of file vrml1_material.cpp.

43  :
44  WRL1NODE( aDictionary )
45 {
46  colors[0] = nullptr;
47  colors[1] = nullptr;
49  m_Parent = aParent;
50 
51  if( nullptr != m_Parent )
52  m_Parent->AddChildNode( this );
53 }
SGNODE * colors[2]
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:91
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
WRL1NODES m_Type
Definition: vrml1_node.h:227
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::AddChildNode(), colors, WRL1NODE::m_Parent, WRL1NODE::m_Type, and WRL1_MATERIAL.

◆ ~WRL1MATERIAL()

WRL1MATERIAL::~WRL1MATERIAL ( )
virtual

Definition at line 56 of file vrml1_material.cpp.

57 {
58  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Material node." ) );
59 
60  // destroy any orphaned color nodes
61  for( int i = 0; i < 2; ++i )
62  {
63  if( nullptr != colors[i] )
64  {
65  if( nullptr == S3D::GetSGNodeParent( colors[i] ) )
67 
68  wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] destroyed SGCOLOR #%d" ), i );
69  }
70  }
71 }
SGNODE * colors[2]
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:494
SGLIB_API void DestroyNode(SGNODE *aNode) noexcept
Function DestroyNode deletes the given SG* class node.
Definition: ifsg_api.cpp:149
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References colors, S3D::DestroyNode(), S3D::GetSGNodeParent(), and traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool WRL1MATERIAL::AddChildNode ( WRL1NODE aNode)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 81 of file vrml1_material.cpp.

82 {
83  // this node may not own or reference any other node
84  wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
85 }

◆ addNodeRef()

void WRL1NODE::addNodeRef ( WRL1NODE aNode)
inherited

Add a pointer to a node which references, but does not own, this node.

Such back-pointers are required to ensure that invalidated references are removed when a node is deleted

Parameters
aNodeis the node holding a reference to this object.

Definition at line 216 of file vrml1_node.cpp.

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

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

Referenced by WRL1NODE::AddRefNode().

◆ AddRefNode()

bool WRL1MATERIAL::AddRefNode ( WRL1NODE aNode)
overridevirtual

Reimplemented from WRL1NODE.

Definition at line 74 of file vrml1_material.cpp.

75 {
76  // this node may not own or reference any other node
77  wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
78 }

◆ 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
WRL1NODES m_Type
Definition: vrml1_node.h:227
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().

◆ checkRange()

void WRL1MATERIAL::checkRange ( float &  aValue)
private

Definition at line 533 of file vrml1_material.cpp.

534 {
535  if( aValue < 0.0 )
536  aValue = 0.0;
537  else if( aValue > 1.0 )
538  aValue = 1.0;
539 }

Referenced by GetAppearance(), and GetColor().

◆ 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 }
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

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
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246

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

Referenced by WRL1BASE::implementUse().

◆ GetAppearance()

SGNODE * WRL1MATERIAL::GetAppearance ( int  aIndex)

Return an SGAPPEARANCE node representing the appearance for an IndexedFaceSet.

Definition at line 255 of file vrml1_material.cpp.

256 {
257  ++aIndex;
258 
259  // invalid indices result in the default colors
260  if( aIndex != 0 && aIndex != 1 )
261  aIndex = 0;
262 
263  if( nullptr != colors[ aIndex ] )
264  return colors[ aIndex ];
265 
266  IFSG_APPEARANCE app( true );
267 
268  float red, green, blue, val;
269 
270  if( aIndex == 0 || transparency.empty() )
271  val = 0.0;
272  else
273  val = transparency[0];
274 
275  checkRange( val );
276  app.SetTransparency( val );
277 
278  if( aIndex == 0 || shininess.empty() )
279  val = 0.2f;
280  else
281  val = shininess[0];
282 
283  checkRange( val );
284  app.SetShininess( val );
285 
286  if( aIndex ==0 || ambientColor.empty() )
287  {
288  red = 0.2f;
289  green = 0.2f;
290  blue = 0.2f;
291  }
292  else
293  {
294  red = ambientColor[0].x;
295  green = ambientColor[0].y;
296  blue = ambientColor[0].z;
297  }
298 
299  checkRange( red );
300  checkRange( green );
301  checkRange( blue );
302  app.SetAmbient( red, green, blue );
303 
304  if( aIndex == 0 || diffuseColor.empty() )
305  {
306  red = 0.8f;
307  green = 0.8f;
308  blue = 0.8f;
309  }
310  else
311  {
312  red = diffuseColor[0].x;
313  green = diffuseColor[0].y;
314  blue = diffuseColor[0].z;
315  }
316 
317  checkRange( red );
318  checkRange( green );
319  checkRange( blue );
320  app.SetDiffuse( red, green, blue );
321 
322  if( aIndex > (int)emissiveColor.size() )
323  {
324  red = 0.0;
325  green = 0.0;
326  blue = 0.0;
327  }
328  else
329  {
330  red = emissiveColor[0].x;
331  green = emissiveColor[0].y;
332  blue = emissiveColor[0].z;
333  }
334 
335  checkRange( red );
336  checkRange( green );
337  checkRange( blue );
338  app.SetEmissive( red, green, blue );
339 
340  if( aIndex > (int)specularColor.size() )
341  {
342  red = 0.0;
343  green = 0.0;
344  blue = 0.0;
345  }
346  else
347  {
348  red = specularColor[0].x;
349  green = specularColor[0].y;
350  blue = specularColor[0].z;
351  }
352 
353  checkRange( red );
354  checkRange( green );
355  checkRange( blue );
356  app.SetSpecular( red, green, blue );
357 
358  colors[aIndex] = app.GetRawPtr();
359 
360  return colors[aIndex];
361 }
std::vector< WRLVEC3F > emissiveColor
SGNODE * colors[2]
void checkRange(float &aValue)
std::vector< WRLVEC3F > ambientColor
std::vector< float > shininess
std::vector< float > transparency
std::vector< WRLVEC3F > specularColor
std::vector< WRLVEC3F > diffuseColor

References ambientColor, checkRange(), colors, diffuseColor, emissiveColor, IFSG_NODE::GetRawPtr(), red, IFSG_APPEARANCE::SetAmbient(), IFSG_APPEARANCE::SetDiffuse(), IFSG_APPEARANCE::SetEmissive(), IFSG_APPEARANCE::SetShininess(), IFSG_APPEARANCE::SetSpecular(), IFSG_APPEARANCE::SetTransparency(), shininess, specularColor, and transparency.

Referenced by WRL1FACESET::TranslateToSG().

◆ GetColor()

void WRL1MATERIAL::GetColor ( SGCOLOR aColor,
int  aIndex 
)

Compute an SGCOLOR representing the appearance of a vertex or face.

Definition at line 364 of file vrml1_material.cpp.

365 {
366  if( nullptr == aColor )
367  return;
368 
369  // Calculate the color based on the given index using the formula:
370  // color = ( emission + ambient + diffuse + shininess * specular ) / N
371  // where N = number of non-zero components or 1 (if all zero)
372  // If the index exceeds the number of items in a list, use the LAST
373  // item rather than the default; this behavior caters to some bad
374  // models.
375 
376  WRLVEC3F rgb;
377  float dRed, dBlue, dGreen;
378  float eRed, eBlue, eGreen;
379  float aRed, aBlue, aGreen;
380  float sRed, sBlue, sGreen;
381  float shiny;
382 
383  if( aIndex < 0 || ( aIndex >= (int)diffuseColor.size() ) )
384  {
385  if( !diffuseColor.empty() )
386  {
387  rgb = diffuseColor.back();
388  dRed = rgb.x;
389  dGreen = rgb.y;
390  dBlue = rgb.z;
391  }
392  else
393  {
394  dRed = 0.8f;
395  dGreen = 0.8f;
396  dBlue = 0.8f;
397  }
398  }
399  else
400  {
401  rgb = diffuseColor[aIndex];
402  dRed = rgb.x;
403  dGreen = rgb.y;
404  dBlue = rgb.z;
405  }
406 
407  if( aIndex < 0 || ( aIndex >= (int)emissiveColor.size() ) )
408  {
409  if( !emissiveColor.empty() )
410  {
411  rgb = emissiveColor.back();
412  eRed = rgb.x;
413  eGreen = rgb.y;
414  eBlue = rgb.z;
415  }
416  else
417  {
418  eRed = 0.0f;
419  eGreen = 0.0f;
420  eBlue = 0.0f;
421  }
422  }
423  else
424  {
425  rgb = emissiveColor[aIndex];
426  eRed = rgb.x;
427  eGreen = rgb.y;
428  eBlue = rgb.z;
429  }
430 
431  if( aIndex < 0 || ( aIndex >= (int)ambientColor.size() ) )
432  {
433  if( !ambientColor.empty() )
434  {
435  rgb = ambientColor.back();
436  aRed = rgb.x;
437  aGreen = rgb.y;
438  aBlue = rgb.z;
439  }
440  else
441  {
442  aRed = 0.2f;
443  aGreen = 0.2f;
444  aBlue = 0.2f;
445  }
446  }
447  else
448  {
449  rgb = ambientColor[aIndex];
450  aRed = rgb.x;
451  aGreen = rgb.y;
452  aBlue = rgb.z;
453  }
454 
455  if( aIndex < 0 || ( aIndex >= (int)specularColor.size() ) )
456  {
457  if( !specularColor.empty() )
458  {
459  rgb = specularColor.back();
460  sRed = rgb.x;
461  sGreen = rgb.y;
462  sBlue = rgb.z;
463  }
464  else
465  {
466  sRed = 0.2f;
467  sGreen = 0.2f;
468  sBlue = 0.2f;
469  }
470  }
471  else
472  {
473  rgb = specularColor[aIndex];
474  sRed = rgb.x;
475  sGreen = rgb.y;
476  sBlue = rgb.z;
477  }
478 
479  if( aIndex < 0 || ( aIndex >= (int)shininess.size() ) )
480  {
481  if( !shininess.empty() )
482  shiny = shininess.back();
483  else
484  shiny = 0.2f;
485  }
486  else
487  {
488  shiny = shininess[aIndex];
489  }
490 
491  checkRange( aRed );
492  checkRange( aGreen );
493  checkRange( aBlue );
494  checkRange( eRed );
495  checkRange( eGreen );
496  checkRange( eBlue );
497  checkRange( dRed );
498  checkRange( dGreen );
499  checkRange( dBlue );
500  checkRange( sRed );
501  checkRange( sGreen );
502  checkRange( sBlue );
503 
504  int n = 0;
505 
506  if( aRed + aGreen + aBlue > 0.01f )
507  ++n;
508 
509  if( eRed + eGreen + eBlue > 0.01f )
510  ++n;
511 
512  if( dRed + dGreen + dBlue > 0.01f )
513  ++n;
514 
515  if( ( sRed + sGreen + sBlue ) * shiny > 0.01f )
516  ++n;
517 
518  if( 0 == n )
519  ++n;
520 
521  float red, green, blue;
522 
523  red = (eRed + aRed + dRed + sRed * shiny) / n;
524  green = (eGreen + aGreen + dGreen + sGreen * shiny) / n;
525  blue = (eBlue + aBlue + dBlue + sBlue * shiny) / n;
526  checkRange( red );
527  checkRange( green );
528  checkRange( blue );
529  aColor->SetColor( red, green, blue );
530 }
std::vector< WRLVEC3F > emissiveColor
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition: sg_base.cpp:85
void checkRange(float &aValue)
std::vector< WRLVEC3F > ambientColor
std::vector< float > shininess
std::vector< WRLVEC3F > specularColor
std::vector< WRLVEC3F > diffuseColor

References ambientColor, checkRange(), diffuseColor, emissiveColor, red, SGCOLOR::SetColor(), shininess, and specularColor.

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 }
std::list< WRL1NODE * > m_Items
Definition: vrml1_node.h:233

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 }
WRL1NODES m_Type
Definition: vrml1_node.h:227

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 }
static NODEMAP nodenames
Definition: vrml1_node.cpp:88

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 }
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

References WRL1NODE::m_Parent.

Referenced by WRL1NODE::AddChildNode().

◆ Read()

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

Implements WRL1NODE.

Definition at line 88 of file vrml1_material.cpp.

89 {
90  wxCHECK_MSG( aTopNode, false, wxT( "aTopNode is nullptr." ) );
91 
92  char tok = proc.Peek();
93 
94  if( proc.eof() )
95  {
96  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
97  " * [INFO] bad file format; unexpected eof %s." ),
98  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
99 
100  return false;
101  }
102 
103  if( '{' != tok )
104  {
105  wxLogTrace( traceVrmlPlugin,
106  wxT( "%s:%s:%d\n"
107  " * [INFO] bad file format; expecting '{' but got '%s' %s" ),
108  __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
109 
110  return false;
111  }
112 
113  proc.Pop();
114  std::string glob;
115 
116  while( true )
117  {
118  if( proc.Peek() == '}' )
119  {
120  proc.Pop();
121  break;
122  }
123 
124  if( !proc.ReadName( glob ) )
125  {
126  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
127  "%s" ),
128  __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
129 
130  return false;
131  }
132 
133  // expecting one of:
134  // ambientColor
135  // diffuseColor
136  // emissiveColor
137  // shininess
138  // specularColor
139  // transparency
140 
141  if( !glob.compare( "specularColor" ) )
142  {
143  if( !proc.ReadMFVec3f( specularColor ) )
144  {
145  wxLogTrace( traceVrmlPlugin,
146  wxT( "%s:%s:%d\n"
147  " * [INFO] invalid specularColor %s\n"
148  " * [INFO] file: '%s'\n"
149  "%s" ),
150  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
151  proc.GetFileName(), proc.GetError() );
152 
153  return false;
154  }
155  }
156  else if( !glob.compare( "diffuseColor" ) )
157  {
158  if( !proc.ReadMFVec3f( diffuseColor ) )
159  {
160  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
161  " * [INFO] invalid diffuseColor %s\n"
162  " * [INFO] file: '%s'\n"
163  " * [INFO] error: '%s'." ),
164  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
165  proc.GetFileName(), proc.GetError() );
166 
167  return false;
168  }
169  }
170  else if( !glob.compare( "emissiveColor" ) )
171  {
172  if( !proc.ReadMFVec3f( emissiveColor ) )
173  {
174  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
175  " * [INFO] invalid emissiveColor %s\n"
176  " * [INFO] file: '%s'\n"
177  "%s" ),
178  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
179  proc.GetFileName(), proc.GetError() );
180 
181  return false;
182  }
183  }
184  else if( !glob.compare( "shininess" ) )
185  {
186  if( !proc.ReadMFFloat( shininess ) )
187  {
188  wxLogTrace( traceVrmlPlugin,
189  wxT( "%s:%s:%d\n"
190  " * [INFO] invalid shininess %s\n"
191  " * [INFO] file: '%s'\n"
192  " * [INFO] error: '%s'." ),
193  __FILE__, __FUNCTION__, __LINE__, proc.GetFileName(),
194  proc.GetFileName(), proc.GetError() );
195 
196  return false;
197  }
198  }
199  else if( !glob.compare( "transparency" ) )
200  {
201  if( !proc.ReadMFFloat( transparency ) )
202  {
203  wxLogTrace( traceVrmlPlugin,
204  wxT( "%s:%s:%d\n"
205  " * [INFO] invalid transparency %s\n"
206  " * [INFO] file: '%s'\n"
207  " * [INFO] error: '%s'." ),
208  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
209  proc.GetFileName(), proc.GetError() );
210 
211  return false;
212  }
213  }
214  else if( !glob.compare( "ambientColor" ) )
215  {
216  if( !proc.ReadMFVec3f( ambientColor ) )
217  {
218  wxLogTrace( traceVrmlPlugin,
219  wxT( "%s:%s:%d\n"
220  " * [INFO] invalid ambientColor %s\n"
221  " * [INFO] file: '%s'\n"
222  " * [INFO] error: '%s'." ),
223  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
224  proc.GetFileName(), proc.GetError() );
225 
226  return false;
227  }
228  }
229  else
230  {
231  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
232  "* [INFO] bad Material %s.\n"
233  "* [INFO] file: '%s'." ),
234  __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
235  proc.GetFileName() );
236 
237  return false;
238  }
239  } // while( true ) -- reading contents of Material{}
240 
241  return true;
242 }
bool ReadMFFloat(std::vector< float > &aMFFloat)
Definition: wrlproc.cpp:1393
bool ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition: wrlproc.cpp:1839
std::vector< WRLVEC3F > emissiveColor
void Pop(void)
Definition: wrlproc.cpp:2035
std::vector< WRLVEC3F > ambientColor
std::vector< float > shininess
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982
char Peek(void)
Definition: wrlproc.cpp:2007
std::string GetFileName(void)
Definition: wrlproc.cpp:1995
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
std::vector< float > transparency
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::vector< WRLVEC3F > specularColor
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool eof(void)
Definition: wrlproc.cpp:1954
std::vector< WRLVEC3F > diffuseColor

References ambientColor, diffuseColor, emissiveColor, WRLPROC::eof(), WRLPROC::GetError(), WRLPROC::GetFileName(), WRLPROC::GetFilePosition(), WRLPROC::Peek(), WRLPROC::Pop(), WRLPROC::ReadMFFloat(), WRLPROC::ReadMFVec3f(), WRLPROC::ReadName(), shininess, specularColor, traceVrmlPlugin, and transparency.

Referenced by WRL1BASE::readMaterial().

◆ Reclaim()

void WRL1MATERIAL::Reclaim ( SGNODE aColor)

Destroy the given color node if it does not have a parent.

Definition at line 542 of file vrml1_material.cpp.

543 {
544  if( nullptr == aColor )
545  return;
546 
547  if( aColor == colors[0] )
548  {
549  if( nullptr == S3D::GetSGNodeParent( aColor ) )
550  {
551  colors[0] = nullptr;
552  S3D::DestroyNode( aColor );
553  }
554 
555  return;
556  }
557 
558  if( aColor == colors[1] && nullptr == S3D::GetSGNodeParent( aColor ) )
559  {
560  colors[1] = nullptr;
561  S3D::DestroyNode( aColor );
562  }
563 }
SGNODE * colors[2]
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:494
SGLIB_API void DestroyNode(SGNODE *aNode) noexcept
Function DestroyNode deletes the given SG* class node.
Definition: ifsg_api.cpp:149

References colors, S3D::DestroyNode(), and S3D::GetSGNodeParent().

◆ 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 }
std::string m_Name
Definition: vrml1_node.h:228
bool AddName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:39
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246
#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
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
WRL1NODE * m_Parent
Definition: vrml1_node.h:226

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

Referenced by WRL1NODE::AddChildNode().

◆ TranslateToSG()

SGNODE * WRL1MATERIAL::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 245 of file vrml1_material.cpp.

246 {
247  wxCHECK_MSG( sp, nullptr, wxT( "Bad model: no base data given." ) );
248 
249  sp->mat = this;
250 
251  return nullptr;
252 }
WRL1MATERIAL * mat
Definition: vrml1_node.h:88

References WRL1STATUS::mat.

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

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
void delItem(const WRL1NODE *aNode)
Definition: vrml1_node.cpp:464

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

Member Data Documentation

◆ ambientColor

std::vector< WRLVEC3F > WRL1MATERIAL::ambientColor
private

Definition at line 74 of file vrml1_material.h.

Referenced by GetAppearance(), GetColor(), and Read().

◆ colors

SGNODE* WRL1MATERIAL::colors[2]
private

Definition at line 78 of file vrml1_material.h.

Referenced by GetAppearance(), Reclaim(), WRL1MATERIAL(), and ~WRL1MATERIAL().

◆ diffuseColor

std::vector< WRLVEC3F > WRL1MATERIAL::diffuseColor
private

Definition at line 71 of file vrml1_material.h.

Referenced by GetAppearance(), GetColor(), and Read().

◆ emissiveColor

std::vector< WRLVEC3F > WRL1MATERIAL::emissiveColor
private

Definition at line 72 of file vrml1_material.h.

Referenced by GetAppearance(), GetColor(), and Read().

◆ 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

◆ shininess

std::vector< float > WRL1MATERIAL::shininess
private

Definition at line 75 of file vrml1_material.h.

Referenced by GetAppearance(), GetColor(), and Read().

◆ specularColor

std::vector< WRLVEC3F > WRL1MATERIAL::specularColor
private

Definition at line 73 of file vrml1_material.h.

Referenced by GetAppearance(), GetColor(), and Read().

◆ transparency

std::vector< float > WRL1MATERIAL::transparency
private

Definition at line 76 of file vrml1_material.h.

Referenced by GetAppearance(), and Read().


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