KiCad PCB EDA Suite
ifsg_normals.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  * 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 
26 #include <iostream>
27 #include <sstream>
28 #include <wx/log.h>
29 
31 #include "3d_cache/sg/sg_normals.h"
32 
33 
34 extern char BadParent[];
35 extern char WrongParent[];
36 
37 
39 {
40  m_node = nullptr;
41 
42  if( !create )
43  return;
44 
45  m_node = new SGNORMALS( nullptr );
46 
48 }
49 
50 
52 {
53  m_node = new SGNORMALS( nullptr );
54 
55  if( !m_node->SetParent( aParent ) )
56  {
57  delete m_node;
58  m_node = nullptr;
59 
60  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, WrongParent );
61 
62  return;
63  }
64 
66 }
67 
68 
70 {
71  SGNODE* pp = aParent.GetRawPtr();
72 
73 #ifdef DEBUG
74  if( ! pp )
75  {
76  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, BadParent );
77  }
78 #endif
79 
80  m_node = new SGNORMALS( nullptr );
81 
82  if( !m_node->SetParent( pp ) )
83  {
84  delete m_node;
85  m_node = nullptr;
86 
87  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, WrongParent );
88 
89  return;
90  }
91 
93 }
94 
95 
97 {
98  if( m_node )
100 
101  m_node = nullptr;
102 
103  if( !aNode )
104  return false;
105 
106  if( S3D::SGTYPE_NORMALS != aNode->GetNodeType() )
107  {
108  return false;
109  }
110 
111  m_node = aNode;
113 
114  return true;
115 }
116 
117 
119 {
120  if( m_node )
122 
123  m_node = new SGNORMALS( aParent );
124 
125  if( aParent != m_node->GetParent() )
126  {
127  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGNORMALS",
128  __FILE__, __FUNCTION__, __LINE__,
129  aParent->GetNodeTypeName( aParent->GetNodeType() ) );
130 
131  delete m_node;
132  m_node = nullptr;
133  return false;
134  }
135 
137 
138  return true;
139 }
140 
141 
143 {
144  SGNODE* np = aParent.GetRawPtr();
145 
146  wxCHECK( np, false );
147 
148  return NewNode( np );
149 }
150 
151 
152 bool IFSG_NORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList )
153 {
154  wxCHECK( m_node, false );
155 
156  return ( (SGNORMALS*) m_node )->GetNormalList( aListSize, aNormalList );
157 }
158 
159 
160 bool IFSG_NORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList )
161 {
162  wxCHECK( m_node, false );
163 
164  ( (SGNORMALS*) m_node )->SetNormalList( aListSize, aNormalList );
165  return true;
166 }
167 
168 
169 bool IFSG_NORMALS::AddNormal( double aXValue, double aYValue, double aZValue )
170 {
171  wxCHECK( m_node, false );
172 
173  ( (SGNORMALS*) m_node )->AddNormal( aXValue, aYValue, aZValue );
174  return true;
175 }
176 
177 
178 bool IFSG_NORMALS::AddNormal( const SGVECTOR& aNormal )
179 {
180  wxCHECK( m_node, false );
181 
182  ( (SGNORMALS*) m_node )->AddNormal( aNormal );
183  return true;
184 }
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
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
Define a set of vertex normals for a scene graph object.
Definition: sg_normals.h:38
bool AddNormal(double aXValue, double aYValue, double aZValue)
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
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
IFSG_NORMALS(bool create)
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 SetNormalList(size_t aListSize, const SGVECTOR *aNormalList)
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Set the parent SGNODE of this object.
char BadParent[]
Definition: ifsg_node.cpp:38
char WrongParent[]
Definition: ifsg_node.cpp:39
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104