KiCad PCB EDA Suite
vrml1_shapehints.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 <cmath>
29#include <wx/log.h>
30
31#include "vrml1_base.h"
32#include "vrml1_shapehints.h"
34
35
37{
40 m_crease = 0.733f; // approx 42 degrees; this is larger than VRML spec.
41}
42
43
45 WRL1NODE( aDictionary )
46{
49 m_crease = 0.733f; // approx 42 degrees; this is larger than VRML spec.
50 m_Parent = aParent;
51
52 if( nullptr != m_Parent )
53 m_Parent->AddChildNode( this );
54}
55
56
58{
59 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying ShapeHints node." ) );
60}
61
62
64{
65 // this node may not own or reference any other node
66 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
67}
68
69
71{
72 // this node may not own or reference any other node
73 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
74}
75
76
77bool WRL1SHAPEHINTS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
78{
79 wxCHECK_MSG( aTopNode, false, wxT( "Invalid top node." ) );
80
81 char tok = proc.Peek();
82
83 if( proc.eof() )
84 {
85 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
86 " * [INFO] bad file format; unexpected eof %s." ),
87 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
88
89 return false;
90 }
91
92 if( '{' != tok )
93 {
94 wxLogTrace( traceVrmlPlugin,
95 wxT( "%s:%s:%d\n"
96 " * [INFO] bad file format; expecting '{' but got '%s' %s.\n"
97 "%s" ),
98 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition(),
99 proc.GetError() );
100
101 return false;
102 }
103
104 proc.Pop();
105 std::string glob;
106
107 while( true )
108 {
109 if( proc.Peek() == '}' )
110 {
111 proc.Pop();
112 break;
113 }
114
115 if( !proc.ReadName( glob ) )
116 {
117 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
118 "%s" ),
119 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
120
121 return false;
122 }
123
124 // expecting one of:
125 // vertexOrdering
126 // shapeType
127 // faceType
128 // creaseAngle
129
130 if( !glob.compare( "vertexOrdering" ) )
131 {
132 if( !proc.ReadName( glob ) )
133 {
134 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
135 "%s" ),
136 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
137
138 return false;
139 }
140
141 if( !glob.compare( "UNKNOWN_ORDERING" ) )
142 {
144 }
145 else if( !glob.compare( "CLOCKWISE" ) )
146 {
148 }
149 else if( !glob.compare( "COUNTERCLOCKWISE" ) )
150 {
152 }
153 else
154 {
155 wxLogTrace( traceVrmlPlugin,
156 wxT( "%s:%s:%d\n"
157 " * [INFO] bad ShapeHints %s (invalid value '%s')\n"
158 " * [INFO] file: '%s'" ),
159 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), glob,
160 proc.GetFileName() );
161
162 return false;
163 }
164 }
165 else if( !glob.compare( "shapeType" ) )
166 {
167 if( !proc.ReadName( glob ) )
168 {
169 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
170 "%s" ),
171 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
172
173 return false;
174 }
175
176 // expected values:
177 // UNKNOWN_SHAPE_TYPE
178 // SOLID
179 }
180 else if( !glob.compare( "faceType" ) )
181 {
182 if( !proc.ReadName( glob ) )
183 {
184 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
185 "%s" ),
186 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
187
188 return false;
189 }
190
191 // expected values:
192 // UNKNOWN_FACE_TYPE
193 // CONVEX
194 }
195 else if( !glob.compare( "creaseAngle" ) )
196 {
197 float tmp;
198
199 if( !proc.ReadSFFloat( tmp ) )
200 {
201 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
202 "%s" ),
203 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
204
205 return false;
206 }
207
208 if( tmp < 0.0 )
209 tmp = 0.0f;
210 else if( tmp > M_PI )
211 tmp = static_cast<float>( M_PI );
212
213 m_crease = tmp;
214 }
215 else
216 {
217 wxLogTrace( traceVrmlPlugin,
218 wxT( "%s:%s:%d\n"
219 " * [INFO] bad ShapeHints %s (unexpected keyword '%s')\n"
220 " * [INFO] file: '%s'" ),
221 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), glob,
222 proc.GetFileName() );
223
224 return false;
225 }
226 } // while( true ) -- reading contents of ShapeHints{}
227
228 return true;
229}
230
231
233{
234 // note: this is not fully implemented since it is unlikely we shall
235 // ever make use of the fields shapeType, faceType, and creaseAngle
236 wxCHECK_MSG( sp, nullptr, wxT( "Invalid base data." ) );
237
238 sp->order = m_order;
239 sp->creaseLimit = cosf(m_crease);
240
241 if( sp->creaseLimit < 0.0 )
242 sp->creaseLimit = 0.0;
243
244 return nullptr;
245}
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
Represent the top node of a VRML1 model.
Definition: vrml1_base.h:46
The base class of all VRML1 nodes.
Definition: vrml1_node.h:117
WRL1NODES m_Type
Definition: vrml1_node.h:227
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
WRL1NODE * m_Parent
Definition: vrml1_node.h:226
WRL1_ORDER m_order
SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
WRL1SHAPEHINTS(NAMEREGISTER *aDictionary)
virtual ~WRL1SHAPEHINTS()
bool AddChildNode(WRL1NODE *aNode) override
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override
bool AddRefNode(WRL1NODE *aNode) override
void Pop(void)
Definition: wrlproc.cpp:2035
bool ReadSFFloat(float &aSFFloat)
Definition: wrlproc.cpp:806
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 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
collects header files for all SG* wrappers and the API
WRL1_ORDER order
Definition: vrml1_node.h:106
float creaseLimit
Definition: vrml1_node.h:109