KiCad PCB EDA Suite
x3d_base.h
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 <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
31 #ifndef X3D_BASE_H
32 #define X3D_BASE_H
33 
34 #include <list>
35 #include <map>
36 #include <string>
37 #include <vector>
38 #include <wx/string.h>
39 
40 class X3DNODE;
41 class SGNODE;
42 class wxXmlNode;
43 
44 typedef std::vector< wxXmlNode* > NODE_LIST;
45 
46 
47 // a class to hold the dictionary of node DEFs
48 class X3D_DICT
49 {
50 private:
51  std::map< wxString, X3DNODE* > reg;
52 
53 public:
54  bool AddName( const wxString& aName, X3DNODE* aNode );
55  bool DelName( const wxString& aName, X3DNODE* aNode );
56  X3DNODE* FindName( const wxString& aName );
57 };
58 
60 {
61  X3D_TRANSFORM = 0, // Transform or Group node
69 };
70 
75 class X3DNODE
76 {
77 protected:
78  X3DNODE* m_Parent; // pointer to parent node; may be NULL for top level node
79  X3DNODES m_Type; // type of node
80  X3D_DICT* m_Dict; // reference to dictionary
81 
82  std::list< X3DNODE* > m_BackPointers; // nodes which hold a reference to this
83  std::list< X3DNODE* > m_Children; // nodes owned by this node
84  std::list< X3DNODE* > m_Refs; // nodes referenced by this node
85  std::string m_error;
86 
87  wxString m_Name; // name to use for referencing the node by name
88  SGNODE* m_sgNode; // the SGNODE representation of the display data
89 
90 public:
91 
99  virtual void unlinkChildNode( const X3DNODE* aNode );
100 
108  virtual void unlinkRefNode( const X3DNODE* aNode );
109 
118  void addNodeRef( X3DNODE* aNode );
119 
126  void delNodeRef( X3DNODE* aNode );
127 
128 public:
129  X3DNODE();
130  virtual ~X3DNODE();
131 
132  // read data and return TRUE on success
133  virtual bool Read( wxXmlNode* aNode, X3DNODE* aTopNode, X3D_DICT& aDict ) = 0;
134 
139  X3DNODES GetNodeType( void ) const;
140 
146  X3DNODE* GetParent( void ) const;
147 
152  wxString GetName( void ) const;
153 
164  virtual bool SetParent( X3DNODE* aParent, bool doUnlink = true ) = 0;
165 
166  virtual bool AddChildNode( X3DNODE* aNode ) = 0;
167 
168  virtual bool AddRefNode( X3DNODE* aNode ) = 0;
169 
170  std::string GetError( void );
171 
180  virtual SGNODE* TranslateToSG( SGNODE* aParent ) = 0;
181 };
182 
183 #endif // X3D_BASE_H
virtual bool SetParent(X3DNODE *aParent, bool doUnlink=true)=0
Function SetParent sets the parent X3DNODE of this object.
virtual ~X3DNODE()
Definition: x3d_base.cpp:93
std::list< X3DNODE * > m_BackPointers
Definition: x3d_base.h:82
std::string GetError(void)
Definition: x3d_base.cpp:205
void delNodeRef(X3DNODE *aNode)
Function delNodeRef removes a pointer to a node which references, but does not own,...
Definition: x3d_base.cpp:165
X3DNODE * FindName(const wxString &aName)
Definition: x3d_base.cpp:68
X3DNODES m_Type
Definition: x3d_base.h:79
X3DNODE * GetParent(void) const
Function GetParent returns a pointer to the parent node of this object or NULL if the object has no p...
Definition: x3d_base.cpp:193
bool DelName(const wxString &aName, X3DNODE *aNode)
Definition: x3d_base.cpp:51
wxString m_Name
Definition: x3d_base.h:87
std::string m_error
Definition: x3d_base.h:85
X3DNODE()
Definition: x3d_base.cpp:82
void addNodeRef(X3DNODE *aNode)
Function addNodeRef adds a pointer to a node which references, but does not own, this node.
Definition: x3d_base.cpp:142
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
std::list< X3DNODE * > m_Children
Definition: x3d_base.h:83
X3DNODE represents the base class of all X3D nodes.
Definition: x3d_base.h:75
virtual void unlinkRefNode(const X3DNODE *aNode)
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
Definition: x3d_base.cpp:122
virtual bool Read(wxXmlNode *aNode, X3DNODE *aTopNode, X3D_DICT &aDict)=0
virtual SGNODE * TranslateToSG(SGNODE *aParent)=0
Function TranslateToSG produces a representation of the data using the intermediate scenegraph struct...
virtual bool AddChildNode(X3DNODE *aNode)=0
X3DNODES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: x3d_base.cpp:187
std::map< wxString, X3DNODE * > reg
Definition: x3d_base.h:51
virtual void unlinkChildNode(const X3DNODE *aNode)
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
Definition: x3d_base.cpp:102
bool AddName(const wxString &aName, X3DNODE *aNode)
Definition: x3d_base.cpp:35
virtual bool AddRefNode(X3DNODE *aNode)=0
SGNODE * m_sgNode
Definition: x3d_base.h:88
X3DNODE * m_Parent
Definition: x3d_base.h:78
std::vector< wxXmlNode * > NODE_LIST
Definition: x3d_base.h:42
wxString GetName(void) const
Function GetName returns the name of this object.
Definition: x3d_base.cpp:199
X3DNODES
Definition: x3d_base.h:59
X3D_DICT * m_Dict
Definition: x3d_base.h:80
std::list< X3DNODE * > m_Refs
Definition: x3d_base.h:84