casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Annotations.h
Go to the documentation of this file.
1 //# Annotations.h : Control class for DisplayShape
2 //# Copyright (C) 1998,1999,2000,2001,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id:
27 
28 #ifndef TRIALDISPLAY_ANNOTATIONS_H
29 #define TRIALDISPLAY_ANNOTATIONS_H
30 
31 #include <casa/aips.h>
32 
37 #include <casa/OS/Timer.h>
38 
40 #include <list>
41 
42 #include <casa/Containers/Record.h>
43 #include <casa/Arrays/Matrix.h>
44 #include <casa/Arrays/Vector.h>
45 
46 namespace casa { //# NAMESPACE CASA - BEGIN
47 
48  class DisplayShape;
49  class PanelDisplay;
50 
51 
52 // <summary>
53 // Control class for a collection of DisplayShapeInterfaces.
54 // </summary>
55 //
56 // <prerequisite>
57 // <li> <linkto class="DisplayShapeInterface">DisplayShapeInterface</linkto>
58 // </prerequisite>
59 //
60 // <etymology>
61 // Annotations is a method by which a collection of shapes can be managed
62 // on a pixel canvas.
63 // </etymology>
64 //
65 // <synopsis>
66 // Annotations registers itself as an event handler on whichever pixelcanvas
67 // it is supplied. It can then add, delete or modify shapes based on function
68 // calls and user mouse input.
69 //
70 // The class is essentially a casacore::PtrBlock of DisplayShapeInterfaces, with
71 // pixelcanvas event handling to control them.
72 // </synopsis>
73 //
74 // <motivation>
75 // To allow a collection of shapes to be displayed and cotrolled by one class.
76 // </motivation>
77 //
78 // <example>
79 // <srcblock>
80 // </srcblock>
81 // </example>
82 
83 
84  class Annotations : public PCPositionEH,
85  public PCMotionEH,
86  public PCRefreshEH,
87  public WCRefreshEH {
88 
89  public:
90  // Used to determine the state of the class. The state may change due
91  // to mouse events, or function calls.
94  };
95 
96  // This is used to handle the creation of shapes by mouse events. Some
97  // types of shapes require special treatment when constructed with
98  // the mouse.
100 
101  // Destructor, and constructor, taking the panelDisplay to which the
102  // Annotator will attach itself to, and which mouse button to listen to.
103  // <group>
104  Annotations(PanelDisplay* panDisp,
106  const casacore::Bool useEH = true);
107  virtual ~Annotations();
108  // </group>
109 
110  // The event handlers.
111  // <group>
112  virtual void operator()(const PCPositionEvent& ev);
113  virtual void operator()(const PCMotionEvent& ev);
114  virtual void operator()(const PCRefreshEvent& ev);
115  virtual void operator()(const WCRefreshEvent& ev);
116  // </group>
117 
118  // Redraw all the shapes. Turns all handles off if noHandles is true
119  virtual void draw(PixelCanvas* pc, const casacore::Bool noHandles = false);
120 
121  // Instantly creates a shape on screen, and hence requires
122  // certain information in its record such as the center of the
123  // new object on screen. Refresh == false can be used to surpress a
124  // refresh.
125  virtual void newShape(casacore::Record& settings, const casacore::Bool& refresh = true);
126 
127  // Set the key assigned to control shapes.
128  virtual void setKey(const Display::KeySym& newKey);
129 
130  // Create a shape, based on the information contained in the record.
131  // This function does not require the center to be specified, as once
132  // createShape is called, the user can "drag" out the shape required.
133  // If createShape is called, and the shape is no longer required,
134  // the function 'cancelShapes' can be used to reset the state of the
135  // annotator.
136  virtual void createShape(casacore::Record& settings);
137 
138  // Disable event handling (with the exception of refresh calls). This stops
139  // the user from moving shapes etc via the mouse motion / position event
140  // handlers. These do not recognize nested calls (e.g. two disables,
141  // followed by an enable will enable the handlers).
142  // <group>
143  virtual void enable();
144  virtual void disable();
145  // </group>
146 
147  // Cancels creation of any pending shapes, unselects all shapes and
148  // turns off drawing of all handles.
149  virtual void cancelShapes();
150 
151  // Delete the shape at the specified point in the collection of shapes
152  // The current (selected) shape can be determined by using the
153  // activeShape() function.
154  virtual casacore::Bool deleteShape(const casacore::uInt& toDel);
155 
156  // These allow shapes to be "locked" together. Adding a locked shape
157  // to the current shape means that whenever the current shape
158  // moves, so too will the specified shape. removeLockedFromCurrent
159  // can be used to remove this effect.
160  // <group>
161  virtual void removeLockedFromCurrent(const casacore::uInt& removeMe);
162  virtual void addLockedToCurrent(const casacore::uInt& addMe);
163  // </group>
164 
165  // Return the currently selected shapes' index
166  virtual casacore::Int activeShape();
167 
168  // Return a brief summary of all current shapes
170 
171  // Set the options for the specified shape. The user selected shape
172  // can be determined by call the 'activeShape' method. To see a list of
173  // available options for different types of shapes / objects, see their
174  // individual documentation.
175  virtual void setShapeOptions(const casacore::uInt& whichShape,
176  const casacore::Record& newOptions);
177 
178  // Returns a record containing the options for the specified shape.
179  // The user selected shape can be determined by calling the 'activeShape'
180  // method. To see a list of the options returned by shapes / objects,
181  // see their individual documentation.
182  virtual casacore::Record getShapeOptions(const casacore::uInt& whichShape);
183 
184  // Returns a record which contains a sub record (containing options) for
185  // each shape. e.g. To obtain options for the first shape:
186  // <srcblock>
187  // casacore::Record all = myAnnotator.getAllOptions();
188  // casacore::Record shape = all.subRecord(0);
189  // </srcblock>
191 
192  // Deletes all existing shapes, and rebuilds new shapes based on records
193  // in sub records of the supplied record. A record returned from
194  // getAllOptions() can therefore be used to copy a set of shapes.
195  virtual void setAllOptions(const casacore::Record& newSettings);
196 
197  // Called when a refresh is required. It copies back to front buffer,
198  // then causes a refresh with reason = backCopiedToFront.
199  virtual void update(PixelCanvas* pc);
200 
201  // Overwrite this to fire glish events.
202  virtual void annotEvent(const casacore::String& /*event*/) {};
203 
204  // Functions for changing the co-ords system of a shape
205  // <group>
206  virtual casacore::Bool revertToPix(const casacore::Int& whichOne);
207  virtual casacore::Bool revertToFrac(const casacore::Int& whichOne);
208  virtual casacore::Bool lockToWC(const casacore::Int& whichOne);
209  // </group>
210 
211  // Returns a list of shapes annotations knows about
213 
214 
215  protected:
216 
217  private:
218 
219  // My private variables...
220 
221  // The PanelDisplay I was given on construction and some stuff I got out
222  // of it
223  // <group>
226  // </group>
227 
228  // My copy of the list of Worldcanvases. I can check this against
229  // itsPanelDisplay to see if anything has changed.
230  std::list<WorldCanvas* > itsWCs;
231 
232  // casacore::List of shapes
234 
235  // Some overall settings
236  // <group>
239  // </group>
240 
241  // Stuff to remember my current state:
242  // <group>
251  // </group>
252  //
253 
254 
255  // Internal functions
256  // <group>
258  const casacore::String& currentCoords, const casacore::String& toCoords);
259 
260  DisplayShape* constructShape(const casacore::Record& settings);
261  void handleKeyUp();
262  void handleCreation(const PCPositionEvent& ev);
268  void select(const casacore::Int i);
270  void registerToWCs();
272  void changedWC();
274  void polyLineToPolygon(const casacore::Int whichShape);
275  // </group>
276  };
277 
278 // Ostream, mainly for debugging the state of the annotator.
279  std::ostream& operator << (std::ostream& os, Annotations::State st);
280 
281 
282 } //# NAMESPACE CASA - END
283 
284 #endif
virtual void cancelShapes()
Cancels creation of any pending shapes, unselects all shapes and turns off drawing of all handles...
void polyLineToPolygon(const casacore::Int whichShape)
int Int
Definition: aipstype.h:50
Annotations::CreationType itsCreation
Definition: Annotations.h:244
void select(const casacore::Int i)
Class which stores WorldCanvas refresh event information.
casacore::Int itsActiveShape
Definition: Annotations.h:246
WorldCanvas Event Handler for managing events.
Definition: PCRefreshEH.h:76
casacore::Bool itsRefreshedYet
Definition: Annotations.h:250
ostream & operator<<(ostream &os, const PageHeaderCache &cache)
void handleArrowCreation(const casacore::Vector< casacore::Float > &createPix)
virtual void update(PixelCanvas *pc)
Called when a refresh is required.
Annotations::State itsState
Stuff to remember my current state:
Definition: Annotations.h:243
virtual Type type()
Return the type enum.
Definition: ds9lex.h:71
casacore::Bool validateWCs()
virtual void operator()(const PCPositionEvent &ev)
The event handlers.
virtual casacore::Bool revertToPix(const casacore::Int &whichOne)
Functions for changing the co-ords system of a shape.
virtual void draw(PixelCanvas *pc, const casacore::Bool noHandles=false)
Redraw all the shapes.
casacore::Bool determineState(const PCPositionEvent &ev)
void handlePolyLineCreation(const casacore::Vector< casacore::Float > &createPix)
Class which stores PixelCanvas motion event information.
Definition: PCMotionEvent.h:82
void handleCreation(const PCPositionEvent &ev)
virtual ~Annotations()
virtual void newShape(casacore::Record &settings, const casacore::Bool &refresh=true)
Instantly creates a shape on screen, and hence requires certain information in its record such as the...
Control class for a collection of DisplayShapeInterfaces.
Definition: Annotations.h:84
Base class defining interface to pixel-based output devices.
Definition: PixelCanvas.h:161
casacore::uInt itsX
Definition: Annotations.h:248
Base class for handling WorldCanvas refresh events.
Definition: WCRefreshEH.h:95
virtual void annotEvent(const casacore::String &)
Overwrite this to fire glish events.
Definition: Annotations.h:202
Class which stores PixelCanvas refresh event information.
State
Used to determine the state of the class.
Definition: Annotations.h:92
virtual void enable()
Disable event handling (with the exception of refresh calls).
void handlePolygonCreation(const casacore::Vector< casacore::Float > &createPix)
casacore::Bool changeCoordSys(const casacore::Int shapeIndex, const casacore::String &type, const casacore::String &currentCoords, const casacore::String &toCoords)
Internal functions.
virtual casacore::Record getAllOptions()
Returns a record which contains a sub record (containing options) for each shape. ...
The abstract base class for all &quot;DisplayShapes&quot;.
Definition: DisplayShape.h:77
virtual void setKey(const Display::KeySym &newKey)
Set the key assigned to control shapes.
casacore::Bool itsEnabled
Definition: Annotations.h:249
void handleMarkerCreation(const casacore::Vector< casacore::Float > &createPix)
virtual casacore::Record availableShapes()
Returns a list of shapes annotations knows about.
DisplayShape * constructShape(const casacore::Record &settings)
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool itsUseEH
Definition: Annotations.h:238
CreationType
This is used to handle the creation of shapes by mouse events.
Definition: Annotations.h:99
PixelCanvas Event Handler for managing keyboard and mouse button events.
Definition: PCPositionEH.h:74
std::list< WorldCanvas * > itsWCs
My copy of the list of Worldcanvases.
Definition: Annotations.h:230
casacore::PtrBlock< DisplayShape * > itsShapes
casacore::List of shapes
Definition: Annotations.h:233
A drop-in replacement for Block&lt;T*&gt;.
Definition: WProjectFT.h:54
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
PanelDisplay * itsPanelDisplay
My private variables...
Definition: Annotations.h:224
casacore::uInt itsY
Definition: Annotations.h:248
virtual void disable()
virtual void removeLockedFromCurrent(const casacore::uInt &removeMe)
These allow shapes to be &quot;locked&quot; together.
virtual casacore::Record shapesSummary()
Return a brief summary of all current shapes.
casacore::Bool itsShapeMoved
Definition: Annotations.h:245
Annotations(PanelDisplay *panDisp, const Display::KeySym &keysym=Display::K_Pointer_Button1, const casacore::Bool useEH=true)
Destructor, and constructor, taking the panelDisplay to which the Annotator will attach itself to...
Class which stores PixelCanvas position event information.
virtual void setShapeOptions(const casacore::uInt &whichShape, const casacore::Record &newOptions)
Set the options for the specified shape.
A class which creates and manages &quot;panelled&quot; displays.
Definition: PanelDisplay.h:79
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual casacore::Int activeShape()
Return the currently selected shapes&#39; index.
virtual void createShape(casacore::Record &settings)
Create a shape, based on the information contained in the record.
virtual casacore::Record getShapeOptions(const casacore::uInt &whichShape)
Returns a record containing the options for the specified shape.
void handleNormalCreation(const casacore::Vector< casacore::Float > &createPix)
PixelCanvas Event Handler for managing pointer motion events.
Definition: PCMotionEH.h:72
casacore::Bool validShape(const casacore::Record &shape)
KeySym
Keysyms for PixelCanvas keyboard events.
Definition: DisplayEnums.h:412
Display::KeySym itsKey
Some overall settings.
Definition: Annotations.h:237
PixelCanvas * itsPC
Definition: Annotations.h:225
virtual void setAllOptions(const casacore::Record &newSettings)
Deletes all existing shapes, and rebuilds new shapes based on records in sub records of the supplied ...
unsigned int uInt
Definition: aipstype.h:51
virtual casacore::Bool revertToFrac(const casacore::Int &whichOne)
virtual void addLockedToCurrent(const casacore::uInt &addMe)
casacore::Int itsActiveHandle
Definition: Annotations.h:247
virtual casacore::Bool deleteShape(const casacore::uInt &toDel)
Delete the shape at the specified point in the collection of shapes The current (selected) shape can ...
virtual casacore::Bool lockToWC(const casacore::Int &whichOne)