KiCad PCB EDA Suite
Loading...
Searching...
No Matches
x3d_base.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) 2016 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 <utility>
25#include <algorithm>
26#include <wx/log.h>
27#include "x3d_base.h"
28#include "wrltypes.h"
29
30
31bool X3D_DICT::AddName( const wxString& aName, X3DNODE* aNode )
32{
33 if( aName.empty() )
34 return false;
35
36 std::map< wxString, X3DNODE* >::iterator ir = reg.find( aName );
37
38 if( ir != reg.end() )
39 reg.erase( ir );
40
41 reg.emplace( aName, aNode );
42
43 return true;
44}
45
46
47bool X3D_DICT::DelName( const wxString& aName, X3DNODE* aNode )
48{
49 if( aName.empty() )
50 return false;
51
52 std::map< wxString, X3DNODE* >::iterator ir = reg.find( aName );
53
54 if( ir != reg.end() && ir->second == aNode )
55 {
56 reg.erase( ir );
57 return true;
58 }
59
60 return false;
61}
62
63
64X3DNODE* X3D_DICT::FindName( const wxString& aName )
65{
66 if( aName.empty() )
67 return nullptr;
68
69 std::map< wxString, X3DNODE* >::iterator ir = reg.find( aName );
70
71 if( ir != reg.end() )
72 return ir->second;
73
74 return nullptr;
75}
76
77
79{
81 m_Parent = nullptr;
82 m_sgNode = nullptr;
83 m_Dict = nullptr;
84
85 return;
86}
87
88
90{
91 if( !m_Name.empty() && nullptr != m_Dict )
92 m_Dict->DelName( m_Name, this );
93
94 return;
95}
96
97
99{
100 std::list< X3DNODE* >::iterator sL = m_Children.begin();
101 std::list< X3DNODE* >::iterator eL = m_Children.end();
102
103 while( sL != eL )
104 {
105 if( *sL == aNode )
106 {
107 m_Children.erase( sL );
108 return;
109 }
110
111 ++sL;
112 }
113
114 return;
115}
116
117
118void X3DNODE::unlinkRefNode( const X3DNODE* aNode )
119{
120 std::list< X3DNODE* >::iterator sL = m_Refs.begin();
121 std::list< X3DNODE* >::iterator eL = m_Refs.end();
122
123 while( sL != eL )
124 {
125 if( *sL == aNode )
126 {
127 m_Refs.erase( sL );
128 return;
129 }
130
131 ++sL;
132 }
133
134 return;
135}
136
137
139{
140 // the parent node must never be added as a backpointer
141 if( aNode == m_Parent )
142 return;
143
144 std::list< X3DNODE* >::iterator sR = m_BackPointers.begin();
145 std::list< X3DNODE* >::iterator eR = m_BackPointers.end();
146
147 while( sR != eR )
148 {
149 if( *sR == aNode )
150 return;
151
152 ++sR;
153 }
154
155 m_BackPointers.push_back( aNode );
156
157 return;
158}
159
160
162{
163 std::list< X3DNODE* >::iterator np =
164 std::find( m_BackPointers.begin(), m_BackPointers.end(), aNode );
165
166 if( np != m_BackPointers.end() )
167 {
168 m_BackPointers.erase( np );
169 return;
170 }
171
172 wxLogTrace( traceVrmlPlugin, wxT( "%s:%s:%d\n"
173 " * [BUG] delNodeRef() did not find its target." ),
174 __FILE__, __FUNCTION__, __LINE__ );
175
176 return;
177}
178
179
181{
182 return m_Type;
183}
184
185
187{
188 return m_Parent;
189}
190
191
192wxString X3DNODE::GetName( void ) const
193{
194 return m_Name;
195}
196
197
198std::string X3DNODE::GetError( void )
199{
200 return m_error;
201}
The base class of all X3D nodes.
Definition x3d_base.h:71
X3DNODES m_Type
Definition x3d_base.h:156
void addNodeRef(X3DNODE *aNode)
Add a pointer to a node which references, but does not own, this node.
Definition x3d_base.cpp:138
std::list< X3DNODE * > m_Children
Definition x3d_base.h:160
SGNODE * m_sgNode
Definition x3d_base.h:165
std::list< X3DNODE * > m_BackPointers
Definition x3d_base.h:159
X3DNODE * m_Parent
Definition x3d_base.h:155
virtual ~X3DNODE()
Definition x3d_base.cpp:89
wxString GetName(void) const
Return the name of this object.
Definition x3d_base.cpp:192
std::list< X3DNODE * > m_Refs
Definition x3d_base.h:161
X3DNODES GetNodeType(void) const
Return the type of this node instance.
Definition x3d_base.cpp:180
X3DNODE * GetParent(void) const
Return a pointer to the parent node of this object or NULL if the object has no parent (ie.
Definition x3d_base.cpp:186
wxString m_Name
Definition x3d_base.h:164
virtual void unlinkRefNode(const X3DNODE *aNode)
Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure...
Definition x3d_base.cpp:118
std::string GetError(void)
Definition x3d_base.cpp:198
void delNodeRef(X3DNODE *aNode)
Remove a pointer to a node which references, but does not own, this node.
Definition x3d_base.cpp:161
virtual void unlinkChildNode(const X3DNODE *aNode)
Remove references to an owned child; it is invoked by the child upon destruction to ensure that the p...
Definition x3d_base.cpp:98
std::string m_error
Definition x3d_base.h:162
X3D_DICT * m_Dict
Definition x3d_base.h:157
bool DelName(const wxString &aName, X3DNODE *aNode)
Definition x3d_base.cpp:47
std::map< wxString, X3DNODE * > reg
Definition x3d_base.h:52
bool AddName(const wxString &aName, X3DNODE *aNode)
Definition x3d_base.cpp:31
X3DNODE * FindName(const wxString &aName)
Definition x3d_base.cpp:64
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition vrml.cpp:59
declares some compound types used for VRML
declares base class of X3D tree
X3DNODES
Definition x3d_base.h:56
@ X3D_INVALID
Definition x3d_base.h:63