brushnode.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_BRUSHNODE_H)
00023 #define INCLUDED_BRUSHNODE_H
00024 
00025 #include "instancelib.h"
00026 #include "brush.h"
00027 #include "brushtokens.h"
00028 
00029 class BrushNode: public scene::Node, public scene::Instantiable, public scene::Cloneable
00030 {
00031         // The typecast class (needed to cast this node onto other types)
00032         class TypeCasts
00033         {
00034                 NodeTypeCastTable m_casts;
00035             public:
00036                 TypeCasts ()
00037                 {
00038                     NodeContainedCast<BrushNode, Snappable>::install(m_casts);
00039                     NodeContainedCast<BrushNode, TransformNode>::install(m_casts);
00040                     NodeContainedCast<BrushNode, Brush>::install(m_casts);
00041                     NodeContainedCast<BrushNode, MapImporter>::install(m_casts);
00042                     NodeContainedCast<BrushNode, MapExporter>::install(m_casts);
00043                 }
00044                 NodeTypeCastTable& get ()
00045                 {
00046                     return m_casts;
00047                 }
00048         };
00049 
00050         // The instances of this node
00051         InstanceSet m_instances;
00052         // The actual contained brush (NO reference)
00053         Brush m_brush;
00054         // The map importer/exporters
00055         BrushTokenImporter m_mapImporter;
00056         BrushTokenExporter m_mapExporter;
00057 
00058     public:
00059 
00060         typedef LazyStatic<TypeCasts> StaticTypeCasts;
00061 
00062         // greebo: Returns the casted types of this node
00063         Snappable& get (NullType<Snappable> )
00064         {
00065             return m_brush;
00066         }
00067         TransformNode& get (NullType<TransformNode> )
00068         {
00069             return m_brush;
00070         }
00071         Brush& get (NullType<Brush> )
00072         {
00073             return m_brush;
00074         }
00075         MapImporter& get (NullType<MapImporter> )
00076         {
00077             return m_mapImporter;
00078         }
00079         MapExporter& get (NullType<MapExporter> )
00080         {
00081             return m_mapExporter;
00082         }
00083         Nameable& get (NullType<Nameable> )
00084         {
00085             return m_brush;
00086         }
00087         // Constructor
00088         BrushNode () :
00089             scene::Node(this, StaticTypeCasts::instance().get()), m_brush(*this, InstanceSetEvaluateTransform<
00090                     BrushInstance>::Caller(m_instances), InstanceSet::BoundsChangedCaller(m_instances)), m_mapImporter(
00091                     m_brush), m_mapExporter(m_brush)
00092         {
00093         }
00094         // Copy Constructor
00095         BrushNode (const BrushNode& other) :
00096             scene::Node(this, StaticTypeCasts::instance().get()), scene::Instantiable(other), scene::Cloneable(other),
00097                     m_brush(other.m_brush, *this, InstanceSetEvaluateTransform<BrushInstance>::Caller(m_instances),
00098                             InstanceSet::BoundsChangedCaller(m_instances)), m_mapImporter(m_brush), m_mapExporter(
00099                             m_brush)
00100         {
00101         }
00102 
00103         // Returns the actual scene node
00104         scene::Node& node ()
00105         {
00106             return *this;
00107         }
00108 
00109         scene::Node& clone () const
00110         {
00111             return (new BrushNode(*this))->node();
00112         }
00113         // Creates a new instance on the heap
00114         scene::Instance* create (const scene::Path& path, scene::Instance* parent)
00115         {
00116             return new BrushInstance(path, parent, m_brush);
00117         }
00118         // Loops through all instances with the given visitor class
00119         void forEachInstance (const scene::Instantiable::Visitor& visitor)
00120         {
00121             m_instances.forEachInstance(visitor);
00122         }
00123         // Inserts / erases an instance
00124         void insert (scene::Instantiable::Observer* observer, const scene::Path& path, scene::Instance* instance)
00125         {
00126             m_instances.insert(observer, path, instance);
00127         }
00128         scene::Instance* erase (scene::Instantiable::Observer* observer, const scene::Path& path)
00129         {
00130             return m_instances.erase(observer, path);
00131         }
00132 };
00133 
00134 // Casts the node onto a Brush and returns the pointer to it
00135 inline Brush* Node_getBrush (scene::Node& node)
00136 {
00137     return NodeTypeCast<Brush>::cast(node);
00138 }
00139 
00140 #endif

Generated by  doxygen 1.6.2