KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[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 BadParent[];
31extern char WrongParent[];
32
33
35{
36 m_node = nullptr;
37
38 if( !create )
39 return;
40
41 m_node = new SGNORMALS( nullptr );
42
43 m_node->AssociateWrapper( &m_node );
44}
45
46
48{
49 m_node = new SGNORMALS( nullptr );
50
51 if( !m_node->SetParent( aParent ) )
52 {
53 delete m_node;
54 m_node = nullptr;
55
56 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
58
59 return;
60 }
61
62 m_node->AssociateWrapper( &m_node );
63}
64
65
67{
68 SGNODE* pp = aParent.GetRawPtr();
69
70#ifdef DEBUG
71 if( ! pp )
72 {
73 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
74 BadParent );
75 }
76#endif
77
78 m_node = new SGNORMALS( nullptr );
79
80 if( !m_node->SetParent( pp ) )
81 {
82 delete m_node;
83 m_node = nullptr;
84
85 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
87
88 return;
89 }
90
91 m_node->AssociateWrapper( &m_node );
92}
93
94
96{
97 if( m_node )
98 m_node->DisassociateWrapper( &m_node );
99
100 m_node = nullptr;
101
102 if( !aNode )
103 return false;
104
105 if( S3D::SGTYPE_NORMALS != aNode->GetNodeType() )
106 {
107 return false;
108 }
109
110 m_node = aNode;
111 m_node->AssociateWrapper( &m_node );
112
113 return true;
114}
115
116
118{
119 if( m_node )
120 m_node->DisassociateWrapper( &m_node );
121
122 m_node = new SGNORMALS( aParent );
123
124 if( aParent != m_node->GetParent() )
125 {
126 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGNORMALS" ),
127 __FILE__, __FUNCTION__, __LINE__,
128 aParent->GetNodeTypeName( aParent->GetNodeType() ) );
129
130 delete m_node;
131 m_node = nullptr;
132 return false;
133 }
134
135 m_node->AssociateWrapper( &m_node );
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
151bool IFSG_NORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList )
152{
153 wxCHECK( m_node, false );
154
155 return ( (SGNORMALS*) m_node )->GetNormalList( aListSize, aNormalList );
156}
157
158
159bool IFSG_NORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList )
160{
161 wxCHECK( m_node, false );
162
163 ( (SGNORMALS*) m_node )->SetNormalList( aListSize, aNormalList );
164 return true;
165}
166
167
168bool IFSG_NORMALS::AddNormal( double aXValue, double aYValue, double aZValue )
169{
170 wxCHECK( m_node, false );
171
172 ( (SGNORMALS*) m_node )->AddNormal( aXValue, aYValue, aZValue );
173 return true;
174}
175
176
177bool IFSG_NORMALS::AddNormal( const SGVECTOR& aNormal )
178{
179 wxCHECK( m_node, false );
180
181 ( (SGNORMALS*) m_node )->AddNormal( aNormal );
182 return true;
183}
SGNODE * GetRawPtr(void) noexcept
Return the raw internal SGNODE pointer.
Definition ifsg_node.cpp:61
SGNODE * m_node
Definition ifsg_node.h:47
bool SetNormalList(size_t aListSize, const SGVECTOR *aNormalList)
bool NewNode(SGNODE *aParent) override
Create a new node to associate with this wrapper.
bool AddNormal(double aXValue, double aYValue, double aZValue)
bool Attach(SGNODE *aNode) override
Associate a given SGNODE* with this wrapper.
bool GetNormalList(size_t &aListSize, SGVECTOR *&aNormalList)
IFSG_NORMALS(bool create)
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
Define a set of vertex normals for a scene graph object.
Definition sg_normals.h:35
char BadParent[]
Definition ifsg_node.cpp:34
char WrongParent[]
Definition ifsg_node.cpp:35
@ SGTYPE_NORMALS
Definition sg_types.h:40