]> icculus.org git repositories - divverent/netradiant.git/blob - radiant/brushnode.h
fix issues with embedded models
[divverent/netradiant.git] / radiant / brushnode.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant 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 GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #if !defined(INCLUDED_BRUSHNODE_H)
23 #define INCLUDED_BRUSHNODE_H
24
25 #include "instancelib.h"
26 #include "brush.h"
27 #include "brushtokens.h"
28 #include "brushxml.h"
29
30 class BrushNode :
31 public scene::Node::Symbiot,
32 public scene::Instantiable,
33 public scene::Cloneable
34 {
35   class TypeCasts
36   {
37     NodeTypeCastTable m_casts;
38   public:
39     TypeCasts()
40     {
41       NodeStaticCast<BrushNode, scene::Instantiable>::install(m_casts);
42       NodeStaticCast<BrushNode, scene::Cloneable>::install(m_casts);
43       NodeContainedCast<BrushNode, Snappable>::install(m_casts);
44       NodeContainedCast<BrushNode, TransformNode>::install(m_casts);
45       NodeContainedCast<BrushNode, Brush>::install(m_casts);
46       NodeContainedCast<BrushNode, XMLImporter>::install(m_casts);
47       NodeContainedCast<BrushNode, XMLExporter>::install(m_casts);
48       NodeContainedCast<BrushNode, MapImporter>::install(m_casts);
49       NodeContainedCast<BrushNode, MapExporter>::install(m_casts);
50       NodeContainedCast<BrushNode, Nameable>::install(m_casts);
51       NodeContainedCast<BrushNode, BrushDoom3>::install(m_casts);
52     }
53     NodeTypeCastTable& get()
54     {
55       return m_casts;
56     }
57   };
58
59
60   scene::Node m_node;
61   InstanceSet m_instances;
62   Brush m_brush;
63   BrushTokenImporter m_mapImporter;
64   BrushTokenExporter m_mapExporter;
65   BrushXMLImporter m_xmlImporter;
66   BrushXMLExporter m_xmlExporter;
67
68 public:
69
70   typedef LazyStatic<TypeCasts> StaticTypeCasts;
71
72   Snappable& get(NullType<Snappable>)
73   {
74     return m_brush;
75   }
76   TransformNode& get(NullType<TransformNode>)
77   {
78     return m_brush;
79   }
80   Brush& get(NullType<Brush>)
81   {
82     return m_brush;
83   }
84   XMLImporter& get(NullType<XMLImporter>)
85   {
86     return m_xmlImporter;
87   }
88   XMLExporter& get(NullType<XMLExporter>)
89   {
90     return m_xmlExporter;
91   }
92   MapImporter& get(NullType<MapImporter>)
93   {
94     return m_mapImporter;
95   }
96   MapExporter& get(NullType<MapExporter>)
97   {
98     return m_mapExporter;
99   }
100   Nameable& get(NullType<Nameable>)
101   {
102     return m_brush;
103   }
104   BrushDoom3& get(NullType<BrushDoom3>)
105   {
106     return m_brush;
107   }
108
109   BrushNode() :
110     m_node(this, this, StaticTypeCasts::instance().get()),
111     m_brush(m_node, InstanceSetEvaluateTransform<BrushInstance>::Caller(m_instances), InstanceSet::BoundsChangedCaller(m_instances)),
112     m_mapImporter(m_brush),
113     m_mapExporter(m_brush),
114     m_xmlImporter(m_brush),
115     m_xmlExporter(m_brush)
116   {
117   }
118   BrushNode(const BrushNode& other) :
119     scene::Node::Symbiot(other),
120     scene::Instantiable(other),
121     scene::Cloneable(other),
122     m_node(this, this, StaticTypeCasts::instance().get()),
123     m_brush(other.m_brush, m_node, InstanceSetEvaluateTransform<BrushInstance>::Caller(m_instances), InstanceSet::BoundsChangedCaller(m_instances)),
124     m_mapImporter(m_brush),
125     m_mapExporter(m_brush),
126     m_xmlImporter(m_brush),
127     m_xmlExporter(m_brush)
128   {
129   }
130   void release()
131   {
132     delete this;
133   }
134   scene::Node& node()
135   {
136     return m_node;
137   }
138   
139   scene::Node& clone() const
140   {
141     return (new BrushNode(*this))->node();
142   }
143
144   scene::Instance* create(const scene::Path& path, scene::Instance* parent)
145   {
146     return new BrushInstance(path, parent, m_brush);
147   }
148   void forEachInstance(const scene::Instantiable::Visitor& visitor)
149   {
150     m_instances.forEachInstance(visitor);
151   }
152   void insert(scene::Instantiable::Observer* observer, const scene::Path& path, scene::Instance* instance)
153   {
154     m_instances.insert(observer, path, instance);
155   }
156   scene::Instance* erase(scene::Instantiable::Observer* observer, const scene::Path& path)
157   {
158     return m_instances.erase(observer, path);
159   }
160 };
161
162 inline Brush* Node_getBrush(scene::Node& node)
163 {
164   return NodeTypeCast<Brush>::cast(node);
165 }
166
167 #endif