KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml2_lineset.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 <sstream>
24#include <wx/log.h>
25
26#include "vrml2_base.h"
27#include "vrml2_lineset.h"
28#include "vrml2_coords.h"
29#include "vrml2_color.h"
31
32
38
39
41{
44 m_Parent = aParent;
45
46 if( nullptr != m_Parent )
47 m_Parent->AddChildNode( this );
48}
49
50
52{
53 wxLogTrace( traceVrmlPlugin,
54 wxT( " * [INFO] Destroying IndexedLineSet node with %zu children, %zu"
55 "references, and %zu back pointers." ),
56 m_Children.size(), m_Refs.size(), m_BackPointers.size() );
57}
58
59
61{
62 color = nullptr;
63 coord = nullptr;
64 colorPerVertex = true;
65}
66
67
69{
70 // nodes must be one of:
71 // Color
72 // Coordinate
73
74 switch( aType )
75 {
78 break;
79
80 default:
81 return false;
82 break;
83 }
84
85 return true;
86}
87
88
90{
91 // this node is dangling unless it has a parent of type WRL2_SHAPE
92
93 if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_SHAPE )
94 return true;
95
96 return false;
97}
98
99
101{
102 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
103
104 WRL2NODES type = aNode->GetNodeType();
105
106 if( !checkNodeType( type ) )
107 {
108 wxLogTrace( traceVrmlPlugin,
109 wxT( "%s:%s:%d\n"
110 " * [INFO] bad file format; unexpected child node '%s'." ),
111 __FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
112
113 return false;
114 }
115
116 if( WRL2NODES::WRL2_COLOR == type )
117 {
118 if( nullptr != color )
119 {
120 wxLogTrace( traceVrmlPlugin,
121 wxT( "%s:%s:%d\n"
122 " * [INFO] bad file format; multiple color nodes." ),
123 __FILE__, __FUNCTION__, __LINE__ );
124
125 return false;
126 }
127
128 color = aNode;
129 return WRL2NODE::AddRefNode( aNode );
130 }
131
132 if( WRL2NODES::WRL2_COORDINATE == type )
133 {
134 if( nullptr != coord )
135 {
136 wxLogTrace( traceVrmlPlugin,
137 wxT( "%s:%s:%d\n"
138 " * [INFO] bad file format; multiple coord nodes." ),
139 __FILE__, __FUNCTION__, __LINE__ );
140
141 return false;
142 }
143
144 coord = aNode;
145 return WRL2NODE::AddRefNode( aNode );
146 }
147
148 return WRL2NODE::AddRefNode( aNode );
149}
150
151
153{
154 wxCHECK_MSG( aNode, false, wxT( "Invalid node." ) );
155
156 WRL2NODES type = aNode->GetNodeType();
157
158 if( !checkNodeType( type ) )
159 {
160 wxLogTrace( traceVrmlPlugin,
161 wxT( "%s:%s:%d\n"
162 " * [INFO] bad file format; unexpected child node '%s'." ),
163 __FILE__, __FUNCTION__, __LINE__, aNode->GetNodeTypeName( type ) );
164
165 return false;
166 }
167
168 if( WRL2NODES::WRL2_COLOR == type )
169 {
170 if( nullptr != color )
171 {
172 wxLogTrace( traceVrmlPlugin,
173 wxT( "%s:%s:%d\n"
174 " * [INFO] bad file format; multiple color nodes." ),
175 __FILE__, __FUNCTION__, __LINE__ );
176
177 return false;
178 }
179
180 color = aNode;
181 return WRL2NODE::AddChildNode( aNode );
182 }
183
184 if( WRL2NODES::WRL2_COORDINATE == type )
185 {
186 if( nullptr != coord )
187 {
188 wxLogTrace( traceVrmlPlugin,
189 wxT( "%s:%s:%d\n"
190 " * [INFO] bad file format; multiple coord nodes." ),
191 __FILE__, __FUNCTION__, __LINE__ );
192
193 return false;
194 }
195
196 coord = aNode;
197 return WRL2NODE::AddChildNode( aNode );
198 }
199
200 return WRL2NODE::AddChildNode( aNode );
201}
202
203
204
205bool WRL2LINESET::Read( WRLPROC& proc, WRL2BASE* aTopNode )
206{
207 char tok = proc.Peek();
208
209 if( proc.eof() )
210 {
211 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
212 " * [INFO] bad file format; unexpected eof %s." ),
213 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
214
215 return false;
216 }
217
218 if( '{' != tok )
219 {
220 wxLogTrace( traceVrmlPlugin,
221 wxT( "%s:%s:%d\n"
222 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
223 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
224
225 return false;
226 }
227
228 proc.Pop();
229 std::string glob;
230
231 while( true )
232 {
233 if( proc.Peek() == '}' )
234 {
235 proc.Pop();
236 break;
237 }
238
239 if( !proc.ReadName( glob ) )
240 {
241 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
242 "%s" ),
243 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
244
245 return false;
246 }
247
248 // expecting one of:
249 // [node]
250 // color
251 // coord
252 // [bool]
253 // colorPerVertex
254 // [ vector<int> ]
255 // colorIndex
256 // coordIndex
257
258 if( !glob.compare( "colorPerVertex" ) )
259 {
260 if( !proc.ReadSFBool( colorPerVertex ) )
261 {
262 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
263 " * [INFO] invalid colorPerVertex %s\n"
264 " * [INFO] file: '%s'\n"
265 "%s" ),
266 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
267 proc.GetFileName(), proc.GetError() );
268
269 return false;
270 }
271 }
272 else if( !glob.compare( "colorIndex" ) )
273 {
274 if( !proc.ReadMFInt( colorIndex ) )
275 {
276 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
277 " * [INFO] invalid colorIndex %s\n"
278 " * [INFO] file: '%s'\n"
279 "%s" ),
280 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
281 proc.GetFileName(), proc.GetError() );
282
283 return false;
284 }
285 }
286 else if( !glob.compare( "coordIndex" ) )
287 {
288 if( !proc.ReadMFInt( coordIndex ) )
289 {
290 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
291 " * [INFO] invalid coordIndex %s\n"
292 " * [INFO] file: '%s'\n"
293 "%s" ),
294 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
295 proc.GetFileName(), proc.GetError() );
296
297 return false;
298 }
299 }
300 else if( !glob.compare( "color" ) )
301 {
302 if( !aTopNode->ReadNode( proc, this, nullptr ) )
303 {
304 wxLogTrace( traceVrmlPlugin,
305 wxT( "%s:%s:%d\n"
306 " * [INFO] could not read color node information." ),
307 __FILE__, __FUNCTION__, __LINE__ );
308
309 return false;
310 }
311 }
312 else if( !glob.compare( "coord" ) )
313 {
314 if( !aTopNode->ReadNode( proc, this, nullptr ) )
315 {
316 wxLogTrace( traceVrmlPlugin,
317 wxT( "%s:%s:%d\n"
318 " * [INFO] could not read coord node information." ),
319 __FILE__, __FUNCTION__, __LINE__ );
320
321 return false;
322 }
323 }
324 else
325 {
326 wxLogTrace( traceVrmlPlugin,
327 wxT( "%s:%s:%d\n"
328 " * [INFO] invalid IndexedFaceSet %s\n"
329 " * [INFO] file: '%s'\n" ),
330 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
331 proc.GetFileName() );
332
333 return false;
334 }
335 } // while( true ) -- reading contents of IndexedLineSet{}
336
337 return true;
338}
339
340
342{
343 // note: there are no plans to support drawing of lines
344 return nullptr;
345}
346
347
349{
350 if( nullptr == aNode )
351 return;
352
353 if( aNode->GetParent() == this )
354 {
355 if( aNode == color )
356 color = nullptr;
357 else if( aNode == coord )
358 coord = nullptr;
359 }
360
362}
363
364
366{
367 if( nullptr == aNode )
368 return;
369
370 if( aNode->GetParent() != this )
371 {
372 if( aNode == color )
373 color = nullptr;
374 else if( aNode == coord )
375 coord = nullptr;
376 }
377
379}
380
381
383{
384 if( nullptr == color )
385 return false;
386
387 return ((WRL2COLOR*) color)->HasColors();
388}
The base class of all Scene Graph nodes.
Definition sg_node.h:71
The top node of a VRML2 model.
Definition vrml2_base.h:56
bool ReadNode(WRLPROC &proc, WRL2NODE *aParent, WRL2NODE **aNode)
bool HasColors(void)
bool Read(WRLPROC &proc, WRL2BASE *aTopNode) override
void setDefaults(void)
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
bool isDangling(void) override
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
bool colorPerVertex
std::vector< int > coordIndex
void unlinkRefNode(const WRL2NODE *aNode) override
Remove pointers to a referenced node.
virtual ~WRL2LINESET()
std::vector< int > colorIndex
bool AddChildNode(WRL2NODE *aNode) override
WRL2NODE * color
void unlinkChildNode(const WRL2NODE *aNode) override
Remove references to an owned child.
bool AddRefNode(WRL2NODE *aNode) override
bool checkNodeType(WRL2NODES aType)
WRL2NODE * coord
std::list< WRL2NODE * > m_BackPointers
Definition vrml2_node.h:169
WRL2NODE * GetParent(void) const
virtual void unlinkChildNode(const WRL2NODE *aNode)
Remove references to an owned child.
WRL2NODE * m_Parent
Definition vrml2_node.h:165
std::list< WRL2NODE * > m_Children
Definition vrml2_node.h:170
WRL2NODES m_Type
Definition vrml2_node.h:166
virtual bool AddRefNode(WRL2NODE *aNode)
virtual void unlinkRefNode(const WRL2NODE *aNode)
Remove pointers to a referenced node.
const char * GetNodeTypeName(WRL2NODES aNodeType) const
WRL2NODES GetNodeType(void) const
std::list< WRL2NODE * > m_Refs
Definition vrml2_node.h:171
virtual bool AddChildNode(WRL2NODE *aNode)
void Pop(void)
Definition wrlproc.cpp:2031
char Peek(void)
Definition wrlproc.cpp:2003
std::string GetFileName(void)
Definition wrlproc.cpp:1991
bool ReadMFInt(std::vector< int > &aMFInt32)
Definition wrlproc.cpp:1500
std::string GetError(void)
Definition wrlproc.cpp:1956
bool ReadSFBool(bool &aSFBool)
Definition wrlproc.cpp:725
bool eof(void)
Definition wrlproc.cpp:1950
bool ReadName(std::string &aName)
Definition wrlproc.cpp:285
std::string GetFilePosition() const
Definition wrlproc.cpp:1978
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition vrml.cpp:59
collects header files for all SG* wrappers and the API
WRL2NODES
Definition wrltypes.h:121
@ WRL2_INDEXEDLINESET
Definition wrltypes.h:146
@ WRL2_COORDINATE
Definition wrltypes.h:134