iselection.h

Go to the documentation of this file.
00001 
00005 /*
00006  Copyright (C) 2001-2006, William Joseph.
00007  All Rights Reserved.
00008 
00009  This file is part of GtkRadiant.
00010 
00011  GtkRadiant is free software; you can redistribute it and/or modify
00012  it under the terms of the GNU General Public License as published by
00013  the Free Software Foundation; either version 2 of the License, or
00014  (at your option) any later version.
00015 
00016  GtkRadiant is distributed in the hope that it will be useful,
00017  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  GNU General Public License for more details.
00020 
00021  You should have received a copy of the GNU General Public License
00022  along with GtkRadiant; if not, write to the Free Software
00023  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00024  */
00025 
00026 #if !defined(INCLUDED_ISELECTION_H)
00027 #define INCLUDED_ISELECTION_H
00028 
00029 #include <cstddef>
00030 #include "generic/constant.h"
00031 #include "generic/callbackfwd.h"
00032 #include "signal/signalfwd.h"
00033 
00034 class Renderer;
00035 class View;
00036 
00041 class Selectable
00042 {
00043     public:
00044         STRING_CONSTANT(Name, "Selectable");
00045 
00046         virtual ~Selectable ()
00047         {
00048         }
00049 
00050         // Set the selection status of this object
00051         virtual void setSelected (bool select) = 0;
00052         // Check the selection status of this object (TRUE == selected)
00053         virtual bool isSelected () const = 0;
00054         // Toggle the selection status
00055         // TODO:
00056         // virtual void invertSelected() = 0;
00057 };
00058 
00059 namespace scene
00060 {
00061     class Instance;
00062 }
00063 ;
00064 
00065 class InstanceSelectionObserver
00066 {
00067     public:
00068         virtual ~InstanceSelectionObserver ()
00069         {
00070         }
00071 
00072         virtual void onSelectedChanged (scene::Instance& instance) = 0;
00073 };
00074 
00075 template<typename Element> class BasicVector3;
00076 typedef BasicVector3<float> Vector3;
00077 template<typename Element> class BasicVector4;
00078 typedef BasicVector4<float> Vector4;
00079 class Matrix4;
00080 typedef Vector4 Quaternion;
00081 
00082 typedef Callback1<const Selectable&> SelectionChangeCallback;
00083 typedef SignalHandler1<const Selectable&> SelectionChangeHandler;
00084 
00085 class SelectionSystem
00086 {
00087     public:
00088         INTEGER_CONSTANT(Version, 1);
00089         STRING_CONSTANT(Name, "selection");
00090 
00091         enum EMode
00092         {
00093             eEntity, 
00094             ePrimitive, 
00095             eComponent,
00097         };
00098 
00099         // The possible modes when in "component manipulation mode"
00100         enum EComponentMode
00101         {
00102             eDefault, eVertex, eEdge, eFace,
00103         };
00104 
00105         // The possible manipulator modes
00106         enum EManipulatorMode
00107         {
00108             eTranslate, eRotate, eScale, eDrag, eClip,
00109         };
00110 
00111         virtual ~SelectionSystem ()
00112         {
00113         }
00114 
00115         virtual void SetMode (EMode mode) = 0;
00116         virtual EMode Mode () const = 0;
00117         virtual void SetComponentMode (EComponentMode mode) = 0;
00118         virtual EComponentMode ComponentMode () const = 0;
00119         virtual void SetManipulatorMode (EManipulatorMode mode) = 0;
00120         virtual EManipulatorMode ManipulatorMode () const = 0;
00121 
00122         virtual SelectionChangeCallback getObserver (EMode mode) = 0;
00123         // amount of selected primitives (brushes)
00124         virtual std::size_t countSelected () const = 0;
00125         // amount of selected components (vertices, edges, faces)
00126         virtual std::size_t countSelectedComponents () const = 0;
00127         // amount of selected faces
00128         virtual std::size_t countSelectedFaces () const = 0;
00129         // only checks whether faces are selected, but does not count them
00130         virtual bool areFacesSelected () const = 0;
00131         virtual void onSelectedChanged (scene::Instance& instance, const Selectable& selectable) = 0;
00132         virtual void onComponentSelection (scene::Instance& instance, const Selectable& selectable) = 0;
00133         virtual scene::Instance& ultimateSelected () const = 0;
00134         virtual scene::Instance& penultimateSelected () const = 0;
00142         virtual void setSelectedAll (bool selected) = 0;
00143         virtual void setSelectedAllComponents (bool selected) = 0;
00144 
00152         class Visitor
00153         {
00154             public:
00155                 virtual ~Visitor ()
00156                 {
00157                 }
00158 
00162                 virtual void visit (scene::Instance& instance) const = 0;
00163         };
00167         virtual void foreachSelected (const Visitor& visitor) const = 0;
00171         virtual void foreachSelectedComponent (const Visitor& visitor) const = 0;
00172 
00173         virtual void addSelectionChangeCallback (const SelectionChangeHandler& handler) = 0;
00174 
00175         virtual void NudgeManipulator (const Vector3& nudge, const Vector3& view) = 0;
00176 
00177         virtual void translateSelected (const Vector3& translation) = 0;
00178         virtual void rotateSelected (const Quaternion& rotation) = 0;
00179         virtual void scaleSelected (const Vector3& scaling) = 0;
00180 
00181         virtual void pivotChanged () const = 0;
00182 };
00183 
00184 #include "modulesystem.h"
00185 
00186 template<typename Type>
00187 class GlobalModule;
00188 typedef GlobalModule<SelectionSystem> GlobalSelectionModule;
00189 
00190 template<typename Type>
00191 class GlobalModuleRef;
00192 typedef GlobalModuleRef<SelectionSystem> GlobalSelectionModuleRef;
00193 
00194 inline SelectionSystem& GlobalSelectionSystem ()
00195 {
00196     return GlobalSelectionModule::getTable();
00197 }
00198 
00199 #endif

Generated by  doxygen 1.6.2