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  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
25 #include <iostream>
26 #include <sstream>
27 #include <wx/log.h>
30 
31 
32 extern char BadObject[];
33 extern char BadOperand[];
34 extern char BadParent[];
35 extern char WrongParent[];
36 
37 
39 {
40  m_node = NULL;
41 
42  if( !create )
43  return ;
44 
45  m_node = new SGAPPEARANCE( NULL );
46 
47  if( m_node )
49 
50  return;
51 }
52 
53 
55 {
56  m_node = new SGAPPEARANCE( NULL );
57 
58  if( m_node )
59  {
60  if( !m_node->SetParent( aParent ) )
61  {
62  delete m_node;
63  m_node = NULL;
64 
65  #ifdef DEBUG
66  do {
67  std::ostringstream ostr;
68  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
69  ostr << WrongParent;
70  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
71  } while( 0 );
72  #endif
73 
74  return;
75  }
76 
78  }
79 
80  return;
81 }
82 
83 
85 {
86  SGNODE* pp = aParent.GetRawPtr();
87 
88  #ifdef DEBUG
89  if( ! pp )
90  {
91  std::ostringstream ostr;
92  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
93  ostr << BadParent;
94  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
95  }
96  #endif
97 
98  m_node = new SGAPPEARANCE( NULL );
99 
100  if( m_node )
101  {
102  if( !m_node->SetParent( pp ) )
103  {
104  delete m_node;
105  m_node = NULL;
106 
107  #ifdef DEBUG
108  std::ostringstream ostr;
109  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
110  ostr << WrongParent;
111  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
112  #endif
113 
114  return;
115  }
116 
118  }
119 
120  return;
121 }
122 
123 
125 {
126  if( m_node )
128 
129  m_node = NULL;
130 
131  if( !aNode )
132  return false;
133 
134  if( S3D::SGTYPE_APPEARANCE != aNode->GetNodeType() )
135  {
136  return false;
137  }
138 
139  m_node = aNode;
141 
142  return true;
143 }
144 
145 
147 {
148  if( m_node )
150 
151  m_node = new SGAPPEARANCE( aParent );
152 
153  if( aParent != m_node->GetParent() )
154  {
155  #ifdef DEBUG
156  std::ostringstream ostr;
157  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
158  ostr << " * [BUG] invalid SGNODE parent (";
159  ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
160  ostr << ") to SGAPPEARANCE";
161  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
162  #endif
163 
164  delete m_node;
165  m_node = NULL;
166  return false;
167  }
168 
170 
171  return true;
172 }
173 
174 
176 {
177  SGNODE* np = aParent.GetRawPtr();
178 
179  if( NULL == np )
180  {
181  #ifdef DEBUG
182  std::ostringstream ostr;
183  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
184  ostr << BadParent;
185  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
186  #endif
187 
188  return false;
189  }
190 
191  return NewNode( np );
192 }
193 
194 
195 bool IFSG_APPEARANCE::SetEmissive( float aRVal, float aGVal, float aBVal )
196 {
197  if( NULL == m_node )
198  {
199  #ifdef DEBUG
200  std::ostringstream ostr;
201  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
202  ostr << BadObject << "\n";
203  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
204  #endif
205 
206  return false;
207  }
208 
209  return ((SGAPPEARANCE*)m_node)->SetEmissive( aRVal, aGVal, aBVal );
210 }
211 
212 
213 bool IFSG_APPEARANCE::SetEmissive( const SGCOLOR* aRGBColor )
214 {
215  if( NULL == m_node )
216  {
217  #ifdef DEBUG
218  std::ostringstream ostr;
219  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
220  ostr << BadObject << "\n";
221  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
222  #endif
223 
224  return false;
225  }
226 
227  return ((SGAPPEARANCE*)m_node)->SetEmissive( aRGBColor );
228 }
229 
230 
231 bool IFSG_APPEARANCE::SetEmissive( const SGCOLOR& aRGBColor )
232 {
233  if( NULL == m_node )
234  {
235  #ifdef DEBUG
236  std::ostringstream ostr;
237  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
238  ostr << BadObject;
239  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
240  #endif
241 
242  return false;
243  }
244 
245  return ((SGAPPEARANCE*)m_node)->SetEmissive( aRGBColor );
246 }
247 
248 
249 bool IFSG_APPEARANCE::SetDiffuse( float aRVal, float aGVal, float aBVal )
250 {
251  if( NULL == m_node )
252  {
253  #ifdef DEBUG
254  std::ostringstream ostr;
255  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
256  ostr << BadObject;
257  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
258  #endif
259 
260  return false;
261  }
262 
263  return ((SGAPPEARANCE*)m_node)->SetDiffuse( aRVal, aGVal, aBVal );
264 }
265 
266 
267 bool IFSG_APPEARANCE::SetDiffuse( const SGCOLOR* aRGBColor )
268 {
269  if( NULL == m_node )
270  {
271  #ifdef DEBUG
272  std::ostringstream ostr;
273  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
274  ostr << BadObject;
275  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
276  #endif
277 
278  return false;
279  }
280 
281  return ((SGAPPEARANCE*)m_node)->SetDiffuse( aRGBColor );
282 }
283 
284 
285 bool IFSG_APPEARANCE::SetDiffuse( const SGCOLOR& aRGBColor )
286 {
287  if( NULL == m_node )
288  {
289  #ifdef DEBUG
290  std::ostringstream ostr;
291  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
292  ostr << BadObject;
293  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
294  #endif
295 
296  return false;
297  }
298 
299  return ((SGAPPEARANCE*)m_node)->SetDiffuse( aRGBColor );
300 }
301 
302 
303 bool IFSG_APPEARANCE::SetSpecular( float aRVal, float aGVal, float aBVal )
304 {
305  if( NULL == m_node )
306  {
307  #ifdef DEBUG
308  std::ostringstream ostr;
309  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
310  ostr << BadObject;
311  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
312  #endif
313 
314  return false;
315  }
316 
317  return ((SGAPPEARANCE*)m_node)->SetSpecular( aRVal, aGVal, aBVal );
318 }
319 
320 
321 bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR* aRGBColor )
322 {
323  if( NULL == m_node )
324  {
325  #ifdef DEBUG
326  std::ostringstream ostr;
327  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
328  ostr << BadObject;
329  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
330  #endif
331 
332  return false;
333  }
334 
335  return ((SGAPPEARANCE*)m_node)->SetSpecular( aRGBColor );
336 }
337 
338 
339 bool IFSG_APPEARANCE::SetSpecular( const SGCOLOR& aRGBColor )
340 {
341  if( NULL == m_node )
342  {
343  #ifdef DEBUG
344  std::ostringstream ostr;
345  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
346  ostr << BadObject;
347  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
348  #endif
349 
350  return false;
351  }
352 
353  return ((SGAPPEARANCE*)m_node)->SetSpecular( aRGBColor );
354 }
355 
356 
357 bool IFSG_APPEARANCE::SetAmbient( float aRVal, float aGVal, float aBVal )
358 {
359  if( NULL == m_node )
360  {
361  #ifdef DEBUG
362  std::ostringstream ostr;
363  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
364  ostr << BadObject;
365  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
366  #endif
367 
368  return false;
369  }
370 
371  return ((SGAPPEARANCE*)m_node)->SetAmbient( aRVal, aGVal, aBVal );
372 }
373 
374 
375 bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR* aRGBColor )
376 {
377  if( NULL == m_node )
378  {
379  #ifdef DEBUG
380  std::ostringstream ostr;
381  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
382  ostr << BadObject;
383  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
384  #endif
385 
386  return false;
387  }
388 
389  return ((SGAPPEARANCE*)m_node)->SetAmbient( aRGBColor );
390 }
391 
392 
393 bool IFSG_APPEARANCE::SetAmbient( const SGCOLOR& aRGBColor )
394 {
395  if( NULL == m_node )
396  {
397  #ifdef DEBUG
398  std::ostringstream ostr;
399  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
400  ostr << BadObject;
401  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
402  #endif
403 
404  return false;
405  }
406 
407  return ((SGAPPEARANCE*)m_node)->SetAmbient( aRGBColor );
408 }
409 
410 
411 bool IFSG_APPEARANCE::SetShininess( float aShininess )
412 {
413  if( NULL == m_node )
414  {
415  #ifdef DEBUG
416  std::ostringstream ostr;
417  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
418  ostr << BadObject;
419  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
420  #endif
421 
422  return false;
423  }
424 
425  if( aShininess < 0 || aShininess > 1.0 )
426  {
427  #ifdef DEBUG
428  std::ostringstream ostr;
429  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
430  ostr << " * [BUG] shininess out of range [0..1]";
431  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
432  #endif
433 
434  return false;
435  }
436 
437  ((SGAPPEARANCE*)m_node)->shininess = aShininess;
438 
439  return true;
440 }
441 
442 
443 bool IFSG_APPEARANCE::SetTransparency( float aTransparency )
444 {
445  if( NULL == m_node )
446  {
447  #ifdef DEBUG
448  std::ostringstream ostr;
449  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
450  ostr << BadObject;
451  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
452  #endif
453 
454  return false;
455  }
456 
457  if( aTransparency < 0 || aTransparency > 1.0 )
458  {
459  #ifdef DEBUG
460  std::ostringstream ostr;
461  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
462  ostr << " * [BUG] transparency out of range [0..1]";
463  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
464  #endif
465 
466  return false;
467  }
468 
469  ((SGAPPEARANCE*)m_node)->transparency = aTransparency;
470 
471  return true;
472 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
char WrongParent[]
Definition: ifsg_node.cpp:37
bool SetDiffuse(float aRVal, float aGVal, float aBVal)
bool SetTransparency(float aTransparency)
IFSG_APPEARANCE(bool create)
SGNODE * m_node
Definition: ifsg_node.h:57
Class IFSG_NODE represents the base class of all DLL-safe Scene Graph nodes.
Definition: ifsg_node.h:54
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
defines the generic material appearance of a scenegraph object
bool SetAmbient(float aRVal, float aGVal, float aBVal)
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
void AssociateWrapper(SGNODE **aWrapperRef)
Function AssociateWrapper associates this object with a handle to itself; this handle is typically he...
Definition: sg_node.cpp:219
char BadParent[]
Definition: ifsg_node.cpp:36
bool SetEmissive(float aRVal, float aGVal, float aBVal)
char BadOperand[]
Definition: ifsg_node.cpp:35
bool SetSpecular(float aRVal, float aGVal, float aBVal)
bool SetShininess(float aShininess)
void DisassociateWrapper(SGNODE **aWrapperRef)
Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object...
Definition: sg_node.cpp:264
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Function SetParent sets the parent SGNODE of this object.
char BadObject[]
Definition: ifsg_node.cpp:34
defines the wrapper of the SGAPPEARANCE class
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Definition: sg_node.cpp:170
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.