KiCad PCB EDA Suite
Loading...
Searching...
No Matches
x3d_coords.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Cirilo Bernardo <[email protected]>
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <iostream>
27#include <wx/xml/xml.h>
28#include <wx/tokenzr.h>
29#include <wx/log.h>
30#include "x3d_ops.h"
31#include "x3d_coords.h"
32
33
35{
37}
38
39
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}
55
56
58{
59 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Coordinate" ) );
60}
61
62
63bool X3DCOORDS::Read( wxXmlNode* aNode, X3DNODE* aTopNode, X3D_DICT& aDict )
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 == wxT( "DEF" ) )
76 {
77 m_Name = prop->GetValue();
78 m_Dict->AddName( m_Name, this );
79 }
80 else if( pname == wxT( "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}
130
131
132bool X3DCOORDS::SetParent( X3DNODE* aParent, bool doUnlink )
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}
155
156
158{
159 return false;
160}
161
162
164{
165 return false;
166}
167
168
169void X3DCOORDS::GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize )
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}
181
182
184{
185 return nullptr;
186}
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
bool SetParent(X3DNODE *aParent, bool doUnlink=true) override
Set the parent X3DNODE of this object.
Definition: x3d_coords.cpp:132
bool AddRefNode(X3DNODE *aNode) override
Definition: x3d_coords.cpp:163
bool Read(wxXmlNode *aNode, X3DNODE *aTopNode, X3D_DICT &aDict) override
Definition: x3d_coords.cpp:63
bool AddChildNode(X3DNODE *aNode) override
Definition: x3d_coords.cpp:157
void GetCoords(WRLVEC3F *&aCoordList, size_t &aListSize)
Definition: x3d_coords.cpp:169
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
Definition: x3d_coords.cpp:183
virtual ~X3DCOORDS()
Definition: x3d_coords.cpp:57
std::vector< WRLVEC3F > points
Definition: x3d_coords.h:56
The base class of all X3D nodes.
Definition: x3d_base.h:75
X3DNODES m_Type
Definition: x3d_base.h:160
X3DNODE * m_Parent
Definition: x3d_base.h:159
virtual bool AddChildNode(X3DNODE *aNode)=0
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition: x3d_base.cpp:184
wxString m_Name
Definition: x3d_base.h:168
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
X3D_DICT * m_Dict
Definition: x3d_base.h:161
bool AddName(const wxString &aName, X3DNODE *aNode)
Definition: x3d_base.cpp:35
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188
X3DNODES
Definition: x3d_base.h:60
@ X3D_COORDINATE
Definition: x3d_base.h:66
@ X3D_INDEXED_FACE_SET
Definition: x3d_base.h:65