casa
$Rev:20696$
|
Base class for WorldCanvas event-based polygon tools. More...
#include <MWCPolyTool.h>
Public Member Functions | |
MWCPolyTool (Display::KeySym keysym=Display::K_Pointer_Button1, const Bool persistent=False) | |
Constructor. | |
virtual | ~MWCPolyTool () |
Destructor. | |
virtual void | disable () |
Switch the tool off - this calls the base class disable, and then erases the polygon if it's around. | |
virtual void | reset (Bool skipRefresh=False) |
reset to non-existent, non-active polygon. | |
virtual Bool | polygonDefined () |
Is a polygon currently defined? | |
Protected Member Functions | |
virtual void | keyPressed (const WCPositionEvent &) |
Functions called by the base class event handling operators--and normally only those. | |
virtual void | moved (const WCMotionEvent &, const viewer::region::region_list_type &) |
virtual void | keyReleased (const WCPositionEvent &) |
virtual void | otherKeyPressed (const WCPositionEvent &) |
virtual void | draw (const WCRefreshEvent &, const viewer::region::region_list_type &) |
draw the polygon (if any) on the object's currently active WC. | |
virtual void | doubleInside () |
Output callback functions--to be overridden in derived class as needed. | |
virtual void | doubleOutside () |
virtual void | polygonReady () |
Function called when a polygon is ready and not being edited. | |
virtual void | get (Vector< Int > &x, Vector< Int > &y) const |
Retrieve polygon vertices, or a single vertex, in screen pixels. | |
virtual void | get (Int &x, Int &y, const Int pt) const |
Private Types | |
enum | AdjustMode { Off, Def, Ready, Move, Resize } |
state of the polygon tool More... | |
Private Member Functions | |
virtual void | set (const Vector< Int > &x, const Vector< Int > &y) |
virtual void | set (const Int x, const Int y, const Int pt) |
replace a single vertex. | |
void | pushPoint (Int x1, Int y1) |
push/pop last vertex | |
void | popPoint () |
Bool | inPolygon (const Int &x, const Int &y) const |
are we inside the polygon? | |
Bool | inHandle (const Int &pt, const Int &x, const Int &y) const |
are we within the specified handle? | |
Private Attributes | |
Bool | itsPolygonPersistent |
should the polygon remain on screen after double clicks? | |
MWCPolyTool::AdjustMode | itsMode |
Bool | itsEmitted |
set True on double-click, if the polygon is persistent. | |
Int | itsNPoints |
Number of points. | |
Vector< Double > | itsX |
Polygon points (linear). | |
Vector< Double > | itsY |
Int | itsHandleSize |
size in pixels of the handles | |
Int | itsSelectedHandle |
vertex being moved | |
Int | itsBaseMoveX |
position that move started from | |
Int | itsBaseMoveY |
Double | itsLastPressTime |
times of the last two presses | |
Double | its2ndLastPressTime |
Base class for WorldCanvas event-based polygon tools.
Public interface
<prerequisites> (see ())WCTool </prerequisites>
MWCPolyTool stands for Multi-WorldCanvas Polygon Tool
This class adds to its base MWCTool to provide a tool for drawing, reshaping and moving polygons on a WorldCanvas. While MWCPolyTool is not abstract, it performs no useful function. The programmer should derive from this class and override the functions doubleInside and doubleOutside at the very least. These are called when the user double-clicks a particular key or mouse button inside or outside an existing polygon respectively. It is up to the programmer to decide what these events mean, but it is recommended that an internal double- click correspond to the main action of the tool, eg. emitting the polygon vertices to the application, and that an external double-click correspond to a secondary action of the tool, if indeed there are additional actions suitable to the tool.
The polygon is drawn by clicking at each of the vertices, and clicking again on the last or first vertex to complete the polygon. Once drawn, the vertices can be moved by dragging their handles, and the entire polygon relocated by dragging inside the polygon. The polygon is removed from the display when the Esc key is pressed.
Many activities on the WorldCanvas will be based on the user drawing a polygon and using the polygon in some operation.
Definition at line 88 of file MWCPolyTool.h.
enum casa::MWCPolyTool::AdjustMode [private] |
state of the polygon tool
Definition at line 174 of file MWCPolyTool.h.
casa::MWCPolyTool::MWCPolyTool | ( | Display::KeySym | keysym = Display::K_Pointer_Button1 , |
const Bool | persistent = False |
||
) |
Constructor.
virtual casa::MWCPolyTool::~MWCPolyTool | ( | ) | [virtual] |
Destructor.
virtual void casa::MWCPolyTool::disable | ( | ) | [virtual] |
Switch the tool off - this calls the base class disable, and then erases the polygon if it's around.
Reimplemented from casa::MultiWCTool.
virtual void casa::MWCPolyTool::doubleInside | ( | ) | [inline, protected, virtual] |
Output callback functions--to be overridden in derived class as needed.
Called when there is a double click inside/outside the polygon
Reimplemented in casa::MWCPTRegion.
Definition at line 133 of file MWCPolyTool.h.
virtual void casa::MWCPolyTool::doubleOutside | ( | ) | [inline, protected, virtual] |
Definition at line 134 of file MWCPolyTool.h.
virtual void casa::MWCPolyTool::draw | ( | const WCRefreshEvent & | , |
const viewer::region::region_list_type & | |||
) | [protected, virtual] |
draw the polygon (if any) on the object's currently active WC.
Only to be called by the base class refresh event handler. Derived objects should use refresh() if they need to redraw, but even that is normally handled automatically by this class.
Reimplemented from casa::MultiWCTool.
virtual void casa::MWCPolyTool::get | ( | Vector< Int > & | x, |
Vector< Int > & | y | ||
) | const [protected, virtual] |
Retrieve polygon vertices, or a single vertex, in screen pixels.
Valid results during the callback functions; to be used by them, as well as internally.
virtual void casa::MWCPolyTool::get | ( | Int & | x, |
Int & | y, | ||
const Int | pt | ||
) | const [protected, virtual] |
Bool casa::MWCPolyTool::inHandle | ( | const Int & | pt, |
const Int & | x, | ||
const Int & | y | ||
) | const [private] |
are we within the specified handle?
Bool casa::MWCPolyTool::inPolygon | ( | const Int & | x, |
const Int & | y | ||
) | const [private] |
are we inside the polygon?
virtual void casa::MWCPolyTool::keyPressed | ( | const WCPositionEvent & | ) | [protected, virtual] |
Functions called by the base class event handling operators--and normally only those.
This is the input that controls the polygon's appearance and action. When the polygon is ready and double-click is received, the doubleInside/Outside routine is invoked.
Reimplemented from casa::MultiWCTool.
virtual void casa::MWCPolyTool::keyReleased | ( | const WCPositionEvent & | ) | [protected, virtual] |
Reimplemented from casa::MultiWCTool.
virtual void casa::MWCPolyTool::moved | ( | const WCMotionEvent & | , |
const viewer::region::region_list_type & | |||
) | [protected, virtual] |
Reimplemented from casa::MultiWCTool.
virtual void casa::MWCPolyTool::otherKeyPressed | ( | const WCPositionEvent & | ) | [protected, virtual] |
Reimplemented from casa::MultiWCTool.
virtual Bool casa::MWCPolyTool::polygonDefined | ( | ) | [inline, virtual] |
Is a polygon currently defined?
Definition at line 109 of file MWCPolyTool.h.
virtual void casa::MWCPolyTool::polygonReady | ( | ) | [inline, protected, virtual] |
Function called when a polygon is ready and not being edited.
(Unused so far on the glish level (12/01)).
Reimplemented in casa::QtOldPTRegion.
Definition at line 139 of file MWCPolyTool.h.
void casa::MWCPolyTool::popPoint | ( | ) | [private] |
void casa::MWCPolyTool::pushPoint | ( | Int | x1, |
Int | y1 | ||
) | [private] |
push/pop last vertex
virtual void casa::MWCPolyTool::reset | ( | Bool | skipRefresh = False | ) | [virtual] |
reset to non-existent, non-active polygon.
Refreshes if necessary to erase (unless skipRefresh==True). (Does not unregister from WCs or disable future event handling).
Reimplemented from casa::MultiWCTool.
virtual void casa::MWCPolyTool::set | ( | const Vector< Int > & | x, |
const Vector< Int > & | y | ||
) | [private, virtual] |
Set the polygon vertices. itsNPoints should already be set, and x and y must contain (at least) this many points.
virtual void casa::MWCPolyTool::set | ( | const Int | x, |
const Int | y, | ||
const Int | pt | ||
) | [private, virtual] |
replace a single vertex.
Double casa::MWCPolyTool::its2ndLastPressTime [private] |
Definition at line 206 of file MWCPolyTool.h.
Int casa::MWCPolyTool::itsBaseMoveX [private] |
position that move started from
Definition at line 203 of file MWCPolyTool.h.
Int casa::MWCPolyTool::itsBaseMoveY [private] |
Definition at line 203 of file MWCPolyTool.h.
Bool casa::MWCPolyTool::itsEmitted [private] |
set True on double-click, if the polygon is persistent.
set False when the polygon is moved, resized or reset. If True, a click outside the polygon will erase it and begin definition of a new one.
Definition at line 186 of file MWCPolyTool.h.
Int casa::MWCPolyTool::itsHandleSize [private] |
size in pixels of the handles
Definition at line 197 of file MWCPolyTool.h.
Double casa::MWCPolyTool::itsLastPressTime [private] |
times of the last two presses
Definition at line 206 of file MWCPolyTool.h.
Definition at line 180 of file MWCPolyTool.h.
Referenced by polygonDefined().
Int casa::MWCPolyTool::itsNPoints [private] |
Number of points.
Definition at line 189 of file MWCPolyTool.h.
Bool casa::MWCPolyTool::itsPolygonPersistent [private] |
should the polygon remain on screen after double clicks?
Definition at line 171 of file MWCPolyTool.h.
Int casa::MWCPolyTool::itsSelectedHandle [private] |
vertex being moved
Definition at line 200 of file MWCPolyTool.h.
Vector<Double> casa::MWCPolyTool::itsX [private] |
Polygon points (linear).
Not to be used directly. use get, set, push, pop instead, which take pixel coordinate arguments. It's done this way so that zooms work on the figures.
Definition at line 194 of file MWCPolyTool.h.
Vector<Double> casa::MWCPolyTool::itsY [private] |
Definition at line 194 of file MWCPolyTool.h.