KiCad PCB EDA Suite
vrml1_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 
30 #ifndef VRML1_NODE_H
31 #define VRML1_NODE_H
32 
33 #define GLM_FORCE_RADIANS
34 
35 #include <glm/gtc/matrix_transform.hpp>
36 
37 #include <list>
38 #include <map>
39 #include <string>
40 
41 #include "wrlproc.h"
42 
43 class WRL1NODE;
44 
45 // a class to hold the dictionary of node DEFs
47 {
48 private:
49  std::map< std::string, WRL1NODE* > reg;
50 
51 public:
52  bool AddName( const std::string& aName, WRL1NODE* aNode );
53  bool DelName( const std::string& aName, WRL1NODE* aNode );
54  WRL1NODE* FindName( const std::string& aName );
55 };
56 
57 
58 class WRL1BASE;
59 class WRL1MATERIAL;
60 class WRL1COORDS;
61 class SGNODE;
62 
63 
64 // current settings which may affect all subsequent nodes
65 // during translation / rendering
66 struct WRL1STATUS
67 {
68  // material
70  // normals
72  // coordinate3
74  // material binding
76  // normal binding
78  // transform
79  glm::mat4 txmatrix;
80  // winding order of vertices
82 
83  // cos( creaseAngle ) defines a boundary for normals smoothing
84  float creaseLimit;
85 
87  {
88  Init();
89  return;
90  }
91 
92  void Init()
93  {
94  mat = NULL;
96  norm = NULL;
98  coord = NULL;
99  txmatrix = glm::scale( glm::mat4( 1.0 ), glm::vec3( 1.0 ) );
100  order = ORD_UNKNOWN;
101  creaseLimit = 0.878f;
102  return;
103  }
104 };
105 
106 
111 class WRL1NODE
112 {
113 private:
114  void addItem( WRL1NODE* aNode );
115  void delItem( const WRL1NODE* aNode );
116 
117 protected:
118  WRL1NODE* m_Parent; // pointer to parent node; may be NULL for top level node
119  WRL1NODES m_Type; // type of VRML node
120  std::string m_Name; // name to use for referencing the node by name
121 
122  std::list< WRL1NODE* > m_BackPointers; // nodes which hold a reference to this
123  std::list< WRL1NODE* > m_Children; // nodes owned by this node
124  std::list< WRL1NODE* > m_Refs; // nodes referenced by this node
125  std::list< WRL1NODE* > m_Items; // all nodes in order of addition
126  std::string m_error;
127 
128  WRL1STATUS m_current; // current settings
129  SGNODE* m_sgNode; // the SGNODE representation of the display data
130 
131  // note: once a node is orphaned from a base node it must never access
132  // the dictionary since there is no guarantee the dictionary had not
133  // been destroyed. It may be possible to enforce this rule via the
134  // SetParent() routine if we implement a GetDictionary() function so
135  // that a node can obtain the dictionary of its parent. Note that the
136  // dictionary must be propagated to all children as well - perhaps
137  // this is best done via a SetDictionary() function.
139 
140 public:
141  #if defined( DEBUG_VRML1 ) && ( DEBUG_VRML1 > 2 )
142  static std::string tabs;
143  #endif
144 
145  // cancel the dictionary pointer; for internal use only
146  void cancelDict( void );
147 
153  WRL1NODES getNodeTypeID( const std::string& aNodeName );
154 
162  virtual void unlinkChildNode( const WRL1NODE* aNode );
163 
171  virtual void unlinkRefNode( const WRL1NODE* aNode );
172 
181  void addNodeRef( WRL1NODE* aNode );
182 
189  void delNodeRef( WRL1NODE* aNode );
190 
191 public:
192  WRL1NODE( NAMEREGISTER* aDictionary );
193  virtual ~WRL1NODE();
194 
195  // read data via the given file processor and WRL1BASE object
196  virtual bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) = 0;
197 
202  WRL1NODES GetNodeType( void ) const;
203 
209  WRL1NODE* GetParent( void ) const;
210 
221  virtual bool SetParent( WRL1NODE* aParent, bool doUnlink = true );
222 
223  virtual std::string GetName( void );
224  virtual bool SetName( const std::string& aName );
225 
226  const char* GetNodeTypeName( WRL1NODES aNodeType ) const;
227 
228  size_t GetNItems( void ) const;
229 
238  virtual WRL1NODE* FindNode( const std::string& aNodeName );
239 
240  virtual bool AddChildNode( WRL1NODE* aNode );
241 
242  virtual bool AddRefNode( WRL1NODE* aNode );
243 
244  std::string GetError( void );
245 
254  virtual SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) = 0;
255 };
256 
257 #endif // VRML1_NODE_H
WRL1BASE represents the top node of a VRML1 model.
Definition: vrml1_base.h:45
defines the basic input class for VRML
void delNodeRef(WRL1NODE *aNode)
Function delNodeRef removes a pointer to a node which references, but does not own,...
Definition: vrml1_node.cpp:286
virtual WRL1NODE * FindNode(const std::string &aNodeName)
Function FindNode searches the tree of linked nodes and returns a reference to the current node with ...
Definition: vrml1_node.cpp:416
const char * GetNodeTypeName(WRL1NODES aNodeType) const
Definition: vrml1_node.cpp:378
void cancelDict(void)
Definition: vrml1_node.cpp:244
WRL1_BINDING normbind
Definition: vrml1_node.h:77
void addNodeRef(WRL1NODE *aNode)
Function addNodeRef adds a pointer to a node which references, but does not own, this node.
Definition: vrml1_node.cpp:263
WRL1_BINDING matbind
Definition: vrml1_node.h:75
WRL1STATUS m_current
Definition: vrml1_node.h:128
virtual ~WRL1NODE()
Definition: vrml1_node.cpp:143
WRL1COORDS * coord
Definition: vrml1_node.h:73
float creaseLimit
Definition: vrml1_node.h:84
virtual void unlinkRefNode(const WRL1NODE *aNode)
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
Definition: vrml1_node.cpp:541
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
WRL1NODES getNodeTypeID(const std::string &aNodeName)
Function getNodeTypeID returns the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no s...
Definition: vrml1_node.cpp:393
void Init()
Definition: vrml1_node.h:92
WRL1COORDS.
Definition: vrml1_coords.h:42
std::string m_Name
Definition: vrml1_node.h:120
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:122
virtual bool Read(WRLPROC &proc, WRL1BASE *aTopNode)=0
WRL1NODE * norm
Definition: vrml1_node.h:71
size_t GetNItems(void) const
Definition: vrml1_node.cpp:404
glm::mat4 txmatrix
Definition: vrml1_node.h:79
std::string GetError(void)
Definition: vrml1_node.cpp:410
std::map< std::string, WRL1NODE * > reg
Definition: vrml1_node.h:49
bool DelName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:54
bool AddName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:38
WRL1_BINDING
Definition: wrltypes.h:97
#define NULL
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:124
WRL1NODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: vrml1_node.cpp:316
virtual void unlinkChildNode(const WRL1NODE *aNode)
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
Definition: vrml1_node.cpp:520
virtual bool AddRefNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:479
WRL1_ORDER
Definition: wrltypes.h:110
WRL1NODE represents the base class of all VRML1 nodes.
Definition: vrml1_node.h:111
WRL1NODE(NAMEREGISTER *aDictionary)
Definition: vrml1_node.cpp:93
void delItem(const WRL1NODE *aNode)
Definition: vrml1_node.cpp:569
std::string m_error
Definition: vrml1_node.h:126
WRL1MATERIAL.
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:442
WRL1NODE * FindName(const std::string &aName)
Definition: vrml1_node.cpp:71
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:138
virtual bool SetParent(WRL1NODE *aParent, bool doUnlink=true)
Function SetParent sets the parent WRL1NODE of this object.
Definition: vrml1_node.cpp:425
WRL1NODES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: vrml1_node.cpp:310
WRL1NODES m_Type
Definition: vrml1_node.h:119
const int scale
std::list< WRL1NODE * > m_Items
Definition: vrml1_node.h:125
virtual SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp)=0
Function TranslateToSG produces a representation of the data using the intermediate scenegraph struct...
WRL1NODES
Definition: wrltypes.h:52
WRL1NODE * m_Parent
Definition: vrml1_node.h:118
void addItem(WRL1NODE *aNode)
Definition: vrml1_node.cpp:562
SGNODE * m_sgNode
Definition: vrml1_node.h:129
virtual std::string GetName(void)
Definition: vrml1_node.cpp:322
virtual bool SetName(const std::string &aName)
Definition: vrml1_node.cpp:328
WRL1_ORDER order
Definition: vrml1_node.h:81
WRL1MATERIAL * mat
Definition: vrml1_node.h:69
std::list< WRL1NODE * > m_Children
Definition: vrml1_node.h:123