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