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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <iostream>
23#include <wx/xml/xml.h>
24#include <wx/tokenzr.h>
25#include <wx/log.h>
26#include "x3d_ops.h"
27#include "x3d_coords.h"
28
29
34
35
37{
39
40 if( nullptr != aParent )
41 {
42 X3DNODES ptype = aParent->GetNodeType();
43
44 if( X3D_INDEXED_FACE_SET == ptype )
45 m_Parent = aParent;
46 }
47
48 if( nullptr != m_Parent )
49 m_Parent->AddChildNode( this );
50}
51
52
54{
55 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Coordinate" ) );
56}
57
58
59bool X3DCOORDS::Read( wxXmlNode* aNode, X3DNODE* aTopNode, X3D_DICT& aDict )
60{
61 if( nullptr == aTopNode || nullptr == aNode )
62 return false;
63
64 m_Dict = &aDict;
65 wxXmlAttribute* prop;
66
67 for( prop = aNode->GetAttributes(); prop != nullptr; prop = prop->GetNext() )
68 {
69 const wxString& pname = prop->GetName();
70
71 if( pname == wxT( "DEF" ) )
72 {
73 m_Name = prop->GetValue();
74 m_Dict->AddName( m_Name, this );
75 }
76 else if( pname == wxT( "point" ) )
77 {
78 // Save points to vector as doubles
79 wxStringTokenizer plist( prop->GetValue() );
80 double point = 0.0;
81 WRLVEC3F pt;
82 int i = 0;
83
84 while( plist.HasMoreTokens() )
85 {
86 if( plist.GetNextToken().ToCDouble( &point ) )
87 {
88 // note: coordinates are multiplied by 2.54 to retain
89 // legacy behavior of 1 X3D unit = 0.1 inch; the SG*
90 // classes expect all units in mm.
91 switch( i % 3 )
92 {
93 case 0:
94 pt.x = point * 2.54;
95 break;
96
97 case 1:
98 pt.y = point * 2.54;
99 break;
100
101 case 2:
102 pt.z = point * 2.54;
103 points.push_back( pt );
104 break;
105
106 }
107 }
108 else
109 {
110 return false;
111 }
112
113 ++i;
114 }
115 }
116 }
117
118 if( points.size() < 3 )
119 return false;
120
121 if( !SetParent( aTopNode ) )
122 return false;
123
124 return true;
125}
126
127
128bool X3DCOORDS::SetParent( X3DNODE* aParent, bool doUnlink )
129{
130 if( aParent == m_Parent )
131 return true;
132
133 if( nullptr != aParent )
134 {
135 X3DNODES nt = aParent->GetNodeType();
136
137 if( nt != X3D_INDEXED_FACE_SET )
138 return false;
139 }
140
141 if( nullptr != m_Parent && doUnlink )
142 m_Parent->unlinkChildNode( this );
143
144 m_Parent = aParent;
145
146 if( nullptr != m_Parent )
147 m_Parent->AddChildNode( this );
148
149 return true;
150}
151
152
154{
155 return false;
156}
157
158
160{
161 return false;
162}
163
164
165void X3DCOORDS::GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize )
166{
167 if( points.size() < 3 )
168 {
169 aCoordList = nullptr;
170 aListSize = 0;
171 return;
172 }
173
174 aCoordList = &points[0];
175 aListSize = points.size();
176}
177
178
180{
181 return nullptr;
182}
The base class of all Scene Graph nodes.
Definition sg_node.h:71
bool SetParent(X3DNODE *aParent, bool doUnlink=true) override
Set the parent X3DNODE of this object.
bool AddRefNode(X3DNODE *aNode) override
bool Read(wxXmlNode *aNode, X3DNODE *aTopNode, X3D_DICT &aDict) override
bool AddChildNode(X3DNODE *aNode) override
void GetCoords(WRLVEC3F *&aCoordList, size_t &aListSize)
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
virtual ~X3DCOORDS()
std::vector< WRLVEC3F > points
Definition x3d_coords.h:52
X3DNODES m_Type
Definition x3d_base.h:156
X3DNODE * m_Parent
Definition x3d_base.h:155
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition x3d_base.cpp:180
wxString m_Name
Definition x3d_base.h:164
X3D_DICT * m_Dict
Definition x3d_base.h:157
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition vrml.cpp:59
glm::vec3 WRLVEC3F
Definition wrltypes.h:184
X3DNODES
Definition x3d_base.h:56
@ X3D_COORDINATE
Definition x3d_base.h:62
@ X3D_INDEXED_FACE_SET
Definition x3d_base.h:61