MultiPolylineTool.h

Go to the documentation of this file.
00001 //# Copyright (C) 1999,2000,2001,2002
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 //#
00025 //# $Id$
00026 
00027 #ifndef DISPLAY_MULTIPOLYLINETOOL_H
00028 #define DISPLAY_MULTIPOLYLINETOOL_H
00029 
00030 #include <casa/aips.h>
00031 #include <display/DisplayEvents/RegionTool.h>
00032 #include <display/DisplayEvents/DTVisible.h>
00033 #include <display/region/RegionSourceFactory.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // Base class for WorldCanvas event-based polyline tools
00039 // </summary>
00040 //
00041 // <use visibility=export>
00042 //
00043 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00044 // </reviewed>
00045 //
00046 // <prerequisites>
00047 //   <li><linkto>WCTool</linkto>
00048 // </prerequisites>
00049 //
00050 // <etymology>
00051 // MultiPolylineTool stands for Multi-WorldCanvas Polyline Tool
00052 // </etymology>
00053 //
00054 // <synopsis>
00055 // This class adds to its base MWCTool to provide a tool for drawing,
00056 // reshaping and moving polylines on a WorldCanvas.  While MultiPolylineTool
00057 // is not abstract, it performs no useful function.  The programmer
00058 // should derive from this class and override the functions doubleInside
00059 // and doubleOutside at the very least.  These are called when the user
00060 // double-clicks a particular key or mouse button inside or outside an
00061 // existing polyline respectively.  It is up to the programmer to decide
00062 // what these events mean, but it is recommended that an internal double-
00063 // click correspond to the main action of the tool, eg. emitting the
00064 // polyline vertices to the application, and that an external double-click
00065 // correspond to a secondary action of the tool, if indeed there are
00066 // additional actions suitable to the tool.
00067 //
00068 // The polyline is drawn by clicking at each of the vertices, and
00069 // clicking again on the last or first vertex to complete the polyline.
00070 // Once drawn, the vertices can be moved by dragging their handles,
00071 // and the entire polyline relocated by dragging inside the polyline.
00072 // The polyline is removed from the display when the Esc key is
00073 // pressed.
00074 // </synopsis>
00075 //
00076 // <example>
00077 // </example>
00078 //
00079 
00080 
00081 
00082         class MultiPolylineTool : public RegionTool, public DTVisible, public viewer::RegionCreator {
00083 
00084         public:
00085 
00086                 // Constructor
00087                 MultiPolylineTool( viewer::RegionSourceFactory *rsf, PanelDisplay* pd,
00088                                    Display::KeySym keysym = Display::K_Pointer_Button1, const Bool persistent = False );
00089 
00090                 // Destructor
00091                 virtual ~MultiPolylineTool();
00092 
00093                 // Switch the tool off - this calls the base class disable,
00094                 // and then erases the polyline if it's around
00095                 virtual void disable();
00096 
00097                 // reset to non-existent, non-active polyline.
00098                 // Refreshes if necessary to erase (unless skipRefresh==True).
00099                 // (Does not unregister from WCs or disable future event handling).
00100                 virtual void reset(Bool skipRefresh=False);
00101 
00102                 // Is a polyline currently defined?
00103                 virtual Bool polylineDefined() {
00104                         return itsMode>=Ready;
00105                 }
00106 
00107                 viewer::RegionSource *getRegionSource( ) {
00108                         return rfactory;
00109                 }
00110 
00111                 void checkPoint( WorldCanvas *wc, State &state );
00112 
00113                 // called when the user (read GUI user) indicates that a region should be deleted...
00114                 void revokeRegion( viewer::Region * );
00115 
00116                 // returns a set which indicates regions this creator creates...
00117                 const std::set<viewer::region::RegionTypes> &regionsCreated( ) const;
00118 
00119                 bool create( viewer::region::RegionTypes /*region_type*/, WorldCanvas */*wc*/, const std::vector<std::pair<double,double> > &/*pts*/,
00120                              const std::string &/*label*/, viewer::region::TextPosition /*label_pos*/, const std::vector<int> &/*label_off*/,
00121                              const std::string &/*font*/, int /*font_size*/, int /*font_style*/, const std::string &/*font_color*/,
00122                              const std::string &/*line_color*/, viewer::region::LineStyle /*line_style*/, unsigned int /*line_width*/,
00123                              bool /*annotation*/, VOID */*region_specific_state*/ );
00124 
00125                 RegionToolTypes type( ) const {
00126                         return POLYLINETOOL;
00127                 }
00128 
00129         protected:
00130 
00131                 // Functions called by the base class event handling operators--and
00132                 // normally only those.  This is the input that controls the polyline's
00133                 // appearance and action.  When the polyline is ready and double-click
00134                 // is received, the doubleInside/Outside routine is invoked.
00135                 // <group>
00136                 virtual void keyPressed(const WCPositionEvent &/*ev*/);
00137                 virtual void moved(const WCMotionEvent &/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00138                 virtual void keyReleased(const WCPositionEvent &/*ev*/);
00139                 virtual void otherKeyPressed(const WCPositionEvent &/*ev*/);
00140                 // </group>
00141 
00142                 // draw the polyline (if any) on the object's currently active WC.
00143                 // Only to be called by the base class refresh event handler.  Derived
00144                 // objects should use refresh() if they need to redraw, but even that
00145                 // is normally handled automatically by this class.
00146                 virtual void draw(const WCRefreshEvent&/*ev*/, const viewer::region::region_list_type & /*selected_regions*/);
00147 
00148                 // Output callback functions--to be overridden in derived class as needed.
00149                 // Called when there is a double click inside/outside the polyline
00150                 // <group>
00151                 virtual void doubleInside() { };
00152                 virtual void doubleOutside() { };
00153                 // </group>
00154 
00155                 // Function called when a polyline is ready and not being
00156                 // edited.  (Unused so far on the glish level (12/01)).
00157                 virtual void polylineReady() { };
00158 
00159                 // Retrieve polyline vertices, or a single vertex, in screen pixels.
00160                 // Valid results during the callback functions; to be used by them,
00161                 // as well as internally.
00162                 // <group>
00163                 virtual void get(Vector<Int> &x, Vector<Int> &y) const;
00164                 virtual void get(Int &x, Int &y, const Int pt) const;
00165                 // </group>
00166 
00167                 virtual bool checkType( viewer::region::RegionTypes t ) {
00168                         return t == viewer::region::PolylineRegion;
00169                 }
00170 
00171         private:
00172                 typedef std::list<SHARED_PTR<viewer::Polyline> > polylinelist;
00173                 void start_new_polyline( WorldCanvas *, int x, int y );
00174 
00175                 // Set the polyline vertices. itsNPoints should already be set, and
00176                 // x and y must contain (at least) this many points.
00177                 virtual void set(const Vector<Int> &x, const Vector<Int> &y);
00178 
00179                 // replace a single vertex.
00180                 virtual void set(const Int x, const Int y, const Int pt);
00181 
00182                 SHARED_PTR<viewer::Polyline> resizing_region;
00183                 SHARED_PTR<viewer::Polyline> creating_region;
00184 
00185                 // push/pop last vertex
00186                 // <group>
00187                 void pushPoint(Int x1, Int y1);
00188                 void popPoint();
00189                 // </group>
00190 
00191                 // are we inside the polyline?
00192                 Bool inPolyline(const Int &x, const Int &y) const;
00193 
00194                 // are we within the specified handle?
00195                 Bool inHandle(const Int &pt, const Int &x, const Int &y) const;
00196 
00197 
00198                 // should the polyline remain on screen after double clicks?
00199                 Bool itsPolylinePersistent;
00200 
00201                 // state of the polyline tool
00202                 enum AdjustMode {
00203                     Off,        // Nothing exists yet
00204                     Def,        // defining initial polyline
00205                     Ready,      // polyline finished, no current activity
00206                     Move,       // moving entire polyline
00207                     Resize
00208                 };      // moving single vertex whose handle was pressed
00209                 MultiPolylineTool::AdjustMode itsMode;
00210 
00211                 // set True on double-click, if the polyline is persistent.
00212                 // set False when the polyline is moved, resized or reset.
00213                 // If True, a click outside the polyline will erase it and begin
00214                 // definition of a new one.
00215                 Bool itsEmitted;
00216 
00217                 // Number of points
00218                 Int itsNPoints;
00219 
00220                 // Polyline points (linear).  Not to be used directly.
00221                 // use get, set, push, pop instead, which take pixel coordinate arguments.
00222                 // It's done this way so that zooms work on the figures.
00223                 Vector<Double> itsX, itsY;
00224                 // pixel coordinates of the pan vector.  1 = anchor, 2 = new position.
00225                 Int itsX1, itsY1, itsX2, itsY2, itsX3, itsY3;
00226 
00227 
00228                 // size in pixels of the handles
00229                 Int itsHandleSize;
00230 
00231                 // vertex being moved
00232                 Int itsSelectedHandle;
00233 
00234                 // position that move started from
00235                 Int itsBaseMoveX, itsBaseMoveY;
00236 
00237                 // may not be needed...
00238                 int resizing_region_handle;
00239 
00240                 polylinelist moving_regions;
00241                 double moving_linx_;
00242                 double moving_liny_;
00243 
00244                 SHARED_PTR<viewer::Polyline> building_polyline;
00245                 viewer::RegionSource *rfactory;
00246                 polylinelist polylines;
00247                 PanelDisplay *pd_;
00248         };
00249 
00250 } //# NAMESPACE CASA - END
00251 
00252 #endif
00253 
00254 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1