KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml1_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 (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 "vrml1_base.h"
31#include "vrml1_coords.h"
32
33
34WRL1COORDS::WRL1COORDS( NAMEREGISTER* aDictionary ) : WRL1NODE( aDictionary )
35{
36 m_Type = WRL1NODES::WRL1_COORDINATE3;
37}
38
39
40WRL1COORDS::WRL1COORDS( NAMEREGISTER* aDictionary, WRL1NODE* aParent ) :
41 WRL1NODE( aDictionary )
42{
43 m_Type = WRL1NODES::WRL1_COORDINATE3;
44 m_Parent = aParent;
45
46 if( nullptr != m_Parent )
47 m_Parent->AddChildNode( this );
48}
49
50
52{
53 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Coordinate3 node." ) );
54}
55
56
58{
59 // this node may not own or reference any other node
60 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
61}
62
63
65{
66 // this node may not own or reference any other node
67 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
68}
69
70
71bool WRL1COORDS::Read( WRLPROC& proc, WRL1BASE* aTopNode )
72{
73 char tok = proc.Peek();
74
75 if( proc.eof() )
76 {
77 wxLogTrace( traceVrmlPlugin,
78 wxT( "%s:%s:%d\n"
79 " * [INFO] bad file format; unexpected eof %s." ),
80 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
81
82 return false;
83 }
84
85 if( '{' != tok )
86 {
87 wxLogTrace( traceVrmlPlugin,
88 wxT( "%s:%s:%d\n"
89 " * [INFO] bad file format; expecting '{' but got '%s' %s" ),
90 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
91
92 return false;
93 }
94
95 proc.Pop();
96 std::string glob;
97
98 if( proc.Peek() == '}' )
99 {
100 proc.Pop();
101 return true;
102 }
103
104 if( !proc.ReadName( glob ) )
105 {
106 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n%s" ),
107 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
108
109 return false;
110 }
111
112 // expecting 'point'
113 if( !glob.compare( "point" ) )
114 {
115 if( !proc.ReadMFVec3f( points ) )
116 {
117 wxLogTrace( traceVrmlPlugin,
118 wxT( "%s:%s:%d\n"
119 " * [INFO] invalid point set %s\n"
120 " * [INFO] file: '%s'\n"
121 "%s" ),
122 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
123 proc.GetFileName(), proc.GetError() );
124
125 return false;
126 }
127 }
128 else
129 {
130 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
131 "* [INFO] bad Coordinate %s.\n"
132 "* [INFO] file: '%s'." ),
133 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
134
135 return false;
136 }
137
138 // assuming legacy KiCad expectation of 1U = 0.1 inch,
139 // convert to mm to meet the expectations of the SG structure
140 std::vector< WRLVEC3F >::iterator sP = points.begin();
141 std::vector< WRLVEC3F >::iterator eP = points.end();
142
143 while( sP != eP )
144 {
145 sP->x *= 2.54f;
146 sP->y *= 2.54f;
147 sP->z *= 2.54f;
148 ++sP;
149 }
150
151 if( proc.Peek() == '}' )
152 {
153 proc.Pop();
154 return true;
155 }
156
157 wxLogTrace( traceVrmlPlugin,
158 wxT( "%s:%s:%d\n"
159 " * [INFO] bad Coordinate %s (no closing brace)." ),
160 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
161
162 return false;
163}
164
165
166void WRL1COORDS::GetCoords( WRLVEC3F*& aCoordList, size_t& aListSize )
167{
168 if( points.size() < 3 )
169 {
170 aCoordList = nullptr;
171 aListSize = 0;
172 return;
173 }
174
175 aCoordList = &points[0];
176 aListSize = points.size();
177}
178
179
181{
182 wxCHECK_MSG( sp, nullptr, wxT( "Invalid base data." ) );
183
184 sp->coord = this;
185
186 return nullptr;
187}
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
bool Read(WRLPROC &proc, WRL1BASE *aTopNode) override
bool AddRefNode(WRL1NODE *aNode) override
void GetCoords(WRLVEC3F *&aCoordList, size_t &aListSize)
bool AddChildNode(WRL1NODE *aNode) override
SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
std::vector< WRLVEC3F > points
Definition: vrml1_coords.h:56
WRL1COORDS(NAMEREGISTER *aDictionary)
virtual ~WRL1COORDS()
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
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
WRL1COORDS * coord
Definition: vrml1_node.h:94
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188