KiCad PCB EDA Suite
scenegraph.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 Cirilo Bernardo <cirilo.bernardo@gmail.com>
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 SCENE_GRAPH_H
31 #define SCENE_GRAPH_H
32 
33 #include <vector>
34 #include "3d_cache/sg/sg_node.h"
35 
36 class SGSHAPE;
37 
44 class SCENEGRAPH : public SGNODE
45 {
46 public:
47  void unlinkChildNode( const SGNODE* aNode ) override;
48  void unlinkRefNode( const SGNODE* aNode ) override;
49 
50  SCENEGRAPH( SGNODE* aParent );
51  virtual ~SCENEGRAPH();
52 
53  virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
54  SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller) override;
55  bool AddRefNode( SGNODE* aNode ) override;
56  bool AddChildNode( SGNODE* aNode ) override;
57 
58  void ReNameNodes( void ) override;
59  bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
60 
61  bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
62  bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
63 
64  bool Prepare( const glm::dmat4* aTransform, S3D::MATLIST& materials,
65  std::vector< SMESH >& meshes );
66 
67 private:
68  void unlinkNode( const SGNODE* aNode, bool isChild );
69  bool addNode( SGNODE* aNode, bool isChild );
70 
71 public:
72  // note: order of transformation is Translate, Rotate, Offset
76  double rotation_angle; // radians
79  double scale_angle; // radians
80 
81 private:
82  // The following are items which may be defined for reuse
83  // in a VRML output file. They do not necessarily correspond
84  // to the use of DEF within a VRML input file; it is the
85  // responsibility of the plugin to perform any necessary
86  // conversions to comply with the restrictions imposed by
87  // this scene graph structure
88  std::vector< SCENEGRAPH* > m_Transforms; // local Transform nodes
89  std::vector< SGSHAPE* > m_Shape; // local Shape nodes
90 
91  std::vector< SCENEGRAPH* > m_RTransforms; // referenced Transform nodes
92  std::vector< SGSHAPE* > m_RShape; // referenced Shape nodes
93 };
94 
95 /*
96  p.120
97  Transform {
98  center 0 0 0
99  children []
100  rotation 0 0 1 0
101  scale 1 1 1
102  scaleOrientation 0 0 1 0
103  translation 0 0 0
104  bboxCenter 0 0 0
105  bboxSize -1 -1 -1
106  }
107 */
108 
109 #endif // SCENE_GRAPH_H
SGVECTOR rotation_axis
Definition: scenegraph.h:75
Define a complex 3D shape for a scenegraph object.
Definition: sg_shape.h:42
SGPOINT center
Definition: scenegraph.h:73
void unlinkRefNode(const SGNODE *aNode) override
Remove pointers to a referenced node.
Definition: scenegraph.cpp:155
virtual ~SCENEGRAPH()
Definition: scenegraph.cpp:62
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
SGPOINT translation
Definition: scenegraph.h:74
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: scenegraph.cpp:458
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: scenegraph.cpp:226
SGVECTOR scale_axis
Definition: scenegraph.h:78
double rotation_angle
Definition: scenegraph.h:76
std::vector< SCENEGRAPH * > m_RTransforms
Definition: scenegraph.h:91
std::vector< SGSHAPE * > m_RShape
Definition: scenegraph.h:92
std::vector< SGSHAPE * > m_Shape
Definition: scenegraph.h:89
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: scenegraph.cpp:332
bool AddChildNode(SGNODE *aNode) override
Definition: scenegraph.cpp:182
double scale_angle
Definition: scenegraph.h:79
void unlinkNode(const SGNODE *aNode, bool isChild)
Definition: scenegraph.cpp:123
bool addNode(SGNODE *aNode, bool isChild)
Definition: scenegraph.cpp:162
std::vector< SCENEGRAPH * > m_Transforms
Definition: scenegraph.h:88
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: scenegraph.cpp:188
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: scenegraph.cpp:74
bool AddRefNode(SGNODE *aNode) override
Definition: scenegraph.cpp:176
void unlinkChildNode(const SGNODE *aNode) override
Remove references to an owned child.
Definition: scenegraph.cpp:148
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:44
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: scenegraph.cpp:104
SCENEGRAPH(SGNODE *aParent)
Definition: scenegraph.cpp:38
SGPOINT scale
Definition: scenegraph.h:77
bool Prepare(const glm::dmat4 *aTransform, S3D::MATLIST &materials, std::vector< SMESH > &meshes)
Definition: scenegraph.cpp:639