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