KiCad PCB EDA Suite
ifsg_transform.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/scenegraph.h"
31 
32 
33 extern char BadObject[];
34 extern char BadOperand[];
35 extern char BadParent[];
36 extern char WrongParent[];
37 
39 {
40  m_node = NULL;
41 
42  if( !create )
43  return;
44 
45  m_node = new SCENEGRAPH( NULL );
46 
47  if( m_node )
49 
50  return;
51 }
52 
53 
55 {
56  m_node = new SCENEGRAPH( 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  std::ostringstream ostr;
67  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
68  ostr << WrongParent;
69  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
70  #endif
71 
72  return;
73  }
74 
76  }
77 
78  return;
79 }
80 
81 
83 {
84  if( m_node )
86 
87  m_node = NULL;
88 
89  if( !aNode )
90  return false;
91 
92  if( S3D::SGTYPE_TRANSFORM != aNode->GetNodeType() )
93  {
94  return false;
95  }
96 
97  m_node = aNode;
99 
100  return true;
101 }
102 
103 
105 {
106  if( m_node )
108 
109  m_node = new SCENEGRAPH( aParent );
110 
111  if( aParent != m_node->GetParent() )
112  {
113  #ifdef DEBUG
114  std::ostringstream ostr;
115  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
116  ostr << " * [BUG] invalid SGNODE parent (";
117  ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
118  ostr << ") to SCENEGRAPH";
119  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
120  #endif
121 
122  delete m_node;
123  m_node = NULL;
124  return false;
125  }
126 
128 
129  return true;
130 }
131 
132 
134 {
135  SGNODE* np = aParent.GetRawPtr();
136 
137  if( NULL == np )
138  {
139  #ifdef DEBUG
140  std::ostringstream ostr;
141  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
142  ostr << BadParent;
143  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
144  #endif
145 
146  return false;
147  }
148 
149  return NewNode( np );
150 }
151 
152 
153 bool IFSG_TRANSFORM::SetRotation( const SGVECTOR& aRotationAxis, double aAngle )
154 {
155  if( NULL == m_node )
156  {
157  #ifdef DEBUG
158  std::ostringstream ostr;
159  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
160  ostr << BadObject;
161  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
162  #endif
163 
164  return false;
165  }
166 
167  ((SCENEGRAPH*)m_node)->rotation_axis = aRotationAxis;
168  ((SCENEGRAPH*)m_node)->rotation_angle = aAngle;
169 
170  return true;
171 }
172 
173 
174 bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale )
175 {
176  if( NULL == m_node )
177  {
178  #ifdef DEBUG
179  std::ostringstream ostr;
180  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
181  ostr << BadObject;
182  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
183  #endif
184 
185  return false;
186  }
187 
188  ((SCENEGRAPH*)m_node)->scale = aScale;
189 
190  return true;
191 }
192 
193 
194 bool IFSG_TRANSFORM::SetScale( double aScale )
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  if( aScale < 1e-8 && aScale > -1e-8 )
209  {
210  #ifdef DEBUG
211  std::ostringstream ostr;
212  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
213  ostr << " * [BUG] |scale| is < 1e-8 - this seems strange";
214  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
215  #endif
216 
217  return false;
218  }
219 
220  ((SCENEGRAPH*)m_node)->scale = SGPOINT( aScale, aScale, aScale );
221 
222  return true;
223 }
224 
225 
226 bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation )
227 {
228  if( NULL == m_node )
229  {
230  #ifdef DEBUG
231  std::ostringstream ostr;
232  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
233  ostr << BadObject;
234  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
235  #endif
236 
237  return false;
238  }
239 
240  ((SCENEGRAPH*)m_node)->translation = aTranslation;
241 
242  return true;
243 }
244 
245 
246 bool IFSG_TRANSFORM::SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle )
247 {
248  if( NULL == m_node )
249  {
250  #ifdef DEBUG
251  std::ostringstream ostr;
252  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
253  ostr << BadObject;
254  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
255  #endif
256 
257  return false;
258  }
259 
260  ((SCENEGRAPH*)m_node)->scale_axis = aScaleAxis;
261  ((SCENEGRAPH*)m_node)->scale_angle = aAngle;
262 
263  return true;
264 }
265 
266 
267 bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter )
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  ((SCENEGRAPH*)m_node)->center = aCenter;
282 
283  return true;
284 }
bool SetTranslation(const SGPOINT &aTranslation)
char WrongParent[]
Definition: ifsg_node.cpp:37
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
char BadParent[]
Definition: ifsg_node.cpp:36
defines the wrapper for the SGNORMALS class
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 SetScale(const SGPOINT &aScale)
defines the basic data set required to represent a 3D model; this model must remain compatible with V...
bool SetScaleOrientation(const SGVECTOR &aScaleAxis, double aAngle)
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
bool SetCenter(const SGPOINT &aCenter)
IFSG_TRANSFORM(bool create)
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
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.
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
char BadOperand[]
Definition: ifsg_node.cpp:35
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Definition: sg_node.cpp:170
char BadObject[]
Definition: ifsg_node.cpp:34