KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
32
33
34extern 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, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
61
62 return;
63 }
64
66}
67
68
70{
71 if( m_node )
73
74 m_node = nullptr;
75
76 if( !aNode )
77 return false;
78
79 if( S3D::SGTYPE_TRANSFORM != aNode->GetNodeType() )
80 {
81 return false;
82 }
83
84 m_node = aNode;
86
87 return true;
88}
89
90
92{
93 if( m_node )
95
96 m_node = new SCENEGRAPH( aParent );
97
98 if( aParent != m_node->GetParent() )
99 {
100 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SCENEGRAPH" ),
101 __FILE__, __FUNCTION__, __LINE__,
102 aParent->GetNodeTypeName( aParent->GetNodeType() ) );
103
104 delete m_node;
105 m_node = nullptr;
106 return false;
107 }
108
110
111 return true;
112}
113
114
116{
117 SGNODE* np = aParent.GetRawPtr();
118
119 wxCHECK( np, false );
120
121 return NewNode( np );
122}
123
124
125bool IFSG_TRANSFORM::SetRotation( const SGVECTOR& aRotationAxis, double aAngle )
126{
127 wxCHECK( m_node, false );
128
129 ( (SCENEGRAPH*) m_node )->rotation_axis = aRotationAxis;
130 ( (SCENEGRAPH*) m_node )->rotation_angle = aAngle;
131
132 return true;
133}
134
135
136bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale ) noexcept
137{
138 wxCHECK( m_node, false );
139
140 ( (SCENEGRAPH*) m_node )->scale = aScale;
141
142 return true;
143}
144
145
146bool IFSG_TRANSFORM::SetScale( double aScale )
147{
148 wxCHECK( m_node, false );
149
150 if( aScale < 1e-8 && aScale > -1e-8 )
151 {
152 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] |scale| is < 1e-8 - this seems strange" ),
153 __FILE__, __FUNCTION__, __LINE__ );
154
155 return false;
156 }
157
158 ( (SCENEGRAPH*) m_node )->scale = SGPOINT( aScale, aScale, aScale );
159
160 return true;
161}
162
163
164bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation ) noexcept
165{
166 wxCHECK( m_node, false );
167
168 ( (SCENEGRAPH*) m_node )->translation = aTranslation;
169
170 return true;
171}
172
173
174bool IFSG_TRANSFORM::SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle )
175{
176 wxCHECK( m_node, false );
177
178 ( (SCENEGRAPH*) m_node )->scale_axis = aScaleAxis;
179 ( (SCENEGRAPH*) m_node )->scale_angle = aAngle;
180
181 return true;
182}
183
184
185bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter ) noexcept
186{
187 wxCHECK( m_node, false );
188
189 ( (SCENEGRAPH*) m_node )->center = aCenter;
190
191 return true;
192}
IFSG_NODE represents the base class of all DLL-safe Scene Graph nodes.
Definition: ifsg_node.h:55
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:65
SGNODE * m_node
Definition: ifsg_node.h:57
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
IFSG_TRANSFORM(bool create)
bool SetTranslation(const SGPOINT &aTranslation) noexcept
bool SetScaleOrientation(const SGVECTOR &aScaleAxis, double aAngle)
bool SetCenter(const SGPOINT &aCenter) noexcept
bool SetRotation(const SGVECTOR &aRotationAxis, double aAngle)
bool SetScale(const SGPOINT &aScale) noexcept
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:45
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Set the parent SGNODE of this object.
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
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition: sg_node.cpp:207
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition: sg_node.cpp:164
void DisassociateWrapper(SGNODE **aWrapperRef) noexcept
Remove the association between an IFSG* wrapper object and this object.
Definition: sg_node.cpp:225
char WrongParent[]
Definition: ifsg_node.cpp:39
char WrongParent[]
Definition: ifsg_node.cpp:39
defines the wrapper for the SGNORMALS class
@ SGTYPE_TRANSFORM
Definition: sg_types.h:36