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 (C) 2020 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
30#ifndef SG_NODE_H
31#define SG_NODE_H
32
33#include <iostream>
34#include <string>
35#include <list>
36#include <vector>
37#include <map>
38#include <glm/glm.hpp>
39
43
44class SGNODE;
45class SGAPPEARANCE;
46
47namespace S3D
48{
52 char const* GetNodeTypeName( S3D::SGTYPES aType ) noexcept;
53
54 struct MATLIST
55 {
56 std::vector< SGAPPEARANCE const* > matorder; // materials in order of addition
57 std::map< SGAPPEARANCE const*, int > matmap; // mapping from material to index
58 };
59
60 bool GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex );
61
62 void INIT_SMATERIAL( SMATERIAL& aMaterial );
63 void INIT_SMESH( SMESH& aMesh ) noexcept;
64 void INIT_S3DMODEL( S3DMODEL& aModel ) noexcept;
65
66 void FREE_SMESH( SMESH& aMesh) noexcept;
67 void FREE_S3DMODEL( S3DMODEL& aModel );
68}
69
70
74class SGNODE
75{
76public:
77 SGNODE( SGNODE* aParent );
78 virtual ~SGNODE();
79
83 S3D::SGTYPES GetNodeType( void ) const noexcept;
84
89 SGNODE* GetParent( void ) const noexcept;
90
98 virtual bool SetParent( SGNODE* aParent, bool notify = true ) = 0;
99
108 bool SwapParent( SGNODE* aNewParent );
109
110 const char* GetName( void );
111 void SetName(const char *aName);
112
113 const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const noexcept;
114
125 virtual SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ) = 0;
126
127 virtual bool AddRefNode( SGNODE* aNode ) = 0;
128
129 virtual bool AddChildNode( SGNODE* aNode ) = 0;
130
138 void AssociateWrapper( SGNODE** aWrapperRef ) noexcept;
139
143 void DisassociateWrapper( SGNODE** aWrapperRef ) noexcept;
144
148 void ResetNodeIndex( void ) noexcept;
149
153 virtual void ReNameNodes( void ) = 0;
154
160 virtual bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) = 0;
161
168 virtual bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) = 0;
169
176 virtual bool ReadCache( std::istream& aFile, SGNODE* parentNode ) = 0;
177
186 virtual void unlinkChildNode( const SGNODE* aNode ) = 0;
187
196 virtual void unlinkRefNode( const SGNODE* aNode ) = 0;
197
206 void addNodeRef( SGNODE* aNode );
207
213 void delNodeRef( const SGNODE* aNode );
214
220 bool isWritten( void ) noexcept
221 {
222 return m_written;
223 }
224
225protected:
226 std::list< SGNODE* > m_BackPointers;
229 std::string m_Name;
231
232private:
234};
235
236#endif // SG_NODE_H
define an internal structure to be used by the 3D renders
Defines the generic material appearance of a scenegraph object.
Definition: sg_appearance.h:38
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
void SetName(const char *aName)
Definition: sg_node.cpp:155
void ResetNodeIndex(void) noexcept
Reset the global SG* node indices in preparation for write operations.
Definition: sg_node.cpp:238
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:146
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:220
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:110
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:104
virtual bool AddChildNode(SGNODE *aNode)=0
virtual ~SGNODE()
Definition: sg_node.cpp:85
SGNODE ** m_Association
Handle to the instance held by a wrapper.
Definition: sg_node.h:233
void AssociateWrapper(SGNODE **aWrapperRef) noexcept
Associate this object with a handle to itself.
Definition: sg_node.cpp:207
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:226
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const noexcept
Definition: sg_node.cpp:164
SGNODE * m_Parent
Pointer to parent node; may be NULL for top level transform.
Definition: sg_node.h:227
std::string m_Name
name to use for referencing the entity by name.
Definition: sg_node.h:229
void addNodeRef(SGNODE *aNode)
Add a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:170
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:225
void delNodeRef(const SGNODE *aNode)
Remove a pointer to a node which references this node, but does not own.
Definition: sg_node.cpp:185
bool m_written
Set to true when the object has been written after a ReNameNodes().
Definition: sg_node.h:230
S3D::SGTYPES m_SGtype
Type of Scene Graph node.
Definition: sg_node.h:228
bool SwapParent(SGNODE *aNewParent)
Swap the ownership with the given parent.
Definition: sg_node.cpp:116
virtual void unlinkRefNode(const SGNODE *aNode)=0
Remove pointers to a referenced node.
void INIT_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:276
char const * GetNodeTypeName(S3D::SGTYPES aType) noexcept
Return the name of the given type of node.
Definition: sg_node.cpp:53
bool GetMatIndex(MATLIST &aList, SGNODE *aNode, int &aIndex)
Definition: sg_node.cpp:245
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition: sg_node.cpp:270
SGTYPES
Definition: sg_types.h:35
void FREE_SMESH(SMESH &aMesh) noexcept
Definition: sg_node.cpp:288
void INIT_S3DMODEL(S3DMODEL &aModel) noexcept
Definition: sg_node.cpp:282
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:326
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:56
std::map< SGAPPEARANCE const *, int > matmap
Definition: sg_node.h:57
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:77