KiCad PCB EDA Suite
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 <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
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 
40 #include "plugins/3dapi/c3dmodel.h"
41 #include "plugins/3dapi/sg_base.h"
42 #include "plugins/3dapi/sg_types.h"
43 
44 class SGNODE;
45 class SGAPPEARANCE;
46 
47 namespace S3D
48 {
53  char const* GetNodeTypeName( S3D::SGTYPES aType );
54 
55  struct MATLIST
56  {
57  std::vector< SGAPPEARANCE const* > matorder; // materials in order of addition
58  std::map< SGAPPEARANCE const*, int > matmap; // mapping from material to index
59  };
60 
61  bool GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex );
62 
63  void INIT_SMATERIAL( SMATERIAL& aMaterial );
64  void INIT_SMESH( SMESH& aMesh );
65  void INIT_S3DMODEL( S3DMODEL& aModel );
66 
67  void FREE_SMESH( SMESH& aMesh);
68  void FREE_S3DMODEL( S3DMODEL& aModel );
69 };
70 
71 
76 class SGNODE
77 {
78 private:
79  SGNODE** m_Association; // handle to the instance held by a wrapper
80 
81 protected:
82  std::list< SGNODE* > m_BackPointers; // nodes which hold a reference to this
83  SGNODE* m_Parent; // pointer to parent node; may be NULL for top level transform
84  S3D::SGTYPES m_SGtype; // type of SG node
85  std::string m_Name; // name to use for referencing the entity by name
86  bool m_written; // set true when the object has been written after a ReNameNodes()
87 
88 public:
96  virtual void unlinkChildNode( const SGNODE* aNode ) = 0;
97 
105  virtual void unlinkRefNode( const SGNODE* aNode ) = 0;
106 
115  void addNodeRef( SGNODE* aNode );
116 
123  void delNodeRef( const SGNODE* aNode );
124 
130  bool isWritten( void )
131  {
132  return m_written;
133  }
134 
135 public:
136  SGNODE( SGNODE* aParent );
137  virtual ~SGNODE();
138 
143  S3D::SGTYPES GetNodeType( void ) const;
144 
150  SGNODE* GetParent( void ) const;
151 
161  virtual bool SetParent( SGNODE* aParent, bool notify = true ) = 0;
162 
172  bool SwapParent( SGNODE* aNewParent );
173 
174  const char* GetName( void );
175  void SetName(const char *aName);
176 
177  const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const;
178 
188  virtual SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ) = 0;
189 
190  virtual bool AddRefNode( SGNODE* aNode ) = 0;
191 
192  virtual bool AddChildNode( SGNODE* aNode ) = 0;
193 
202  void AssociateWrapper( SGNODE** aWrapperRef );
203 
209  void DisassociateWrapper( SGNODE** aWrapperRef );
210 
216  void ResetNodeIndex( void );
217 
223  virtual void ReNameNodes( void ) = 0;
224 
230  virtual bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) = 0;
231 
239  virtual bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) = 0;
240 
247  virtual bool ReadCache( std::istream& aFile, SGNODE* parentNode ) = 0;
248 };
249 
250 #endif // SG_NODE_H
define an internal structure to be used by the 3D renders
virtual void ReNameNodes(void)=0
Function ReNameNodes renames a node and all its child nodes in preparation for Write() operations...
defines the types of intermediate scene graph objects
void addNodeRef(SGNODE *aNode)
Function addNodeRef adds a pointer to a node which references, but does not own, this node...
Definition: sg_node.cpp:176
virtual bool AddRefNode(SGNODE *aNode)=0
SGNODE * m_Parent
Definition: sg_node.h:83
void FREE_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:420
virtual ~SGNODE()
Definition: sg_node.cpp:87
SGNODE ** m_Association
Definition: sg_node.h:79
bool GetMatIndex(MATLIST &aList, SGNODE *aNode, int &aIndex)
Definition: sg_node.cpp:313
std::map< SGAPPEARANCE const *, int > matmap
Definition: sg_node.h:58
Class SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
S3D::SGTYPES GetNodeType(void) const
Function GetNodeType returns the type of this node instance.
Definition: sg_node.cpp:108
void delNodeRef(const SGNODE *aNode)
Function delNodeRef removes a pointer to a node which references, but does not own, this node.
Definition: sg_node.cpp:192
Per-vertex normal/color/texcoors structure.
Definition: c3dmodel.h:76
virtual bool ReadCache(std::istream &aFile, SGNODE *parentNode)=0
Function ReadCache Reads binary format data from a cache file.
void FREE_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:380
virtual void unlinkRefNode(const SGNODE *aNode)=0
Function unlinkRef removes pointers to a referenced node; it is invoked by the referenced node upon d...
const char * GetName(void)
Definition: sg_node.cpp:150
defines the low level classes common to scene graph nodes
bool m_written
Definition: sg_node.h:86
SGNODE * GetParent(void) const
Function GetParent returns a pointer to the parent SGNODE of this object or NULL if the object has no...
Definition: sg_node.cpp:114
virtual void unlinkChildNode(const SGNODE *aNode)=0
Function unlinkChild removes references to an owned child; it is invoked by the child upon destructio...
bool SwapParent(SGNODE *aNewParent)
Function SwapParent swaps the ownership with the given parent.
Definition: sg_node.cpp:120
void AssociateWrapper(SGNODE **aWrapperRef)
Function AssociateWrapper associates this object with a handle to itself; this handle is typically he...
Definition: sg_node.cpp:219
SGNODE(SGNODE *aParent)
Definition: sg_node.cpp:76
virtual SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller)=0
Function FindNode searches the tree of linked nodes and returns a reference to the first node found w...
void SetName(const char *aName)
Definition: sg_node.cpp:159
std::string m_Name
Definition: sg_node.h:85
SGTYPES
Definition: sg_types.h:34
virtual bool WriteCache(std::ostream &aFile, SGNODE *parentNode)=0
Function WriteCache write's this node's data to a binary cache file; the data includes all data of ch...
S3D::SGTYPES m_SGtype
Definition: sg_node.h:84
void INIT_SMESH(SMESH &aMesh)
Definition: sg_node.cpp:366
void DisassociateWrapper(SGNODE **aWrapperRef)
Function DisassociateWrapper removes the association between an IFSG* wrapper object and this object...
Definition: sg_node.cpp:264
void INIT_S3DMODEL(S3DMODEL &aModel)
Definition: sg_node.cpp:373
std::vector< SGAPPEARANCE const * > matorder
Definition: sg_node.h:57
virtual bool SetParent(SGNODE *aParent, bool notify=true)=0
Function SetParent sets the parent SGNODE of this object.
void INIT_SMATERIAL(SMATERIAL &aMaterial)
Definition: sg_node.cpp:359
virtual bool AddChildNode(SGNODE *aNode)=0
std::list< SGNODE * > m_BackPointers
Definition: sg_node.h:82
char const * GetNodeTypeName(S3D::SGTYPES aType)
Function GetNodeTypeName returns the name of the given type of node.
Definition: sg_node.cpp:51
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
const char * GetNodeTypeName(S3D::SGTYPES aNodeType) const
Definition: sg_node.cpp:170
void ResetNodeIndex(void)
Function ResetNodeIndex resets the global SG* node indices in preparation for Write() operations...
Definition: sg_node.cpp:304
virtual bool WriteVRML(std::ostream &aFile, bool aReuseFlag)=0
Function WriteVRML writes this node's data to a VRML file; this includes all data of child and refere...
bool isWritten(void)
Function IsWritten returns true if the object had already been written to a cache file or VRML file; ...
Definition: sg_node.h:130