KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[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
25
26
27#ifndef VRML1_NODE_H
28#define VRML1_NODE_H
29
30#define GLM_FORCE_RADIANS
31
32#include <glm/gtc/matrix_transform.hpp>
33
34#include <list>
35#include <map>
36#include <string>
37
38#include "wrlproc.h"
39
40class WRL1NODE;
41
42// The dictionary of node DEFs
44{
45public:
46 bool AddName( const std::string& aName, WRL1NODE* aNode );
47 bool DelName( const std::string& aName, WRL1NODE* aNode );
48 WRL1NODE* FindName( const std::string& aName );
49
50private:
51 std::map< std::string, WRL1NODE* > reg;
52};
53
54
55class WRL1BASE;
56class WRL1MATERIAL;
57class WRL1COORDS;
58class SGNODE;
59
60
61// current settings which may affect all subsequent nodes during translation / rendering
63{
65 {
66 Init();
67 return;
68 }
69
70 void Init()
71 {
72 mat = nullptr;
74 norm = nullptr;
76 coord = nullptr;
77 txmatrix = glm::scale( glm::mat4( 1.0 ), glm::vec3( 1.0 ) );
79 creaseLimit = 0.878f;
80 return;
81 }
82
83 // material
85
86 // normals
88
89 // coordinate3
91
92 // material binding
94
95 // normal binding
97
98 // transform
99 glm::mat4 txmatrix;
100
101 // winding order of vertices
103
104 // cos( creaseAngle ) defines a boundary for normals smoothing
106};
107
108
113{
114public:
115 // cancel the dictionary pointer; for internal use only
116 void cancelDict( void );
117
122 WRL1NODES getNodeTypeID( const std::string& aNodeName );
123
130 virtual void unlinkChildNode( const WRL1NODE* aNode );
131
138 virtual void unlinkRefNode( const WRL1NODE* aNode );
139
148 void addNodeRef( WRL1NODE* aNode );
149
155 void delNodeRef( WRL1NODE* aNode );
156
157 WRL1NODE( NAMEREGISTER* aDictionary );
158 virtual ~WRL1NODE();
159
160 // read data via the given file processor and WRL1BASE object
161 virtual bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) = 0;
162
166 WRL1NODES GetNodeType( void ) const;
167
172 WRL1NODE* GetParent( void ) const;
173
182 virtual bool SetParent( WRL1NODE* aParent, bool doUnlink = true );
183
184 virtual std::string GetName( void );
185 virtual bool SetName( const std::string& aName );
186
187 const char* GetNodeTypeName( WRL1NODES aNodeType ) const;
188
189 size_t GetNItems( void ) const;
190
200 virtual WRL1NODE* FindNode( const std::string& aNodeName );
201
202 virtual bool AddChildNode( WRL1NODE* aNode );
203
204 virtual bool AddRefNode( WRL1NODE* aNode );
205
206 std::string GetError( void );
207
215 virtual SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) = 0;
216
217private:
218 void addItem( WRL1NODE* aNode );
219 void delItem( const WRL1NODE* aNode );
220
221protected:
222 WRL1NODE* m_Parent; // pointer to parent node; may be NULL for top level node
223 WRL1NODES m_Type; // type of VRML node
224 std::string m_Name; // name to use for referencing the node by name
225
226 std::list< WRL1NODE* > m_BackPointers; // nodes which hold a reference to this
227 std::list< WRL1NODE* > m_Children; // nodes owned by this node
228 std::list< WRL1NODE* > m_Refs; // nodes referenced by this node
229 std::list< WRL1NODE* > m_Items; // all nodes in order of addition
230 std::string m_error;
231
232 WRL1STATUS m_current; // current settings
233 SGNODE* m_sgNode; // the SGNODE representation of the display data
234
235 // note: once a node is orphaned from a base node it must never access
236 // the dictionary since there is no guarantee the dictionary had not
237 // been destroyed. It may be possible to enforce this rule via the
238 // SetParent() routine if we implement a GetDictionary() function so
239 // that a node can obtain the dictionary of its parent. Note that the
240 // dictionary must be propagated to all children as well - perhaps
241 // this is best done via a SetDictionary() function.
243};
244
245#endif // VRML1_NODE_H
bool AddName(const std::string &aName, WRL1NODE *aNode)
WRL1NODE * FindName(const std::string &aName)
bool DelName(const std::string &aName, WRL1NODE *aNode)
std::map< std::string, WRL1NODE * > reg
Definition vrml1_node.h:51
The base class of all Scene Graph nodes.
Definition sg_node.h:71
Represent the top node of a VRML1 model.
Definition vrml1_base.h:42
The base class of all VRML1 nodes.
Definition vrml1_node.h:113
std::string m_Name
Definition vrml1_node.h:224
WRL1NODE * GetParent(void) const
Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
std::string GetError(void)
void delNodeRef(WRL1NODE *aNode)
Remove a pointer to a node which references, but does not own, this node.
WRL1NODE(NAMEREGISTER *aDictionary)
WRL1NODES m_Type
Definition vrml1_node.h:223
WRL1NODES getNodeTypeID(const std::string &aNodeName)
Return the ID based on the given aNodeName or WRL1_INVALID (WRL1_END) if no such node name exists.
std::list< WRL1NODE * > m_Items
Definition vrml1_node.h:229
NAMEREGISTER * m_dictionary
Definition vrml1_node.h:242
virtual WRL1NODE * FindNode(const std::string &aNodeName)
Search the tree of linked nodes and returns a reference to the current node with the given name.
void addNodeRef(WRL1NODE *aNode)
Add a pointer to a node which references, but does not own, this node.
void cancelDict(void)
WRL1STATUS m_current
Definition vrml1_node.h:232
virtual bool AddRefNode(WRL1NODE *aNode)
virtual bool AddChildNode(WRL1NODE *aNode)
virtual std::string GetName(void)
virtual bool SetParent(WRL1NODE *aParent, bool doUnlink=true)
Set the parent WRL1NODE of this object.
std::list< WRL1NODE * > m_BackPointers
Definition vrml1_node.h:226
virtual void unlinkChildNode(const WRL1NODE *aNode)
Remove references to an owned child; it is invoked by the child upon destruction to ensure that the p...
virtual SGNODE * TranslateToSG(SGNODE *aParent, WRL1STATUS *sp)=0
Produce a representation of the data using the intermediate scenegraph structures of the kicad_3dsg l...
std::list< WRL1NODE * > m_Children
Definition vrml1_node.h:227
virtual ~WRL1NODE()
size_t GetNItems(void) const
std::string m_error
Definition vrml1_node.h:230
virtual bool Read(WRLPROC &proc, WRL1BASE *aTopNode)=0
virtual bool SetName(const std::string &aName)
WRL1NODE * m_Parent
Definition vrml1_node.h:222
void addItem(WRL1NODE *aNode)
const char * GetNodeTypeName(WRL1NODES aNodeType) const
std::list< WRL1NODE * > m_Refs
Definition vrml1_node.h:228
virtual void unlinkRefNode(const WRL1NODE *aNode)
Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure...
SGNODE * m_sgNode
Definition vrml1_node.h:233
WRL1NODES GetNodeType(void) const
Return the type of this node instance.
void delItem(const WRL1NODE *aNode)
glm::mat4 txmatrix
Definition vrml1_node.h:99
WRL1_BINDING matbind
Definition vrml1_node.h:93
WRL1MATERIAL * mat
Definition vrml1_node.h:84
void Init()
Definition vrml1_node.h:70
WRL1_BINDING normbind
Definition vrml1_node.h:96
WRL1_ORDER order
Definition vrml1_node.h:102
float creaseLimit
Definition vrml1_node.h:105
WRL1COORDS * coord
Definition vrml1_node.h:90
WRL1NODE * norm
Definition vrml1_node.h:87
defines the basic input class for VRML
WRL1NODES
Definition wrltypes.h:52
WRL1_ORDER
Definition wrltypes.h:110
WRL1_BINDING
Definition wrltypes.h:97