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 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_coords.h"
28
29
34
35
37{
39 m_Parent = aParent;
40
41 if( nullptr != m_Parent )
42 m_Parent->AddChildNode( this );
43}
44
45
47{
48 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Coordinate node." ) );
49}
50
51
53{
54 // this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
55
56 if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_INDEXEDFACESET )
57 return true;
58
59 return false;
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 WRL2COORDS::Read( WRLPROC& proc, WRL2BASE* aTopNode )
78{
79 char tok = proc.Peek();
80
81 if( proc.eof() )
82 {
83 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
84 " * [INFO] bad file format; unexpected eof %s." ),
85 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
86
87 return false;
88 }
89
90 if( '{' != tok )
91 {
92 wxLogTrace( traceVrmlPlugin,
93 wxT( "%s:%s:%d\n"
94 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
95 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
96
97 return false;
98 }
99
100 proc.Pop();
101 std::string glob;
102
103 if( proc.Peek() == '}' )
104 {
105 proc.Pop();
106 return true;
107 }
108
109 if( !proc.ReadName( glob ) )
110 {
111 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
112 "%s" ),
113 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
114
115 return false;
116 }
117
118 // expecting 'point'
119 if( !glob.compare( "point" ) )
120 {
121 if( !proc.ReadMFVec3f( points ) )
122 {
123 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
124 " * [INFO] invalid Coordinate point set %s\n"
125 " * [INFO] file: '%s'\n"
126 "%s" ),
127 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
128 proc.GetFileName(), proc.GetError() );
129
130 return false;
131 }
132 }
133 else
134 {
135 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
136 " * [INFO] invalid Coordinate %s\n"
137 " * [INFO] file: '%s'\n" ),
138 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
139
140 return false;
141 }
142
143 // For legacy KiCad VRML files (1U = 0.1 inch), convert to mm.
144 // For PCBnew exports with top-level scale, skip conversion as coordinates are already correct.
145 if( aTopNode->GetApplyUnitConversion() )
146 {
147 std::vector< WRLVEC3F >::iterator sP = points.begin();
148 std::vector< WRLVEC3F >::iterator eP = points.end();
149
150 while( sP != eP )
151 {
152 sP->x *= 2.54f;
153 sP->y *= 2.54f;
154 sP->z *= 2.54f;
155 ++sP;
156 }
157 }
158
159 if( proc.Peek() == '}' )
160 {
161 proc.Pop();
162 return true;
163 }
164
165 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d"
166 " * [INFO] invalid Coordinate %s (no closing brace)\n"
167 " * [INFO] file: '%s'\n" ),
168 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
169
170 return false;
171}
172
173
174void WRL2COORDS::GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize )
175{
176 if( points.size() < 3 )
177 {
178 aCoordList = nullptr;
179 aListSize = 0;
180 return;
181 }
182
183 aCoordList = &points[0];
184 aListSize = points.size();
185}
186
187
189{
190 // any data manipulation must be performed by the parent node
191 return nullptr;
192}
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 GetApplyUnitConversion(void) const
bool AddChildNode(WRL2NODE *aNode) override
bool AddRefNode(WRL2NODE *aNode) override
void GetCoords(WRLVEC3F *&aCoordList, size_t &aListSize)
std::vector< WRLVEC3F > points
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:165
WRL2NODES m_Type
Definition vrml2_node.h:166
void Pop(void)
Definition wrlproc.cpp:2031
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 ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition wrlproc.cpp:1835
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
@ WRL2_INDEXEDFACESET
Definition wrltypes.h:145
@ WRL2_COORDINATE
Definition wrltypes.h:134
glm::vec3 WRLVEC3F
Definition wrltypes.h:184