KiCad PCB EDA Suite
ifsg_coords.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 #include <iostream>
25 #include <sstream>
26 #include <wx/log.h>
27 
29 #include "3d_cache/sg/sg_coords.h"
30 
31 
32 extern char BadObject[];
33 extern char BadParent[];
34 extern char WrongParent[];
35 
36 
38 {
39  m_node = NULL;
40 
41  if( !create )
42  return ;
43 
44  m_node = new SGCOORDS( NULL );
45 
46  if( m_node )
48 
49  return;
50 }
51 
52 
54 {
55  m_node = new SGCOORDS( NULL );
56 
57  if( m_node )
58  {
59  if( !m_node->SetParent( aParent ) )
60  {
61  delete m_node;
62  m_node = NULL;
63 
64  #ifdef DEBUG
65  std::ostringstream ostr;
66  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
67  ostr << WrongParent;
68  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
69  #endif
70 
71  return;
72  }
73 
75  }
76 
77  return;
78 }
79 
80 
82 {
83  SGNODE* pp = aParent.GetRawPtr();
84 
85  #ifdef DEBUG
86  if( ! pp )
87  {
88  std::ostringstream ostr;
89  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
90  ostr << BadParent;
91  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
92  }
93  #endif
94 
95  m_node = new SGCOORDS( NULL );
96 
97  if( m_node )
98  {
99  if( !m_node->SetParent( pp ) )
100  {
101  delete m_node;
102  m_node = NULL;
103 
104  #ifdef DEBUG
105  std::ostringstream ostr;
106  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
107  ostr << WrongParent;
108  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
109  #endif
110 
111  return;
112  }
113 
115  }
116 
117  return;
118 }
119 
120 
122 {
123  if( m_node )
125 
126  m_node = NULL;
127 
128  if( !aNode )
129  return false;
130 
131  if( S3D::SGTYPE_COORDS != aNode->GetNodeType() )
132  {
133  return false;
134  }
135 
136  m_node = aNode;
138 
139  return true;
140 }
141 
142 
143 bool IFSG_COORDS::NewNode( SGNODE* aParent )
144 {
145  if( m_node )
147 
148  m_node = new SGCOORDS( aParent );
149 
150  if( aParent != m_node->GetParent() )
151  {
152  #ifdef DEBUG
153  std::ostringstream ostr;
154  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
155  ostr << " * [BUG] invalid SGNODE parent (";
156  ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
157  ostr << ") to SGCOORDS";
158  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
159  #endif
160 
161  delete m_node;
162  m_node = NULL;
163  return false;
164  }
165 
167 
168  return true;
169 }
170 
171 
173 {
174  SGNODE* np = aParent.GetRawPtr();
175 
176  if( NULL == np )
177  {
178  #ifdef DEBUG
179  std::ostringstream ostr;
180  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
181  ostr << BadParent;
182  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
183  #endif
184 
185  return false;
186  }
187 
188  return NewNode( np );
189 }
190 
191 
192 bool IFSG_COORDS::GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList )
193 {
194  if( NULL == m_node )
195  {
196  #ifdef DEBUG
197  std::ostringstream ostr;
198  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
199  ostr << BadObject;
200  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
201  #endif
202 
203  return false;
204  }
205 
206  return ((SGCOORDS*)m_node)->GetCoordsList( aListSize, aCoordsList );
207 }
208 
209 
210 bool IFSG_COORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList )
211 {
212  if( NULL == m_node )
213  {
214  #ifdef DEBUG
215  std::ostringstream ostr;
216  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
217  ostr << BadObject;
218  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
219  #endif
220 
221  return false;
222  }
223 
224  ((SGCOORDS*)m_node)->SetCoordsList( aListSize, aCoordsList );
225 
226  return true;
227 }
228 
229 
230 bool IFSG_COORDS::AddCoord( double aXValue, double aYValue, double aZValue )
231 {
232  if( NULL == m_node )
233  {
234  #ifdef DEBUG
235  std::ostringstream ostr;
236  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
237  ostr << BadObject;
238  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
239  #endif
240 
241  return false;
242  }
243 
244  ((SGCOORDS*)m_node)->AddCoord( aXValue, aYValue, aZValue );
245 
246  return true;
247 }
248 
249 
250 bool IFSG_COORDS::AddCoord( const SGPOINT& aPoint )
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  ((SGCOORDS*)m_node)->AddCoord( aPoint );
265 
266  return true;
267 }
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
defines a vertex coordinate set for a scenegraph object
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
char BadObject[]
Definition: ifsg_node.cpp:34
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 GetCoordsList(size_t &aListSize, SGPOINT *&aCoordsList)
IFSG_COORDS(bool create)
Definition: ifsg_coords.cpp:37
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 NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
bool SetCoordsList(size_t aListSize, const SGPOINT *aCoordsList)
void DisassociateWrapper(SGNODE **aWrapperRef)
Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object...
Definition: sg_node.cpp:264
defines the coordinate list wrapper
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Function SetParent sets the parent SGNODE of this object.
char WrongParent[]
Definition: ifsg_node.cpp:37
char BadParent[]
Definition: ifsg_node.cpp:36
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Definition: sg_node.cpp:170
bool AddCoord(double aXValue, double aYValue, double aZValue)