OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gfx_node.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_GFX_NODE_HH
20 #define OST_GFX_NODE_HH
21 
22 /*
23  Author: Ansgar Philippsen
24 */
25 
26 #include <vector>
27 
28 #include <boost/enable_shared_from_this.hpp>
29 
30 #include <ost/gfx/module_config.hh>
31 
32 #include "render_pass.hh"
33 #include "gfx_node_fw.hh"
34 #include "gfx_object_fw.hh"
35 #include "gfx_node_visitor.hh"
36 #include "povray_fw.hh"
37 #include "exporter_fw.hh"
38 
39 namespace ost { namespace gfx {
40 
41 typedef std::vector<GfxNodeP> GfxNodeVector;
42 
43 class DLLEXPORT_OST_GFX GfxNode: public boost::enable_shared_from_this<GfxNode>
44 {
45  public:
46 
47  // initialize with a name
48  GfxNode(const String& name);
49 
50  virtual ~GfxNode();
51 
52  // deep copy interface
53  virtual GfxNodeP Copy() const;
54 
55  virtual void DeepSwap(GfxNode& n);
56 
57  // render all child leaves and nodes
58  virtual void RenderGL(RenderPass pass);
59 
60  // render all child leaves and nodes into POVray state
61  virtual void RenderPov(PovState& pov);
62 
63  virtual void Export(Exporter* ex);
64 
65  // visitor interface
66  virtual void Apply(GfxNodeVisitor& v, GfxNodeVisitor::Stack st);
67 
68  virtual int GetType() const;
69 
70  // return name
71  String GetName() const;
72 
73  // remove all child nodes
74  void RemoveAll();
75  // change name
76  void Rename(const String& name);
77 
78  // add a graphical object - leaf
79  void Add(GfxObjP obj);
80 
81 
84  bool IsNameAvailable(const String& name) const;
85 
86 
87  // remove given graphical object
88  void Remove(GfxObjP obj);
89 
90  // add another node - branch
91  void Add(GfxNodeP node);
92 
93  // remove given node
94  void Remove(GfxNodeP node);
95 
96  // remove obj or node of given name (or several if multiple matches)
97  void Remove(const String& name);
98 
99  size_t GetChildCount() const;
100 
101  // hide all child leafs and nodes
102  void Hide();
103  // display all child leafs and nodes
104  void Show();
105  // return visibility state
106  bool IsVisible() const;
107 
108  virtual void ContextSwitch();
109 
112  bool IsAttachedToScene() const;
113 
114 
115  gfx::GfxNodeP GetParent() const;
116 
117  const GfxNodeVector& GetChildren() const { return node_vector_; }
118  GfxNodeVector& GetChildren() { return node_vector_; }
119  private:
120  GfxNode(const GfxNode& o);
121  GfxNode& operator=(const GfxNode&);
122 
123 
124  String name_;
125  bool show_;
126  GfxNodeVector node_vector_;
127  boost::weak_ptr<GfxNode> parent_;
128 };
129 
130 }}
131 
132 #endif
std::vector< GfxNodeP > GfxNodeVector
Definition: gfx_node.hh:41
boost::shared_ptr< GfxObj > GfxObjP
std::string String
Definition: base.hh:54
GfxNodeVector & GetChildren()
Definition: gfx_node.hh:118
const GfxNodeVector & GetChildren() const
Definition: gfx_node.hh:117
#define DLLEXPORT_OST_GFX
std::stack< GfxNode * > Stack
boost::shared_ptr< GfxNode > GfxNodeP
Definition: gfx_node_fw.hh:31