KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml2_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 <sstream>
28#include <wx/log.h>
29
30#include "vrml2_base.h"
31#include "vrml2_coords.h"
32
33
35{
36 m_Type = WRL2NODES::WRL2_COORDINATE;
37}
38
39
41{
42 m_Type = WRL2NODES::WRL2_COORDINATE;
43 m_Parent = aParent;
44
45 if( nullptr != m_Parent )
46 m_Parent->AddChildNode( this );
47}
48
49
51{
52 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Coordinate node." ) );
53}
54
55
57{
58 // this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
59
60 if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_INDEXEDFACESET )
61 return true;
62
63 return false;
64}
65
66
68{
69 // this node may not own or reference any other node
70 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
71}
72
73
75{
76 // this node may not own or reference any other node
77 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
78}
79
80
81bool WRL2COORDS::Read( WRLPROC& proc, WRL2BASE* aTopNode )
82{
83 char tok = proc.Peek();
84
85 if( proc.eof() )
86 {
87 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
88 " * [INFO] bad file format; unexpected eof %s." ),
89 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
90
91 return false;
92 }
93
94 if( '{' != tok )
95 {
96 wxLogTrace( traceVrmlPlugin,
97 wxT( "%s:%s:%d\n"
98 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
99 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
100
101 return false;
102 }
103
104 proc.Pop();
105 std::string glob;
106
107 if( proc.Peek() == '}' )
108 {
109 proc.Pop();
110 return true;
111 }
112
113 if( !proc.ReadName( glob ) )
114 {
115 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
116 "%s" ),
117 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
118
119 return false;
120 }
121
122 // expecting 'point'
123 if( !glob.compare( "point" ) )
124 {
125 if( !proc.ReadMFVec3f( points ) )
126 {
127 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
128 " * [INFO] invalid Coordinate point set %s\n"
129 " * [INFO] file: '%s'\n"
130 "%s" ),
131 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
132 proc.GetFileName(), proc.GetError() );
133
134 return false;
135 }
136 }
137 else
138 {
139 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
140 " * [INFO] invalid Coordinate %s\n"
141 " * [INFO] file: '%s'\n" ),
142 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
143
144 return false;
145 }
146
147 // assuming legacy KiCad expectation of 1U = 0.1 inch,
148 // convert to mm to meet the expectations of the SG structure
149 std::vector< WRLVEC3F >::iterator sP = points.begin();
150 std::vector< WRLVEC3F >::iterator eP = points.end();
151
152 while( sP != eP )
153 {
154 sP->x *= 2.54f;
155 sP->y *= 2.54f;
156 sP->z *= 2.54f;
157 ++sP;
158 }
159
160 if( proc.Peek() == '}' )
161 {
162 proc.Pop();
163 return true;
164 }
165
166 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
167 " * [INFO] invalid Coordinate %s (no closing brace)\n"
168 " * [INFO] file: '%s'\n" ),
169 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
170
171 return false;
172}
173
174
175void WRL2COORDS::GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize )
176{
177 if( points.size() < 3 )
178 {
179 aCoordList = nullptr;
180 aListSize = 0;
181 return;
182 }
183
184 aCoordList = &points[0];
185 aListSize = points.size();
186}
187
188
190{
191 // any data manipulation must be performed by the parent node
192 return nullptr;
193}
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
The top node of a VRML2 model.
Definition: vrml2_base.h:60
bool AddChildNode(WRL2NODE *aNode) override
bool AddRefNode(WRL2NODE *aNode) override
void GetCoords(WRLVEC3F *&aCoordList, size_t &aListSize)
std::vector< WRLVEC3F > points
Definition: vrml2_coords.h:57
bool isDangling(void) override
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
bool Read(WRLPROC &proc, WRL2BASE *aTopNode) override
virtual ~WRL2COORDS()
WRL2NODE * m_Parent
Definition: vrml2_node.h:169
WRL2NODES m_Type
Definition: vrml2_node.h:170
WRL2NODES GetNodeType(void) const
Definition: vrml2_node.cpp:204
virtual bool AddChildNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:356
void Pop(void)
Definition: wrlproc.cpp:2035
char Peek(void)
Definition: wrlproc.cpp:2007
std::string GetFileName(void)
Definition: wrlproc.cpp:1995
std::string GetError(void)
Definition: wrlproc.cpp:1960
bool eof(void)
Definition: wrlproc.cpp:1954
bool ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition: wrlproc.cpp:1839
bool ReadName(std::string &aName)
Definition: wrlproc.cpp:289
std::string GetFilePosition() const
Definition: wrlproc.cpp:1982
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition: vrml.cpp:63
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188