]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/brushnode.h
Initial python support
[xonotic/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     class TypeCasts {
35         NodeTypeCastTable m_casts;
36     public:
37         TypeCasts()
38         {
39             NodeStaticCast<BrushNode, scene::Instantiable>::install(m_casts);
40             NodeStaticCast<BrushNode, scene::Cloneable>::install(m_casts);
41             NodeContainedCast<BrushNode, Snappable>::install(m_casts);
42             NodeContainedCast<BrushNode, TransformNode>::install(m_casts);
43             NodeContainedCast<BrushNode, Brush>::install(m_casts);
44             NodeContainedCast<BrushNode, XMLImporter>::install(m_casts);
45             NodeContainedCast<BrushNode, XMLExporter>::install(m_casts);
46             NodeContainedCast<BrushNode, MapImporter>::install(m_casts);
47             NodeContainedCast<BrushNode, MapExporter>::install(m_casts);
48             NodeContainedCast<BrushNode, Nameable>::install(m_casts);
49             NodeContainedCast<BrushNode, BrushDoom3>::install(m_casts);
50         }
51
52         NodeTypeCastTable &get()
53         {
54             return m_casts;
55         }
56     };
57
58
59     scene::Node m_node;
60     InstanceSet m_instances;
61     Brush m_brush;
62     BrushTokenImporter m_mapImporter;
63     BrushTokenExporter m_mapExporter;
64     BrushXMLImporter m_xmlImporter;
65     BrushXMLExporter m_xmlExporter;
66
67 public:
68
69     typedef LazyStatic<TypeCasts> StaticTypeCasts;
70
71     Snappable &get(NullType<Snappable>)
72     {
73         return m_brush;
74     }
75
76     TransformNode &get(NullType<TransformNode>)
77     {
78         return m_brush;
79     }
80
81     Brush &get(NullType<Brush>)
82     {
83         return m_brush;
84     }
85
86     XMLImporter &get(NullType<XMLImporter>)
87     {
88         return m_xmlImporter;
89     }
90
91     XMLExporter &get(NullType<XMLExporter>)
92     {
93         return m_xmlExporter;
94     }
95
96     MapImporter &get(NullType<MapImporter>)
97     {
98         return m_mapImporter;
99     }
100
101     MapExporter &get(NullType<MapExporter>)
102     {
103         return m_mapExporter;
104     }
105
106     Nameable &get(NullType<Nameable>)
107     {
108         return m_brush;
109     }
110
111     BrushDoom3 &get(NullType<BrushDoom3>)
112     {
113         return m_brush;
114     }
115
116     BrushNode() :
117             m_node(this, this, StaticTypeCasts::instance().get()),
118             m_brush(m_node, InstanceSetEvaluateTransform<BrushInstance>::Caller(m_instances),
119                     InstanceSet::BoundsChangedCaller(m_instances)),
120             m_mapImporter(m_brush),
121             m_mapExporter(m_brush),
122             m_xmlImporter(m_brush),
123             m_xmlExporter(m_brush)
124     {
125     }
126
127     BrushNode(const BrushNode &other) :
128             scene::Node::Symbiot(other),
129             scene::Instantiable(other),
130             scene::Cloneable(other),
131             m_node(this, this, StaticTypeCasts::instance().get()),
132             m_brush(other.m_brush, m_node, InstanceSetEvaluateTransform<BrushInstance>::Caller(m_instances),
133                     InstanceSet::BoundsChangedCaller(m_instances)),
134             m_mapImporter(m_brush),
135             m_mapExporter(m_brush),
136             m_xmlImporter(m_brush),
137             m_xmlExporter(m_brush)
138     {
139     }
140
141     void release()
142     {
143         delete this;
144     }
145
146     scene::Node &node()
147     {
148         return m_node;
149     }
150
151     scene::Node &clone() const
152     {
153         return (new BrushNode(*this))->node();
154     }
155
156     scene::Instance *create(const scene::Path &path, scene::Instance *parent)
157     {
158         return new BrushInstance(path, parent, m_brush);
159     }
160
161     void forEachInstance(const scene::Instantiable::Visitor &visitor)
162     {
163         m_instances.forEachInstance(visitor);
164     }
165
166     void insert(scene::Instantiable::Observer *observer, const scene::Path &path, scene::Instance *instance)
167     {
168         m_instances.insert(observer, path, instance);
169     }
170
171     scene::Instance *erase(scene::Instantiable::Observer *observer, const scene::Path &path)
172     {
173         return m_instances.erase(observer, path);
174     }
175 };
176
177 inline Brush *Node_getBrush(scene::Node &node)
178 {
179     return NodeTypeCast<Brush>::cast(node);
180 }
181
182 #endif