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 
30 #include "3d_cache/sg/sg_colors.h"
31 
32 
33 extern char BadParent[];
34 extern 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, "%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, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__, BadParent );
77  }
78 #endif
79 
80  m_node = new SGCOLORS( nullptr );
81 
82  if( !m_node->SetParent( pp ) )
83  {
84  delete m_node;
85  m_node = nullptr;
86 
87  wxLogTrace( MASK_3D_SG, "%s:%s:%d %s", __FILE__, __FUNCTION__, __LINE__,
88  WrongParent );
89 
90  return;
91  }
92 
94 }
95 
96 
98 {
99  if( m_node )
101 
102  m_node = nullptr;
103 
104  if( !aNode )
105  return false;
106 
107  if( S3D::SGTYPE_COLORS != aNode->GetNodeType() )
108  {
109  return false;
110  }
111 
112  m_node = aNode;
114 
115  return true;
116 }
117 
118 
119 bool IFSG_COLORS::NewNode( SGNODE* aParent )
120 {
121  if( m_node )
123 
124  m_node = new SGCOLORS( aParent );
125 
126  if( aParent != m_node->GetParent() )
127  {
128  wxLogTrace( MASK_3D_SG, "%s:%s:%d * [BUG] invalid SGNODE parent (%s) to SGCOLORS",
129  __FILE__, __FUNCTION__, __LINE__,
130  aParent->GetNodeTypeName( aParent->GetNodeType() ) );
131 
132  delete m_node;
133  m_node = nullptr;
134  return false;
135  }
136 
138 
139  return true;
140 }
141 
142 
144 {
145  SGNODE* np = aParent.GetRawPtr();
146 
147  wxCHECK( np, false );
148 
149  return NewNode( np );
150 }
151 
152 
153 bool IFSG_COLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList )
154 {
155  wxCHECK( m_node, false );
156 
157  return ( (SGCOLORS*) m_node )->GetColorList( aListSize, aColorList );
158 }
159 
160 
161 bool IFSG_COLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList )
162 {
163  wxCHECK( m_node, false );
164 
165  ( (SGCOLORS*) m_node )->SetColorList( aListSize, aColorList );
166 
167  return true;
168 }
169 
170 
171 bool IFSG_COLORS::AddColor( double aRedValue, double aGreenValue, double aBlueValue )
172 {
173  wxCHECK( m_node, false );
174 
175  ( (SGCOLORS*) m_node )->AddColor( aRedValue, aGreenValue, aBlueValue );
176 
177  return true;
178 }
179 
180 
181 bool IFSG_COLORS::AddColor( const SGCOLOR& aColor )
182 {
183  wxCHECK( m_node, false );
184 
185  ( (SGCOLORS*) m_node )->AddColor( aColor );
186 
187  return true;
188 }
Define an RGB color set for a scenegraph object.
Definition: sg_colors.h:38
IFSG_COLORS(bool create)
Definition: ifsg_colors.cpp:37
bool GetColorList(size_t &aListSize, SGCOLOR *&aColorList)
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition: sg_node.cpp:205
SGNODE * m_node
Definition: ifsg_node.h:57
IFSG_NODE represents the base class of all DLL-safe Scene Graph nodes.
Definition: ifsg_node.h:54
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
bool AddColor(double aRedValue, double aGreenValue, double aBlueValue)
char WrongParent[]
Definition: ifsg_node.cpp:39
SGNODE * GetRawPtr(void) noexcept
Function GetRawPtr() returns the raw internal SGNODE pointer.
Definition: ifsg_node.cpp:65
void DisassociateWrapper(SGNODE **aWrapperRef) noexcept
Remove the association between an IFSG* wrapper object and this object.
Definition: sg_node.cpp:223
defines the color list wrapper
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition: sg_node.cpp:164
bool SetColorList(size_t aListSize, const SGCOLOR *aColorList)
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
bool Attach(SGNODE *aNode) override
Function Attach associates a given SGNODE* with this wrapper.
Definition: ifsg_colors.cpp:97
char BadParent[]
Definition: ifsg_node.cpp:38
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Set the parent SGNODE of this object.
bool NewNode(SGNODE *aParent) override
Function NewNode creates a new node to associate with this wrapper.
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition: sg_node.cpp:104