KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml2_color.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_color.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 Color node" ) );
49}
50
51
53{
54 // this node is dangling unless it has a parent of type WRL2_INDEXEDFACESET
55 if( nullptr == m_Parent || m_Parent->GetNodeType() != WRL2NODES::WRL2_INDEXEDFACESET )
56 return true;
57
58 return false;
59}
60
61
63{
64 // this node may not own or reference any other node
65 wxCHECK_MSG( false, false, wxT( "AddRefNode is not applicable." ) );
66}
67
68
70{
71 // this node may not own or reference any other node
72 wxCHECK_MSG( false, false, wxT( "AddChildNode is not applicable." ) );
73}
74
75
76bool WRL2COLOR::Read( WRLPROC& proc, WRL2BASE* aTopNode )
77{
78 char tok = proc.Peek();
79
80 if( proc.eof() )
81 {
82 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
83 " * [INFO] bad file format; unexpected eof %s." ),
84 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition() );
85
86 return false;
87 }
88
89 if( '{' != tok )
90 {
91 wxLogTrace( traceVrmlPlugin,
92 wxT( "%s:%s:%d\n"
93 " * [INFO] bad file format; expecting '{' but got '%s' %s." ),
94 __FILE__, __FUNCTION__, __LINE__, tok, proc.GetFilePosition() );
95
96 return false;
97 }
98
99 proc.Pop();
100 std::string glob;
101
102 if( proc.Peek() == '}' )
103 {
104 proc.Pop();
105 return true;
106 }
107
108 if( !proc.ReadName( glob ) )
109 {
110 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
111 "%s" ),
112 __FILE__, __FUNCTION__, __LINE__ , proc.GetError() );
113
114 return false;
115 }
116
117 // expecting 'color'
118 if( !glob.compare( "color" ) )
119 {
120 if( !proc.ReadMFVec3f( colors ) )
121 {
122 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
123 " * [INFO] invalid color set %s\n"
124 " * [INFO] file: '%s'\n"
125 "%s" ),
126 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(),
127 proc.GetFileName(), proc.GetError() );
128
129 return false;
130 }
131 }
132 else
133 {
134 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
135 " * [INFO] invalid Color %s\n"
136 " * [INFO] file: '%s'\n" ),
137 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
138
139 return false;
140 }
141
142 if( proc.Peek() == '}' )
143 {
144 proc.Pop();
145 return true;
146 }
147
148 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
149 " * [INFO] invalid Color %s (no closing brace)\n"
150 " * [INFO] file: '%s'\n" ),
151 __FILE__, __FUNCTION__, __LINE__, proc.GetFilePosition(), proc.GetFileName() );
152
153 return false;
154}
155
156
158{
159 // any data manipulation must be performed by the parent node
160 return nullptr;
161}
162
163
165{
166 if( colors.empty() )
167 return false;
168
169 return true;
170}
171
172
173void WRL2COLOR::GetColor( int aIndex, float& red, float& green, float& blue )
174{
175 if( aIndex < 0 || aIndex >= (int)colors.size() )
176 {
177 red = 0.8f;
178 green = 0.8f;
179 blue = 0.8f;
180 return;
181 }
182
183 red = colors[aIndex].x;
184 green = colors[aIndex].y;
185 blue = colors[aIndex].z;
186}
187
188
189void WRL2COLOR::GetColors( WRLVEC3F*& aColorList, size_t& aListSize)
190{
191 if( colors.empty() )
192 {
193 aColorList = nullptr;
194 aListSize = 0;
195 return;
196 }
197
198 aColorList = &colors[0];
199 aListSize = colors.size();
200}
int blue
int red
int green
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
bool Read(WRLPROC &proc, WRL2BASE *aTopNode) override
std::vector< WRLVEC3F > colors
Definition vrml2_color.h:66
void GetColor(int aIndex, float &red, float &green, float &blue)
Retrieve the given color (or default 0.8, 0.8, 0.8 if index is invalid).
bool HasColors(void)
bool AddChildNode(WRL2NODE *aNode) override
bool AddRefNode(WRL2NODE *aNode) override
bool isDangling(void) override
Determine whether an object should be moved to a different parent during the VRML to SG* translation.
virtual ~WRL2COLOR()
void GetColors(WRLVEC3F *&aColorList, size_t &aListSize)
Retrieve the current list of colors.
SGNODE * TranslateToSG(SGNODE *aParent) override
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
WRL2NODE * m_Parent
Definition vrml2_node.h:165
WRL2NODES m_Type
Definition vrml2_node.h:166
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
glm::vec3 WRLVEC3F
Definition wrltypes.h:184