KiCad PCB EDA Suite
ifsg_colors.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#include <iostream>
26#include <sstream>
27#include <wx/log.h>
28
31
32
33extern char BadParent[];
34extern char WrongParent[];
35
36
38{
39 m_node = nullptr;
40
41 if( !create )
42 return;
43
44 m_node = new SGCOLORS( nullptr );
45
47}
48
49
51{
52 m_node = new SGCOLORS( 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" ), __FILE__, __FUNCTION__, __LINE__ );
60
61 return;
62 }
63
65}
66
67
69{
70 SGNODE* pp = aParent.GetRawPtr();
71
72#ifdef DEBUG
73 // Braces needed due to dangling else warning from wxLogTrace macro
74 if( !pp )
75 {
76 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
77 BadParent );
78 }
79#endif
80
81 m_node = new SGCOLORS( nullptr );
82
83 if( !m_node->SetParent( pp ) )
84 {
85 delete m_node;
86 m_node = nullptr;
87
88 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d %s" ), __FILE__, __FUNCTION__, __LINE__,
90
91 return;
92 }
93
95}
96
97
99{
100 if( m_node )
102
103 m_node = nullptr;
104
105 if( !aNode )
106 return false;
107
108 if( S3D::SGTYPE_COLORS != aNode->GetNodeType() )
109 {
110 return false;
111 }
112
113 m_node = aNode;
115
116 return true;
117}
118
119
121{
122 if( m_node )
124
125 m_node = new SGCOLORS( aParent );
126
127 if( aParent != m_node->GetParent() )
128 {
129 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGCOLORS" ),
130 __FILE__, __FUNCTION__, __LINE__,
131 aParent->GetNodeTypeName( aParent->GetNodeType() ) );
132
133 delete m_node;
134 m_node = nullptr;
135 return false;
136 }
137
139
140 return true;
141}
142
143
145{
146 SGNODE* np = aParent.GetRawPtr();
147
148 wxCHECK( np, false );
149
150 return NewNode( np );
151}
152
153
154bool IFSG_COLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList )
155{
156 wxCHECK( m_node, false );
157
158 return ( (SGCOLORS*) m_node )->GetColorList( aListSize, aColorList );
159}
160
161
162bool IFSG_COLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
163{
164 wxCHECK( m_node, false );
165
166 ( (SGCOLORS*) m_node )->SetColorList( aListSize, aColorList );
167
168 return true;
169}
170
171
172bool IFSG_COLORS::AddColor( double aRedValue, double aGreenValue, double aBlueValue )
173{
174 wxCHECK( m_node, false );
175
176 ( (SGCOLORS*) m_node )->AddColor( aRedValue, aGreenValue, aBlueValue );
177
178 return true;
179}
180
181
182bool IFSG_COLORS::AddColor( const SGCOLOR& aColor )
183{
184 wxCHECK( m_node, false );
185
186 ( (SGCOLORS*) m_node )->AddColor( aColor );
187
188 return true;
189}
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
Definition: ifsg_colors.cpp:98
bool GetColorList(size_t &aListSize, SGCOLOR *&aColorList)
bool AddColor(double aRedValue, double aGreenValue, double aBlueValue)
bool SetColorList(size_t aListSize, const SGCOLOR *aColorList)
IFSG_COLORS(bool create)
Definition: ifsg_colors.cpp:37
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
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
Define an RGB color set for a scenegraph object.
Definition: sg_colors.h:39
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 BadParent[]
Definition: ifsg_node.cpp:38
char WrongParent[]
Definition: ifsg_node.cpp:39
defines the color list wrapper
@ SGTYPE_COLORS
Definition: sg_types.h:38