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