KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml2_inline.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_inline.h"
27#include "vrml2_base.h"
29
30
32{
33 m_VRML2Base = nullptr;
35 m_Parent = nullptr;
36}
37
38
40{
41 m_VRML2Base = nullptr;
43 m_Parent = aParent;
44
45 if( nullptr != m_Parent )
46 m_Parent->AddChildNode( this );
47}
48
49
51{
52 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying Inline node." ) );
53}
54
55
57{
58 // this node is never dangling
59 return false;
60}
61
62
63bool WRL2INLINE::Read( WRLPROC& proc, WRL2BASE* aTopNode )
64{
65 if( aTopNode == nullptr || aTopNode->GetNodeType() != WRL2NODES::WRL2_BASE )
66 return false;
67
68 m_VRML2Base = aTopNode;
69 char tok = proc.Peek();
70
71 if( proc.eof() )
72 {
73 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
74 " * [INFO] bad file format; unexpected eof %s." ),
75 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
76
77 return false;
78 }
79
80 if( '{' != tok )
81 {
82 wxLogTrace( traceVrmlPlugin,
83 wxT( "%s:%s:%d\n"
84 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
85 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
86
87 return false;
88 }
89
90 proc.Pop();
91
92 while( ( tok = proc.Peek() ) != 0 )
93 {
94 std::string glob;
95
96 if( tok == '}' )
97 {
98 proc.Pop();
99 return true;
100 }
101
102 if( !proc.ReadName( glob ) )
103 {
104 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
105 "%s" ),
106 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
107
108 return false;
109 }
110
111 // expecting one of 'url', 'bboxCenter', 'bboxSize'
112 if( !glob.compare( "url" ) )
113 {
114 if( !proc.ReadMFString( url ) )
115 {
116 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
117 " * [INFO] invalid url %s\n"
118 " * [INFO] file: '%s'\n"
119 "%s" ),
120 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
121 proc.GetFileName(), proc.GetError() );
122
123 return false;
124 }
125 }
126 else if( !glob.compare( "bboxCenter" ) )
127 {
128 if( !proc.ReadSFVec3f( bboxCenter ) )
129 {
130 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
131 " * [INFO] invalid bboxCenter %s\n"
132 " * [INFO] file: '%s'\n"
133 "%s" ),
134 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
135 proc.GetFileName(), proc.GetError() );
136
137 return false;
138 }
139 }
140 else if( !glob.compare( "bboxSize" ) )
141 {
142 if( !proc.ReadSFVec3f( bboxSize ) )
143 {
144 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
145 " * [INFO] invalid bboxSize %s\n"
146 " * [INFO] file: '%s'\n"
147 "%s" ),
148 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
149 proc.GetFileName(), proc.GetError() );
150
151 return false;
152 }
153 }
154 else
155 {
156 wxLogTrace( traceVrmlPlugin,
157 wxT( "%s:%s:%d\n"
158 " * [INFO] invalid Inline %s\n"
159 " * [INFO] file: '%s'\n" ),
160 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
161 proc.GetFileName() );
162
163 return false;
164 }
165 }
166
167 wxLogTrace( traceVrmlPlugin,
168 wxT( "%s:%s:%d\n"
169 " * [INFO] invalid Inline %s (no closing brace)\n"
170 " * [INFO] file: '%s'\n" ),
171 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
172 proc.GetFileName() );
173
174 return false;
175}
176
177
179{
180 // this node may not own or reference any other node
181 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
182}
183
184
186{
187 // this node may not own or reference any other node
188 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
189
190 return false;
191}
192
193
195{
196 if( nullptr == aParent || nullptr == m_VRML2Base )
197 return nullptr;
198
199 if( url.empty() )
200 return nullptr;
201
202 S3D::SGTYPES ptype = S3D::GetSGNodeType( aParent );
203
204 wxCHECK_MSG( aParent && ( ptype == S3D::SGTYPE_TRANSFORM ), nullptr,
205 wxString::Format( wxT( " * [BUG] Appearance does not have a Transform parent "
206 "(parent ID: %d)." ), ptype ) );
207
208 SGNODE* np = m_VRML2Base->GetInlineData( url.front() );
209
210 if( nullptr == np )
211 return nullptr;
212
213 bool OK = false;
214
215 if( nullptr == S3D::GetSGNodeParent( np ) )
216 OK = S3D::AddSGNodeChild( aParent, np );
217 else
218 OK = S3D::AddSGNodeRef( aParent, np );
219
220 if( !OK )
221 return nullptr;
222
223 return np;
224}
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
virtual ~WRL2INLINE()
std::vector< std::string > url
bool Read(WRLPROC &proc, WRL2BASE *aTopNode) override
WRLVEC3F bboxSize
bool AddRefNode(WRL2NODE *aNode) override
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
bool isDangling(void) override
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
WRL2BASE * m_VRML2Base
bool AddChildNode(WRL2NODE *aNode) override
WRLVEC3F bboxCenter
WRL2NODE * m_Parent
Definition vrml2_node.h:165
WRL2NODES m_Type
Definition vrml2_node.h:166
WRL2NODES GetNodeType(void) const
bool ReadMFString(std::vector< std::string > &aMFString)
Definition wrlproc.cpp:1158
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 ReadName(std::string &aName)
Definition wrlproc.cpp:285
std::string GetFilePosition() const
Definition wrlproc.cpp:1978
bool ReadSFVec3f(WRLVEC3F &aSFVec3f)
Definition wrlproc.cpp:1078
#define OK
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
SGLIB_API S3D::SGTYPES GetSGNodeType(SGNODE *aNode)
Definition ifsg_api.cpp:481
SGLIB_API SGNODE * GetSGNodeParent(SGNODE *aNode)
Definition ifsg_api.cpp:490
SGTYPES
Definition sg_types.h:32
@ SGTYPE_TRANSFORM
Definition sg_types.h:33
SGLIB_API bool AddSGNodeChild(SGNODE *aParent, SGNODE *aChild)
Definition ifsg_api.cpp:508
SGLIB_API bool AddSGNodeRef(SGNODE *aParent, SGNODE *aChild)
Definition ifsg_api.cpp:499
@ WRL2_INLINE
Definition wrltypes.h:147