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 <[email protected]>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <iostream>
26 #include <sstream>
27 #include <wx/log.h>
28 
30 #include "3d_cache/sg/sg_coords.h"
31 
32 
33 extern char BadParent[];
34 extern char WrongParent[];
35 
36 
38 {
39  m_node = nullptr;
40 
41  if( !create )
42  return ;
43 
44  m_node = new SGCOORDS( nullptr );
45 
47 }
48 
49 
51 {
52  m_node = new SGCOORDS( nullptr );
53 
54  if( !m_node->SetParent( aParent ) )
55  {
56  delete m_node;
57  m_node = nullptr;
58 
59  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, WrongParent );
60 
61  return;
62  }
63 
65 }
66 
67 
69 {
70  SGNODE* pp = aParent.GetRawPtr();
71 
72 #ifdef DEBUG
73  if( !pp )
74  {
75  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, BadParent );
76  }
77 #endif
78 
79  m_node = new SGCOORDS( nullptr );
80 
81  if( !m_node->SetParent( pp ) )
82  {
83  delete m_node;
84  m_node = nullptr;
85 
86  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, WrongParent );
87 
88  return;
89  }
90 
92 }
93 
94 
96 {
97  if( m_node )
99 
100  m_node = nullptr;
101 
102  if( !aNode )
103  return false;
104 
105  if( S3D::SGTYPE_COORDS != aNode->GetNodeType() )
106  {
107  return false;
108  }
109 
110  m_node = aNode;
112 
113  return true;
114 }
115 
116 
117 bool IFSG_COORDS::NewNode( SGNODE* aParent )
118 {
119  if( m_node )
121 
122  m_node = new SGCOORDS( aParent );
123 
124  if( aParent != m_node->GetParent() )
125  {
126  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGCOORDS",
127  __FILE__, __FUNCTION__, __LINE__,
128  aParent->GetNodeTypeName( aParent->GetNodeType() ) );
129 
130  delete m_node;
131  m_node = nullptr;
132  return false;
133  }
134 
136 
137  return true;
138 }
139 
140 
142 {
143  SGNODE* np = aParent.GetRawPtr();
144 
145  wxCHECK( np, false );
146 
147  return NewNode( np );
148 }
149 
150 
151 bool IFSG_COORDS::GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList )
152 {
153  wxCHECK( m_node, false );
154 
155  return ( (SGCOORDS*) m_node )->GetCoordsList( aListSize, aCoordsList );
156 }
157 
158 
159 bool IFSG_COORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList )
160 {
161  wxCHECK( m_node, false );
162 
163  ( (SGCOORDS*) m_node )->SetCoordsList( aListSize, aCoordsList );
164 
165  return true;
166 }
167 
168 
169 bool IFSG_COORDS::AddCoord( double aXValue, double aYValue, double aZValue )
170 {
171  wxCHECK( m_node, false );
172 
173  ( (SGCOORDS*) m_node )->AddCoord( aXValue, aYValue, aZValue );
174 
175  return true;
176 }
177 
178 
179 bool IFSG_COORDS::AddCoord( const SGPOINT& aPoint )
180 {
181  wxCHECK( m_node, false );
182 
183  ( (SGCOORDS*) m_node )->AddCoord( aPoint );
184 
185  return true;
186 }
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
Definition: ifsg_coords.cpp:95
Define a vertex coordinate set for a scenegraph object.
Definition: sg_coords.h:40
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition: sg_node.cpp:205
SGNODE * m_node
Definition: ifsg_node.h:57
IFSG_NODE represents the base class of all DLL-safe Scene Graph nodes.
Definition: ifsg_node.h:54
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:65
bool GetCoordsList(size_t &aListSize, SGPOINT *&aCoordsList)
IFSG_COORDS(bool create)
Definition: ifsg_coords.cpp:37
void DisassociateWrapper(SGNODE **aWrapperRef) noexcept
Remove the association between an IFSG* wrapper object and this object.
Definition: sg_node.cpp:223
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition: sg_node.cpp:164
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition: sg_node.cpp:110
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
bool SetCoordsList(size_t aListSize, const SGPOINT *aCoordsList)
defines the coordinate list wrapper
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Set the parent SGNODE of this object.
char WrongParent[]
Definition: ifsg_node.cpp:39
char BadParent[]
Definition: ifsg_node.cpp:38
bool AddCoord(double aXValue, double aYValue, double aZValue)
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104