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