core/vgui/vgui_soview.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_soview.h
00002 #ifndef vgui_soview_h_
00003 #define vgui_soview_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author  Philip C. Pritchett, Robotics Research Group, University of Oxford
00010 // \date    24 Mar 99
00011 // \brief   Spatial object view (base class for 2 & 3D geometric objects).
00012 //
00013 //  Contains classes: vgui_soview
00014 //  Notes: We use floats instead of doubles as size is a speed issue (sic.)
00015 //
00016 
00017 #include "dll.h"
00018 
00019 #include <vcl_string.h>
00020 #include <vcl_iosfwd.h>
00021 #include <vcl_vector.h>
00022 
00023 #include "vgui_style_sptr.h"
00024 
00025 class vgui_observer;
00026 class vgui_message;
00027 
00028 //: Spatial object view (base class for 2 & 3D geometric objects).
00029 //
00030 //  This class is the base class for vgui_soview2D and vgui_soview3D
00031 //  and contains the functionality they have in common.
00032 class vgui_soview
00033 {
00034  public:
00035   //: Constructor - create a default soview.
00036   vgui_soview() : selectable(true), style(0) { add_id(); }
00037 
00038   //: Destructor - delete this soview.
00039   virtual ~vgui_soview();
00040 
00041   //: Render this soview on the display.
00042   virtual void draw() const = 0;
00043 
00044   //: Render this soview for selection purposes.
00045   //
00046   // By default, this will call draw(). However, some objects take
00047   // time to draw, especially in GL_SELECT mode. The routine allows
00048   // such objects to render a simplified version for the selection
00049   // process. Note that during selection, the object is not rendered
00050   // on screen. The "rendering" is used by OpenGL internals to
00051   // determine if the object is in the selection region (e.g. area
00052   // around mouse pointer).
00053   //
00054   virtual void draw_select() const;
00055 
00056   //: Calls OpenGL function glLoadName with this soview's id.
00057   virtual void load_name() const;
00058 
00059   //: Prints the ID of this soview.
00060   virtual vcl_ostream& print(vcl_ostream& s) const;
00061 
00062   //: This should never be called, derived classes should implement this.
00063   virtual vcl_string type_name() const { return "vgui_soview"; }
00064 
00065   //: Set the style (colour, line width) of the soview.
00066   virtual void set_style(const vgui_style_sptr& newstyle) { style = newstyle; }
00067 
00068   //: Return the style (colour, line width) of the soview.
00069   virtual vgui_style_sptr get_style() const { return style; }
00070 
00071   //: Set the colour of the soview.
00072   void set_colour(float r, float g, float b);
00073 
00074   //: Set the point radius of the soview.
00075   void set_point_size(float s);
00076 
00077   //: Set the line width of the soview.
00078   void set_line_width(float w);
00079 
00080   //: Attach given observer to this soview.
00081   void attach(vgui_observer*);
00082 
00083   //: Detach the given observer from this soview.
00084   void detach(vgui_observer*);
00085 
00086   //: Get a list of all observers attached to this soview.
00087   void get_observers(vcl_vector<vgui_observer*>&) const;
00088 
00089   //: Update all observers.
00090   virtual void notify() const;
00091 
00092   //: Send message to all observers.
00093   virtual void notify(vgui_message const &) const;
00094 
00095   // fsm. new old message model
00096   static vgui_DLLDATA const void * const msg_select;
00097   static vgui_DLLDATA const void * const msg_deselect;
00098   static vgui_DLLDATA const void * const msg_highlight;
00099   static vgui_DLLDATA const void * const msg_unhighlight;
00100 
00101   //: Returns the ID of this soview.
00102   virtual unsigned get_id() const {return id;}
00103 
00104   //: Returns a pointer to the vgui_soview, given the ID.
00105   static vgui_soview* id_to_object(unsigned id);
00106 
00107   //: Create a new ID.
00108   static unsigned create_id();
00109 
00110   //: Return true if it is possible to select this soview.
00111   bool get_selectable() const { return selectable; }
00112 
00113   //: Make this soview selectable/non-selectable.
00114   void set_selectable( bool s) { selectable= s; }
00115 
00116  protected:
00117   //: ID of this soview.
00118   unsigned id;
00119 
00120   //: Whether this soview is selectable.
00121   bool selectable;
00122 
00123   //: Style (colour, line width, etc) of this soview.
00124   vgui_style_sptr style;
00125 
00126  private:
00127   void add_id();
00128   static vgui_DLLDATA unsigned current_id;
00129 };
00130 
00131 inline vcl_ostream& operator<<(vcl_ostream& s, const vgui_soview& so)
00132 {
00133   return so.print(s);
00134 }
00135 
00136 #endif // vgui_soview_h_