KiCad PCB EDA Suite
ifsg_faceset.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_faceset.h"
31 
32 
33 extern char BadObject[];
34 extern char BadParent[];
35 extern char WrongParent[];
36 
37 
39 {
40  m_node = NULL;
41 
42  if( !create )
43  return ;
44 
45  m_node = new SGFACESET( NULL );
46 
47  if( m_node )
49 
50  return;
51 }
52 
53 
55 {
56  m_node = new SGFACESET( 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  SGNODE* pp = aParent.GetRawPtr();
85 
86  #ifdef DEBUG
87  if( ! pp )
88  {
89  std::ostringstream ostr;
90  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
91  ostr << BadParent;
92  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
93  }
94  #endif
95 
96  m_node = new SGFACESET( NULL );
97 
98  if( m_node )
99  {
100  if( !m_node->SetParent( pp ) )
101  {
102  delete m_node;
103  m_node = NULL;
104 
105  #ifdef DEBUG
106  std::ostringstream ostr;
107  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
108  ostr << WrongParent;
109  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
110  #endif
111 
112  return;
113  }
114 
116  }
117 
118  return;
119 }
120 
121 
123 {
124  if( m_node )
126 
127  m_node = NULL;
128 
129  if( !aNode )
130  return false;
131 
132  if( S3D::SGTYPE_FACESET != aNode->GetNodeType() )
133  {
134  return false;
135  }
136 
137  m_node = aNode;
139 
140  return true;
141 }
142 
143 
145 {
146  if( m_node )
148 
149  m_node = new SGFACESET( aParent );
150 
151  if( aParent != m_node->GetParent() )
152  {
153  #ifdef DEBUG
154  std::ostringstream ostr;
155  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
156  ostr << " * [BUG] invalid SGNODE parent (";
157  ostr << aParent->GetNodeTypeName( aParent->GetNodeType() );
158  ostr << ") to SGFACESET";
159  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
160  #endif
161 
162  delete m_node;
163  m_node = NULL;
164  return false;
165  }
166 
168 
169  return true;
170 }
171 
172 
174 {
175  SGNODE* np = aParent.GetRawPtr();
176 
177  if( NULL == np )
178  {
179  #ifdef DEBUG
180  std::ostringstream ostr;
181  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
182  ostr << BadParent;
183  wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
184  #endif
185 
186  return false;
187  }
188 
189  return NewNode( np );
190 }
191 
192 
194 {
195  if( m_node )
196  return ((SGFACESET*)m_node)->CalcNormals( aPtr );
197 
198  return false;
199 }
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.
IFSG_FACESET(bool create)
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 BadParent[]
Definition: ifsg_node.cpp:36
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
defines an indexed face set for a scenegraph
bool CalcNormals(SGNODE **aPtr)
char BadObject[]
Definition: ifsg_node.cpp:34
void DisassociateWrapper(SGNODE **aWrapperRef)
Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object...
Definition: sg_node.cpp:264
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this 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
defines the wrapper for the SGFACESET class
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Definition: sg_node.cpp:170