KiCad PCB EDA Suite
X3DSHAPE Class Reference

#include <x3d_shape.h>

Inheritance diagram for X3DSHAPE:
X3DNODE

Public Member Functions

 X3DSHAPE ()
 
 X3DSHAPE (X3DNODE *aParent)
 
virtual ~X3DSHAPE ()
 
bool Read (wxXmlNode *aNode, X3DNODE *aTopNode, X3D_DICT &aDict) override
 
bool SetParent (X3DNODE *aParent, bool doUnlink=true) override
 Set the parent X3DNODE of this object. More...
 
bool AddChildNode (X3DNODE *aNode) override
 
bool AddRefNode (X3DNODE *aNode) override
 
SGNODETranslateToSG (SGNODE *aParent) override
 Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg library. More...
 
virtual void unlinkChildNode (const X3DNODE *aNode) override
 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 X3DNODE *aNode) override
 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 (X3DNODE *aNode)
 Add a pointer to a node which references, but does not own, this node. More...
 
void delNodeRef (X3DNODE *aNode)
 Remove a pointer to a node which references, but does not own, this node. More...
 
X3DNODES GetNodeType (void) const
 Return the type of this node instance. More...
 
X3DNODEGetParent (void) const
 Return a pointer to the parent node of this object or NULL if the object has no parent (ie. More...
 
wxString GetName (void) const
 Return the name of this object. More...
 
std::string GetError (void)
 

Protected Attributes

X3DNODEm_Parent
 
X3DNODES m_Type
 
X3D_DICTm_Dict
 
std::list< X3DNODE * > m_BackPointers
 
std::list< X3DNODE * > m_Children
 
std::list< X3DNODE * > m_Refs
 
std::string m_error
 
wxString m_Name
 
SGNODEm_sgNode
 

Private Attributes

X3DNODEappearance
 
X3DNODEgeometry
 

Detailed Description

Definition at line 39 of file x3d_shape.h.

Constructor & Destructor Documentation

◆ X3DSHAPE() [1/2]

X3DSHAPE::X3DSHAPE ( )

Definition at line 35 of file x3d_shape.cpp.

35  : X3DNODE()
36 {
37  m_Type = X3D_SHAPE;
38  appearance = nullptr;
39  geometry = nullptr;
40 }
X3DNODES m_Type
Definition: x3d_base.h:160
X3DNODE()
Definition: x3d_base.cpp:82
X3DNODE * appearance
Definition: x3d_shape.h:56
X3DNODE * geometry
Definition: x3d_shape.h:57

References appearance, geometry, X3DNODE::m_Type, and X3D_SHAPE.

◆ X3DSHAPE() [2/2]

X3DSHAPE::X3DSHAPE ( X3DNODE aParent)

Definition at line 43 of file x3d_shape.cpp.

43  : X3DNODE()
44 {
45  m_Type = X3D_SHAPE;
46  appearance = nullptr;
47  geometry = nullptr;
48 
49  if( nullptr != aParent )
50  {
51  X3DNODES ptype = aParent->GetNodeType();
52 
53  if( X3D_TRANSFORM == ptype || X3D_SWITCH == ptype )
54  m_Parent = aParent;
55  }
56 
57  if( nullptr != m_Parent )
58  m_Parent->AddChildNode( this );
59 }
X3DNODES m_Type
Definition: x3d_base.h:160
X3DNODE()
Definition: x3d_base.cpp:82
X3DNODE * appearance
Definition: x3d_shape.h:56
virtual bool AddChildNode(X3DNODE *aNode)=0
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition: x3d_base.cpp:184
X3DNODE * m_Parent
Definition: x3d_base.h:159
X3DNODES
Definition: x3d_base.h:59
X3DNODE * geometry
Definition: x3d_shape.h:57

References X3DNODE::AddChildNode(), appearance, geometry, X3DNODE::GetNodeType(), X3DNODE::m_Parent, X3DNODE::m_Type, X3D_SHAPE, X3D_SWITCH, and X3D_TRANSFORM.

◆ ~X3DSHAPE()

X3DSHAPE::~X3DSHAPE ( )
virtual

Definition at line 62 of file x3d_shape.cpp.

63 {
64  wxLogTrace( traceVrmlPlugin,
65  wxT( " * [INFO] Destroying Shape with %zu children, %zu references, "
66  "%and ul back pointers." ),
67  m_Children.size(), m_Refs.size(), m_BackPointers.size() );
68 }
std::list< X3DNODE * > m_BackPointers
Definition: x3d_base.h:163
std::list< X3DNODE * > m_Children
Definition: x3d_base.h:164
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
std::list< X3DNODE * > m_Refs
Definition: x3d_base.h:165

References X3DNODE::m_BackPointers, X3DNODE::m_Children, X3DNODE::m_Refs, and traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool X3DSHAPE::AddChildNode ( X3DNODE aNode)
overridevirtual

Implements X3DNODE.

Definition at line 138 of file x3d_shape.cpp.

139 {
140  if( nullptr == aNode )
141  return false;
142 
143  X3DNODES tchild = aNode->GetNodeType();
144 
145  if( X3D_APPEARANCE != tchild && X3D_INDEXED_FACE_SET != tchild )
146  return false;
147 
148  std::list< X3DNODE* >::iterator sC = m_Children.begin();
149  std::list< X3DNODE* >::iterator eC = m_Children.end();
150 
151  while( sC != eC )
152  {
153  if( *sC == aNode )
154  return false;
155 
156  ++sC;
157  }
158 
159  if( X3D_APPEARANCE == tchild )
160  {
161  if( nullptr == appearance )
162  {
163  m_Children.push_back( aNode );
164  appearance = aNode;
165  }
166  else
167  {
168  return false;
169  }
170  }
171  else
172  {
173  if( nullptr == geometry )
174  {
175  m_Children.push_back( aNode );
176  geometry = aNode;
177  }
178  else
179  {
180  return false;
181  }
182  }
183 
184  if( aNode->GetParent() != this )
185  aNode->SetParent( this );
186 
187  return true;
188 }
virtual bool SetParent(X3DNODE *aParent, bool doUnlink=true)=0
Set the parent X3DNODE of this object.
X3DNODE * GetParent(void) const
Return a pointer to the parent node of this object or NULL if the object has no parent (ie.
Definition: x3d_base.cpp:190
X3DNODE * appearance
Definition: x3d_shape.h:56
std::list< X3DNODE * > m_Children
Definition: x3d_base.h:164
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition: x3d_base.cpp:184
X3DNODES
Definition: x3d_base.h:59
X3DNODE * geometry
Definition: x3d_shape.h:57

References appearance, geometry, X3DNODE::GetNodeType(), X3DNODE::GetParent(), X3DNODE::m_Children, X3DNODE::SetParent(), X3D_APPEARANCE, and X3D_INDEXED_FACE_SET.

◆ addNodeRef()

void X3DNODE::addNodeRef ( X3DNODE 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 142 of file x3d_base.cpp.

143 {
144  // the parent node must never be added as a backpointer
145  if( aNode == m_Parent )
146  return;
147 
148  std::list< X3DNODE* >::iterator sR = m_BackPointers.begin();
149  std::list< X3DNODE* >::iterator eR = m_BackPointers.end();
150 
151  while( sR != eR )
152  {
153  if( *sR == aNode )
154  return;
155 
156  ++sR;
157  }
158 
159  m_BackPointers.push_back( aNode );
160 
161  return;
162 }
std::list< X3DNODE * > m_BackPointers
Definition: x3d_base.h:163
X3DNODE * m_Parent
Definition: x3d_base.h:159

References X3DNODE::m_BackPointers, and X3DNODE::m_Parent.

Referenced by X3DIFACESET::AddRefNode(), X3DTRANSFORM::AddRefNode(), and AddRefNode().

◆ AddRefNode()

bool X3DSHAPE::AddRefNode ( X3DNODE aNode)
overridevirtual

Implements X3DNODE.

Definition at line 191 of file x3d_shape.cpp.

192 {
193  if( nullptr == aNode )
194  return false;
195 
196  X3DNODES tchild = aNode->GetNodeType();
197 
198  if( X3D_APPEARANCE != tchild && X3D_INDEXED_FACE_SET != tchild )
199  return false;
200 
201  std::list< X3DNODE* >::iterator sR = m_Refs.begin();
202  std::list< X3DNODE* >::iterator eR = m_Refs.end();
203 
204  while( sR != eR )
205  {
206  if( *sR == aNode )
207  return false;
208 
209  ++sR;
210  }
211 
212  if( X3D_APPEARANCE == tchild )
213  {
214  if( nullptr == appearance )
215  {
216  m_Refs.push_back( aNode );
217  aNode->addNodeRef( this );
218  appearance = aNode;
219  }
220  else
221  {
222  return false;
223  }
224  }
225  else
226  {
227  if( nullptr == geometry )
228  {
229  m_Refs.push_back( aNode );
230  aNode->addNodeRef( this );
231  geometry = aNode;
232  }
233  else
234  {
235  return false;
236  }
237  }
238 
239  return true;
240 }
X3DNODE * appearance
Definition: x3d_shape.h:56
void addNodeRef(X3DNODE *aNode)
Add a pointer to a node which references, but does not own, this node.
Definition: x3d_base.cpp:142
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition: x3d_base.cpp:184
X3DNODES
Definition: x3d_base.h:59
X3DNODE * geometry
Definition: x3d_shape.h:57
std::list< X3DNODE * > m_Refs
Definition: x3d_base.h:165

References X3DNODE::addNodeRef(), appearance, geometry, X3DNODE::GetNodeType(), X3DNODE::m_Refs, X3D_APPEARANCE, and X3D_INDEXED_FACE_SET.

◆ delNodeRef()

void X3DNODE::delNodeRef ( X3DNODE 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 165 of file x3d_base.cpp.

166 {
167  std::list< X3DNODE* >::iterator np =
168  std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
169 
170  if( np != m_BackPointers.end() )
171  {
172  m_BackPointers.erase( np );
173  return;
174  }
175 
176  wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
177  " * [BUG] delNodeRef() did not find its target." ),
178  __FILE__, __FUNCTION__, __LINE__ );
179 
180  return;
181 }
std::list< X3DNODE * > m_BackPointers
Definition: x3d_base.h:163
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References X3DNODE::m_BackPointers, and traceVrmlPlugin.

◆ GetError()

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

Definition at line 202 of file x3d_base.cpp.

203 {
204  return m_error;
205 }
std::string m_error
Definition: x3d_base.h:166

References X3DNODE::m_error.

◆ GetName()

wxString X3DNODE::GetName ( void  ) const
inherited

Return the name of this object.

Definition at line 196 of file x3d_base.cpp.

197 {
198  return m_Name;
199 }
wxString m_Name
Definition: x3d_base.h:168

References X3DNODE::m_Name.

◆ GetNodeType()

◆ GetParent()

X3DNODE * X3DNODE::GetParent ( void  ) const
inherited

Return a pointer to the parent node of this object or NULL if the object has no parent (ie.

top level transform).

Definition at line 190 of file x3d_base.cpp.

191 {
192  return m_Parent;
193 }
X3DNODE * m_Parent
Definition: x3d_base.h:159

References X3DNODE::m_Parent.

Referenced by X3DIFACESET::AddChildNode(), X3DTRANSFORM::AddChildNode(), and AddChildNode().

◆ Read()

bool X3DSHAPE::Read ( wxXmlNode *  aNode,
X3DNODE aTopNode,
X3D_DICT aDict 
)
overridevirtual

Implements X3DNODE.

Definition at line 71 of file x3d_shape.cpp.

72 {
73  if( nullptr == aTopNode || nullptr == aNode )
74  return false;
75 
76  if( nullptr != appearance || nullptr != geometry )
77  return false;
78 
79  m_Dict = &aDict;
80  wxXmlAttribute* prop;
81 
82  for( prop = aNode->GetAttributes(); prop != nullptr; prop = prop->GetNext() )
83  {
84  const wxString& pname = prop->GetName();
85 
86  if( pname == "DEF" )
87  {
88  m_Name = prop->GetValue();
89  m_Dict->AddName( m_Name, this );
90  }
91  }
92 
93  for( wxXmlNode* child = aNode->GetChildren(); child != nullptr; child = child->GetNext() )
94  {
95  wxString name = child->GetName();
96 
97  if( name == "Appearance" && nullptr == appearance )
98  X3D::ReadAppearance( child, this, aDict );
99  else if( name == "IndexedFaceSet" && nullptr == geometry )
100  X3D::ReadIndexedFaceSet( child, this, aDict );
101  }
102 
103  if( nullptr == appearance || nullptr == geometry )
104  return false;
105 
106  if( !SetParent( aTopNode ) )
107  return false;
108 
109  return true;
110 }
bool ReadIndexedFaceSet(wxXmlNode *aNode, X3DNODE *aParent, X3D_DICT &aDict)
Definition: x3d_ops.cpp:155
wxString m_Name
Definition: x3d_base.h:168
X3DNODE * appearance
Definition: x3d_shape.h:56
bool SetParent(X3DNODE *aParent, bool doUnlink=true) override
Set the parent X3DNODE of this object.
Definition: x3d_shape.cpp:113
bool ReadAppearance(wxXmlNode *aNode, X3DNODE *aParent, X3D_DICT &aDict)
Definition: x3d_ops.cpp:117
bool AddName(const wxString &aName, X3DNODE *aNode)
Definition: x3d_base.cpp:35
const char * name
Definition: DXF_plotter.cpp:56
X3D_DICT * m_Dict
Definition: x3d_base.h:161
X3DNODE * geometry
Definition: x3d_shape.h:57

References X3D_DICT::AddName(), appearance, geometry, X3DNODE::m_Dict, X3DNODE::m_Name, name, X3D::ReadAppearance(), X3D::ReadIndexedFaceSet(), and SetParent().

◆ SetParent()

bool X3DSHAPE::SetParent ( X3DNODE aParent,
bool  doUnlink = true 
)
overridevirtual

Set the parent X3DNODE 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 or false if the given node is not allowed to be a parent to the derived object.

Implements X3DNODE.

Definition at line 113 of file x3d_shape.cpp.

114 {
115  if( aParent == m_Parent )
116  return true;
117 
118  if( nullptr != aParent )
119  {
120  X3DNODES nt = aParent->GetNodeType();
121 
122  if( nt != X3D_SWITCH && nt != X3D_TRANSFORM )
123  return false;
124  }
125 
126  if( nullptr != m_Parent && doUnlink )
127  m_Parent->unlinkChildNode( this );
128 
129  m_Parent = aParent;
130 
131  if( nullptr != m_Parent )
132  m_Parent->AddChildNode( this );
133 
134  return true;
135 }
virtual bool AddChildNode(X3DNODE *aNode)=0
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition: x3d_base.cpp:184
virtual void unlinkChildNode(const X3DNODE *aNode)
Remove references to an owned child; it is invoked by the child upon destruction to ensure that the p...
Definition: x3d_base.cpp:102
X3DNODE * m_Parent
Definition: x3d_base.h:159
X3DNODES
Definition: x3d_base.h:59

References X3DNODE::AddChildNode(), X3DNODE::GetNodeType(), X3DNODE::m_Parent, X3DNODE::unlinkChildNode(), X3D_SWITCH, and X3D_TRANSFORM.

Referenced by Read().

◆ TranslateToSG()

SGNODE * X3DSHAPE::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 X3DNODE.

Definition at line 243 of file x3d_shape.cpp.

244 {
245  if( nullptr == geometry || nullptr == appearance )
246  return nullptr;
247 
248  wxLogTrace( traceVrmlPlugin,
249  wxT( " * [INFO] Translating Shape with %zu children, %zu references, "
250  "and %zu back pointers." ),
251  m_Children.size(), m_Refs.size(), m_BackPointers.size() );
252 
253  S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
254 
255  wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_TRANSFORM ), nullptr,
256  wxString::Format( wxT( "Shape does not have a Transform parent (parent ID: %d)" ),
257  ptype ) );
258 
259  if( m_sgNode )
260  {
261  if( nullptr != aParent )
262  {
263  if( nullptr == S3D::GetSGNodeParent( m_sgNode )
264  && !S3D::AddSGNodeChild( aParent, m_sgNode ) )
265  {
266  return nullptr;
267  }
268  else if( aParent != S3D::GetSGNodeParent( m_sgNode )
269  && !S3D::AddSGNodeRef( aParent, m_sgNode ) )
270  {
271  return nullptr;
272  }
273  }
274 
275  return m_sgNode;
276  }
277 
278  IFSG_SHAPE shNode( aParent );
279 
280  SGNODE* pShape = shNode.GetRawPtr();
281  SGNODE* pGeom = geometry->TranslateToSG( pShape );
282  SGNODE* pApp = appearance->TranslateToSG( pShape );
283 
284  if( nullptr == pApp || nullptr == pGeom )
285  {
286  if( pGeom )
287  {
288  IFSG_FACESET tmp( false );
289  tmp.Attach( pGeom );
290  tmp.Destroy();
291  }
292 
293  if( pApp )
294  {
295  IFSG_APPEARANCE tmp( false );
296  tmp.Attach( pApp );
297  tmp.Destroy();
298  }
299 
300  shNode.Destroy();
301  return nullptr;
302  }
303 
304  m_sgNode = shNode.GetRawPtr();
305 
306  return m_sgNode;
307 }
std::list< X3DNODE * > m_BackPointers
Definition: x3d_base.h:163
X3DNODE * appearance
Definition: x3d_shape.h:56
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition: ifsg_api.cpp:492
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:501
std::list< X3DNODE * > m_Children
Definition: x3d_base.h:164
virtual SGNODE * TranslateToSG(SGNODE *aParent)=0
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition: ifsg_api.cpp:510
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
SGTYPES
Definition: sg_types.h:34
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
SGNODE * m_sgNode
Definition: x3d_base.h:169
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition: ifsg_api.cpp:483
IFSG_FACESET is the wrapper for the SGFACESET class.
Definition: ifsg_faceset.h:40
X3DNODE * geometry
Definition: x3d_shape.h:57
IFSG_SHAPE is the wrapper for the SGSHAPE class.
Definition: ifsg_shape.h:40
std::list< X3DNODE * > m_Refs
Definition: x3d_base.h:165

References S3D::AddSGNodeChild(), S3D::AddSGNodeRef(), appearance, IFSG_APPEARANCE::Attach(), IFSG_FACESET::Attach(), IFSG_NODE::Destroy(), Format(), geometry, IFSG_NODE::GetRawPtr(), S3D::GetSGNodeParent(), S3D::GetSGNodeType(), X3DNODE::m_BackPointers, X3DNODE::m_Children, X3DNODE::m_Refs, X3DNODE::m_sgNode, S3D::SGTYPE_TRANSFORM, traceVrmlPlugin, and X3DNODE::TranslateToSG().

◆ unlinkChildNode()

void X3DSHAPE::unlinkChildNode ( const X3DNODE aNode)
overridevirtual

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 X3DNODE.

Definition at line 310 of file x3d_shape.cpp.

311 {
312  if( nullptr == aNode )
313  return;
314 
315  if( aNode == appearance )
316  appearance = nullptr;
317  else if( aNode == geometry )
318  geometry = nullptr;
319 
320  X3DNODE::unlinkChildNode( aNode );
321 }
X3DNODE * appearance
Definition: x3d_shape.h:56
virtual void unlinkChildNode(const X3DNODE *aNode)
Remove references to an owned child; it is invoked by the child upon destruction to ensure that the p...
Definition: x3d_base.cpp:102
X3DNODE * geometry
Definition: x3d_shape.h:57

References appearance, geometry, and X3DNODE::unlinkChildNode().

◆ unlinkRefNode()

void X3DSHAPE::unlinkRefNode ( const X3DNODE aNode)
overridevirtual

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 X3DNODE.

Definition at line 324 of file x3d_shape.cpp.

325 {
326  if( nullptr == aNode )
327  return;
328 
329  if( aNode == appearance )
330  appearance = nullptr;
331  else if( aNode == geometry )
332  geometry = nullptr;
333 
334  X3DNODE::unlinkRefNode( aNode );
335 }
X3DNODE * appearance
Definition: x3d_shape.h:56
virtual void unlinkRefNode(const X3DNODE *aNode)
Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure...
Definition: x3d_base.cpp:122
X3DNODE * geometry
Definition: x3d_shape.h:57

References appearance, geometry, and X3DNODE::unlinkRefNode().

Member Data Documentation

◆ appearance

X3DNODE* X3DSHAPE::appearance
private

◆ geometry

X3DNODE* X3DSHAPE::geometry
private

◆ m_BackPointers

◆ m_Children

◆ m_Dict

◆ m_error

std::string X3DNODE::m_error
protectedinherited

Definition at line 166 of file x3d_base.h.

Referenced by X3DNODE::GetError().

◆ m_Name

wxString X3DNODE::m_Name
protectedinherited

◆ m_Parent

◆ m_Refs

◆ m_sgNode

SGNODE* X3DNODE::m_sgNode
protectedinherited

◆ m_Type


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