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 (C) 2021 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
31#ifndef VRML1_NODE_H
32#define VRML1_NODE_H
33
34#define GLM_FORCE_RADIANS
35
36#include <glm/gtc/matrix_transform.hpp>
37
38#include <list>
39#include <map>
40#include <string>
41
42#include "wrlproc.h"
43
44class WRL1NODE;
45
46// The dictionary of node DEFs
48{
49public:
50 bool AddName( const std::string& aName, WRL1NODE* aNode );
51 bool DelName( const std::string& aName, WRL1NODE* aNode );
52 WRL1NODE* FindName( const std::string& aName );
53
54private:
55 std::map< std::string, WRL1NODE* > reg;
56};
57
58
59class WRL1BASE;
60class WRL1MATERIAL;
61class WRL1COORDS;
62class SGNODE;
63
64
65// current settings which may affect all subsequent nodes during translation / rendering
67{
69 {
70 Init();
71 return;
72 }
73
74 void Init()
75 {
76 mat = nullptr;
77 matbind = WRL1_BINDING::BIND_OVERALL;
78 norm = nullptr;
79 normbind = WRL1_BINDING::BIND_DEFAULT;
80 coord = nullptr;
81 txmatrix = glm::scale( glm::mat4( 1.0 ), glm::vec3( 1.0 ) );
82 order = WRL1_ORDER::ORD_UNKNOWN;
83 creaseLimit = 0.878f;
84 return;
85 }
86
87 // material
89
90 // normals
92
93 // coordinate3
95
96 // material binding
98
99 // normal binding
101
102 // transform
103 glm::mat4 txmatrix;
104
105 // winding order of vertices
107
108 // cos( creaseAngle ) defines a boundary for normals smoothing
110};
111
112
117{
118public:
119 // cancel the dictionary pointer; for internal use only
120 void cancelDict( void );
121
126 WRL1NODES getNodeTypeID( const std::string& aNodeName );
127
134 virtual void unlinkChildNode( const WRL1NODE* aNode );
135
142 virtual void unlinkRefNode( const WRL1NODE* aNode );
143
152 void addNodeRef( WRL1NODE* aNode );
153
159 void delNodeRef( WRL1NODE* aNode );
160
161 WRL1NODE( NAMEREGISTER* aDictionary );
162 virtual ~WRL1NODE();
163
164 // read data via the given file processor and WRL1BASE object
165 virtual bool Read( WRLPROC& proc, WRL1BASE* aTopNode ) = 0;
166
170 WRL1NODES GetNodeType( void ) const;
171
176 WRL1NODE* GetParent( void ) const;
177
186 virtual bool SetParent( WRL1NODE* aParent, bool doUnlink = true );
187
188 virtual std::string GetName( void );
189 virtual bool SetName( const std::string& aName );
190
191 const char* GetNodeTypeName( WRL1NODES aNodeType ) const;
192
193 size_t GetNItems( void ) const;
194
204 virtual WRL1NODE* FindNode( const std::string& aNodeName );
205
206 virtual bool AddChildNode( WRL1NODE* aNode );
207
208 virtual bool AddRefNode( WRL1NODE* aNode );
209
210 std::string GetError( void );
211
219 virtual SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ) = 0;
220
221private:
222 void addItem( WRL1NODE* aNode );
223 void delItem( const WRL1NODE* aNode );
224
225protected:
226 WRL1NODE* m_Parent; // pointer to parent node; may be NULL for top level node
227 WRL1NODES m_Type; // type of VRML node
228 std::string m_Name; // name to use for referencing the node by name
229
230 std::list< WRL1NODE* > m_BackPointers; // nodes which hold a reference to this
231 std::list< WRL1NODE* > m_Children; // nodes owned by this node
232 std::list< WRL1NODE* > m_Refs; // nodes referenced by this node
233 std::list< WRL1NODE* > m_Items; // all nodes in order of addition
234 std::string m_error;
235
236 WRL1STATUS m_current; // current settings
237 SGNODE* m_sgNode; // the SGNODE representation of the display data
238
239 // note: once a node is orphaned from a base node it must never access
240 // the dictionary since there is no guarantee the dictionary had not
241 // been destroyed. It may be possible to enforce this rule via the
242 // SetParent() routine if we implement a GetDictionary() function so
243 // that a node can obtain the dictionary of its parent. Note that the
244 // dictionary must be propagated to all children as well - perhaps
245 // this is best done via a SetDictionary() function.
247};
248
249#endif // VRML1_NODE_H
bool AddName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:39
WRL1NODE * FindName(const std::string &aName)
Definition: vrml1_node.cpp:72
bool DelName(const std::string &aName, WRL1NODE *aNode)
Definition: vrml1_node.cpp:55
std::map< std::string, WRL1NODE * > reg
Definition: vrml1_node.h:55
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
Represent the top node of a VRML1 model.
Definition: vrml1_base.h:46
The base class of all VRML1 nodes.
Definition: vrml1_node.h:117
std::string m_Name
Definition: vrml1_node.h:228
WRL1NODE * GetParent(void) const
Return a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition: vrml1_node.cpp:260
std::string GetError(void)
Definition: vrml1_node.cpp:344
void delNodeRef(WRL1NODE *aNode)
Remove a pointer to a node which references, but does not own, this node.
Definition: vrml1_node.cpp:237
WRL1NODES m_Type
Definition: vrml1_node.h:227
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.
Definition: vrml1_node.cpp:327
std::list< WRL1NODE * > m_Items
Definition: vrml1_node.h:233
NAMEREGISTER * m_dictionary
Definition: vrml1_node.h:246
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.
Definition: vrml1_node.cpp:350
void addNodeRef(WRL1NODE *aNode)
Add a pointer to a node which references, but does not own, this node.
Definition: vrml1_node.cpp:216
void cancelDict(void)
Definition: vrml1_node.cpp:198
WRL1STATUS m_current
Definition: vrml1_node.h:236
virtual bool AddRefNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:403
virtual bool AddChildNode(WRL1NODE *aNode)
Definition: vrml1_node.cpp:376
virtual std::string GetName(void)
Definition: vrml1_node.cpp:266
virtual bool SetParent(WRL1NODE *aParent, bool doUnlink=true)
Set the parent WRL1NODE of this object.
Definition: vrml1_node.cpp:359
std::list< WRL1NODE * > m_BackPointers
Definition: vrml1_node.h:230
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...
Definition: vrml1_node.cpp:420
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:231
virtual ~WRL1NODE()
Definition: vrml1_node.cpp:139
size_t GetNItems(void) const
Definition: vrml1_node.cpp:338
std::string m_error
Definition: vrml1_node.h:234
virtual bool Read(WRLPROC &proc, WRL1BASE *aTopNode)=0
virtual bool SetName(const std::string &aName)
Definition: vrml1_node.cpp:272
WRL1NODE * m_Parent
Definition: vrml1_node.h:226
void addItem(WRL1NODE *aNode)
Definition: vrml1_node.cpp:458
const char * GetNodeTypeName(WRL1NODES aNodeType) const
Definition: vrml1_node.cpp:312
std::list< WRL1NODE * > m_Refs
Definition: vrml1_node.h:232
virtual void unlinkRefNode(const WRL1NODE *aNode)
Remove pointers to a referenced node; it is invoked by the referenced node upon destruction to ensure...
Definition: vrml1_node.cpp:439
SGNODE * m_sgNode
Definition: vrml1_node.h:237
WRL1NODES GetNodeType(void) const
Return the type of this node instance.
Definition: vrml1_node.cpp:254
void delItem(const WRL1NODE *aNode)
Definition: vrml1_node.cpp:464
glm::mat4 txmatrix
Definition: vrml1_node.h:103
WRL1_BINDING matbind
Definition: vrml1_node.h:97
WRL1MATERIAL * mat
Definition: vrml1_node.h:88
void Init()
Definition: vrml1_node.h:74
WRL1_BINDING normbind
Definition: vrml1_node.h:100
WRL1_ORDER order
Definition: vrml1_node.h:106
float creaseLimit
Definition: vrml1_node.h:109
WRL1COORDS * coord
Definition: vrml1_node.h:94
WRL1NODE * norm
Definition: vrml1_node.h:91
defines the basic input class for VRML
WRL1NODES
Definition: wrltypes.h:56
WRL1_ORDER
Definition: wrltypes.h:114
WRL1_BINDING
Definition: wrltypes.h:101