KiCad PCB EDA Suite
vrml2_norms.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_norms.h"
32
33
35{
37}
38
39
41{
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 Normal node." ) );
53}
54
55
57{
58 // this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
59
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 WRL2NORMS::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 'vector'
123 if( !glob.compare( "vector" ) )
124 {
125 if( !proc.ReadMFVec3f( vectors ) )
126 {
127 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
128 " * [INFO] invalid vector 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\n"
140 " * [INFO] invalid Normal %s\n"
141 " * [INFO] file: '%s'" ),
142 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
143
144 return false;
145 }
146
147 if( proc.Peek() == '}' )
148 {
149 proc.Pop();
150 return true;
151 }
152
153 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
154 " * [INFO] invalid Normal %s (no closing brace)\n"
155 " * [INFO] file: '%s'" ),
156 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
157
158 return false;
159}
160
161
163{
164 // any data manipulation must be performed by the parent node
165 return nullptr;
166}
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
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
bool isDangling(void) override
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
Definition: vrml2_norms.cpp:56
bool Read(WRLPROC &proc, WRL2BASE *aTopNode) override
Definition: vrml2_norms.cpp:81
bool AddRefNode(WRL2NODE *aNode) override
Definition: vrml2_norms.cpp:67
bool AddChildNode(WRL2NODE *aNode) override
Definition: vrml2_norms.cpp:74
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
virtual ~WRL2NORMS()
Definition: vrml2_norms.cpp:50
std::vector< WRLVEC3F > vectors
Definition: vrml2_norms.h:55
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
@ WRL2_INDEXEDFACESET