KiCad PCB EDA Suite
ifsg_normals.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>
28 
30 #include "3d_cache/sg/sg_normals.h"
31 
32 
33 extern char BadObject[];
34 extern char BadOperand[];
35 extern char BadParent[];
36 extern char WrongParent[];
37 
38 
40 {
41  m_node = NULL;
42 
43  if( !create )
44  return;
45 
46  m_node = new SGNORMALS( NULL );
47 
48  if( m_node )
50 
51  return;
52 }
53 
54 
56 {
57  m_node = new SGNORMALS( NULL );
58 
59  if( m_node )
60  {
61  if( !m_node->SetParent( aParent ) )
62  {
63  delete m_node;
64  m_node = NULL;
65 
66  #ifdef DEBUG
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  #endif
72 
73  return;
74  }
75 
77  }
78 
79  return;
80 }
81 
82 
84 {
85  SGNODE* pp = aParent.GetRawPtr();
86 
87  #ifdef DEBUG
88  if( ! pp )
89  {
90  std::ostringstream ostr;
91  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
92  ostr << BadParent;
93  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
94  }
95  #endif
96 
97  m_node = new SGNORMALS( NULL );
98 
99  if( m_node )
100  {
101  if( !m_node->SetParent( pp ) )
102  {
103  delete m_node;
104  m_node = NULL;
105 
106  #ifdef DEBUG
107  std::ostringstream ostr;
108  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
109  ostr << WrongParent;
110  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
111  #endif
112 
113  return;
114  }
115 
117  }
118 
119  return;
120 }
121 
122 
124 {
125  if( m_node )
127 
128  m_node = NULL;
129 
130  if( !aNode )
131  return false;
132 
133  if( S3D::SGTYPE_NORMALS != aNode->GetNodeType() )
134  {
135  return false;
136  }
137 
138  m_node = aNode;
140 
141  return true;
142 }
143 
144 
146 {
147  if( m_node )
149 
150  m_node = new SGNORMALS( aParent );
151 
152  if( aParent != m_node->GetParent() )
153  {
154  #ifdef DEBUG
155  std::ostringstream ostr;
156  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
157  ostr << " * [BUG] invalid SGNODE parent (";
158  ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
159  ostr << ") to SGNORMALS";
160  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
161  #endif
162 
163  delete m_node;
164  m_node = NULL;
165  return false;
166  }
167 
169 
170  return true;
171 }
172 
173 
175 {
176  SGNODE* np = aParent.GetRawPtr();
177 
178  if( NULL == np )
179  {
180  #ifdef DEBUG
181  std::ostringstream ostr;
182  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
183  ostr << BadParent;
184  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
185  #endif
186 
187  return false;
188  }
189 
190  return NewNode( np );
191 }
192 
193 
194 bool IFSG_NORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList )
195 {
196  if( NULL == m_node )
197  {
198  #ifdef DEBUG
199  std::ostringstream ostr;
200  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
201  ostr << BadObject;
202  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
203  #endif
204 
205  return false;
206  }
207 
208  return ((SGNORMALS*)m_node)->GetNormalList( aListSize, aNormalList );
209 }
210 
211 
212 bool IFSG_NORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList )
213 {
214  if( NULL == m_node )
215  {
216  #ifdef DEBUG
217  std::ostringstream ostr;
218  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
219  ostr << BadObject;
220  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
221  #endif
222 
223  return false;
224  }
225 
226  ((SGNORMALS*)m_node)->SetNormalList( aListSize, aNormalList );
227  return true;
228 }
229 
230 
231 bool IFSG_NORMALS::AddNormal( double aXValue, double aYValue, double aZValue )
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  ((SGNORMALS*)m_node)->AddNormal( aXValue, aYValue, aZValue );
246  return true;
247 }
248 
249 
250 bool IFSG_NORMALS::AddNormal( const SGVECTOR& aNormal )
251 {
252  if( NULL == m_node )
253  {
254  #ifdef DEBUG
255  std::ostringstream ostr;
256  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
257  ostr << BadObject;
258  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
259  #endif
260 
261  return false;
262  }
263 
264  ((SGNORMALS*)m_node)->AddNormal( aNormal );
265  return true;
266 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
defines a set of vertex normals for a scene graph object
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
char BadOperand[]
Definition: ifsg_node.cpp:35
bool AddNormal(double aXValue, double aYValue, double aZValue)
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
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
IFSG_NORMALS(bool create)
void DisassociateWrapper(SGNODE **aWrapperRef)
Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object...
Definition: sg_node.cpp:264
bool SetNormalList(size_t aListSize, const SGVECTOR *aNormalList)
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Function SetParent sets the parent SGNODE of this object.
char BadParent[]
Definition: ifsg_node.cpp:36
char BadObject[]
Definition: ifsg_node.cpp:34
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Definition: sg_node.cpp:170
char WrongParent[]
Definition: ifsg_node.cpp:37