KiCad PCB EDA Suite
ifsg_coordindex.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 
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 SGCOORDINDEX( NULL );
47 
48  if( m_node )
50 
51  return;
52 }
53 
54 
56 {
57  m_node = new SGCOORDINDEX( NULL );
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  return;
77 }
78 
79 
81 {
82  SGNODE* pp = aParent.GetRawPtr();
83 
84  if( !pp )
85  {
86  #ifdef DEBUG
87  std::ostringstream ostr;
88  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
89  ostr << BadParent;
90  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
91  #endif
92 
93  return;
94  }
95 
96  m_node = new SGCOORDINDEX( NULL );
97 
98  if( !m_node->SetParent( pp ) )
99  {
100  #ifdef DEBUG
101  std::ostringstream ostr;
102  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
103  ostr << WrongParent;
104  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
105  #endif
106 
107  delete m_node;
108  m_node = NULL;
109  return;
110  }
111 
113 
114  return;
115 }
116 
117 
119 {
120  if( m_node )
122 
123  m_node = NULL;
124 
125  if( !aNode )
126  return false;
127 
128  if( S3D::SGTYPE_COORDINDEX != aNode->GetNodeType() )
129  {
130  return false;
131  }
132 
133  m_node = aNode;
135 
136  return true;
137 }
138 
139 
141 {
142  if( m_node )
144 
145  m_node = new SGCOORDINDEX( aParent );
146 
147  if( aParent != m_node->GetParent() )
148  {
149  #ifdef DEBUG
150  std::ostringstream ostr;
151  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
152  ostr << " * [BUG] invalid SGNODE parent (";
153  ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
154  ostr << ") to SGCOORDINDEX";
155  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
156  #endif
157 
158  delete m_node;
159  m_node = NULL;
160  return false;
161  }
162 
164 
165  return true;
166 }
167 
168 
170 {
171  SGNODE* np = aParent.GetRawPtr();
172 
173  if( NULL == np )
174  {
175  #ifdef DEBUG
176  std::ostringstream ostr;
177  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
178  ostr << BadParent;
179  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
180  #endif
181 
182  return false;
183  }
184 
185  return NewNode( np );
186 }
char BadParent[]
Definition: ifsg_node.cpp:36
SGNODE * GetRawPtr(void)
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:66
Class SGCOORDINDEX is a class which maintains a coordinate index list.
Definition: sg_coordindex.h:44
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
char BadOperand[]
Definition: ifsg_node.cpp:35
IFSG_COORDINDEX(bool create)
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 an coordinate index set for a scenegraph object
void AssociateWrapper(SGNODE **aWrapperRef)
Function AssociateWrapper associates this object with a handle to itself; this handle is typically he...
Definition: sg_node.cpp:219
defines the CoordIndex node wrapper
void DisassociateWrapper(SGNODE **aWrapperRef)
Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object...
Definition: sg_node.cpp:264
char WrongParent[]
Definition: ifsg_node.cpp:37
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Function SetParent sets the parent SGNODE of this object.
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
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.