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 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_matbinding.h"
29
30
36
37
39 WRL1NODE( aDictionary )
40{
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 MaterialBinding node\n" ) );
53}
54
55
57{
58 // this node may not own or reference any other node
59 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
60}
61
62
64{
65 // this node may not own or reference any other node
66 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
67}
68
69
70bool WRL1MATBINDING::Read( WRLPROC& proc, WRL1BASE* aTopNode )
71{
72 wxCHECK_MSG( aTopNode, false, wxT( "aTopNode is NULL." ) );
73
74 char tok = proc.Peek();
75
76 if( proc.eof() )
77 {
78 wxLogTrace( traceVrmlPlugin,
79 wxT( "%s:%s:%d\n"
80 " * [INFO] bad file format; unexpected eof %s." ),
81 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
82
83 return false;
84 }
85
86 if( '{' != tok )
87 {
88 wxLogTrace( traceVrmlPlugin,
89 wxT( "%s:%s:%d\n"
90 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
91 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
92
93 return false;
94 }
95
96 proc.Pop();
97 std::string glob;
98
99 while( true )
100 {
101 if( proc.Peek() == '}' )
102 {
103 proc.Pop();
104 break;
105 }
106
107 if( !proc.ReadName( glob ) )
108 {
109 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
110 "%s" ),
111 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
112
113 return false;
114 }
115
116 if( glob.compare( "value" ) )
117 {
118 wxLogTrace( traceVrmlPlugin,
119 wxT( "%s:%s:%d\n"
120 " * [INFO] bad MaterialBinding %s (expecting keyword 'value').\n"
121 " * [INFO] file: '%s'." ),
122 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
123 proc.GetFileName() );
124
125 return false;
126 }
127
128 if( !proc.ReadName( glob ) )
129 {
130 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
131 "%s" ),
132 __FILE__, __FUNCTION__, __LINE__, proc.GetError() );
133
134 return false;
135 }
136
137 // expecting one of:
138 // DEFAULT
139 // OVERALL
140 // PER_PART
141 // PER_PART_INDEXED
142 // PER_FACE
143 // PER_FACE_INDEXED
144 // PER_VERTEX
145 // PER_VERTEX_INDEXED
146
147 if( !glob.compare( "DEFAULT" ) )
148 {
150 }
151 else if( !glob.compare( "OVERALL" ) )
152 {
154 }
155 else if( !glob.compare( "PER_PART" ) )
156 {
158 }
159 else if( !glob.compare( "PER_PART_INDEXED" ) )
160 {
162 }
163 else if( !glob.compare( "PER_FACE" ) )
164 {
166 }
167 else if( !glob.compare( "PER_FACE_INDEXED" ) )
168 {
170 }
171 else if( !glob.compare( "PER_VERTEX" ) )
172 {
174 }
175 else if( !glob.compare( "PER_VERTEX_INDEXED" ) )
176 {
178 }
179 else
180 {
181 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
182 " * [INFO] bad MaterialBinding %s\n"
183 " * [INFO] file: '%s'" ),
184 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
185 proc.GetFileName() );
186
188 }
189 } // while( true ) -- reading contents of MaterialBinding{}
190
191 return true;
192}
193
194
196{
197 wxCHECK_MSG ( sp, nullptr, wxT( "Bad model: no base data given." ) );
198
199 sp->matbind = m_binding;
200
201 return nullptr;
202}
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 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
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 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
collects header files for all SG* wrappers and the API
WRL1_BINDING matbind
Definition vrml1_node.h:93
@ WRL1_MATERIALBINDING
Definition wrltypes.h:68
@ BIND_PER_PART_INDEXED
Definition wrltypes.h:102
@ BIND_PER_VERTEX_INDEXED
Definition wrltypes.h:105
@ BIND_PER_FACE_INDEXED
Definition wrltypes.h:103