casa
$Rev:20696$
|
00001 //# Annotations.h : Control class for DisplayShape 00002 //# Copyright (C) 1998,1999,2000,2001,2002,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: 00027 00028 #ifndef TRIALDISPLAY_ANNOTATIONS_H 00029 #define TRIALDISPLAY_ANNOTATIONS_H 00030 00031 #include <casa/aips.h> 00032 00033 #include <display/DisplayEvents/PCPositionEH.h> 00034 #include <display/DisplayEvents/PCMotionEH.h> 00035 #include <display/DisplayEvents/PCRefreshEH.h> 00036 #include <display/DisplayEvents/WCRefreshEH.h> 00037 #include <casa/OS/Timer.h> 00038 00039 #include <display/Display/WorldCanvas.h> 00040 #include <casa/Containers/List.h> 00041 00042 #include <casa/Containers/Record.h> 00043 #include <casa/Arrays/Matrix.h> 00044 #include <casa/Arrays/Vector.h> 00045 00046 namespace casa { //# NAMESPACE CASA - BEGIN 00047 00048 class DisplayShape; 00049 class PanelDisplay; 00050 00051 00052 // <summary> 00053 // Control class for a collection of DisplayShapeInterfaces. 00054 // </summary> 00055 // 00056 // <prerequisite> 00057 // <li> <linkto class="DisplayShapeInterface">DisplayShapeInterface</linkto> 00058 // </prerequisite> 00059 // 00060 // <etymology> 00061 // Annotations is a method by which a collection of shapes can be managed 00062 // on a pixel canvas. 00063 // </etymology> 00064 // 00065 // <synopsis> 00066 // Annotations registers itself as an event handler on whichever pixelcanvas 00067 // it is supplied. It can then add, delete or modify shapes based on function 00068 // calls and user mouse input. 00069 // 00070 // The class is essentially a PtrBlock of DisplayShapeInterfaces, with 00071 // pixelcanvas event handling to control them. 00072 // </synopsis> 00073 // 00074 // <motivation> 00075 // To allow a collection of shapes to be displayed and cotrolled by one class. 00076 // </motivation> 00077 // 00078 // <example> 00079 // <srcblock> 00080 // </srcblock> 00081 // </example> 00082 00083 00084 class Annotations : public PCPositionEH, 00085 public PCMotionEH, 00086 public PCRefreshEH, 00087 public WCRefreshEH { 00088 00089 public: 00090 // Used to determine the state of the class. The state may change due 00091 // to mouse events, or function calls. 00092 enum State {Nothing, Creation, WcCreation, Handle, OtherHandle, Move, 00093 OtherMove}; 00094 00095 // This is used to handle the creation of shapes by mouse events. Some 00096 // types of shapes require special treatment when constructed with 00097 // the mouse. 00098 enum CreationType {Normal, Arrow, Polygon, PolyLine, Marker}; 00099 00100 // Destructor, and constructor, taking the panelDisplay to which the 00101 // Annotator will attach itself to, and which mouse button to listen to. 00102 // <group> 00103 Annotations(PanelDisplay* panDisp, 00104 const Display::KeySym& keysym = Display::K_Pointer_Button1, 00105 const Bool useEH = True); 00106 virtual ~Annotations(); 00107 // </group> 00108 00109 // The event handlers. 00110 // <group> 00111 virtual void operator()(const PCPositionEvent& ev); 00112 virtual void operator()(const PCMotionEvent& ev); 00113 virtual void operator()(const PCRefreshEvent& ev); 00114 virtual void operator()(const WCRefreshEvent& ev); 00115 // </group> 00116 00117 // Redraw all the shapes. Turns all handles off if noHandles is True 00118 virtual void draw(PixelCanvas* pc, const Bool noHandles = False); 00119 00120 // Instantly creates a shape on screen, and hence requires 00121 // certain information in its record such as the center of the 00122 // new object on screen. Refresh == False can be used to surpress a 00123 // refresh. 00124 virtual void newShape(Record& settings, const Bool& refresh = True); 00125 00126 // Set the key assigned to control shapes. 00127 virtual void setKey(const Display::KeySym& newKey); 00128 00129 // Create a shape, based on the information contained in the record. 00130 // This function does not require the center to be specified, as once 00131 // createShape is called, the user can "drag" out the shape required. 00132 // If createShape is called, and the shape is no longer required, 00133 // the function 'cancelShapes' can be used to reset the state of the 00134 // annotator. 00135 virtual void createShape(Record& settings); 00136 00137 // Disable event handling (with the exception of refresh calls). This stops 00138 // the user from moving shapes etc via the mouse motion / position event 00139 // handlers. These do not recognize nested calls (e.g. two disables, 00140 // followed by an enable will enable the handlers). 00141 // <group> 00142 virtual void enable(); 00143 virtual void disable(); 00144 // </group> 00145 00146 // Cancels creation of any pending shapes, unselects all shapes and 00147 // turns off drawing of all handles. 00148 virtual void cancelShapes(); 00149 00150 // Delete the shape at the specified point in the collection of shapes 00151 // The current (selected) shape can be determined by using the 00152 // activeShape() function. 00153 virtual Bool deleteShape(const uInt& toDel); 00154 00155 // These allow shapes to be "locked" together. Adding a locked shape 00156 // to the current shape means that whenever the current shape 00157 // moves, so too will the specified shape. removeLockedFromCurrent 00158 // can be used to remove this effect. 00159 // <group> 00160 virtual void removeLockedFromCurrent(const uInt& removeMe); 00161 virtual void addLockedToCurrent(const uInt& addMe); 00162 // </group> 00163 00164 // Return the currently selected shapes' index 00165 virtual Int activeShape(); 00166 00167 // Return a brief summary of all current shapes 00168 virtual Record shapesSummary(); 00169 00170 // Set the options for the specified shape. The user selected shape 00171 // can be determined by call the 'activeShape' method. To see a list of 00172 // available options for different types of shapes / objects, see their 00173 // individual documentation. 00174 virtual void setShapeOptions(const uInt& whichShape, 00175 const Record& newOptions); 00176 00177 // Returns a record containing the options for the specified shape. 00178 // The user selected shape can be determined by calling the 'activeShape' 00179 // method. To see a list of the options returned by shapes / objects, 00180 // see their individual documentation. 00181 virtual Record getShapeOptions(const uInt& whichShape); 00182 00183 // Returns a record which contains a sub record (containing options) for 00184 // each shape. e.g. To obtain options for the first shape: 00185 // <srcblock> 00186 // Record all = myAnnotator.getAllOptions(); 00187 // Record shape = all.subRecord(0); 00188 // </srcblock> 00189 virtual Record getAllOptions(); 00190 00191 // Deletes all existing shapes, and rebuilds new shapes based on records 00192 // in sub records of the supplied record. A record returned from 00193 // getAllOptions() can therefore be used to copy a set of shapes. 00194 virtual void setAllOptions(const Record& newSettings); 00195 00196 // Called when a refresh is required. It copies back to front buffer, 00197 // then causes a refresh with reason = backCopiedToFront. 00198 virtual void update(PixelCanvas* pc); 00199 00200 // Overwrite this to fire glish events. 00201 virtual void annotEvent(const String& /*event*/) {}; 00202 00203 // Functions for changing the co-ords system of a shape 00204 // <group> 00205 virtual Bool revertToPix(const Int& whichOne); 00206 virtual Bool revertToFrac(const Int& whichOne); 00207 virtual Bool lockToWC(const Int& whichOne); 00208 // </group> 00209 00210 // Returns a list of shapes annotations knows about 00211 virtual Record availableShapes(); 00212 00213 00214 protected: 00215 00216 private: 00217 00218 // My private variables... 00219 00220 // The PanelDisplay I was given on construction and some stuff I got out 00221 // of it 00222 // <group> 00223 PanelDisplay* itsPanelDisplay; 00224 PixelCanvas* itsPC; 00225 // </group> 00226 00227 // My copy of the list of Worldcanvases. I can check this against 00228 // itsPanelDisplay to see if anything has changed. 00229 ListIter<WorldCanvas* >* itsWCLI; 00230 List<WorldCanvas* > itsWCs; 00231 00232 // List of shapes 00233 PtrBlock<DisplayShape*> itsShapes; 00234 00235 // Some overall settings 00236 // <group> 00237 Display::KeySym itsKey; 00238 Bool itsUseEH; 00239 // </group> 00240 00241 // Stuff to remember my current state: 00242 // <group> 00243 Annotations::State itsState; 00244 Annotations::CreationType itsCreation; 00245 Bool itsShapeMoved; 00246 Int itsActiveShape; 00247 Int itsActiveHandle; 00248 uInt itsX, itsY; 00249 Bool itsEnabled; 00250 Bool itsRefreshedYet; 00251 // </group> 00252 // 00253 00254 00255 // Internal functions 00256 // <group> 00257 Bool changeCoordSys(const Int shapeIndex, const String& type, 00258 const String& currentCoords, const String& toCoords); 00259 00260 DisplayShape* constructShape(const Record& settings); 00261 void handleKeyUp(); 00262 void handleCreation(const PCPositionEvent& ev); 00263 void handleNormalCreation(const Vector<Float>& createPix); 00264 void handleMarkerCreation(const Vector<Float>& createPix); 00265 void handlePolyLineCreation(const Vector<Float>& createPix); 00266 void handlePolygonCreation(const Vector<Float>& createPix); 00267 void handleArrowCreation(const Vector<Float>& createPix); 00268 void select(const Int i); 00269 Bool determineState(const PCPositionEvent& ev); 00270 void registerToWCs(); 00271 Bool validateWCs(); 00272 void changedWC(); 00273 Bool validShape(const Record& shape); 00274 void polyLineToPolygon(const Int whichShape); 00275 // </group> 00276 }; 00277 00278 // Ostream, mainly for debugging the state of the annotator. 00279 ostream& operator << (ostream& os, Annotations::State st); 00280 00281 00282 } //# NAMESPACE CASA - END 00283 00284 #endif