KiCad PCB EDA Suite
sg_index.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  * 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 
29 #ifndef SG_INDEX_H
30 #define SG_INDEX_H
31 
32 #include <vector>
33 #include "3d_cache/sg/sg_node.h"
34 
38 class SGINDEX : public SGNODE
39 {
40 public:
41  SGINDEX( SGNODE* aParent );
42  virtual ~SGINDEX();
43 
44  virtual bool SetParent( SGNODE* aParent, bool notify = true ) override;
45 
46  SGNODE* FindNode(const char* aNodeName, const SGNODE* aCaller) noexcept override;
47  bool AddRefNode( SGNODE* aNode ) noexcept override;
48  bool AddChildNode( SGNODE* aNode ) noexcept override;
49 
50  void unlinkChildNode( const SGNODE* aCaller ) noexcept override;
51  void unlinkRefNode( const SGNODE* aCaller ) noexcept override;
52 
64  bool GetIndices( size_t& nIndices, int*& aIndexList );
65 
72  void SetIndices( size_t nIndices, int* aIndexList );
73 
74 
80  void AddIndex( int aIndex );
81 
82  void ReNameNodes( void ) override;
83  bool WriteVRML( std::ostream& aFile, bool aReuseFlag ) override;
84 
85  bool WriteCache( std::ostream& aFile, SGNODE* parentNode ) override;
86  bool ReadCache( std::istream& aFile, SGNODE* parentNode ) override;
87 
88 protected:
89  bool writeCoordIndex( std::ostream& aFile );
90  bool writeColorIndex( std::ostream& aFile );
91  bool writeIndexList( std::ostream& aFile );
92 
93 public:
94  // for internal SG consumption only
95  std::vector< int > index;
96 };
97 
98 #endif // SG_INDEX_H
SGINDEX(SGNODE *aParent)
Definition: sg_index.cpp:32
bool AddRefNode(SGNODE *aNode) noexcept override
Definition: sg_index.cpp:106
virtual bool SetParent(SGNODE *aParent, bool notify=true) override
Set the parent SGNODE of this object.
Definition: sg_index.cpp:50
bool WriteVRML(std::ostream &aFile, bool aReuseFlag) override
Writes this node's data to a VRML file.
Definition: sg_index.cpp:169
bool writeColorIndex(std::ostream &aFile)
Definition: sg_index.cpp:224
void unlinkChildNode(const SGNODE *aCaller) noexcept override
Remove references to an owned child.
Definition: sg_index.cpp:92
std::vector< int > index
Definition: sg_index.h:95
The base class of all Scene Graph nodes.
Definition: sg_node.h:74
Define a generic index interface for a scenegraph object.
Definition: sg_index.h:38
bool WriteCache(std::ostream &aFile, SGNODE *parentNode) override
Write this node's data to a binary cache file.
Definition: sg_index.cpp:260
void ReNameNodes(void) override
Rename a node and all its child nodes in preparation for write operations.
Definition: sg_index.cpp:159
void unlinkRefNode(const SGNODE *aCaller) noexcept override
Remove pointers to a referenced node.
Definition: sg_index.cpp:99
bool writeCoordIndex(std::ostream &aFile)
Definition: sg_index.cpp:181
bool GetIndices(size_t &nIndices, int *&aIndexList)
Retrieve the number of indices and a pointer to the list.
Definition: sg_index.cpp:124
virtual ~SGINDEX()
Definition: sg_index.cpp:44
bool writeIndexList(std::ostream &aFile)
Definition: sg_index.cpp:231
bool AddChildNode(SGNODE *aNode) noexcept override
Definition: sg_index.cpp:115
bool ReadCache(std::istream &aFile, SGNODE *parentNode) override
Reads binary format data from a cache file.
Definition: sg_index.cpp:305
void SetIndices(size_t nIndices, int *aIndexList)
Set the number of indices and creates a copy of the given index data.
Definition: sg_index.cpp:139
SGNODE * FindNode(const char *aNodeName, const SGNODE *aCaller) noexcept override
Search the tree of linked nodes and return a reference to the first node found with the given name.
Definition: sg_index.cpp:80
void AddIndex(int aIndex)
Add a single index to the list.
Definition: sg_index.cpp:153