KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml2_norms.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_norms.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 Normal 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 WRL2NORMS::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 'vector'
119 if( !glob.compare( "vector" ) )
120 {
121 if( !proc.ReadMFVec3f( vectors ) )
122 {
123 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
124 " * [INFO] invalid vector 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\n"
136 " * [INFO] invalid Normal %s\n"
137 " * [INFO] file: '%s'" ),
138 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
139
140 return false;
141 }
142
143 if( proc.Peek() == '}' )
144 {
145 proc.Pop();
146 return true;
147 }
148
149 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
150 " * [INFO] invalid Normal %s (no closing brace)\n"
151 " * [INFO] file: '%s'" ),
152 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
153
154 return false;
155}
156
157
159{
160 // any data manipulation must be performed by the parent node
161 return nullptr;
162}
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
WRL2NODE * m_Parent
Definition vrml2_node.h:165
WRL2NODES m_Type
Definition vrml2_node.h:166
bool isDangling(void) override
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
bool Read(WRLPROC &proc, WRL2BASE *aTopNode) override
bool AddRefNode(WRL2NODE *aNode) override
bool AddChildNode(WRL2NODE *aNode) override
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
virtual ~WRL2NORMS()
std::vector< WRLVEC3F > vectors
Definition vrml2_norms.h:51
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_NORMAL
Definition wrltypes.h:152