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 00096 // This is used to handle the creation of shapes by mouse events. Some 00097 // types of shapes require special treatment when constructed with 00098 // the mouse. 00099 enum CreationType {Normal, Arrow, Polygon, PolyLine, Marker}; 00100 00101 // Destructor, and constructor, taking the panelDisplay to which the 00102 // Annotator will attach itself to, and which mouse button to listen to. 00103 // <group> 00104 Annotations(PanelDisplay* panDisp, 00105 const Display::KeySym& keysym = Display::K_Pointer_Button1, 00106 const Bool useEH = True); 00107 virtual ~Annotations(); 00108 // </group> 00109 00110 // The event handlers. 00111 // <group> 00112 virtual void operator()(const PCPositionEvent& ev); 00113 virtual void operator()(const PCMotionEvent& ev); 00114 virtual void operator()(const PCRefreshEvent& ev); 00115 virtual void operator()(const WCRefreshEvent& ev); 00116 // </group> 00117 00118 // Redraw all the shapes. Turns all handles off if noHandles is True 00119 virtual void draw(PixelCanvas* pc, const Bool noHandles = False); 00120 00121 // Instantly creates a shape on screen, and hence requires 00122 // certain information in its record such as the center of the 00123 // new object on screen. Refresh == False can be used to surpress a 00124 // refresh. 00125 virtual void newShape(Record& settings, const Bool& refresh = True); 00126 00127 // Set the key assigned to control shapes. 00128 virtual void setKey(const Display::KeySym& newKey); 00129 00130 // Create a shape, based on the information contained in the record. 00131 // This function does not require the center to be specified, as once 00132 // createShape is called, the user can "drag" out the shape required. 00133 // If createShape is called, and the shape is no longer required, 00134 // the function 'cancelShapes' can be used to reset the state of the 00135 // annotator. 00136 virtual void createShape(Record& settings); 00137 00138 // Disable event handling (with the exception of refresh calls). This stops 00139 // the user from moving shapes etc via the mouse motion / position event 00140 // handlers. These do not recognize nested calls (e.g. two disables, 00141 // followed by an enable will enable the handlers). 00142 // <group> 00143 virtual void enable(); 00144 virtual void disable(); 00145 // </group> 00146 00147 // Cancels creation of any pending shapes, unselects all shapes and 00148 // turns off drawing of all handles. 00149 virtual void cancelShapes(); 00150 00151 // Delete the shape at the specified point in the collection of shapes 00152 // The current (selected) shape can be determined by using the 00153 // activeShape() function. 00154 virtual Bool deleteShape(const uInt& toDel); 00155 00156 // These allow shapes to be "locked" together. Adding a locked shape 00157 // to the current shape means that whenever the current shape 00158 // moves, so too will the specified shape. removeLockedFromCurrent 00159 // can be used to remove this effect. 00160 // <group> 00161 virtual void removeLockedFromCurrent(const uInt& removeMe); 00162 virtual void addLockedToCurrent(const uInt& addMe); 00163 // </group> 00164 00165 // Return the currently selected shapes' index 00166 virtual Int activeShape(); 00167 00168 // Return a brief summary of all current shapes 00169 virtual Record shapesSummary(); 00170 00171 // Set the options for the specified shape. The user selected shape 00172 // can be determined by call the 'activeShape' method. To see a list of 00173 // available options for different types of shapes / objects, see their 00174 // individual documentation. 00175 virtual void setShapeOptions(const uInt& whichShape, 00176 const Record& newOptions); 00177 00178 // Returns a record containing the options for the specified shape. 00179 // The user selected shape can be determined by calling the 'activeShape' 00180 // method. To see a list of the options returned by shapes / objects, 00181 // see their individual documentation. 00182 virtual Record getShapeOptions(const uInt& whichShape); 00183 00184 // Returns a record which contains a sub record (containing options) for 00185 // each shape. e.g. To obtain options for the first shape: 00186 // <srcblock> 00187 // Record all = myAnnotator.getAllOptions(); 00188 // Record shape = all.subRecord(0); 00189 // </srcblock> 00190 virtual Record getAllOptions(); 00191 00192 // Deletes all existing shapes, and rebuilds new shapes based on records 00193 // in sub records of the supplied record. A record returned from 00194 // getAllOptions() can therefore be used to copy a set of shapes. 00195 virtual void setAllOptions(const Record& newSettings); 00196 00197 // Called when a refresh is required. It copies back to front buffer, 00198 // then causes a refresh with reason = backCopiedToFront. 00199 virtual void update(PixelCanvas* pc); 00200 00201 // Overwrite this to fire glish events. 00202 virtual void annotEvent(const String& /*event*/) {}; 00203 00204 // Functions for changing the co-ords system of a shape 00205 // <group> 00206 virtual Bool revertToPix(const Int& whichOne); 00207 virtual Bool revertToFrac(const Int& whichOne); 00208 virtual Bool lockToWC(const Int& whichOne); 00209 // </group> 00210 00211 // Returns a list of shapes annotations knows about 00212 virtual Record availableShapes(); 00213 00214 00215 protected: 00216 00217 private: 00218 00219 // My private variables... 00220 00221 // The PanelDisplay I was given on construction and some stuff I got out 00222 // of it 00223 // <group> 00224 PanelDisplay* itsPanelDisplay; 00225 PixelCanvas* itsPC; 00226 // </group> 00227 00228 // My copy of the list of Worldcanvases. I can check this against 00229 // itsPanelDisplay to see if anything has changed. 00230 ListIter<WorldCanvas* >* itsWCLI; 00231 List<WorldCanvas* > itsWCs; 00232 00233 // List of shapes 00234 PtrBlock<DisplayShape*> itsShapes; 00235 00236 // Some overall settings 00237 // <group> 00238 Display::KeySym itsKey; 00239 Bool itsUseEH; 00240 // </group> 00241 00242 // Stuff to remember my current state: 00243 // <group> 00244 Annotations::State itsState; 00245 Annotations::CreationType itsCreation; 00246 Bool itsShapeMoved; 00247 Int itsActiveShape; 00248 Int itsActiveHandle; 00249 uInt itsX, itsY; 00250 Bool itsEnabled; 00251 Bool itsRefreshedYet; 00252 // </group> 00253 // 00254 00255 00256 // Internal functions 00257 // <group> 00258 Bool changeCoordSys(const Int shapeIndex, const String& type, 00259 const String& currentCoords, const String& toCoords); 00260 00261 DisplayShape* constructShape(const Record& settings); 00262 void handleKeyUp(); 00263 void handleCreation(const PCPositionEvent& ev); 00264 void handleNormalCreation(const Vector<Float>& createPix); 00265 void handleMarkerCreation(const Vector<Float>& createPix); 00266 void handlePolyLineCreation(const Vector<Float>& createPix); 00267 void handlePolygonCreation(const Vector<Float>& createPix); 00268 void handleArrowCreation(const Vector<Float>& createPix); 00269 void select(const Int i); 00270 Bool determineState(const PCPositionEvent& ev); 00271 void registerToWCs(); 00272 Bool validateWCs(); 00273 void changedWC(); 00274 Bool validShape(const Record& shape); 00275 void polyLineToPolygon(const Int whichShape); 00276 // </group> 00277 }; 00278 00279 // Ostream, mainly for debugging the state of the annotator. 00280 ostream& operator << (ostream& os, Annotations::State st); 00281 00282 00283 } //# NAMESPACE CASA - END 00284 00285 #endif