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<double></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 std::string errorMessage( ) const { return ""; } 00279 00280 // Different types for options. 00281 enum OptionType { 00282 STRING, STRINGCHOICE, STRINGARRAY, STRINGCHOICEARRAY, DOUBLE, BOOL 00283 }; 00284 00285 // Different line styles. NOTE: styles other than solid and dashed are 00286 // ONLY supported by QtPixelCanvas. Custom line styles are used for 00287 // custom dash lists. 00288 enum LineStyle { 00289 SOLID, DASHED, DOTTED 00290 }; 00291 00292 // Returns all available line styles. 00293 static vector<LineStyle> allLineStyles() { 00294 static vector<LineStyle> v(3); 00295 v[0] = SOLID; 00296 v[1] = DASHED; 00297 v[2] = DOTTED; 00298 return v; 00299 } 00300 00301 // Convert between line style enum and String. 00302 // <group> 00303 static String convLineStyle(LineStyle style); 00304 static LineStyle convLineStyle(String style); 00305 // </group> 00306 00307 // Defaults. 00308 // <group> 00309 static const String DEFAULT_COLOR; 00310 static const double DEFAULT_WIDTH; 00311 static const LineStyle DEFAULT_STYLE; 00312 // <group> 00313 00314 00315 // Non-Static Members // 00316 00317 // World Constructor. Note: implementing subclasses MUST supply values 00318 // for m_xMin, m_xMax, m_yMin, and m_yMax, or override xMin(), xMax(), 00319 // yMin(), and yMax(). 00320 RegionShape(MDirection::Types worldSys); 00321 00322 // Pixel Constructor. Note: implementing subclasses MUST supply values 00323 // for m_xMin, m_xMax, m_yMin, and m_yMax, or override xMin(), xMax(), 00324 // yMin(), and yMax(). 00325 RegionShape(); 00326 00327 // Record Constructor. 00328 RegionShape(const RecordInterface& properties); 00329 00330 // Destructor 00331 virtual ~RegionShape(); 00332 00333 00334 // PassiveCachingDD methods // 00335 00336 // Implements PassiveCachingDD::dataUnit. 00337 const Unit dataUnit() const; 00338 const IPosition dataShape() const { 00339 return IPosition( ); 00340 } 00341 uInt dataDim() const { 00342 return 0; 00343 } 00344 std::vector<int> displayAxes( ) const { 00345 return std::vector<int>( ); 00346 } 00347 00348 // Implements PassiveCachingDD::classType. 00349 Display::DisplayDataType classType(); 00350 00351 // Implements PassiveCachingDD::newDisplayMethod. 00352 CachingDisplayMethod* newDisplayMethod(WorldCanvas* wc, 00353 AttributeBuffer* wchAttr, AttributeBuffer* ddAttr, 00354 CachingDisplayData* dd); 00355 00356 00357 // Common RegionShape methods // 00358 00359 // Gets/sets this shape's line color. 00360 // <group> 00361 virtual String lineColor() const; 00362 virtual void setLineColor(const String& newColor, bool alsoSetLabel= true); 00363 // </group> 00364 00365 // Gets/sets this shape's line width. 00366 // <group> 00367 virtual double lineWidth() const; 00368 virtual void setLineWidth(double width); 00369 // </group> 00370 00371 // Gets/sets this shape's line style. See RegionShape::LineStyle. 00372 // <group> 00373 virtual LineStyle lineStyle() const; 00374 virtual void setLineStyle(LineStyle style); 00375 // </group> 00376 00377 // Gets/sets this shape's label's text. 00378 // <group> 00379 virtual String text() const; 00380 virtual void setText(const String& text); 00381 // </group> 00382 00383 // Gets/sets this shape's label. 00384 // <group> 00385 virtual const RegionShapeLabel& label() const; 00386 virtual void setLabel(const RegionShapeLabel& label); 00387 // </group> 00388 00389 // Gets/sets this shape's linethrough properties. 00390 // <group> 00391 virtual bool linethrough() const; 00392 virtual String linethroughColor() const; 00393 virtual double linethroughWidth() const; 00394 virtual LineStyle linethroughStyle() const; 00395 virtual void setLinethrough(bool linethrough, String color = "red", 00396 double width = 1, LineStyle style = SOLID); 00397 // </group> 00398 00399 // Min/max methods for world/pixel coordinates. Note that some shapes 00400 // (RSMarker, RSText) may have identical mins/maxes since they only 00401 // take up space in screen pixels. 00402 // <group> 00403 virtual double xMin() const; 00404 virtual double xMax() const; 00405 virtual double yMin() const; 00406 virtual double yMax() const; 00407 // </group> 00408 00409 // Bounding box methods. Returns the min and max of the screen 00410 // coordinates. Note: these are only valid after a call to 00411 // drawAndUpdateBoundingBox! 00412 // <group> 00413 virtual double screenXMin() const; 00414 virtual double screenXMax() const; 00415 virtual double screenYMin() const; 00416 virtual double screenYMax() const; 00417 // </group> 00418 00419 // Returns whether this shape's coordinates are in world or pixel. 00420 virtual bool isWorld() const { 00421 return m_isWorld; 00422 } 00423 00424 // If this shape is in world coordinates, returns the system used. 00425 // Undefined for pixel coordinates. 00426 virtual MDirection::Types worldSystem() const { 00427 return m_worldSystem; 00428 } 00429 00430 // Set world or pixel system. 00431 virtual void setIsWorld(bool isWorld) { 00432 m_isWorld = isWorld; 00433 } 00434 00435 // Set world system. 00436 virtual void setWorldSystem(MDirection::Types sys) { 00437 m_worldSystem = sys; 00438 } 00439 00440 // Returns this shape's type (color + type). 00441 virtual String title() const { 00442 return lineColor() + " " + type(); 00443 } 00444 00445 // Checks whether the given WorldCanvasHolder has a direction coordinate. 00446 // Updates the last WorldCanvasHolder seen to the given, then calls 00447 // drawAndUpdateBoundingBox which actually draws this shape onto the 00448 // world canvas. 00449 bool draw(WorldCanvasHolder& wch); 00450 00451 // Returns whether there was an error during the last call to draw() or 00452 // not. 00453 virtual bool hadDrawingError() const { 00454 return m_hadDrawingError; 00455 } 00456 00457 // Returns the error that occurred during the last call to draw(). 00458 const String& lastDrawingError() const { 00459 return m_drawingError; 00460 } 00461 00462 // Returns this shape's properties as a Record. 00463 Record getProperties() const; 00464 00465 // Synonym. 00466 Record toRecord() const { 00467 return getProperties(); 00468 } 00469 00470 // Sets this shape's properties from the given Record. 00471 void setProperties(const RecordInterface& properties); 00472 00473 00474 // Pure Virtual Methods // 00475 00476 // Draw this shape on the given world canvas and update the bounding box 00477 // protected variables m_screenXMin, m_screenXMax, m_screenYMin, 00478 // and m_screenYMax. NOTE: implementing classes should be sure to set the 00479 // line style of the pixel canvas back to Display::LSSolid when finished. 00480 // The protected method resetLineStyle can be used for this purpose. 00481 virtual bool drawAndUpdateBoundingBox(WorldCanvasHolder& wch, 00482 String* error = NULL) = 0; 00483 00484 // Returns the name/type of this shape, for displaying to the user. 00485 virtual String type() const = 0; 00486 // Pure virtual function from DisplayData... 00487 String dataType() const { 00488 return type( ); 00489 } 00490 00491 00492 // Can be overridden by children. Returns a one-word type. 00493 virtual String oneWordType() const { 00494 return type(); 00495 } 00496 00497 // Returns the current values for the coordinate parameters. The 00498 // number and order depend on the shape type. For world systems 00499 // (RegionShape::isWorld()), these coordinates have unit RegionShape::UNIT 00500 // in the system RegionShape::worldSystem(). 00501 virtual vector<double> coordParameterValues() const = 0; 00502 00503 // Returns the current values for the coordinate parameters in the given 00504 // world system, by using the last WorldCanvasHolder for conversions if 00505 // needed. The number and order depend on the shape type. toSystem 00506 // indivates which system the given values are in and should either be: 00507 // 1) RSUtils::PIXEL for pixel coordinates, or 00508 // 2) a value that can be converted to a MDirection::Types via 00509 // MDirection::getType(). 00510 // Returned coordinates have unit RegionShape::UNIT for world systems. 00511 virtual vector<double> coordParameterValues(String toSystem) const = 0; 00512 00513 // Returns the name for the coordinate parameters, in the same order 00514 // as coordParameterValues(). 00515 virtual vector<String> coordParameterNames() const = 0; 00516 00517 // Returns a vector indicating the types of the coordinate parameters, 00518 // in the same order as coordParameterValues(). 00519 virtual vector<CoordinateParameterType> coordParameterTypes() const = 0; 00520 00521 // Sets the coordinate parameter values to the given, in the same order 00522 // as coordParameterValues(). For world systems (RegionShape::isWorld()), 00523 // the values must be in unit RegionShape::UNIT and system 00524 // RegionShape::worldSystem(). 00525 virtual void setCoordParameters(const vector<double>& vals) = 0; 00526 00527 // Sets the coordinate parameter values to the given, in the same order 00528 // as coordParameterValues(). valSystem indicates which system the given 00529 // values are in and should either be: 00530 // 1) RSUtils::PIXEL for pixel coordinates, or 00531 // 2) a value that can be converted to a MDirection::Types via 00532 // MDirection::getType(). 00533 // Values must be in unit RegionShape::UNIT for world systems. 00534 virtual void setCoordParameters(const vector<double>& vals, 00535 String valSystem) = 0; 00536 00537 // Moves this shape the given delta x and delta y in the given system 00538 // (empty for shape's native system). 00539 virtual void move(double dx, double dy, String system = "") = 0; 00540 00541 // Returns a RSHandle (four points in screen coords that are like a 00542 // bounding box for the shape) for this shape. If the shape has not 00543 // previously been drawn on a canvas, this may return an invalid RSHandle. 00544 // The handle does NOT include the label. 00545 virtual RSHandle getHandle() const = 0; 00546 00547 // Returns the names for options. 00548 virtual vector<String> optionNames() const = 0; 00549 00550 // Returns the types for options. 00551 virtual vector<OptionType> optionTypes() const = 0; 00552 00553 // For options that are string choices, return the available choices. 00554 // May return an empty vector if there are no string choices. 00555 virtual vector<vector<String> > optionChoices() const { 00556 return vector<vector<String> >(); 00557 } 00558 00559 // Returns the current values for options. 00560 virtual vector<RSOption> optionValues() const = 0; 00561 00562 // Sets the options to the given. 00563 virtual void setOptionValues(const vector<RSOption>& options) = 0; 00564 00565 protected: 00566 // Common RegionShape Members // 00567 00568 // Whether this shape uses world or pixel coordinates. 00569 bool m_isWorld; 00570 00571 // World system (undefined if m_isWorld is false). 00572 MDirection::Types m_worldSystem; 00573 00574 // Line color. 00575 String m_color; 00576 00577 // Line width. 00578 double m_width; 00579 00580 // Line style. 00581 LineStyle m_style; 00582 00583 // Label. 00584 RegionShapeLabel m_label; 00585 00586 // Linethrough properties. 00587 // <group> 00588 bool m_lt; 00589 String m_ltColor; 00590 double m_ltWidth; 00591 LineStyle m_ltStyle; 00592 // </group> 00593 00594 // Bounding box, in world/pixel coords. 00595 double m_xMin, m_xMax, m_yMin, m_yMax; 00596 00597 // Bounding box, in screen pixels. 00598 double m_screenXMin, m_screenXMax, m_screenYMin, m_screenYMax; 00599 00600 // Last seen WorldCanvasHolder. Should only be used by 00601 // coordParameterValues. 00602 WorldCanvasHolder* m_lastWCH; 00603 00604 // For keeping track of drawing/conversion errors. 00605 // <group> 00606 bool m_hadDrawingError; 00607 String m_drawingError; 00608 // </group> 00609 00610 00611 // Pure Virtual Methods // 00612 00613 // Puts shape-specific properties in the given record. MUST at least set 00614 // PROP_TYPE. 00615 virtual void getShapeSpecificProperties(Record& properties) const = 0; 00616 00617 // Sets shape-specific properties from the given record. 00618 virtual void setShapeSpecificProperties(const RecordInterface& props) = 0; 00619 00620 00621 // Common RegionShape Methods // 00622 00623 // Sets the line properties (color, width, style) of this shape for the 00624 // given PixelCanvas. 00625 void setLineProperties(PixelCanvas* pc); 00626 00627 // Sets the linethrough properties (color, width, style) of this shape for 00628 // the given PixelCanvas. 00629 void setLinethroughProperties(PixelCanvas* pc); 00630 00631 // Used for resetting the line style on the given PixelCanvas back to 00632 // solid, in case future uses are expecting solid lines. 00633 void resetLineStyle(PixelCanvas* pc) const; 00634 00635 // Convenience access to RSUtils conversion methods. 00636 // <group> 00637 bool worldToPixel(const Quantum<Vector<double> >& worldX, 00638 const Quantum<Vector<double> >& worldY, 00639 Vector<double>& pixelX, Vector<double>& pixelY, 00640 WorldCanvasHolder& wch, bool wrap = true, 00641 String* error = NULL) const { 00642 return RSUtils::worldToPixel(worldX, worldY, pixelX, pixelY, wch, 00643 m_worldSystem, wrap, error); 00644 } 00645 00646 bool pixelToWorld(const Vector<double>& pixelX, 00647 const Vector<double>& pixelY, 00648 Quantum<Vector<double> >& worldX, 00649 Quantum<Vector<double> >& worldY, WorldCanvasHolder& wch, 00650 bool wrap = true, String* error = NULL) const { 00651 return RSUtils::pixelToWorld(pixelX, pixelY, worldX, worldY, wch, 00652 m_worldSystem, wrap, error); 00653 } 00654 00655 bool worldToLinear(const Quantum<Vector<double> >& worldX, 00656 const Quantum<Vector<double> >& worldY, 00657 Vector<double>& linearX, Vector<double>& linearY, 00658 WorldCanvasHolder& wch, bool wrap = true, 00659 String* error = NULL) const { 00660 return RSUtils::worldToLinear(worldX, worldY, linearX, linearY, wch, 00661 m_worldSystem, wrap, error); 00662 } 00663 00664 bool worldToScreen(const Quantum<Vector<double> >& worldX, 00665 const Quantum<Vector<double> >& worldY, 00666 Vector<double>& screenX, Vector<double>& screenY, 00667 WorldCanvasHolder& wch, bool wrap = true, 00668 String* error = NULL) const { 00669 Vector<double> linX(worldX.getValue().size()), 00670 linY(worldY.getValue().size()); 00671 return RSUtils::worldToLinear(worldX, worldY, linX, linY, wch, 00672 m_worldSystem, wrap, error) && 00673 RSUtils::linearToScreen(linX, linY, screenX, screenY,wch,error); 00674 } 00675 00676 bool linearToWorld(const Vector<double>& linearX, 00677 const Vector<double>& linearY, 00678 Quantum<Vector<double> >& worldX, 00679 Quantum<Vector<double> >& worldY, 00680 WorldCanvasHolder& wch, String* error = NULL) const { 00681 return RSUtils::linearToWorld(linearX, linearY, worldX, worldY, wch, 00682 m_worldSystem, vector<int>(), 00683 vector<int>(), false, error); 00684 } 00685 00686 bool linearToWorld(const Vector<double>& linearX, 00687 const Vector<double>& linearY, 00688 Quantum<Vector<double> >& worldX, 00689 Quantum<Vector<double> >& worldY, 00690 WorldCanvasHolder& wch, const vector<int>& xSign, 00691 const vector<int>& ySign, String* error = NULL) const { 00692 return RSUtils::linearToWorld(linearX, linearY, worldX, worldY, wch, 00693 m_worldSystem, xSign, ySign, true, error); 00694 } 00695 00696 bool screenToWorld(const Vector<double>& screenX, 00697 const Vector<double>& screenY, 00698 Quantum<Vector<double> >& worldX, 00699 Quantum<Vector<double> >& worldY, 00700 WorldCanvasHolder& wch, String* error = NULL) const { 00701 Vector<double> linX(screenX.size()), linY(screenY.size()); 00702 return RSUtils::screenToLinear(screenX, screenY, linX,linY,wch,error)&& 00703 RSUtils::linearToWorld(linX, linY, worldX, worldY, wch, 00704 m_worldSystem, vector<int>(), 00705 vector<int>(), false, error); 00706 } 00707 00708 bool screenToWorld(const Vector<double>& screenX, 00709 const Vector<double>& screenY, 00710 Quantum<Vector<double> >& worldX, 00711 Quantum<Vector<double> >& worldY, 00712 WorldCanvasHolder& wch, const vector<int>& xSign, 00713 const vector<int>& ySign, String* error = NULL) const { 00714 Vector<double> linX(screenX.size()), linY(screenY.size()); 00715 return RSUtils::screenToLinear(screenX, screenY, linX,linY,wch,error)&& 00716 RSUtils::linearToWorld(linX, linY, worldX, worldY, wch, 00717 m_worldSystem, xSign, ySign, true,error); 00718 } 00719 // </group> 00720 00721 private: 00722 // Sets default values where needed for all member variables, EXCEPT 00723 // m_isWorld and m_worldSystem. Intended to be called from a constructor. 00724 void initDefaults(); 00725 }; 00726 00727 00728 // Implementation of CachingDisplayMethod to be used by RegionShapes. 00729 // Basically just a call to the shape's draw method. 00730 class RegionShapeDM : public CachingDisplayMethod { 00731 public: 00732 // Constructor that takes the RegionShape to draw, as well as the other 00733 // parameters for the CachingDisplayMethod constructor. 00734 RegionShapeDM(RegionShape& shape, WorldCanvas* wc, AttributeBuffer* wcAttr, 00735 AttributeBuffer* ddAttr, CachingDisplayData* dd); 00736 00737 // Destructor. 00738 ~RegionShapeDM(); 00739 00740 // Implementation of CachingDisplayMethod::drawIntoList. 00741 Bool drawIntoList(Display::RefreshReason reason, WorldCanvasHolder& wch); 00742 00743 private: 00744 RegionShape& m_shape; // Parent shape. 00745 }; 00746 00747 } 00748 00749 #endif /* REGIONSHAPE_H_ */