casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionShape.h
Go to the documentation of this file.
00001 //# RegionShape.h: Parent RegionShape class and helpers.
00002 //# Copyright (C) 2008
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 #ifndef REGIONSHAPE_H_
00028 #define REGIONSHAPE_H_
00029 
00030 #include <display/RegionShapes/RSUtils.qo.h>
00031 
00032 #include <display/DisplayDatas/PassiveCachingDD.h>
00033 #include <display/DisplayDatas/CachingDisplayMethod.h>
00034 #include <display/Display/WorldCanvas.h>
00035 #include <casa/BasicSL/String.h>
00036 #include <casa/Containers/Record.h>
00037 
00038 #include <casa/namespace.h>
00039 
00040 namespace casa {
00041 
00042 class PixelCanvas;
00043 
00044 // Text label associated with a RegionShape.
00045 class RegionShapeLabel {
00046 public:
00047     // Static Members //
00048     
00049     // Defaults.
00050     // <group>
00051     static const String DEFAULT_FONT;
00052     static const int DEFAULT_POINTSIZE;
00053     // </group>
00054     
00055     
00056     // Constructor.
00057     RegionShapeLabel(String text = "");
00058 
00059     // Destructor.
00060     ~RegionShapeLabel();
00061 
00062 
00063     // Sets this label's text to the given.
00064     void setText(const String& text);
00065 
00066     // Sets this label's font family to the given.  How it is handled when 
00067     // being drawn depends on the underlying PixelCanvas implementation.
00068     void setFont(const String& font);
00069 
00070     // Sets the label's font point size to the given.
00071     void setSize(int size);
00072 
00073     // Sets the label's font color to the given.  Note: while there is no
00074     // formal specification for color format, Strings should be accepted in
00075     // common name format ("black") or hexadecimal format ("#000000").
00076     void setColor(const String& color);
00077 
00078     // Sets whether the label's font is italic or not.  Note: only
00079     // QtPixelCanvas currently supports bold.
00080     void setItalic(bool italic = true);
00081 
00082     // Sets whether the label's font is bold or not.  Note: only QtPixelCanvas
00083     // currently supports bold.
00084     void setBold(bool bold = true);
00085 
00086     // Sets the rotation angle to the given (in degrees).  This angle is in
00087     // pixel coordinates.  Rotation is counterclockwise.
00088     void setAngle(double angle);
00089 
00090 
00091     // Returns true if this label has empty text, false otherwise.
00092     bool isEmpty() const;
00093 
00094     // Returns the text for this label.
00095     const String& text() const;
00096 
00097     // Returns the font family for this label.
00098     const String& font() const;
00099 
00100     // Returns the point size for this label.
00101     int size() const;
00102 
00103     // Returns the color for this label.
00104     const String& color() const;
00105 
00106     // Returns true if this label's font is italic, false otherwise.
00107     bool isItalic() const;
00108 
00109     // Returns true if this label's font is bold, false otherwise.
00110     bool isBold() const;
00111 
00112     // Returns this label's angle.
00113     double angle() const;
00114 
00115     
00116     // Sets the font on the given PixelCanvas.  Note: bold/italic only
00117     // work for QtPixelCanvas.
00118     void setFont(PixelCanvas* pc) const;
00119     
00120     // Returns the result of pc->textWidth() after setting the font.
00121     int width(PixelCanvas* pc) const;
00122     
00123     // Returns the result of pc->textHeight() after setting the font.
00124     int height(PixelCanvas* pc) const;
00125     
00126     // Draws itself on the given pixel canvas and returns whether the operation
00127     // succeeded or not.  x and y are the screen pixel coordinates to draw the
00128     // label.  If bottom is false, the label is centered on (x, y); otherwise
00129     // the label is drawn with (x, y) at its bottom center point.
00130     bool draw(PixelCanvas* pc, int x, int y, bool bottom = false,
00131               String* error = NULL);
00132 
00133 private:
00134     String m_text;      // text
00135     String m_font;      // font family name
00136     int m_pointSize; // font point size
00137     String m_color;     // font color
00138     bool m_italic;      // is italic?
00139     bool m_bold;        // is bold?
00140     double m_angle;     // screen rotation angle
00141 };
00142 
00143 
00144 // Parent class for all RegionShapes.  Contains operations and properties
00145 // common to all RegionShapes, such as:
00146 // <ul><li>Line color, width</li>
00147 //     <li>Label (see RegionShapeLabel)</li>
00148 //     <li>Linethrough</li>
00149 //     <li>Minimum/maximum values, both world/pixel and screen</li>
00150 //     <li>World coordinate system (if applicable)</li>
00151 //     <li>Converting between different coordinate systems</li></ul>
00152 // Also contains methods that must be implemented in subclasses:
00153 // <ul><li>Type/name for display</li>
00154 //     <li>Getting/setting coordinates</li>
00155 //     <li>Getting/setting options</li>
00156 //     <li>Moving the shape</li>
00157 //     <li>Drawing on a world canvas</li></ul>
00158 // RegionShapes can also be converted to and from a CASA record.  Fields in
00159 // the record MUST adhere to the properties outlined below and in the shape
00160 // subclasses.  While additional properties may be defined in the shape
00161 // subclasses, properties at the RegionShape level are:
00162 // <ul><li><b>RegionShape::PROPISWORLD</b> (<i>bool</i>): whether the shape has
00163 //         a world system (true) or a pixel system (false).  Note: if true, the
00164 //         world system MUST be defined using the following property.
00165 //         <b>MUST ALWAYS BE DEFINED.</b></li>
00166 //     <li><b>RegionShape::PROPWORLDSYSTEM</b> (<i>String</i>): if the shape
00167 //         is in world coordinates, the world system.  MUST be able to be
00168 //         converted to an MDirection::Types via MDirection::getType().
00169 //         <b>MUST BE DEFINED FOR SHAPES WITH WORLD COORDINATES.</b></li>
00170 //     <li><b>RegionShape::PROPLINE_COLOR</b> (<i>String</i>): line color.
00171 //         <b>OPTIONAL.</b></li>
00172 //     <li><b>RegionShape::PROPLINE_WIDTH</b> (<i>double</i>): line width.
00173 //         <b>OPTIONAL.</b></li>
00174 //     <li><b>RegionShape::PROPLINE_STYLE</b> (<i>String</i>): String
00175 //         representation of line style.  NOTE: styles other than solid and
00176 //         dashed are only supported by QtPixelCanvas.  <b>OPTIONAL.</b></li>
00177 //     <li><b>RegionShape::PROPTEXT</b> (<i>String</i>): label text.
00178 //         <b>OPTIONAL.</b></li>
00179 //     <li><b>RegionShape::PROPTEXT_COLOR</b> (<i>String</i>): label color.
00180 //         <b>OPTIONAL.</b></li>
00181 //     <li><b>RegionShape::PROPTEXT_FONT</b> (<i>String</i>): label font.
00182 //         <b>OPTIONAL.</b></li>
00183 //     <li><b>RegionShape::PROPTEXT_SIZE</b> (<i>int</i>): label point size.
00184 //         <b>OPTIONAL.</b></li>
00185 //     <li><b>RegionShape::PROPTEXT_ITALIC</b> (<i>bool</i>): whether label
00186 //         font is italic.  <b>OPTIONAL.</b></li>
00187 //     <li><b>RegionShape::PROPTEXT_BOLD</b> (<i>bool</i>): whether label font
00188 //         is bold.  <b>OPTIONAL.</b></li>
00189 //     <li><b>RegionShape::PROPLINETHROUGH</b> (<i>bool</li>): whether the
00190 //         shape has a linethrough or not.  <b>OPTIONAL.</b></li>
00191 //     <li><b>RegionShape::PROPLINETHROUGH_COLOR</b> (<i>String</i>):
00192 //         linethrough color.  <b>OPTIONAL.</b></li>
00193 //     <li><b>RegionShape::PROPLINETHROUGH_WIDTH</b> (<i>double</i>):
00194 //         linethrough width.  <b>OPTIONAL.</b></li>
00195 //     <li><b>RegionShape::PROPLINETHROUGH_STYLE</b> (<i>String</i>): String
00196 //         representation of linethrough style.  NOTE: styles other than solid
00197 //         and dashed are only supported by QtPixelCanvas.
00198 //         <b>OPTIONAL.</b></li>
00199 //     <li><b>RegionShape::PROPCOORDINATES</b> (<i>Array&lt;double&gt;</i>):
00200 //         This property will be used to call setCoordParameters, and so is
00201 //         specific to the shape type.  <b>MUST BE DEFINED FOR SHAPE TYPES
00202 //         OTHER THAN RSPolygon AND RSComposite.</b></li>
00203 //     <li><b>RegionShape::PROPOPTIONS</b> (<i>Record</i>): the fields are set
00204 //         in the order defined by each shape type's option methods.  Each
00205 //         field's name should be unique (the specifics are irrelevant since it
00206 //         is the order that matters), and the value should be one of the types
00207 //         supported by RSOption.  <b>OPTIONAL.</b></li></ul>
00208 // RegionShape also defines a shapeFromRecord() method that will create and
00209 // return a new shape based on the given record.  This record has the
00210 // following additional properties:
00211 // <ul><li><b>RegionShape::PROPTYPE</b> (<i>String</i>): for defining which
00212 //         type of shape is defined by the record.  Acceptable choices:
00213 //         <ul><li>RegionShape::PROPTYPE_ELLIPSE</li>
00214 //             <li>RegionShape::PROPTYPE_CIRCLE</li>
00215 //             <li>RegionShape::PROPTYPE_RECTANGLE</li>
00216 //             <li>RegionShape::PROPTYPE_POLYGON</li>
00217 //             <li>RegionShape::PROPTYPE_LINE</li>
00218 //             <li>RegionShape::PROPTYPE_VECTOR</li>
00219 //             <li>RegionShape::PROPTYPE_MARKER</li>
00220 //             <li>RegionShape::PROPTYPE_TEXT</li>
00221 //             <li>RegionShape::PROPTYPE_COMPOSITE.</li></ul>
00222 //         <b>MUST ALWAYS BE DEFINED.</b></li></ul>
00223 class RegionShape : public PassiveCachingDD {
00224 public:
00225     // Static Members //
00226     
00227     // The unit that all native coordinates are in.  Currently set to "deg".
00228     // If this is changed, DS9RegionFileWriter::convertValue() must also be
00229     // updated.
00230     static const String UNIT;
00231     
00232     // Value used for wrapping negative/positive unit values.  Currently set
00233     // to 360 for degrees.
00234     static const double UNIT_WRAPAROUND;
00235     
00236     // Properties.  See RegionShape description.
00237     // <group>
00238     static const String PROPISWORLD;
00239     static const String PROPWORLDSYSTEM;
00240     static const String PROPLINE_COLOR;
00241     static const String PROPLINE_WIDTH;
00242     static const String PROPLINE_STYLE;
00243     static const String PROPTEXT;
00244     static const String PROPTEXT_COLOR;
00245     static const String PROPTEXT_FONT;
00246     static const String PROPTEXT_SIZE;
00247     static const String PROPTEXT_ITALIC;
00248     static const String PROPTEXT_BOLD;
00249     static const String PROPLINETHROUGH;
00250     static const String PROPLINETHROUGH_COLOR;
00251     static const String PROPLINETHROUGH_WIDTH;
00252     static const String PROPLINETHROUGH_STYLE;
00253     static const String PROPCOORDINATES;
00254     static const String PROPOPTIONS;
00255     
00256     static const String PROPTYPE;
00257     static const String PROPTYPE_ELLIPSE;
00258     static const String PROPTYPE_CIRCLE;
00259     static const String PROPTYPE_RECTANGLE;
00260     static const String PROPTYPE_POLYGON;
00261     static const String PROPTYPE_LINE;
00262     static const String PROPTYPE_VECTOR;
00263     static const String PROPTYPE_MARKER;
00264     static const String PROPTYPE_TEXT;
00265     static const String PROPTYPE_COMPOSITE;
00266     // </group>
00267     
00268     // Creates a record of the correct type from the given record (see
00269     // RegionShape class description), or NULL if a fatal error occurred.
00270     static RegionShape* shapeFromRecord(const RecordInterface& properties,
00271                                         String& error);
00272     
00273     // Different types for coordinate parameters.
00274     enum CoordinateParameterType {
00275         POSITION, SIZE, ANGLE, PIXEL
00276     };
00277     
00278     // Different types for options.
00279     enum OptionType {
00280         STRING, STRINGCHOICE, STRINGARRAY, STRINGCHOICEARRAY, DOUBLE, BOOL
00281     };
00282     
00283     // Different line styles.  NOTE: styles other than solid and dashed are
00284     // ONLY supported by QtPixelCanvas.  Custom line styles are used for
00285     // custom dash lists.
00286     enum LineStyle {
00287         SOLID, DASHED, DOTTED
00288     };
00289     
00290     // Returns all available line styles.
00291     static vector<LineStyle> allLineStyles() {
00292         static vector<LineStyle> v(3);
00293         v[0] = SOLID;  v[1] = DASHED;
00294         v[2] = DOTTED;
00295         return v;
00296     }
00297     
00298     // Convert between line style enum and String.
00299     // <group>
00300     static String convLineStyle(LineStyle style);
00301     static LineStyle convLineStyle(String style);
00302     // </group>
00303     
00304     // Defaults.
00305     // <group>
00306     static const String DEFAULT_COLOR;
00307     static const double DEFAULT_WIDTH;
00308     static const LineStyle DEFAULT_STYLE;
00309     // <group>
00310     
00311     
00312     // Non-Static Members //
00313     
00314     // World Constructor.  Note: implementing subclasses MUST supply values
00315     // for m_xMin, m_xMax, m_yMin, and m_yMax, or override xMin(), xMax(),
00316     // yMin(), and yMax().
00317     RegionShape(MDirection::Types worldSys);
00318     
00319     // Pixel Constructor.  Note: implementing subclasses MUST supply values
00320     // for m_xMin, m_xMax, m_yMin, and m_yMax, or override xMin(), xMax(),
00321     // yMin(), and yMax().
00322     RegionShape();
00323     
00324     // Record Constructor.
00325     RegionShape(const RecordInterface& properties);
00326 
00327     // Destructor
00328     virtual ~RegionShape();
00329 
00330     
00331     // PassiveCachingDD methods //
00332     
00333     // Implements PassiveCachingDD::dataUnit.
00334     const Unit dataUnit() const;
00335     const IPosition dataShape() const { return IPosition( ); }
00336     const uInt dataDim() const { return 0; }
00337     std::vector<int> displayAxes( ) const { return std::vector<int>( ); }
00338 
00339     // Implements PassiveCachingDD::classType.
00340     Display::DisplayDataType classType();
00341 
00342     // Implements PassiveCachingDD::newDisplayMethod.
00343     CachingDisplayMethod* newDisplayMethod(WorldCanvas* wc,
00344             AttributeBuffer* wchAttr, AttributeBuffer* ddAttr,
00345             CachingDisplayData* dd);
00346 
00347 
00348     // Common RegionShape methods //
00349     
00350     // Gets/sets this shape's line color.
00351     // <group>
00352     virtual String lineColor() const;
00353     virtual void setLineColor(const String& newColor, bool alsoSetLabel= true);
00354     // </group>
00355     
00356     // Gets/sets this shape's line width.
00357     // <group>
00358     virtual double lineWidth() const;
00359     virtual void setLineWidth(double width);
00360     // </group>
00361     
00362     // Gets/sets this shape's line style.  See RegionShape::LineStyle.
00363     // <group>
00364     virtual LineStyle lineStyle() const;
00365     virtual void setLineStyle(LineStyle style);
00366     // </group>
00367     
00368     // Gets/sets this shape's label's text.
00369     // <group>
00370     virtual String text() const;
00371     virtual void setText(const String& text);
00372     // </group>
00373     
00374     // Gets/sets this shape's label.
00375     // <group>
00376     virtual const RegionShapeLabel& label() const;
00377     virtual void setLabel(const RegionShapeLabel& label);
00378     // </group>
00379     
00380     // Gets/sets this shape's linethrough properties.
00381     // <group>
00382     virtual bool linethrough() const;
00383     virtual String linethroughColor() const;
00384     virtual double linethroughWidth() const;
00385     virtual LineStyle linethroughStyle() const;
00386     virtual void setLinethrough(bool linethrough, String color = "red",
00387                                 double width = 1, LineStyle style = SOLID);
00388     // </group>
00389     
00390     // Min/max methods for world/pixel coordinates.  Note that some shapes
00391     // (RSMarker, RSText) may have identical mins/maxes since they only
00392     // take up space in screen pixels.
00393     // <group>
00394     virtual double xMin() const;
00395     virtual double xMax() const;
00396     virtual double yMin() const;
00397     virtual double yMax() const;
00398     // </group>
00399     
00400     // Bounding box methods.  Returns the min and max of the screen
00401     // coordinates.  Note: these are only valid after a call to
00402     // drawAndUpdateBoundingBox!
00403     // <group>
00404     virtual double screenXMin() const;
00405     virtual double screenXMax() const;
00406     virtual double screenYMin() const;
00407     virtual double screenYMax() const;
00408     // </group>
00409     
00410     // Returns whether this shape's coordinates are in world or pixel.
00411     virtual bool isWorld() const { return m_isWorld; }
00412     
00413     // If this shape is in world coordinates, returns the system used.
00414     // Undefined for pixel coordinates.
00415     virtual MDirection::Types worldSystem() const { return m_worldSystem; }
00416     
00417     // Set world or pixel system.
00418     virtual void setIsWorld(bool isWorld) { m_isWorld = isWorld; }
00419     
00420     // Set world system.
00421     virtual void setWorldSystem(MDirection::Types sys) { m_worldSystem = sys; }
00422     
00423     // Returns this shape's type (color + type).
00424     virtual String title() const { return lineColor() + " " + type(); }
00425     
00426     // Checks whether the given WorldCanvasHolder has a direction coordinate.
00427     // Updates the last WorldCanvasHolder seen to the given, then calls
00428     // drawAndUpdateBoundingBox which actually draws this shape onto the
00429     // world canvas.
00430     bool draw(WorldCanvasHolder& wch);
00431     
00432     // Returns whether there was an error during the last call to draw() or
00433     // not.
00434     virtual bool hadDrawingError() const { return m_hadDrawingError; }
00435     
00436     // Returns the error that occurred during the last call to draw().
00437     const String& lastDrawingError() const { return m_drawingError; }
00438     
00439     // Returns this shape's properties as a Record.
00440     Record getProperties() const;
00441     
00442     // Synonym.
00443     Record toRecord() const { return getProperties(); }
00444     
00445     // Sets this shape's properties from the given Record.
00446     void setProperties(const RecordInterface& properties);
00447     
00448     
00449     // Pure Virtual Methods //
00450 
00451     // Draw this shape on the given world canvas and update the bounding box
00452     // protected variables m_screenXMin, m_screenXMax, m_screenYMin,
00453     // and m_screenYMax.  NOTE: implementing classes should be sure to set the
00454     // line style of the pixel canvas back to Display::LSSolid when finished.
00455     // The protected method resetLineStyle can be used for this purpose.
00456     virtual bool drawAndUpdateBoundingBox(WorldCanvasHolder& wch,
00457                                           String* error = NULL) = 0;
00458 
00459     // Returns the name/type of this shape, for displaying to the user.
00460     virtual String type() const = 0;
00461     // Pure virtual function from DisplayData...
00462     String dataType() const { return type( ); }
00463     
00464     
00465     // Can be overridden by children.  Returns a one-word type.
00466     virtual String oneWordType() const { return type(); }
00467 
00468     // Returns the current values for the coordinate parameters.  The
00469     // number and order depend on the shape type.  For world systems
00470     // (RegionShape::isWorld()), these coordinates have unit RegionShape::UNIT
00471     // in the system RegionShape::worldSystem().
00472     virtual vector<double> coordParameterValues() const = 0;
00473     
00474     // Returns the current values for the coordinate parameters in the given
00475     // world system, by using the last WorldCanvasHolder for conversions if
00476     // needed.  The number and order depend on the shape type.  toSystem
00477     // indivates which system the given values are in and should either be:
00478     // 1) RSUtils::PIXEL for pixel coordinates, or
00479     // 2) a value that can be converted to a MDirection::Types via
00480     //    MDirection::getType().
00481     // Returned coordinates have unit RegionShape::UNIT for world systems.
00482     virtual vector<double> coordParameterValues(String toSystem) const = 0;
00483     
00484     // Returns the name for the coordinate parameters, in the same order
00485     // as coordParameterValues().
00486     virtual vector<String> coordParameterNames() const = 0;
00487     
00488     // Returns a vector indicating the types of the coordinate parameters,
00489     // in the same order as coordParameterValues().
00490     virtual vector<CoordinateParameterType> coordParameterTypes() const = 0;
00491     
00492     // Sets the coordinate parameter values to the given, in the same order
00493     // as coordParameterValues().  For world systems (RegionShape::isWorld()),
00494     // the values must be in unit RegionShape::UNIT and system
00495     // RegionShape::worldSystem().
00496     virtual void setCoordParameters(const vector<double>& vals) = 0;
00497     
00498     // Sets the coordinate parameter values to the given, in the same order
00499     // as coordParameterValues().  valSystem indicates which system the given
00500     // values are in and should either be:
00501     // 1) RSUtils::PIXEL for pixel coordinates, or
00502     // 2) a value that can be converted to a MDirection::Types via
00503     //    MDirection::getType().
00504     // Values must be in unit RegionShape::UNIT for world systems.
00505     virtual void setCoordParameters(const vector<double>& vals,
00506                                     String valSystem) = 0;
00507     
00508     // Moves this shape the given delta x and delta y in the given system
00509     // (empty for shape's native system).
00510     virtual void move(double dx, double dy, String system = "") = 0;
00511     
00512     // Returns a RSHandle (four points in screen coords that are like a
00513     // bounding box for the shape) for this shape.  If the shape has not
00514     // previously been drawn on a canvas, this may return an invalid RSHandle.
00515     // The handle does NOT include the label.
00516     virtual RSHandle getHandle() const = 0;
00517     
00518     // Returns the names for options.
00519     virtual vector<String> optionNames() const = 0;
00520     
00521     // Returns the types for options.
00522     virtual vector<OptionType> optionTypes() const = 0;
00523     
00524     // For options that are string choices, return the available choices.
00525     // May return an empty vector if there are no string choices.
00526     virtual vector<vector<String> > optionChoices() const {
00527         return vector<vector<String> >();
00528     }
00529     
00530     // Returns the current values for options.
00531     virtual vector<RSOption> optionValues() const = 0;
00532     
00533     // Sets the options to the given.
00534     virtual void setOptionValues(const vector<RSOption>& options) = 0;
00535 
00536 protected:
00537     // Common RegionShape Members //
00538     
00539     // Whether this shape uses world or pixel coordinates.
00540     bool m_isWorld;
00541     
00542     // World system (undefined if m_isWorld is false).
00543     MDirection::Types m_worldSystem;
00544     
00545     // Line color.
00546     String m_color;
00547     
00548     // Line width.
00549     double m_width;
00550     
00551     // Line style.
00552     LineStyle m_style;
00553 
00554     // Label.
00555     RegionShapeLabel m_label;
00556 
00557     // Linethrough properties.
00558     // <group>
00559     bool m_lt;
00560     String m_ltColor;
00561     double m_ltWidth;
00562     LineStyle m_ltStyle;
00563     // </group>
00564     
00565     // Bounding box, in world/pixel coords.
00566     double m_xMin, m_xMax, m_yMin, m_yMax;
00567     
00568     // Bounding box, in screen pixels.
00569     double m_screenXMin, m_screenXMax, m_screenYMin, m_screenYMax;
00570     
00571     // Last seen WorldCanvasHolder.  Should only be used by
00572     // coordParameterValues.
00573     WorldCanvasHolder* m_lastWCH;
00574     
00575     // For keeping track of drawing/conversion errors.
00576     // <group>
00577     bool m_hadDrawingError;
00578     String m_drawingError;
00579     // </group>
00580     
00581     
00582     // Pure Virtual Methods //
00583     
00584     // Puts shape-specific properties in the given record.  MUST at least set
00585     // PROP_TYPE.
00586     virtual void getShapeSpecificProperties(Record& properties) const = 0;
00587     
00588     // Sets shape-specific properties from the given record.
00589     virtual void setShapeSpecificProperties(const RecordInterface& props) = 0;
00590     
00591     
00592     // Common RegionShape Methods //
00593     
00594     // Sets the line properties (color, width, style) of this shape for the
00595     // given PixelCanvas.
00596     void setLineProperties(PixelCanvas* pc);
00597     
00598     // Sets the linethrough properties (color, width, style) of this shape for
00599     // the given PixelCanvas.
00600     void setLinethroughProperties(PixelCanvas* pc);
00601     
00602     // Used for resetting the line style on the given PixelCanvas back to
00603     // solid, in case future uses are expecting solid lines.
00604     void resetLineStyle(PixelCanvas* pc) const;
00605     
00606     // Convenience access to RSUtils conversion methods.
00607     // <group>    
00608     bool worldToPixel(const Quantum<Vector<double> >& worldX,
00609                       const Quantum<Vector<double> >& worldY,
00610                       Vector<double>& pixelX, Vector<double>& pixelY,
00611                       WorldCanvasHolder& wch, bool wrap = true,
00612                       String* error = NULL) const {
00613         return RSUtils::worldToPixel(worldX, worldY, pixelX, pixelY, wch,
00614                                      m_worldSystem, wrap, error);
00615     }
00616     
00617     bool pixelToWorld(const Vector<double>& pixelX,
00618                       const Vector<double>& pixelY,
00619                       Quantum<Vector<double> >& worldX,
00620                       Quantum<Vector<double> >& worldY, WorldCanvasHolder& wch,
00621                       bool wrap = true, String* error = NULL) const {
00622         return RSUtils::pixelToWorld(pixelX, pixelY, worldX, worldY, wch,
00623                                      m_worldSystem, wrap, error);
00624     }
00625     
00626     bool worldToLinear(const Quantum<Vector<double> >& worldX,
00627                        const Quantum<Vector<double> >& worldY,
00628                        Vector<double>& linearX, Vector<double>& linearY,
00629                        WorldCanvasHolder& wch, bool wrap = true,
00630                        String* error = NULL) const {
00631         return RSUtils::worldToLinear(worldX, worldY, linearX, linearY, wch,
00632                                       m_worldSystem, wrap, error);
00633     }
00634     
00635     bool worldToScreen(const Quantum<Vector<double> >& worldX,
00636                        const Quantum<Vector<double> >& worldY,
00637                        Vector<double>& screenX, Vector<double>& screenY,
00638                        WorldCanvasHolder& wch, bool wrap = true,
00639                        String* error = NULL) const {
00640         Vector<double> linX(worldX.getValue().size()),
00641                        linY(worldY.getValue().size());
00642         return RSUtils::worldToLinear(worldX, worldY, linX, linY, wch,
00643                                       m_worldSystem, wrap, error) &&
00644                RSUtils::linearToScreen(linX, linY, screenX, screenY,wch,error);
00645     }
00646     
00647     bool linearToWorld(const Vector<double>& linearX,
00648                        const Vector<double>& linearY,
00649                        Quantum<Vector<double> >& worldX,
00650                        Quantum<Vector<double> >& worldY,
00651                        WorldCanvasHolder& wch, String* error = NULL) const {
00652         return RSUtils::linearToWorld(linearX, linearY, worldX, worldY, wch,
00653                                       m_worldSystem, vector<int>(),
00654                                       vector<int>(), false, error);
00655     }
00656     
00657     bool linearToWorld(const Vector<double>& linearX,
00658                        const Vector<double>& linearY,
00659                        Quantum<Vector<double> >& worldX,
00660                        Quantum<Vector<double> >& worldY,
00661                        WorldCanvasHolder& wch, const vector<int>& xSign,
00662                        const vector<int>& ySign, String* error = NULL) const {
00663         return RSUtils::linearToWorld(linearX, linearY, worldX, worldY, wch,
00664                                       m_worldSystem, xSign, ySign, true, error);
00665     }
00666     
00667     bool screenToWorld(const Vector<double>& screenX,
00668                        const Vector<double>& screenY,
00669                        Quantum<Vector<double> >& worldX,
00670                        Quantum<Vector<double> >& worldY,
00671                        WorldCanvasHolder& wch, String* error = NULL) const {
00672         Vector<double> linX(screenX.size()), linY(screenY.size());
00673         return RSUtils::screenToLinear(screenX, screenY, linX,linY,wch,error)&&
00674                RSUtils::linearToWorld(linX, linY, worldX, worldY, wch,
00675                                       m_worldSystem, vector<int>(),
00676                                       vector<int>(), false, error);
00677     }
00678     
00679     bool screenToWorld(const Vector<double>& screenX,
00680                        const Vector<double>& screenY,
00681                        Quantum<Vector<double> >& worldX,
00682                        Quantum<Vector<double> >& worldY,
00683                        WorldCanvasHolder& wch, const vector<int>& xSign,
00684                        const vector<int>& ySign, String* error = NULL) const {
00685         Vector<double> linX(screenX.size()), linY(screenY.size());
00686         return RSUtils::screenToLinear(screenX, screenY, linX,linY,wch,error)&&
00687                RSUtils::linearToWorld(linX, linY, worldX, worldY, wch,
00688                                       m_worldSystem, xSign, ySign, true,error);
00689     }
00690     // </group>
00691     
00692 private:
00693     // Sets default values where needed for all member variables, EXCEPT
00694     // m_isWorld and m_worldSystem.  Intended to be called from a constructor.
00695     void initDefaults();
00696 };
00697 
00698 
00699 // Implementation of CachingDisplayMethod to be used by RegionShapes.
00700 // Basically just a call to the shape's draw method.
00701 class RegionShapeDM : public CachingDisplayMethod {
00702 public:
00703     // Constructor that takes the RegionShape to draw, as well as the other
00704     // parameters for the CachingDisplayMethod constructor.
00705     RegionShapeDM(RegionShape& shape, WorldCanvas* wc, AttributeBuffer* wcAttr,
00706             AttributeBuffer* ddAttr, CachingDisplayData* dd);
00707 
00708     // Destructor.
00709     ~RegionShapeDM();
00710 
00711     // Implementation of CachingDisplayMethod::drawIntoList.
00712     Bool drawIntoList(Display::RefreshReason reason, WorldCanvasHolder& wch);
00713 
00714 private:
00715     RegionShape& m_shape; // Parent shape.
00716 };
00717 
00718 }
00719 
00720 #endif /* REGIONSHAPE_H_ */