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