KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml1_matbinding.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_matbinding.h"
33
34
36{
37 m_binding = WRL1_BINDING::BIND_OVERALL;
38 m_Type = WRL1NODES::WRL1_MATERIALBINDING;
39}
40
41
43 WRL1NODE( aDictionary )
44{
45 m_binding = WRL1_BINDING::BIND_OVERALL;
46 m_Type = WRL1NODES::WRL1_MATERIALBINDING;
47 m_Parent = aParent;
48
49 if( nullptr != m_Parent )
50 m_Parent->AddChildNode( this );
51}
52
53
55{
56 wxLogTrace( traceVrmlPlugin, wxT( " * [INFO] Destroying MaterialBinding node\n" ) );
57}
58
59
61{
62 // this node may not own or reference any other node
63 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
64}
65
66
68{
69 // this node may not own or reference any other node
70 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
71}
72
73
74bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
75{
76 wxCHECK_MSG( aTopNode, false, wxT( "aTopNode is NULL." ) );
77
78 char tok = proc.Peek();
79
80 if( proc.eof() )
81 {
82 wxLogTrace( traceVrmlPlugin,
83 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 while( true )
104 {
105 if( proc.Peek() == '}' )
106 {
107 proc.Pop();
108 break;
109 }
110
111 if( !proc.ReadName( glob ) )
112 {
113 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
114 "%s" ),
115 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
116
117 return false;
118 }
119
120 if( glob.compare( "value" ) )
121 {
122 wxLogTrace( traceVrmlPlugin,
123 wxT( "%s:%s:%d\n"
124 " * [INFO] bad MaterialBinding %s (expecting keyword 'value').\n"
125 " * [INFO] file: '%s'." ),
126 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
127 proc.GetFileName() );
128
129 return false;
130 }
131
132 if( !proc.ReadName( glob ) )
133 {
134 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
135 "%s" ),
136 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
137
138 return false;
139 }
140
141 // expecting one of:
142 // DEFAULT
143 // OVERALL
144 // PER_PART
145 // PER_PART_INDEXED
146 // PER_FACE
147 // PER_FACE_INDEXED
148 // PER_VERTEX
149 // PER_VERTEX_INDEXED
150
151 if( !glob.compare( "DEFAULT" ) )
152 {
153 m_binding = WRL1_BINDING::BIND_DEFAULT;
154 }
155 else if( !glob.compare( "OVERALL" ) )
156 {
157 m_binding = WRL1_BINDING::BIND_OVERALL;
158 }
159 else if( !glob.compare( "PER_PART" ) )
160 {
161 m_binding = WRL1_BINDING::BIND_PER_PART;
162 }
163 else if( !glob.compare( "PER_PART_INDEXED" ) )
164 {
165 m_binding = WRL1_BINDING::BIND_PER_PART_INDEXED;
166 }
167 else if( !glob.compare( "PER_FACE" ) )
168 {
169 m_binding = WRL1_BINDING::BIND_PER_FACE;
170 }
171 else if( !glob.compare( "PER_FACE_INDEXED" ) )
172 {
173 m_binding = WRL1_BINDING::BIND_PER_FACE_INDEXED;
174 }
175 else if( !glob.compare( "PER_VERTEX" ) )
176 {
177 m_binding = WRL1_BINDING::BIND_PER_VERTEX;
178 }
179 else if( !glob.compare( "PER_VERTEX_INDEXED" ) )
180 {
181 m_binding = WRL1_BINDING::BIND_PER_VERTEX_INDEXED;
182 }
183 else
184 {
185 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
186 " * [INFO] bad MaterialBinding %s\n"
187 " * [INFO] file: '%s'" ),
188 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
189 proc.GetFileName() );
190
191 m_binding = WRL1_BINDING::BIND_OVERALL;
192 }
193 } // while( true ) -- reading contents of MaterialBinding{}
194
195 return true;
196}
197
198
200{
201 wxCHECK_MSG ( sp, nullptr, wxT( "Bad model: no base data given." ) );
202
203 sp->matbind = m_binding;
204
205 return nullptr;
206}
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 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...
WRL1MATBINDING(NAMEREGISTER *aDictionary)
bool AddRefNode(WRL1NODE *aNode) override
virtual ~WRL1MATBINDING()
WRL1_BINDING m_binding
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 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
collects header files for all SG* wrappers and the API
WRL1_BINDING matbind
Definition: vrml1_node.h:97