KiCad PCB EDA Suite
ifsg_transform.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 
26 #include <iostream>
27 #include <sstream>
28 #include <wx/log.h>
29 
31 #include "3d_cache/sg/scenegraph.h"
32 
33 
34 extern char WrongParent[];
35 
36 
38 {
39  m_node = nullptr;
40 
41  if( !create )
42  return;
43 
44  m_node = new SCENEGRAPH( nullptr );
45 
47 }
48 
49 
51 {
52  m_node = new SCENEGRAPH( 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  if( m_node )
72 
73  m_node = nullptr;
74 
75  if( !aNode )
76  return false;
77 
78  if( S3D::SGTYPE_TRANSFORM != aNode->GetNodeType() )
79  {
80  return false;
81  }
82 
83  m_node = aNode;
85 
86  return true;
87 }
88 
89 
91 {
92  if( m_node )
94 
95  m_node = new SCENEGRAPH( aParent );
96 
97  if( aParent != m_node->GetParent() )
98  {
99  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SCENEGRAPH",
100  __FILE__, __FUNCTION__, __LINE__,
101  aParent->GetNodeTypeName( aParent->GetNodeType() ) );
102 
103  delete m_node;
104  m_node = nullptr;
105  return false;
106  }
107 
109 
110  return true;
111 }
112 
113 
115 {
116  SGNODE* np = aParent.GetRawPtr();
117 
118  wxCHECK( np, false );
119 
120  return NewNode( np );
121 }
122 
123 
124 bool IFSG_TRANSFORM::SetRotation( const SGVECTOR& aRotationAxis, double aAngle )
125 {
126  wxCHECK( m_node, false );
127 
128  ( (SCENEGRAPH*) m_node )->rotation_axis = aRotationAxis;
129  ( (SCENEGRAPH*) m_node )->rotation_angle = aAngle;
130 
131  return true;
132 }
133 
134 
135 bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale ) noexcept
136 {
137  wxCHECK( m_node, false );
138 
139  ( (SCENEGRAPH*) m_node )->scale = aScale;
140 
141  return true;
142 }
143 
144 
145 bool IFSG_TRANSFORM::SetScale( double aScale )
146 {
147  wxCHECK( m_node, false );
148 
149  if( aScale < 1e-8 && aScale > -1e-8 )
150  {
151  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] |scale| is < 1e-8 - this seems strange",
152  __FILE__, __FUNCTION__, __LINE__ );
153 
154  return false;
155  }
156 
157  ( (SCENEGRAPH*) m_node )->scale = SGPOINT( aScale, aScale, aScale );
158 
159  return true;
160 }
161 
162 
163 bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation ) noexcept
164 {
165  wxCHECK( m_node, false );
166 
167  ( (SCENEGRAPH*) m_node )->translation = aTranslation;
168 
169  return true;
170 }
171 
172 
173 bool IFSG_TRANSFORM::SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle )
174 {
175  wxCHECK( m_node, false );
176 
177  ( (SCENEGRAPH*) m_node )->scale_axis = aScaleAxis;
178  ( (SCENEGRAPH*) m_node )->scale_angle = aAngle;
179 
180  return true;
181 }
182 
183 
184 bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter ) noexcept
185 {
186  wxCHECK( m_node, false );
187 
188  ( (SCENEGRAPH*) m_node )->center = aCenter;
189 
190  return true;
191 }
char WrongParent[]
Definition: ifsg_node.cpp:39
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition: sg_node.cpp:205
defines the wrapper for the SGNORMALS class
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 SetScaleOrientation(const SGVECTOR &aScaleAxis, double aAngle)
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_TRANSFORM(bool create)
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
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 SetCenter(const SGPOINT &aCenter) noexcept
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Set the parent SGNODE of this object.
bool SetTranslation(const SGPOINT &aTranslation) noexcept
bool SetScale(const SGPOINT &aScale) noexcept
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:44
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104