contrib/brl/bbas/bgui/bgui_picker_tableau.h
Go to the documentation of this file.
00001 // This is brl/bbas/bgui/bgui_picker_tableau.h
00002 #ifndef bgui_picker_tableau_h_
00003 #define bgui_picker_tableau_h_
00004 //:
00005 // \file
00006 // \author K.Y.McGaul
00007 // \brief  Tableau to pick points and lines.
00008 //
00009 //  The difference between this picker tableau and vgui_rubberbander is that
00010 //  this keeps control of the event loop until the object has been picked.
00011 //  The functions pick_point/pick_line will only return once the user has
00012 //  picked a point/line.
00013 //   
00014 //  Anchored_pick_point rubberbands a line joining a first point (the anchor)
00015 //  during the motion to select a second point. Useful for corresponding
00016 //  pairs of points - JLM
00017 //
00018 // \verbatim
00019 //  Modifications
00020 //   K.Y.McGaul - 23-MAR-2001 - Initial version.
00021 //   J. Mundy - Jan 9, 2005 - Added anchored pick point
00022 //   K. Kang - May 9, 2005 - Added pick box
00023 // \endverbatim
00024 
00025 #include <vgui/vgui_tableau.h>
00026 #include <vgui/vgui_event.h>
00027 #include <vgui/vgui_event_condition.h>
00028 #include <vgui/vgui_parent_child_link.h>
00029 #include <vsol/vsol_point_2d_sptr.h>
00030 #include <vsol/vsol_polygon_2d_sptr.h>
00031 #include <vsol/vsol_polyline_2d_sptr.h>
00032 #include "bgui_picker_tableau_sptr.h"
00033 
00034 class bgui_picker_tableau : public vgui_tableau
00035 {
00036  public:
00037 
00038   //: Constructor, takes a child tableau.
00039   bgui_picker_tableau(vgui_tableau_sptr const&);
00040   //: Destructor.
00041   ~bgui_picker_tableau();
00042   vcl_string type_name() const { return "bgui_picker_tableau";}
00043 
00044   //: Gets a user selected point.
00045   bool pick_point(float* x, float* y);
00046 
00047   //: Gets a user selected line.
00048   void pick_line(float* x1, float* y1, float* x2, float* y2);
00049 
00050   //: Gets a user selected box specified by corner points)
00051   void pick_box(float* x1, float* y1, float *x2, float* y2);
00052 
00053   //: Gets a user selected polygon 
00054 
00055   //: Pick a point with an anchored line indicator
00056   void anchored_pick_point(const float anch_x,
00057                            const float anch_y,
00058                            float* x, float* y);
00059 
00060   //: Pick a polygon
00061   void pick_polygon(vsol_polygon_2d_sptr& poly);
00062 
00063   //: pick a polyline (set of connected lines)
00064   void pick_polyline(vsol_polyline_2d_sptr& poly);
00065 
00066   bool pick_point_set(vcl_vector< vsol_point_2d_sptr >& ps_list, unsigned max);
00067 
00068   //: Set drawing style, [0 1.0] for colors
00069   void set_color(const float red=1.0f, const float green=1.0f,
00070                  const float blue=1.0f) {r = red; g = green; b = blue;}
00071   void set_line_width(const float width=2.0f){w = width;}
00072 
00073   //: Handles all events for this tableau.
00074   bool handle(const vgui_event&);
00075 
00076  protected:
00077   vgui_parent_child_link child_tab;
00078 
00079  private:
00080   //: Draw a line to help the user pick it.
00081   void draw_line();
00082   void draw_anchor_line();
00083 
00084   //: draw box
00085   void draw_box();
00086 
00087   //: Get next event in the event loop.
00088   bool next();
00089   //: List of possible objects to pick.
00090   enum object_type {none_enum, point_enum, line_enum, anchor_enum, box_enum, 
00091     poly_enum, point_set_enum, polyline_enum};
00092 
00093   //: Type of object we are picking.
00094   static object_type obj_type;
00095 
00096   //: Used in next() to indicate when the event has been used.
00097   bool use_event_;
00098 
00099   //: Start and end points for line and box:
00100   float pointx1, pointy1, pointx2, pointy2;
00101 
00102   //: Anchor point coordinates
00103   float anchor_x, anchor_y;
00104 
00105   //: For polygon
00106   bool active;
00107   vgui_event_condition gesture0;
00108   vgui_event_condition gesture1;
00109   vgui_event_condition gesture2;  
00110 
00111   vcl_vector< vsol_point_2d_sptr > point_list;
00112 
00113   // for point_set
00114   vcl_vector< vsol_point_2d_sptr > point_set_list;
00115 
00116   float last_x;
00117   float last_y;
00118 
00119   //: Style values
00120   float r, g, b, w;
00121   //: Whether this is the first (start) or second (end) point being selected.
00122   bool FIRSTPOINT;
00123   //: Coordinates for point:
00124   float pointx, pointy;
00125   //: True if picked by left mouse button, else false.
00126   bool point_ret;
00127 
00128   //: True if we have completed picking the object.
00129   bool picking_completed;
00130 
00131 };
00132 
00133 
00134 // <vgui_make_sptr>
00135 struct bgui_picker_tableau_new : public bgui_picker_tableau_sptr
00136 {
00137   typedef bgui_picker_tableau_sptr base;
00138   bgui_picker_tableau_new(vgui_tableau_sptr const& arg1000) : base(new bgui_picker_tableau(arg1000)) {}
00139 };
00140 // </vgui_make_sptr>
00141 
00142 #endif   // DO NOT ADD CODE AFTER THIS LINE! END OF DEFINITION FOR CLASS bgui_picker_tableau.