KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sg_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-2017 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
24
25
26#ifndef SG_NODE_H
27#define SG_NODE_H
28
29#include <iostream>
30#include <string>
31#include <list>
32#include <vector>
33#include <map>
34#include <glm/glm.hpp>
35
39
40class SGNODE;
41class SGAPPEARANCE;
42
43namespace S3D
44{
48 char const* GetNodeTypeName( S3D::SGTYPES aType ) noexcept;
49
50 struct MATLIST
51 {
52 std::vector< SGAPPEARANCE const* > matorder; // materials in order of addition
53 std::map< SGAPPEARANCE const*, int > matmap; // mapping from material to index
54 };
55
56 bool GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex );
57
58 void INIT_SMATERIAL( SMATERIAL& aMaterial );
59 void INIT_SMESH( SMESH& aMesh ) noexcept;
60 void INIT_S3DMODEL( S3DMODEL& aModel ) noexcept;
61
62 void FREE_SMESH( SMESH& aMesh) noexcept;
63 void FREE_S3DMODEL( S3DMODEL& aModel );
64}
65
66
70class SGNODE
71{
72public:
73 SGNODE( SGNODE* aParent );
74 virtual ~SGNODE();
75
79 S3D::SGTYPES GetNodeType( void ) const noexcept;
80
85 SGNODE* GetParent( void ) const noexcept;
86
94 virtual bool SetParent( SGNODE* aParent, bool notify = true ) = 0;
95
104 bool SwapParent( SGNODE* aNewParent );
105
106 const char* GetName( void );
107 void SetName(const char *aName);
108
109 const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const noexcept;
110
121 virtual SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ) = 0;
122
123 virtual bool AddRefNode( SGNODE* aNode ) = 0;
124
125 virtual bool AddChildNode( SGNODE* aNode ) = 0;
126
134 void AssociateWrapper( SGNODE** aWrapperRef ) noexcept;
135
139 void DisassociateWrapper( SGNODE** aWrapperRef ) noexcept;
140
144 void ResetNodeIndex( void ) noexcept;
145
149 virtual void ReNameNodes( void ) = 0;
150
156 virtual bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) = 0;
157
164 virtual bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) = 0;
165
172 virtual bool ReadCache( std::istream& aFile, SGNODE* parentNode ) = 0;
173
182 virtual void unlinkChildNode( const SGNODE* aNode ) = 0;
183
192 virtual void unlinkRefNode( const SGNODE* aNode ) = 0;
193
202 void addNodeRef( SGNODE* aNode );
203
209 void delNodeRef( const SGNODE* aNode );
210
216 bool isWritten( void ) noexcept
217 {
218 return m_written;
219 }
220
221protected:
222 std::list< SGNODE* > m_BackPointers;
225 std::string m_Name;
227
228private:
230};
231
232#endif // SG_NODE_H
define an internal structure to be used by the 3D renders
Defines the generic material appearance of a scenegraph object.
The base class of all Scene Graph nodes.
Definition sg_node.h:71
void SetName(const char *aName)
Definition sg_node.cpp:151
void ResetNodeIndex(void) noexcept
Reset the global SG* node indices in preparation for write operations.
Definition sg_node.cpp:234
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Write this node's data to a binary cache file.
virtual bool AddRefNode(SGNODE *aNode)=0
const char * GetName(void)
Definition sg_node.cpp:142
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Set the parent SGNODE of this object.
virtual SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller)=0
Search the tree of linked nodes and return a reference to the first node found with the given name.
bool isWritten(void) noexcept
Return true if the object had already been written to a cache file or VRML file.
Definition sg_node.h:216
SGNODE * GetParent(void) const noexcept
Returns a pointer to the parent SGNODE of this object or NULL if the object has no parent (ie.
Definition sg_node.cpp:106
virtual void ReNameNodes(void)=0
Rename a node and all its child nodes in preparation for write operations.
S3D::SGTYPES GetNodeType(void) const noexcept
Return the type of this node instance.
Definition sg_node.cpp:100
virtual bool AddChildNode(SGNODE *aNode)=0
virtual ~SGNODE()
Definition sg_node.cpp:81
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition sg_node.h:229
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition sg_node.cpp:203
virtual bool WriteVRML(std::ostream &aFile, bool aReuseFlag)=0
Writes this node's data to a VRML file.
std::list< SGNODE * > m_BackPointers
nodes which hold a reference to this.
Definition sg_node.h:222
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition sg_node.cpp:160
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition sg_node.h:223
SGNODE(SGNODE *aParent)
Definition sg_node.cpp:72
std::string m_Name
name to use for referencing the entity by name.
Definition sg_node.h:225
void addNodeRef(SGNODE *aNode)
Add a pointer to a node which references this node, but does not own.
Definition sg_node.cpp:166
virtual bool ReadCache(std::istream &aFile, SGNODE *parentNode)=0
Reads binary format data from a cache file.
virtual void unlinkChildNode(const SGNODE *aNode)=0
Remove references to an owned child.
void DisassociateWrapper(SGNODE **aWrapperRef) noexcept
Remove the association between an IFSG* wrapper object and this object.
Definition sg_node.cpp:221
void delNodeRef(const SGNODE *aNode)
Remove a pointer to a node which references this node, but does not own.
Definition sg_node.cpp:181
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition sg_node.h:226
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition sg_node.h:224
bool SwapParent(SGNODE *aNewParent)
Swap the ownership with the given parent.
Definition sg_node.cpp:112
virtual void unlinkRefNode(const SGNODE *aNode)=0
Remove pointers to a referenced node.
void INIT_SMESH(SMESH &aMesh) noexcept
Definition sg_node.cpp:272
char const * GetNodeTypeName(S3D::SGTYPES aType) noexcept
Return the name of the given type of node.
Definition sg_node.cpp:49
bool GetMatIndex(MATLIST &aList, SGNODE *aNode, int &aIndex)
Definition sg_node.cpp:241
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition sg_node.cpp:266
SGTYPES
Definition sg_types.h:32
void FREE_SMESH(SMESH &aMesh) noexcept
Definition sg_node.cpp:284
void INIT_S3DMODEL(S3DMODEL &aModel) noexcept
Definition sg_node.cpp:278
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition sg_node.cpp:322
defines the low level classes common to scene graph nodes
defines the types of intermediate scene graph objects
Store the a model based on meshes and materials.
Definition c3dmodel.h:91
std::vector< SGAPPEARANCE const * > matorder
Definition sg_node.h:52
std::map< SGAPPEARANCE const *, int > matmap
Definition sg_node.h:53
Per-vertex normal/color/texcoors structure.
Definition c3dmodel.h:77