KiCad PCB EDA Suite
X3DCOORDS Class Reference

#include <x3d_coords.h>

Inheritance diagram for X3DCOORDS:
X3DNODE

Public Member Functions

 X3DCOORDS ()
 
 X3DCOORDS (X3DNODE *aParent)
 
virtual ~X3DCOORDS ()
 
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...
 
void GetCoords (WRLVEC3F *&aCoordList, size_t &aListSize)
 
virtual void unlinkChildNode (const X3DNODE *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 X3DNODE *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 (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

std::vector< WRLVEC3Fpoints
 

Detailed Description

Definition at line 39 of file x3d_coords.h.

Constructor & Destructor Documentation

◆ X3DCOORDS() [1/2]

X3DCOORDS::X3DCOORDS ( )

Definition at line 34 of file x3d_coords.cpp.

34  : X3DNODE()
35 {
37 }
X3DNODES m_Type
Definition: x3d_base.h:160
X3DNODE()
Definition: x3d_base.cpp:82

References X3DNODE::m_Type, and X3D_COORDINATE.

◆ X3DCOORDS() [2/2]

X3DCOORDS::X3DCOORDS ( X3DNODE aParent)

Definition at line 40 of file x3d_coords.cpp.

40  : X3DNODE()
41 {
43 
44  if( nullptr != aParent )
45  {
46  X3DNODES ptype = aParent->GetNodeType();
47 
48  if( X3D_INDEXED_FACE_SET == ptype )
49  m_Parent = aParent;
50  }
51 
52  if( nullptr != m_Parent )
53  m_Parent->AddChildNode( this );
54 }
X3DNODES m_Type
Definition: x3d_base.h:160
X3DNODE()
Definition: x3d_base.cpp:82
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

References X3DNODE::AddChildNode(), X3DNODE::GetNodeType(), X3DNODE::m_Parent, X3DNODE::m_Type, X3D_COORDINATE, and X3D_INDEXED_FACE_SET.

◆ ~X3DCOORDS()

X3DCOORDS::~X3DCOORDS ( )
virtual

Definition at line 57 of file x3d_coords.cpp.

58 {
59  wxLogTrace( traceVrmlPlugin, " * [INFO] Destroying Coordinate" );
60 }
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63

References traceVrmlPlugin.

Member Function Documentation

◆ AddChildNode()

bool X3DCOORDS::AddChildNode ( X3DNODE aNode)
overridevirtual

Implements X3DNODE.

Definition at line 157 of file x3d_coords.cpp.

158 {
159  return false;
160 }

◆ 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(), X3DSHAPE::AddRefNode(), and X3DTRANSFORM::AddRefNode().

◆ AddRefNode()

bool X3DCOORDS::AddRefNode ( X3DNODE aNode)
overridevirtual

Implements X3DNODE.

Definition at line 163 of file x3d_coords.cpp.

164 {
165  return false;
166 }

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

◆ GetCoords()

void X3DCOORDS::GetCoords ( WRLVEC3F *&  aCoordList,
size_t &  aListSize 
)

Definition at line 169 of file x3d_coords.cpp.

170 {
171  if( points.size() < 3 )
172  {
173  aCoordList = nullptr;
174  aListSize = 0;
175  return;
176  }
177 
178  aCoordList = &points[0];
179  aListSize = points.size();
180 }
std::vector< WRLVEC3F > points
Definition: x3d_coords.h:56

References points.

◆ 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(), X3DSHAPE::AddChildNode(), and X3DTRANSFORM::AddChildNode().

◆ Read()

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

Implements X3DNODE.

Definition at line 63 of file x3d_coords.cpp.

64 {
65  if( nullptr == aTopNode || nullptr == aNode )
66  return false;
67 
68  m_Dict = &aDict;
69  wxXmlAttribute* prop;
70 
71  for( prop = aNode->GetAttributes(); prop != nullptr; prop = prop->GetNext() )
72  {
73  const wxString& pname = prop->GetName();
74 
75  if( pname == "DEF" )
76  {
77  m_Name = prop->GetValue();
78  m_Dict->AddName( m_Name, this );
79  }
80  else if( pname == "point" )
81  {
82  // Save points to vector as doubles
83  wxStringTokenizer plist( prop->GetValue() );
84  double point = 0.0;
85  WRLVEC3F pt;
86  int i = 0;
87 
88  while( plist.HasMoreTokens() )
89  {
90  if( plist.GetNextToken().ToCDouble( &point ) )
91  {
92  // note: coordinates are multiplied by 2.54 to retain
93  // legacy behavior of 1 X3D unit = 0.1 inch; the SG*
94  // classes expect all units in mm.
95  switch( i % 3 )
96  {
97  case 0:
98  pt.x = point * 2.54;
99  break;
100 
101  case 1:
102  pt.y = point * 2.54;
103  break;
104 
105  case 2:
106  pt.z = point * 2.54;
107  points.push_back( pt );
108  break;
109 
110  }
111  }
112  else
113  {
114  return false;
115  }
116 
117  ++i;
118  }
119  }
120  }
121 
122  if( points.size() < 3 )
123  return false;
124 
125  if( !SetParent( aTopNode ) )
126  return false;
127 
128  return true;
129 }
std::vector< WRLVEC3F > points
Definition: x3d_coords.h:56
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188
wxString m_Name
Definition: x3d_base.h:168
bool SetParent(X3DNODE *aParent, bool doUnlink=true) override
Set the parent X3DNODE of this object.
Definition: x3d_coords.cpp:132
bool AddName(const wxString &aName, X3DNODE *aNode)
Definition: x3d_base.cpp:35
X3D_DICT * m_Dict
Definition: x3d_base.h:161

References X3D_DICT::AddName(), X3DNODE::m_Dict, X3DNODE::m_Name, points, and SetParent().

◆ SetParent()

bool X3DCOORDS::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 132 of file x3d_coords.cpp.

133 {
134  if( aParent == m_Parent )
135  return true;
136 
137  if( nullptr != aParent )
138  {
139  X3DNODES nt = aParent->GetNodeType();
140 
141  if( nt != X3D_INDEXED_FACE_SET )
142  return false;
143  }
144 
145  if( nullptr != m_Parent && doUnlink )
146  m_Parent->unlinkChildNode( this );
147 
148  m_Parent = aParent;
149 
150  if( nullptr != m_Parent )
151  m_Parent->AddChildNode( this );
152 
153  return true;
154 }
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(), and X3D_INDEXED_FACE_SET.

Referenced by Read().

◆ TranslateToSG()

SGNODE * X3DCOORDS::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 183 of file x3d_coords.cpp.

184 {
185  return nullptr;
186 }

◆ unlinkChildNode()

void X3DNODE::unlinkChildNode ( const X3DNODE aNode)
virtualinherited

Remove references to an owned child; it is invoked by the child upon destruction to ensure that the parent has no invalid references.

Parameters
aNodeis the child which is being deleted.

Reimplemented in X3DSHAPE.

Definition at line 102 of file x3d_base.cpp.

103 {
104  std::list< X3DNODE* >::iterator sL = m_Children.begin();
105  std::list< X3DNODE* >::iterator eL = m_Children.end();
106 
107  while( sL != eL )
108  {
109  if( *sL == aNode )
110  {
111  m_Children.erase( sL );
112  return;
113  }
114 
115  ++sL;
116  }
117 
118  return;
119 }
std::list< X3DNODE * > m_Children
Definition: x3d_base.h:164

References X3DNODE::m_Children.

Referenced by X3DIFACESET::SetParent(), X3DSHAPE::SetParent(), X3DTRANSFORM::SetParent(), SetParent(), X3DAPP::SetParent(), and X3DSHAPE::unlinkChildNode().

◆ unlinkRefNode()

void X3DNODE::unlinkRefNode ( const X3DNODE aNode)
virtualinherited

Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure that the referring node has no invalid references.

Parameters
aNodeis the node which is being deleted.

Reimplemented in X3DSHAPE.

Definition at line 122 of file x3d_base.cpp.

123 {
124  std::list< X3DNODE* >::iterator sL = m_Refs.begin();
125  std::list< X3DNODE* >::iterator eL = m_Refs.end();
126 
127  while( sL != eL )
128  {
129  if( *sL == aNode )
130  {
131  m_Refs.erase( sL );
132  return;
133  }
134 
135  ++sL;
136  }
137 
138  return;
139 }
std::list< X3DNODE * > m_Refs
Definition: x3d_base.h:165

References X3DNODE::m_Refs.

Referenced by X3DSHAPE::unlinkRefNode().

Member Data Documentation

◆ 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

◆ points

std::vector< WRLVEC3F > X3DCOORDS::points
private

Definition at line 56 of file x3d_coords.h.

Referenced by GetCoords(), and Read().


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