KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ifsg_appearance.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) 2015 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>
27
28
29extern char BadParent[];
30extern char WrongParent[];
31
32
34{
35 m_node = nullptr;
36
37 if( !create )
38 return ;
39
40 m_node = new SGAPPEARANCE( nullptr );
41
42 m_node->AssociateWrapper( &m_node );
43}
44
45
47{
48 m_node = new SGAPPEARANCE( nullptr );
49
50 if( !m_node->SetParent( aParent ) )
51 {
52 delete m_node;
53 m_node = nullptr;
54
55 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
57
58 return;
59 }
60
61 m_node->AssociateWrapper( &m_node );
62}
63
64
66{
67 SGNODE* pp = aParent.GetRawPtr();
68
69#ifdef DEBUG
70 if( ! pp )
71 {
72 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
73 BadParent );
74 }
75#endif
76
77 m_node = new SGAPPEARANCE( nullptr );
78
79 if( !m_node->SetParent( pp ) )
80 {
81 delete m_node;
82 m_node = nullptr;
83
84 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
86
87 return;
88 }
89
90 m_node->AssociateWrapper( &m_node );
91}
92
93
95{
96 if( m_node )
97 m_node->DisassociateWrapper( &m_node );
98
99 m_node = nullptr;
100
101 if( !aNode )
102 return false;
103
104 if( S3D::SGTYPE_APPEARANCE != aNode->GetNodeType() )
105 {
106 return false;
107 }
108
109 m_node = aNode;
110 m_node->AssociateWrapper( &m_node );
111
112 return true;
113}
114
115
117{
118 if( m_node )
119 m_node->DisassociateWrapper( &m_node );
120
121 m_node = new SGAPPEARANCE( aParent );
122
123 if( aParent != m_node->GetParent() )
124 {
125 wxLogTrace( MASK_3D_SG,
126 wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGAPPEARANCE" ),
127 __FILE__, __FUNCTION__, __LINE__,
128 aParent->GetNodeTypeName( aParent->GetNodeType() ) );
129
130 delete m_node;
131 m_node = nullptr;
132 return false;
133 }
134
135 m_node->AssociateWrapper( &m_node );
136
137 return true;
138}
139
140
142{
143 SGNODE* np = aParent.GetRawPtr();
144
145 wxCHECK( np, false );
146
147 return NewNode( np );
148}
149
150
151bool IFSG_APPEARANCE::SetEmissive( float aRVal, float aGVal, float aBVal )
152{
153 wxCHECK( m_node, false );
154
155 return ( (SGAPPEARANCE*) m_node )->SetEmissive( aRVal, aGVal, aBVal );
156}
157
158
159bool IFSG_APPEARANCE::SetEmissive( const SGCOLOR* aRGBColor )
160{
161 wxCHECK( m_node, false );
162
163 return ( (SGAPPEARANCE*) m_node )->SetEmissive( aRGBColor );
164}
165
166
167bool IFSG_APPEARANCE::SetEmissive( const SGCOLOR& aRGBColor )
168{
169 wxCHECK( m_node, false );
170
171 return ( (SGAPPEARANCE*) m_node )->SetEmissive( aRGBColor );
172}
173
174
175bool IFSG_APPEARANCE::SetDiffuse( float aRVal, float aGVal, float aBVal )
176{
177 wxCHECK( m_node, false );
178
179 return ( (SGAPPEARANCE*) m_node )->SetDiffuse( aRVal, aGVal, aBVal );
180}
181
182
183bool IFSG_APPEARANCE::SetDiffuse( const SGCOLOR* aRGBColor )
184{
185 wxCHECK( m_node, false );
186
187 return ( (SGAPPEARANCE*) m_node )->SetDiffuse( aRGBColor );
188}
189
190
191bool IFSG_APPEARANCE::SetDiffuse( const SGCOLOR& aRGBColor )
192{
193 wxCHECK( m_node, false );
194
195 return ( (SGAPPEARANCE*) m_node )->SetDiffuse( aRGBColor );
196}
197
198
199bool IFSG_APPEARANCE::SetSpecular( float aRVal, float aGVal, float aBVal )
200{
201 wxCHECK( m_node, false );
202
203 return ( (SGAPPEARANCE*) m_node )->SetSpecular( aRVal, aGVal, aBVal );
204}
205
206
207bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR* aRGBColor )
208{
209 wxCHECK( m_node, false );
210
211 return ( (SGAPPEARANCE*) m_node )->SetSpecular( aRGBColor );
212}
213
214
215bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR& aRGBColor )
216{
217 wxCHECK( m_node, false );
218
219 return ( (SGAPPEARANCE*) m_node )->SetSpecular( aRGBColor );
220}
221
222
223bool IFSG_APPEARANCE::SetAmbient( float aRVal, float aGVal, float aBVal )
224{
225 wxCHECK( m_node, false );
226
227 return ( (SGAPPEARANCE*) m_node )->SetAmbient( aRVal, aGVal, aBVal );
228}
229
230
231bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR* aRGBColor )
232{
233 wxCHECK( m_node, false );
234
235 return ( (SGAPPEARANCE*) m_node )->SetAmbient( aRGBColor );
236}
237
238
239bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR& aRGBColor )
240{
241 wxCHECK( m_node, false );
242
243 return ( (SGAPPEARANCE*) m_node )->SetAmbient( aRGBColor );
244}
245
246
247bool IFSG_APPEARANCE::SetShininess( float aShininess ) noexcept
248{
249 wxCHECK( m_node, false );
250
251 if( aShininess < 0 || aShininess > 1.0 )
252 {
253 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] shininess out of range [0..1]" ),
254 __FILE__, __FUNCTION__, __LINE__ );
255
256 return false;
257 }
258
259 ( (SGAPPEARANCE*) m_node )->shininess = aShininess;
260
261 return true;
262}
263
264
265bool IFSG_APPEARANCE::SetTransparency( float aTransparency ) noexcept
266{
267 wxCHECK( m_node, false );
268
269 if( aTransparency < 0 || aTransparency > 1.0 )
270 {
271 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] transparency out of range [0..1]" ),
272 __FILE__, __FUNCTION__, __LINE__ );
273
274 return false;
275 }
276
277 ( (SGAPPEARANCE*) m_node )->transparency = aTransparency;
278
279 return true;
280}
bool SetDiffuse(float aRVal, float aGVal, float aBVal)
bool SetEmissive(float aRVal, float aGVal, float aBVal)
bool Attach(SGNODE *aNode) override
Associate a given SGNODE* with this wrapper.
bool SetSpecular(float aRVal, float aGVal, float aBVal)
bool SetShininess(float aShininess) noexcept
bool NewNode(SGNODE *aParent) override
Create a new node to associate with this wrapper.
bool SetAmbient(float aRVal, float aGVal, float aBVal)
IFSG_APPEARANCE(bool create)
bool SetTransparency(float aTransparency) noexcept
SGNODE * GetRawPtr(void) noexcept
Return the raw internal SGNODE pointer.
Definition ifsg_node.cpp:61
SGNODE * m_node
Definition ifsg_node.h:47
Defines the generic material appearance of a scenegraph object.
The base class of all Scene Graph nodes.
Definition sg_node.h:71
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition sg_node.cpp:100
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition sg_node.cpp:160
char BadParent[]
Definition ifsg_node.cpp:34
char WrongParent[]
Definition ifsg_node.cpp:35
defines the wrapper of the SGAPPEARANCE class
@ SGTYPE_APPEARANCE
Definition sg_types.h:34