KiCad PCB EDA Suite
ifsg_node.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_node.h"
31 #include "plugins/3dapi/ifsg_api.h"
32 
33 // collection of common error strings used by the wrappers
34 char BadObject[] = " * [BUG] operating on an invalid wrapper (object may have been deleted)";
35 char BadOperand[] = " * [BUG] parameter aNode is an invalid wrapper; its data may have been deleted";
36 char BadParent[] = " * [BUG] invalid parent node (data may have been deleted)";
37 char WrongParent[] = " * [BUG] parent node type is incompatible";
38 
40 {
41  m_node = NULL;
42 }
43 
44 
46 {
47  if( m_node )
49 
50  return;
51 }
52 
53 
54 void IFSG_NODE::Destroy( void )
55 {
56  if( m_node )
58 
59  delete m_node;
60  m_node = NULL;
61 
62  return;
63 }
64 
65 
67 {
68  return m_node;
69 }
70 
71 
73 {
74  if( NULL == m_node )
75  {
76  #ifdef DEBUG
77  std::ostringstream ostr;
78  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
79  ostr << BadObject;
80  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
81  #endif
82 
83  return S3D::SGTYPE_END;
84  }
85 
86  return m_node->GetNodeType();
87 }
88 
89 
91 {
92  if( NULL == m_node )
93  {
94  #ifdef DEBUG
95  std::ostringstream ostr;
96  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
97  ostr << BadObject;
98  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
99  #endif
100 
101  return NULL;
102  }
103 
104  return m_node->GetParent();
105 }
106 
107 
108 bool IFSG_NODE::SetParent( SGNODE* aParent )
109 {
110  if( NULL == m_node )
111  {
112  #ifdef DEBUG
113  std::ostringstream ostr;
114  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
115  ostr << BadObject;
116  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
117  #endif
118 
119  return false;
120  }
121 
122  return m_node->SetParent( aParent );
123 }
124 
125 
126 const char* IFSG_NODE::GetName( void )
127 {
128  if( NULL == m_node )
129  {
130  #ifdef DEBUG
131  std::ostringstream ostr;
132  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
133  ostr << BadObject;
134  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
135  #endif
136 
137  return NULL;
138  }
139 
140  return m_node->GetName();
141 }
142 
143 
144 bool IFSG_NODE::SetName( const char *aName )
145 {
146  if( NULL == m_node )
147  {
148  #ifdef DEBUG
149  std::ostringstream ostr;
150  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
151  ostr << BadObject;
152  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
153  #endif
154 
155  return false;
156  }
157 
158  m_node->SetName( aName );
159  return true;
160 }
161 
162 
163 const char * IFSG_NODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const
164 {
165  if( NULL == m_node )
166  {
167  #ifdef DEBUG
168  std::ostringstream ostr;
169  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
170  ostr << BadObject;
171  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
172  #endif
173 
174  return NULL;
175  }
176 
177  return m_node->GetNodeTypeName( aNodeType );
178 }
179 
180 
181 SGNODE* IFSG_NODE::FindNode( const char *aNodeName )
182 {
183  if( NULL == m_node )
184  {
185  #ifdef DEBUG
186  std::ostringstream ostr;
187  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
188  ostr << BadObject;
189  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
190  #endif
191 
192  return NULL;
193  }
194 
195  return m_node->FindNode( aNodeName, NULL );
196 }
197 
198 
200 {
201  if( NULL == m_node )
202  {
203  #ifdef DEBUG
204  std::ostringstream ostr;
205  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
206  ostr << BadObject;
207  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
208  #endif
209 
210  return false;
211  }
212 
213  return m_node->AddRefNode( aNode );
214 }
215 
216 
218 {
219  if( NULL == m_node )
220  {
221  #ifdef DEBUG
222  std::ostringstream ostr;
223  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
224  ostr << BadObject;
225  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
226  #endif
227 
228  return false;
229  }
230 
231  SGNODE* np = aNode.GetRawPtr();
232 
233  if( NULL == np )
234  {
235  #ifdef DEBUG
236  std::ostringstream ostr;
237  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
238  ostr << BadOperand;
239  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
240  #endif
241 
242  return false;
243  }
244 
245  return m_node->AddRefNode( np );
246 }
247 
248 
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 m_node->AddChildNode( aNode );
264 }
265 
266 
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  SGNODE* np = aNode.GetRawPtr();
282 
283  if( NULL == np )
284  {
285  #ifdef DEBUG
286  std::ostringstream ostr;
287  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
288  ostr << BadOperand;
289  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
290  #endif
291 
292  return false;
293  }
294 
295  return m_node->AddChildNode( np );
296 }
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: ifsg_node.cpp:90
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
char BadOperand[]
Definition: ifsg_node.cpp:35
virtual bool AddRefNode(SGNODE *aNode)=0
defines the wrapper of the base class SG_NODE
bool AddRefNode(SGNODE *aNode)
Function AddRefNode adds a reference to an existing node which is not owned by (not a child of) this ...
Definition: ifsg_node.cpp:199
bool SetParent(SGNODE *aParent)
Function SetParent sets the parent SGNODE of this object.
Definition: ifsg_node.cpp:108
defines the base class of the intermediate scene graph NODE
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
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Function GetNodeTypeName returns the text representation of the node type or NULL if the node somehow...
Definition: ifsg_node.cpp:163
bool AddChildNode(SGNODE *aNode)
Function AddChildNode adds a node as a child owned by this node.
Definition: ifsg_node.cpp:249
virtual ~IFSG_NODE()
Definition: ifsg_node.cpp:45
const char * GetName(void)
Function GetName returns a pointer to the node name (NULL if no name assigned)
Definition: ifsg_node.cpp:126
const char * GetName(void)
Definition: sg_node.cpp:150
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
defines the API calls for the manipulation of SG* classes
virtual SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller)=0
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
void SetName(const char *aName)
Definition: sg_node.cpp:159
SGTYPES
Definition: sg_types.h:34
char BadParent[]
Definition: ifsg_node.cpp:36
SGNODE * FindNode(const char *aNodeName)
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
Definition: ifsg_node.cpp:181
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.
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: ifsg_node.cpp:72
virtual bool AddChildNode(SGNODE *aNode)=0
bool SetName(const char *aName)
Function SetName sets the node's name; if the pointer passed is NULL then the node's name is erased...
Definition: ifsg_node.cpp:144
void Destroy(void)
Function Destroy deletes the object held by this wrapper.
Definition: ifsg_node.cpp:54
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