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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <iostream>
23#include <sstream>
24#include <wx/log.h>
25
28
29
30extern char WrongParent[];
31
32
34{
35 m_node = nullptr;
36
37 if( !create )
38 return;
39
40 m_node = new SCENEGRAPH( nullptr );
41
42 m_node->AssociateWrapper( &m_node );
43}
44
45
47{
48 m_node = new SCENEGRAPH( nullptr );
49
50 if( !m_node->SetParent( aParent ) )
51 {
52 delete m_node;
53 m_node = nullptr;
54
55 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
57
58 return;
59 }
60
61 m_node->AssociateWrapper( &m_node );
62}
63
64
66{
67 if( m_node )
68 m_node->DisassociateWrapper( &m_node );
69
70 m_node = nullptr;
71
72 if( !aNode )
73 return false;
74
75 if( S3D::SGTYPE_TRANSFORM != aNode->GetNodeType() )
76 {
77 return false;
78 }
79
80 m_node = aNode;
81 m_node->AssociateWrapper( &m_node );
82
83 return true;
84}
85
86
88{
89 if( m_node )
90 m_node->DisassociateWrapper( &m_node );
91
92 m_node = new SCENEGRAPH( aParent );
93
94 if( aParent != m_node->GetParent() )
95 {
96 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SCENEGRAPH" ),
97 __FILE__, __FUNCTION__, __LINE__,
98 aParent->GetNodeTypeName( aParent->GetNodeType() ) );
99
100 delete m_node;
101 m_node = nullptr;
102 return false;
103 }
104
105 m_node->AssociateWrapper( &m_node );
106
107 return true;
108}
109
110
112{
113 SGNODE* np = aParent.GetRawPtr();
114
115 wxCHECK( np, false );
116
117 return NewNode( np );
118}
119
120
121bool IFSG_TRANSFORM::SetRotation( const SGVECTOR& aRotationAxis, double aAngle )
122{
123 wxCHECK( m_node, false );
124
125 ( (SCENEGRAPH*) m_node )->rotation_axis = aRotationAxis;
126 ( (SCENEGRAPH*) m_node )->rotation_angle = aAngle;
127
128 return true;
129}
130
131
132bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale ) noexcept
133{
134 wxCHECK( m_node, false );
135
136 ( (SCENEGRAPH*) m_node )->scale = aScale;
137
138 return true;
139}
140
141
142bool IFSG_TRANSFORM::SetScale( double aScale )
143{
144 wxCHECK( m_node, false );
145
146 if( aScale < 1e-8 && aScale > -1e-8 )
147 {
148 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] |scale| is < 1e-8 - this seems strange" ),
149 __FILE__, __FUNCTION__, __LINE__ );
150
151 return false;
152 }
153
154 ( (SCENEGRAPH*) m_node )->scale = SGPOINT( aScale, aScale, aScale );
155
156 return true;
157}
158
159
160bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation ) noexcept
161{
162 wxCHECK( m_node, false );
163
164 ( (SCENEGRAPH*) m_node )->translation = aTranslation;
165
166 return true;
167}
168
169
170bool IFSG_TRANSFORM::SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle )
171{
172 wxCHECK( m_node, false );
173
174 ( (SCENEGRAPH*) m_node )->scale_axis = aScaleAxis;
175 ( (SCENEGRAPH*) m_node )->scale_angle = aAngle;
176
177 return true;
178}
179
180
181bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter ) noexcept
182{
183 wxCHECK( m_node, false );
184
185 ( (SCENEGRAPH*) m_node )->center = aCenter;
186
187 return true;
188}
SGNODE * GetRawPtr(void) noexcept
Return the raw internal SGNODE pointer.
Definition ifsg_node.cpp:61
SGNODE * m_node
Definition ifsg_node.h:47
bool Attach(SGNODE *aNode) override
Associate 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
Create a new node to associate with this wrapper.
Define the basic data set required to represent a 3D model.
Definition scenegraph.h:41
The base class of all Scene Graph nodes.
Definition sg_node.h:71
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition sg_node.cpp:100
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition sg_node.cpp:160
char WrongParent[]
Definition ifsg_node.cpp:35
defines the wrapper for the SGNORMALS class
@ SGTYPE_TRANSFORM
Definition sg_types.h:33