KiCad PCB EDA Suite
vrml2_node.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) 2015-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 
29 /*
30  * Notes on deleting unsupported entities:
31  * 1. PROTO: PROTO ProtoName [parameter list] {body}
32  * the parameter list will always have '[]'. So the items
33  * to delete are: String, List, Body
34  * 2. EXTERNPROTO: EXTERNPROTO extern protoname [] MFstring
35  * delete: string, string, string, list, list
36  * 3. Unsupported node types: NodeName (Optional DEF RefName) {body}
37  * This scheme should also apply to PROTO'd node types.
38  * 4. ROUTE: ROUTE nodename1.event to nodename2.event
39  * Delete a String 3 times
40  * 5. Script: Script { ... }
41  */
42 
43 #ifndef VRML2_NODE_H
44 #define VRML2_NODE_H
45 
46 #include <list>
47 #include <string>
48 
49 #include "wrlproc.h"
50 
51 class WRL2BASE;
52 class SGNODE;
53 
58 class WRL2NODE
59 {
60 protected:
61  WRL2NODE* m_Parent; // pointer to parent node; may be NULL for top level node
62  WRL2NODES m_Type; // type of VRML node
63  std::string m_Name; // name to use for referencing the node by name
64 
65  std::list< WRL2NODE* > m_BackPointers; // nodes which hold a reference to this
66  std::list< WRL2NODE* > m_Children; // nodes owned by this node
67  std::list< WRL2NODE* > m_Refs; // nodes referenced by this node
68  std::string m_error;
69 
70  SGNODE* m_sgNode; // the SGNODE representation of the display data
71 
72 public:
73 
79  WRL2NODES getNodeTypeID( const std::string& aNodeName );
80 
88  virtual void unlinkChildNode( const WRL2NODE* aNode );
89 
97  virtual void unlinkRefNode( const WRL2NODE* aNode );
98 
107  void addNodeRef( WRL2NODE* aNode );
108 
115  void delNodeRef( WRL2NODE* aNode );
116 
124  virtual bool isDangling( void ) = 0;
125 
126 public:
127  WRL2NODE();
128  virtual ~WRL2NODE();
129 
130  // read data via the given file processor and WRL2BASE object
131  virtual bool Read( WRLPROC& proc, WRL2BASE* aTopNode ) = 0;
132 
137  WRL2NODES GetNodeType( void ) const;
138 
144  WRL2NODE* GetParent( void ) const;
145 
156  virtual bool SetParent( WRL2NODE* aParent, bool doUnlink = true );
157 
158  virtual std::string GetName( void );
159  virtual bool SetName( const std::string& aName );
160 
161  const char* GetNodeTypeName( WRL2NODES aNodeType ) const;
162 
172  virtual WRL2NODE* FindNode( const std::string& aNodeName, const WRL2NODE *aCaller );
173 
174  virtual bool AddChildNode( WRL2NODE* aNode );
175 
176  virtual bool AddRefNode( WRL2NODE* aNode );
177 
178  std::string GetError( void );
179 
188  virtual SGNODE* TranslateToSG( SGNODE* aParent ) = 0;
189 };
190 
191 #endif // VRML2_NODE_H
defines the basic input class for VRML
void addNodeRef(WRL2NODE *aNode)
Function addNodeRef adds a pointer to a node which references, but does not own, this node.
Definition: vrml2_node.cpp:170
virtual bool SetParent(WRL2NODE *aParent, bool doUnlink=true)
Function SetParent sets the parent WRL2NODE of this object.
Definition: vrml2_node.cpp:360
virtual SGNODE * TranslateToSG(SGNODE *aParent)=0
Function TranslateToSG produces a representation of the data using the intermediate scenegraph struct...
WRL2NODE represents the base class of all VRML2 nodes.
Definition: vrml2_node.h:58
std::list< WRL2NODE * > m_Children
Definition: vrml2_node.h:66
std::string m_Name
Definition: vrml2_node.h:63
std::string GetError(void)
Definition: vrml2_node.cpp:321
virtual std::string GetName(void)
Definition: vrml2_node.cpp:224
std::list< WRL2NODE * > m_Refs
Definition: vrml2_node.h:67
WRL2NODES m_Type
Definition: vrml2_node.h:62
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
virtual bool SetName(const std::string &aName)
Definition: vrml2_node.cpp:230
WRL2NODES getNodeTypeID(const std::string &aNodeName)
Function getNodeTypeID returns the ID based on the given aNodeName or WRL2_INVALID (WRL2_END) if no s...
Definition: vrml2_node.cpp:310
void delNodeRef(WRL2NODE *aNode)
Function delNodeRef removes a pointer to a node which references, but does not own,...
Definition: vrml2_node.cpp:188
virtual ~WRL2NODE()
Definition: vrml2_node.cpp:131
WRL2NODE * m_Parent
Definition: vrml2_node.h:61
SGNODE * m_sgNode
Definition: vrml2_node.h:70
std::list< WRL2NODE * > m_BackPointers
Definition: vrml2_node.h:65
WRL2NODES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: vrml2_node.cpp:212
WRL2BASE represents the top node of a VRML2 model.
Definition: vrml2_base.h:59
const char * GetNodeTypeName(WRL2NODES aNodeType) const
Definition: vrml2_node.cpp:295
virtual bool isDangling(void)=0
Function isDangling returns true if the object does not have a parent which is a logical container fo...
virtual bool AddChildNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:377
virtual void unlinkRefNode(const WRL2NODE *aNode)
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
Definition: vrml2_node.cpp:484
WRL2NODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: vrml2_node.cpp:218
WRL2NODES
Definition: wrltypes.h:121
virtual void unlinkChildNode(const WRL2NODE *aNode)
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
Definition: vrml2_node.cpp:464
std::string m_error
Definition: vrml2_node.h:68
virtual bool AddRefNode(WRL2NODE *aNode)
Definition: vrml2_node.cpp:416
virtual bool Read(WRLPROC &proc, WRL2BASE *aTopNode)=0
virtual WRL2NODE * FindNode(const std::string &aNodeName, const WRL2NODE *aCaller)
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
Definition: vrml2_node.cpp:327