grtool.h

Go to the documentation of this file.
00001 /**
00002  * \file grtool.h <mi32/grtool.h>
00003  * \brief Definitions for GRTOOL Graphic Tool classes used with MFC
00004  *
00005  * \if NODOC
00006  * $Id: grtool.h_v 1.5 2004/07/12 20:07:13 mju Exp $
00007  *
00008  * $Log: grtool.h_v $
00009  * Revision 1.5  2004/07/12 20:07:13  mju
00010  * Use region2d.
00011  *
00012  * Revision 1.4  2004/03/01 16:58:17  mju
00013  * Update to newer mgui headers.
00014  *
00015  * Revision 1.3  2003/09/15 13:49:56  fileserver!dwilliss
00016  * Doxygen
00017  *
00018  * Revision 1.1  2002/08/13 21:00:37  mju
00019  * Initial revision
00020  *
00021  * 
00022  * 13    12/31/01 11:35a Mju
00023  * Inherit from DLG_BASE.
00024  * 
00025  * 12    12/17/01 9:28a Mju
00026  * Use MGUI::DLG
00027  * 
00028  * 11    12/13/01 10:55a Mju
00029  * MGUI unificiation with X.
00030  * 
00031  * 10    11/05/01 10:57a Mju
00032  * Make GetPenColor non-inline.
00033  * Read pen color from INI in GetPenColor if not previously.
00034  * Write pen color to INI in SetPenColor.
00035  * 
00036  * 9     8/28/01 2:58p Mju
00037  * Define MGUI::FORM interface and have MGUI::CTRL inherit from it.
00038  * 
00039  * 8     8/17/01 4:43p Mju
00040  * Use MGUI namespace
00041  * 
00042  * 1     12/21/00 11:48a Mju
00043  * Definitions for GRTOOL Graphic Tool classes.
00044  * \endif
00045 **/
00046 
00047 #ifndef  INC_MI32_GRTOOL_H
00048 #define  INC_MI32_GRTOOL_H
00049 
00050 #ifndef  INC_MI32_STDAFX_H
00051    #include <mi32/stdafx.h>
00052 #endif
00053 
00054 #ifndef INC_MGUI_DLGBASE_H
00055    #include <mgui/dlgbase.h>
00056 #endif
00057 
00058 #ifndef INC_MGUI_COMMAND_H
00059    #include <mgui/command.h>
00060 #endif
00061 
00062 #ifndef INC_MI32_TRANS2DC_H
00063    #include <mi32/trans2dc.h>
00064 #endif
00065 
00066 #ifndef INC_MI32_REGION2D_H
00067    #include <mi32/region2d.h>
00068 #endif
00069 
00070 #ifndef INC_MI32_DOUBLEAR_H
00071    #include <mi32/doublear.h>
00072 #endif
00073 
00074 #ifndef INC_MI32_ELEMSTYL_H
00075    #include <mi32/elemstyl.h>
00076 #endif
00077 
00078 #include <list>
00079 
00080 namespace MicroImages {
00081 
00082 class GRTOOLVIEW;    //!< Forward declaration
00083 
00084 
00085 
00086 //!
00087 //!   GRTOOL - Base class for graphic tools
00088 //!
00089 class GRTOOL {
00090    public:
00091 
00092       //! Adjustment flags for Move() and Resize() methods.
00093       enum ADJUSTFLAGS {
00094          ADJUST_Default =        0x00,       //!< Values are relative tool coordinates
00095          ADJUST_Absolute =       0x01,       //!< Adjustment values are absolute
00096          ADJUST_ScreenCoords =   0x02,       //!< Adjustment values are in screen pixels
00097          ADJUST_Notify =         0x80        //!< Send notification message
00098          };
00099 
00100       enum CTRLOPT {
00101          CTRLOPT_Default =       0x00,
00102          CTRLOPT_Manual =        0x01,    //!< Include "manual" controls if available
00103          CTRLOPT_GPS =           0x02,    //!< Include "gps" controls if supported
00104          CTRLOPT_SnapGrid =      0x04,    //!< Include "snap to grid" toggle if supported
00105          CTRLOPT_NoManualProj =  0x08     //!< Don't allow manual projection / distance controls
00106          };
00107 
00108       enum MOVESEQ {
00109          MOVESEQ_Begin =            1,
00110          MOVESEQ_Continue =         2,
00111          MOVESEQ_End =              3,
00112          MOVESEQ_Cancel =           4
00113          };
00114 
00115       enum MOVETYPE {
00116          MOVETYPE_None =            0,
00117          MOVETYPE_Shift =           1,
00118          MOVETYPE_Resize =          2,
00119          MOVETYPE_Rotate =          3,
00120          MOVETYPE_Shear =           4,
00121          MOVETYPE_Edit =            5,
00122          MOVETYPE_Create =          6,
00123          MOVETYPE_Clear =           7
00124          };
00125 
00126       //! Marker types, not all types are supported by all tools.
00127       enum MARKER {
00128          MARKER_X =           0,
00129          MARKER_Plus =        1,
00130          MARKER_ArrowIn =     2,             //!< Arrow pointing in for line endpoint
00131          MARKER_ArrowOut =    3,             //!< Arrow pointing out for line endpoint
00132          MARKER_None =        4,
00133          MARKER_Circle =      5,
00134          MARKER_Flat =        6,             //!< Flat line endpoint
00135          MARKER_Square =      7,
00136          };
00137 
00138       enum PENCOLOR {
00139          PENCOLOR_Primary,                   //!< Primary tool drawing color
00140          PENCOLOR_Inactive,                  //!< Color for inactive elements (eg in POLYLINE tool)
00141          PENCOLOR_Highlight,                 //!< Color for highlighting
00142          PENCOLOR_COUNT                      //!< Number of pens, always last
00143          };
00144 
00145       struct SNAPGRIDPARMS {
00146          DPOINT3D BasePt;        //!< Base point of snap grid
00147          double xsize;           //!< X direction size
00148          double ysize;           //!< Y direction size
00149          double zsize;           //!< Z direction size
00150          double rotate;          //!< Rotation angle (snap grid)
00151          MAT3X3 OtoS, StoO;      //!< Translation to/from snap grid coordinates
00152          };
00153 
00154       //! Get global tool pen color reference.
00155       //! @return Color reference.
00156       static DWORD GetPenColor (
00157          PENCOLOR pencolor
00158          );
00159 
00160       //! Set global tool pen color.
00161       static void SetPenColor (
00162          PENCOLOR pencolor,
00163          DWORD ColorRef                      //!< Color reference
00164          );
00165 
00166       //! Destructor
00167       virtual ~GRTOOL () = 0;
00168 
00169       //! Activate the tool.
00170       //! If another tool is currently active in the view it will be automatically deactivated.
00171       void Activate (
00172          );
00173 
00174       //! Clear current tool position, erasing all graphics.
00175       void ClearPosition (
00176          );
00177 
00178       //! Create "form" with tool-specific controls.
00179       virtual MGUI::CTRL* CreateControlForm (
00180          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00181          CTRLOPT ctrlopt                     //!< Control options
00182          );
00183 
00184       //! Create "form" with tool-specific manual-entry controls.
00185       virtual MGUI::CTRL* CreateManualForm (
00186          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00187          CTRLOPT ctrlopt                     //!< Control options
00188          );
00189 
00190       //! Deactivate this tool.
00191       void Deactivate (
00192          );
00193 
00194       //! Generate region from tool.
00195       //! @return TRUE if region generated, FALSE if not, < 0 if error.
00196       virtual int GenerateRegion (
00197          REGION2D& region
00198          ) const;
00199 
00200       //! Get movement values associated with arrow keys.
00201       //! @return Values in "tool" coordinates.
00202       const DPOINT2D& GetArrowKeyDeltas (
00203          ) const { return (m_ArrowDelta); }
00204 
00205       //! Get current control options settings.
00206       CTRLOPT GetControlOptions (
00207          ) const { return (m_ctrlopt); }
00208 
00209       //! Get transformation between "tool" and "window" coordinates.
00210       const TRANS2D_AFFINE& GetTransToWindow (
00211          ) const { return (m_ToolToWindow); }
00212 
00213       //! Get "view" associated with tool.
00214       GRTOOLVIEW* GetView (
00215          ) const { return (m_view); }
00216 
00217       //! Get extents of view.
00218       inline const DRECT2D& GetViewExtents (
00219          ) const;
00220 
00221       //! Determine if tool controls available.
00222       bool HasControls (
00223          ) const { return (m_ControlNeed != CONTROLNEED_None); }
00224 
00225       //! Determine if has manual data entry controls.
00226       bool HasManualControls (
00227          ) const { return (m_HasManualControls); };
00228 
00229       //! Check if tool is currently "active".
00230       bool IsActive (
00231          ) const { return (m_IsActive); }
00232 
00233       //! Determine if tool is "resizable".
00234       bool IsResizable (
00235          ) const { return (m_Resizable); }
00236 
00237       //! Determine if tool is "rotatable".
00238       bool IsRotatable (
00239          ) const { return (m_Rotatable); }
00240 
00241       //! Check if tool is "suspended"
00242       bool IsSuspended (
00243          ) const { return (m_SuspendCount > 0); }
00244 
00245       //! Check if tool has a valid position set
00246       bool HasPosition (
00247          ) const { return (m_PosnSet); }
00248 
00249       //! Move the tool by the specified amount.
00250       void Move (
00251          double dx,
00252          double dy,
00253          ADJUSTFLAGS flags
00254          );
00255 
00256       //! Resize the tool.
00257       void Resize (
00258          double dx,
00259          double dy,
00260          ADJUSTFLAGS flags
00261          );
00262 
00263       //! Resume the tool after performing drawing operation on the view.
00264       void Resume (
00265          );
00266 
00267       //! Set movement amounts associated with arrow keys.
00268       void SetArrowKeyDeltas (
00269          double dx,
00270          double dy
00271          );
00272 
00273       //! Set whether user can start drawing a "new" tool.
00274       void SetCanStartNew (
00275          bool canstartnew
00276          ) { m_CanStartNew = canstartnew; return; }
00277 
00278       //! Set controls to appear on dialog when shown.
00279       //! If used, this must be called before tool is first activated.
00280       void SetControlOptions (
00281          CTRLOPT ctrlopt                        //!< Control settings
00282          ) { m_ctrlopt = ctrlopt; return; }
00283 
00284       //! Set whether tool is resizable.
00285       void SetResizable (
00286          bool resizable
00287          ) { m_Resizable = resizable; return; }
00288 
00289       //! Set whether tool is rotatable.
00290       void SetRotatable (
00291          bool rotatable
00292          ) { m_Rotatable = rotatable; return; }
00293 
00294       //! Set transformation between "tool" and "window" coordinates.
00295       void SetTransToWindow (
00296          const TRANS2D_AFFINE& trans
00297          );
00298 
00299       //! Determine if snap grid is currently in use.
00300       bool SnapGridIsActive (
00301          ) const { return (m_UseSnapGrid); }
00302 
00303       //! Get snap grid settings.
00304       const SNAPGRIDPARMS& SnapGridGet (
00305          ) const { return (m_sgparms); }
00306 
00307       //! Set snap grid parameters.
00308       void SnapGridSet (
00309          SNAPGRIDPARMS& parms
00310          );
00311 
00312       //! Set whether to use snap grid or not.
00313       void SnapGridSetActive (
00314          bool active
00315          ) { m_UseSnapGrid = active; }
00316 
00317       //! Suspend tool prior to performing a drawing operation on the view.
00318       void Suspend (
00319          );
00320 
00321    protected:
00322 
00323       enum CONTROLNEED {
00324          CONTROLNEED_None,
00325          CONTROLNEED_Optional,
00326          CONTROLNEED_Required
00327          };
00328 
00329       enum PENSTYLE {
00330          PENSTYLE_Solid,
00331          PENSTYLE_Dash,
00332          PENSTYLE_COUNT
00333          };
00334 
00335       //! Get pen for drawing tool.
00336       //! @return Pointer to CPen so can use directly in CDC::SelectObject().
00337       static CPen* GetPen (
00338          PENCOLOR PenColor = PENCOLOR_Primary,
00339          PENSTYLE PenStyle = PENSTYLE_Solid
00340          );
00341 
00342       //! Constructor
00343       explicit GRTOOL (
00344          GRTOOLVIEW *view,
00345          CONTROLNEED ControlNeed,         //!< Need for control dialog or form
00346          bool HasManualControls           //!< Optional manual controls available
00347          );
00348 
00349       // Methods used to notify subclasses of changes to tool.
00350 
00351       //! Called when tool is "activated".
00352       //! Derived class must call superclass method BEFORE performing own processing.
00353       virtual void OnActivate (
00354          );
00355 
00356       //! Called when user performs "Cancel" action with tool.
00357       //! Derived class must call superclass method BEFORE performing own processing.
00358       virtual void OnCancel (
00359          );
00360 
00361       //! Called when tool is "cleared" by user action, usually on control dialog.
00362       //! Derived class must call superclass method BEFORE performing own processing.
00363       virtual void OnClear (
00364          );
00365 
00366       //! Called when tool is deactivated.
00367       //! Derived class must call superclass method BEFORE performing own processing.
00368       virtual void OnDeactivate (
00369          );
00370 
00371       //! Called when user alters tool position, shape, size, etc.
00372       //! Derived class must call superclass method BEFORE performing own processing.
00373       virtual void OnMove (
00374          MOVESEQ moveseq,                 //!< Movement sequence
00375          MOVETYPE movetype                //!< Movement type
00376          );
00377 
00378       //! Called when right mouse button pressed.
00379       //! Usually overridden to show a popup menu.
00380       //! Default implementation does nothing.
00381       virtual void OnRButtonDown (UINT nFlags, const CPoint& mpoint);
00382 
00383       //! Called when right mouse button released.
00384       //! Usually overridden to perform an 'apply' action.
00385       //! Default implementation does nothing.
00386       virtual void OnRButtonUp (UINT nFlags, const CPoint& mpoint);
00387 
00388       //! Called when tool is "resumed" after being suspended.
00389       //! Derived class must call superclass method BEFORE performing own processing.
00390       virtual void OnResume (
00391          );
00392 
00393       //! Called when tool to window transformation is set.
00394       //! Derived class must call superclass method BEFORE performing own processing.
00395       virtual void OnSetTransToWindow (
00396          );
00397 
00398       // Methods called by the GRTOOL base class.
00399       // Will be private in tool implementation subclass.
00400       virtual void DoDraw (CDC*) = 0;
00401       virtual void DoMove (double, double, ADJUSTFLAGS);
00402       virtual void DoResize (double, double, ADJUSTFLAGS);
00403 
00404       // Methods called directly by the equivalent GRTOOLVIEW method.
00405       // Will be private in tool implementation subclass.
00406 
00407       virtual void OnCaptureChanged (CWnd *pWnd);
00408 
00409       //! Called when key pressed/released.
00410       //! @return 'true' if key handled, 'false' if not.
00411       virtual bool OnKey (UINT nChar, UINT nRepCnt, UINT nFlags);
00412 
00413       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint) = 0;
00414       virtual void OnLButtonUp (UINT nFlags, const CPoint& mpoint);
00415       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint) = 0;
00416       virtual void OnSize ();
00417 
00418       //! Utility methods for use by tool implementation.
00419 
00420       virtual void AdjustBegin (MOVETYPE movetype, bool redraw = true);
00421 
00422       virtual void AdjustEnd (bool releasecapture = true, bool cancel = false);
00423 
00424       void ApplyMoveDeltas (
00425          DPOINT2D& point,
00426          double dx,
00427          double dy,
00428          ADJUSTFLAGS flags
00429          ) const;
00430 
00431       //! Snap point to current snap grid, if no snapping enabled point unchanged.
00432       void ApplySnap (
00433          DPOINT2D& point                     //!< Point to adjust
00434          ) const;
00435 
00436       bool CanStartNew (
00437          ) const {
00438          return (m_CanStartNew);
00439          }
00440 
00441       //! Check rectangle against tool limits
00442       int CheckBounds (const DRECT2D&, DRECT2D*) const;
00443 
00444       //! Draw a marker (MARKER...) in the position and size specified.
00445       void DrawMarker (CDC* pDC, const POINT& centerpoint, const POINT& dirpoint, MARKER marker, UINT16 size) const;
00446 
00447       bool GetArrowDeltas (int, double*, double*);
00448 
00449       CDC *GetDC ();
00450 
00451       MOVETYPE GetMoveType (
00452          ) const { return (m_MoveType); }
00453 
00454       inline bool IsMouseCaptured (
00455          ) const;
00456 
00457       inline void ReleaseDC (CDC* pDC);
00458 
00459       //! Restore background for entire tool view window.
00460       void RestoreBackground () const;
00461 
00462       //! Restore background for specified rectangle.
00463       void RestoreBackground (
00464          const LRECT2D& rect,
00465          bool AddLineWidth = true            //!< Expand rectangle by 'LineWidth+1'
00466          ) const;
00467 
00468       void SetHasPosition (
00469          bool HasPosition = true
00470          ) { m_PosnSet = HasPosition; return; }
00471 
00472       //! Transform DPOINT2D from "tool" to "window" coordinates.
00473       POINT TransToolToWindow (
00474          const DPOINT2D& point
00475          ) const;
00476 
00477       //! Transform DPOINT3D from "tool" to "window" coordinates.
00478       POINT TransToolToWindow (
00479          const DPOINT3D& point
00480          ) const;
00481 
00482       //! Transform point in "window" to "tool" coordinates.
00483       DPOINT2D TransWindowToTool (
00484          const POINT& point
00485          ) const { return (m_ToolToWindow.ConvertInverse(point.x,point.y)); }
00486 
00487 
00488    private:
00489       #ifndef GENERATING_DOXYGEN_OUTPUT
00490 
00491       class TOOLDLG : public MGUI::DLG_BASE {
00492          public:
00493             TOOLDLG (GRTOOL& tool);
00494             virtual const char* GetDialogHelpID () const;
00495             virtual const char* GetDialogName () const;
00496             virtual ERRVALUE OnInitDialog ();
00497             class PAGECONTROLS : public MGUI::LAYOUT_PAGE {
00498                public:
00499                   PAGECONTROLS (TOOLDLG& dlg): m_dlg(dlg) { }
00500                   virtual ~PAGECONTROLS () { }
00501                protected:
00502                   virtual void OnInitPage ();
00503                private:
00504                   TOOLDLG& m_dlg;
00505                };
00506             class PAGEMANUAL : public MGUI::LAYOUT_PAGE {
00507                public:
00508                   PAGEMANUAL (TOOLDLG& dlg): m_dlg(dlg) { }
00509                   virtual ~PAGEMANUAL () { }
00510                protected:
00511                   virtual void OnInitPage ();
00512                private:
00513                   TOOLDLG& m_dlg;
00514                };
00515             GRTOOL& m_tool;
00516             MGUI::LAYOUT_BOOK m_TabBook;
00517             PAGECONTROLS m_PageControls;
00518             PAGECONTROLS m_PageManual;
00519          };
00520 
00521       // STATIC MEMBERS
00522 
00523       static DWORD s_PenColor[PENCOLOR_COUNT];
00524       static CPen s_Pen[PENCOLOR_COUNT*PENSTYLE_COUNT];
00525 
00526       // Explicitly initialized
00527       GRTOOLVIEW *m_view;
00528       CONTROLNEED m_ControlNeed;          //!< Need for controls
00529       bool m_HasManualControls;           //!< Tool supports manual controls
00530       INT8 m_LineWidth;                   //!< Tool line width
00531       DPOINT2D m_ArrowDelta;              //!< Increments for arrow key movement, tool coords
00532       INT32 m_SuspendCount;               //!< Number of times that this tool has been suspended
00533       MOVETYPE m_MoveType;                //!< Movement type for use with button-up
00534       bool m_IsActive;                    //!< Tool is in use, Activate() has been called
00535       bool m_PosnSet;                     //!< Tool graphic has a position and is viewable
00536       bool m_UseSnapGrid;                 //!< Use snap grid
00537       bool m_HasSnapGrid;                 //!< Has a snap grid to use
00538       bool m_HasArrowDeltas;              //!< Deltas for arrow key movement is set
00539       bool m_IsUserModifying;             //!< Is user modifying tool position
00540       bool m_InDeactivateFunc;            //!< Deactivate() is called, avoid doing redraws
00541       bool m_CanStartNew;                 //!< User can start drawing new tool, default=true
00542       bool m_Resizable;                   //!< Tool is resizable, default=true
00543       bool m_Rotatable;                   //!< Tool is rotatable, default=true
00544       CTRLOPT m_ctrlopt;
00545       TOOLDLG m_ToolDlg;
00546 
00547       // Self-initializing
00548       TRANS2D_AFFINE m_ToolToWindow;      //!< Tool <--> Window transformation
00549       SNAPGRIDPARMS m_sgparms;            //!< Snap grid information structure
00550 
00551       void CreateToolDlg ();
00552       void DrawTool (CDC*);
00553       void DrawTool (CDC*, UINT32);
00554       void DrawTool (UINT32);
00555       void SetView (GRTOOLVIEW *newview) { m_view = newview; return; }
00556 
00557    friend class GRTOOL::TOOLDLG;
00558    friend class GRTOOLVIEW;
00559    #endif // GENERATING_DOXYGEN_OUTPUT
00560    };
00561 DEFINE_ENUM_OPERATORS(GRTOOL::ADJUSTFLAGS);
00562 DEFINE_ENUM_OPERATORS(GRTOOL::CTRLOPT);
00563 
00564 
00565 //!
00566 //! GRTOOL_LIMITED - Tool with limit support
00567 //!
00568 class GRTOOL_LIMITED : public GRTOOL {
00569    public:
00570 
00571       //! Destructor
00572       virtual ~GRTOOL_LIMITED ();
00573 
00574       //! Set coordinate limits.
00575       void SetLimits (
00576          const DRECT2D& rect                    //!< Limits to set
00577          );
00578 
00579       //! Set whether limits are enforced.
00580       //! If SetLimits() has not been called then the tool will be limited to the visible view extent.
00581       void SetLimitsEnforced (
00582          bool enforced = true                   //!< Set if limits are enforced
00583          );
00584 
00585    protected:
00586 
00587       //! Constructor
00588       explicit GRTOOL_LIMITED (
00589          GRTOOLVIEW *view,
00590          CONTROLNEED ControlNeed,         //!< Need for control dialog or form
00591          bool HasManualControls           //!< Optional manual controls available
00592          );
00593 
00594       //! Get limits.
00595       const DRECT2D& GetLimits (
00596          ) const { return (m_Limits); }
00597 
00598       //! Determine if limits are enforced.
00599       bool IsLimitsEnforced (
00600          ) const { return (m_LimitsEnforced); }
00601 
00602       //! Called when tool is "activated".
00603       //! Derived class must call superclass method BEFORE performing own processing.
00604       virtual void OnActivate (
00605          );
00606 
00607       //! Called when limits are changed.
00608       //! Derived class must call superclass method BEFORE performing own processing.
00609       virtual void OnChangeLimits (
00610          );
00611 
00612       //! Called when tool to window transformation is set.
00613       //! Derived class must call superclass method BEFORE performing own processing.
00614       virtual void OnSetTransToWindow (
00615          );
00616 
00617    private:
00618       bool m_LimitsEnforced;              //!< Limits are enforced
00619       bool m_LimitsSet;                   //!< Limits have been set, otherwise defaults to window extents
00620       DRECT2D m_Limits;                   //!< Position ranges, default to entire parent window range
00621 
00622       virtual void OnSize ();
00623       void UpdateLimits ();
00624    };
00625 
00626 
00627 //!
00628 //!   GRTOOL_SELECTPOINT - Point selection tool (no visible graphics)
00629 //!
00630 class GRTOOL_SELECTPOINT : public GRTOOL_LIMITED {
00631    public:
00632 
00633       //! Constructor.
00634       explicit GRTOOL_SELECTPOINT (
00635          GRTOOLVIEW *view
00636          );
00637 
00638       //! Destructor.
00639       virtual ~GRTOOL_SELECTPOINT ();
00640 
00641       //! Get tool point.
00642       const DPOINT2D& GetPoint (
00643          ) const { return (m_point); }
00644 
00645    private:
00646       //! Enumeration constants
00647       enum ZONE {
00648          ZONE_NoFunction = 0,
00649          ZONE_Outside,
00650          };
00651 
00652       class CONTROLFORM : public MGUI::CTRL {
00653          public:
00654             CONTROLFORM (
00655                );
00656             virtual ~CONTROLFORM (
00657                );
00658          private:
00659          };
00660 
00661       //! Tool position values
00662       DPOINT2D m_point;                //!< Tool position
00663 
00664       //! Values used during interaction
00665       ZONE m_CursorZone;                  //!< Current cursor zone
00666 
00667       //! Methods called by the GRTOOL base class
00668       virtual void DoDraw (CDC*);
00669       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
00670       //! Methods called directly by the equivalent GRTOOLVIEW method
00671       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
00672       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
00673 
00674       //! Methods
00675       void ComputeCursorZone (const DPOINT2D&);
00676       void UpdateCursor () const;
00677    };
00678 
00679 
00680 //!
00681 //! GRTOOL_POINT - Point tool
00682 //!
00683 class GRTOOL_POINT : public GRTOOL_LIMITED {
00684    public:
00685 
00686       //! Constructor.
00687       explicit GRTOOL_POINT (
00688          GRTOOLVIEW *view
00689          );
00690 
00691       //! Destructor.
00692       virtual ~GRTOOL_POINT ();
00693 
00694       //! Assignment from DPOINT2D.
00695       GRTOOL_POINT& operator= (
00696          const DPOINT2D& rhs
00697          );
00698 
00699       //! Assigment from DPOINT3D.
00700       GRTOOL_POINT& operator= (
00701          const DPOINT3D& rhs
00702          );
00703 
00704       //! Get current tool point coordinates.
00705       const DPOINT3D& GetPoint (
00706          ) const { return (m_point); }
00707 
00708       //! Set marker type and size.
00709       //! The default marker is MARKER_Plus with a size of 9 pixels.
00710       void SetMarker (
00711          MARKER marker,                      //!< New marker type
00712          UINT16 size = 0                     //!< New marker size, 0 to retain current size
00713          );
00714 
00715    private:
00716       //! Enumeration constants
00717       enum ZONE {
00718          ZONE_NoFunction = 0,
00719          ZONE_Outside,
00720          };
00721       //! Tool settings
00722       MARKER m_marker;
00723       UINT16 m_markersize;
00724       //! Tool position values
00725       DPOINT3D m_point;                //!< Tool position
00726       //! Values used during interaction
00727       ZONE m_CursorZone;                  //!< Current cursor zone
00728 
00729       //! Methods called by the GRTOOL base class
00730       virtual void DoDraw (CDC*);
00731       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
00732       //! Methods called directly by the equivalent GRTOOLVIEW method
00733       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
00734       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
00735 
00736       //! Methods
00737       void ComputeCursorZone (const DPOINT2D&);
00738       void UpdateCursor () const;
00739    };
00740 
00741 
00742 //!
00743 //! GRTOOL_MULTIPOINT - Multi-Point tool
00744 //!
00745 class GRTOOL_MULTIPOINT : public GRTOOL {
00746    public:
00747 
00748       //! Constructor.
00749       explicit GRTOOL_MULTIPOINT (
00750          GRTOOLVIEW *view
00751          );
00752 
00753       //! Destructor.
00754       virtual ~GRTOOL_MULTIPOINT ();
00755 
00756       //! Create "form" with tool-specific controls.
00757       virtual MGUI::CTRL* CreateControlForm (
00758          MGUI::LAYOUT_PANE_BASE& ParentPane, //!< Parent pane
00759          CTRLOPT ctrlopt                     //!< Control options
00760          );
00761 
00762       //! Get active point coordinates.
00763       const DPOINT3D& GetActivePoint (
00764          ) const { return (m_Points[m_ActiveIndex]); }
00765 
00766       //! Get number of points.
00767       int GetNumPoints (
00768          ) const { return (m_Points.GetNumItems()); }
00769 
00770       //! Get single point.
00771       //! If the index is out of range the results are unpredictable.
00772       const DPOINT3D& GetPoint (
00773          int index                           //!< Zero-based index of point to retrieve
00774          ) const { return (m_Points[index]); }
00775 
00776       //! Get points.
00777       const DOUBLE_ARRAY<DPOINT3D> GetPoints (
00778          ) const { return (m_Points); }
00779 
00780       //! Determine if "active" point is valid.
00781       bool IsActiveValid (
00782          ) const { return (m_ActiveIndex >= 0 && m_ActiveIndex < m_Points.GetNumItems()); }
00783 
00784       //! Set marker type and size.
00785       //! The default marker is MARKER_Plus with a size of 9 pixels.
00786       void SetMarker (
00787          MARKER marker,                      //!< New marker type
00788          UINT16 size = 0                     //!< New marker size, 0 to retain current size
00789          );
00790 
00791    protected:
00792 
00793       //! Called when "active element" changed.
00794       //! Derived class must call superclass method BEFORE performing own processing.
00795       virtual void OnChangeActiveElem (
00796          );
00797 
00798       //! Called when tool is "cleared" by user action, usually on control dialog.
00799       //! Derived class must call superclass method BEFORE performing own processing.
00800       virtual void OnClear (
00801          );
00802 
00803    private:
00804 
00805       enum EDITMODE {
00806          EDITMODE_Automatic,                 //!< Auto select when near point, move if selected, add if not near point
00807          EDITMODE_Add,                       //!< Always add new point
00808          EDITMODE_Move,                      //!< Move selected point to cursor
00809          EDITMODE_Select                     //!< Select point by clicking
00810          };
00811 
00812       enum ZONE {
00813          ZONE_NoFunction = 0,
00814          ZONE_Outside,
00815          };
00816 
00817       //! Tool settings
00818       MARKER m_marker;
00819       UINT16 m_markersize;
00820       EDITMODE m_EditMode;
00821       //! Tool position values
00822       DOUBLE_ARRAY<DPOINT3D> m_Points;    //!< Points
00823       int m_ActiveIndex;                  //!< Index of active point
00824       //! Values used during interaction
00825       ZONE m_CursorZone;                  //!< Current cursor zone
00826       DPOINT2D m_prevpt;
00827       bool m_NotifyChangeElem;
00828 
00829       void ActivateClosestPoint (const DPOINT2D&);
00830       void AddPoint (CDC*, const DPOINT2D&);
00831       void AdjustTool (DPOINT2D&, MOVESEQ);
00832       void ComputeCursorZone (const DPOINT2D&);
00833       void DeletePoint ();
00834       virtual void DoDraw (CDC*);
00835       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
00836       void DrawNeighborPoints (CDC*, const LRECT2D&) const;
00837       void DrawPoint (CDC*, int) const;
00838       void ErasePoint (CDC*, bool circleonly = false) const;
00839       int FindClosestPoint (const DPOINT2D&) const;
00840       virtual bool OnKey (UINT nChar, UINT nRepCnt, UINT nFlags);
00841       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
00842       virtual void OnLButtonUp (UINT nFlags, const CPoint& mpoint);
00843       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
00844       void SetActiveIndex (int);
00845       void UpdateCursor () const;
00846    };
00847 
00848 
00849 //!
00850 //! GRTOOL_CROSSHAIR - Crosshair tool
00851 //!
00852 class GRTOOL_CROSSHAIR : public GRTOOL_LIMITED {
00853    public:
00854 
00855       //! Constructor.
00856       explicit GRTOOL_CROSSHAIR (
00857          GRTOOLVIEW *view
00858          );
00859 
00860       //! Destructor.
00861       virtual ~GRTOOL_CROSSHAIR ();
00862 
00863       //! Assignment from DPOINT2D.
00864       GRTOOL_CROSSHAIR& operator= (
00865          const DPOINT2D& rhs
00866          );
00867 
00868       //! Get current rotation angle.
00869       //! @return Rotation angle in RADIANS.
00870       double GetAngle (
00871          ) const { return (m_angle); }
00872 
00873       //! Get current crosshair position.
00874       const DPOINT2D& GetPoint (
00875          ) const { return (m_point); }
00876 
00877    private:
00878       //! Enumeration constants
00879       enum ZONE {
00880          ZONE_NoFunction = 0,
00881          ZONE_Outside,
00882          };
00883       //! Tool position values
00884       DPOINT2D m_point;                   //!< Tool position
00885       double m_angle;                     //!< Rotation angle
00886       //! Values used during interaction
00887       ZONE m_CursorZone;                  //!< Current cursor zone
00888 
00889       //! Methods called by the GRTOOL base class
00890       virtual void DoDraw (CDC*);
00891       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
00892       //! Methods called directly by the equivalent GRTOOLVIEW method
00893       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
00894       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
00895 
00896       //! Methods
00897       void ComputeCursorZone (const DPOINT2D&);
00898       void UpdateCursor () const;
00899    };
00900 
00901 
00902 //!
00903 //!   GRTOOL_SEGMENT - Segment tool
00904 //!
00905 class GRTOOL_SEGMENT : public GRTOOL_LIMITED {
00906    public:
00907 
00908       //! Constructor.
00909       explicit GRTOOL_SEGMENT (
00910          GRTOOLVIEW *view
00911          );
00912 
00913       //! Destructor.
00914       virtual ~GRTOOL_SEGMENT ();
00915 
00916       //! Get segment end point coordinates.
00917       const DPOINT2D& GetEnd (
00918          ) const { return (m_endpoint); }
00919 
00920       //! Get segment start point coordinates
00921       const DPOINT2D& GetStart (
00922          ) const { return (m_startpoint); }
00923 
00924       //! Set markers for start and end points.
00925       void SetMarkers (
00926          MARKER startmarker,                 //!< Starting point marker type
00927          MARKER endmarker,                   //!< Ending point marker type
00928          UINT16 startmarkersize = 0,         //!< Starting point marker size, 0 to retain current size
00929          UINT16 endmarkersize = 0            //!< Ending point marker size, 0 to retain current size
00930          );
00931 
00932    private:
00933       //! Enumeration constants
00934       enum ZONE {
00935          ZONE_NoFunction = 0,
00936          ZONE_Outside,
00937          ZONE_Inside,
00938          ZONE_Start,
00939          ZONE_End
00940          };
00941       //! Tool settings
00942       MARKER m_startmarker;
00943       MARKER m_endmarker;
00944       UINT16 m_startmarkersize;
00945       UINT16 m_endmarkersize;
00946       //! Tool position values
00947       DPOINT2D m_endpoint;
00948       DPOINT2D m_startpoint;
00949       //! Values used during interaction
00950       ZONE m_CursorZone;                  //!< Current cursor zone
00951       DPOINT2D m_prevpt;                  //!< Previous point during button-down
00952       UINT8 m_AdjustMode;                 //!< Adjustment mode, 2=rotate, 1=everything else
00953 
00954       //! Methods called by the GRTOOL base class
00955       virtual void DoDraw (CDC*);
00956       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
00957       //! Methods called directly by the equivalent GRTOOLVIEW method
00958       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
00959       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
00960 
00961       //! Methods
00962       void AdjustTool (const DPOINT2D&, bool firsttime=false);
00963       void ComputeCursorZone (const DPOINT2D&);
00964       void StartTool (const DPOINT2D&);
00965       void UpdateCursor () const;
00966    };
00967 
00968 
00969 //!
00970 //! GRTOOL_CIRCLE - Circle tool
00971 //!
00972 class GRTOOL_CIRCLE : public GRTOOL {
00973    public:
00974 
00975       //! Constructor.
00976       explicit GRTOOL_CIRCLE (
00977          GRTOOLVIEW *view
00978          );
00979 
00980       //! Destructor.
00981       virtual ~GRTOOL_CIRCLE ();
00982 
00983       //! Generate region from tool boundary.
00984       //! @return TRUE if region generated, FALSE if not, < 0 if error.
00985       virtual int GenerateRegion (
00986          REGION2D& region
00987          ) const;
00988 
00989       //! Get current rotation angle.
00990       double GetAngle (
00991          ) const { return (m_angle); }
00992 
00993       //! Get center position.
00994       const DPOINT2D& GetCenter (
00995          ) const { return (m_center); }
00996 
00997       //! Get radius.
00998       double GetRadius (
00999          ) const { return (m_radius); }
01000 
01001       //! Set rotation angle.
01002       //! The rotation will only be visible to the user if SetAngleVisible() has been used.
01003       void SetAngle (
01004          double angle                        //!< New rotation angle in RADIANS
01005          );
01006 
01007       //! Set whether rotation angle indicator is visible.
01008       //! The rotation angle is indicated by a line from the center to the boundary.
01009       void SetAngleVisible (
01010          bool anglevisible = true
01011          );
01012 
01013       //! Set circle center coordinates.
01014       void SetCenter (
01015          const DPOINT2D& center
01016          );
01017 
01018       //! Set marker type and size.
01019       //! The default marker is MARKER_Plus with a size of 9 pixels.
01020       void SetMarker (
01021          MARKER marker,                      //!< New marker type
01022          UINT16 size = 0                     //!< New marker size, 0 to retain current size
01023          );
01024 
01025       //! Set radius.
01026       void SetRadius (
01027          double radius
01028          );
01029 
01030       //! Set allowed radius range.
01031       void SetRadiusRange (
01032          double minradius,                   //!< Minimum radius in tool units
01033          double maxradius                    //!< Maximum radius, <= 0 for no maximum
01034          );
01035 
01036    private:
01037       //! Enumeration constants
01038       enum ZONE {
01039          ZONE_NoFunction = 0,
01040          ZONE_Outside,
01041          ZONE_Inside,
01042          ZONE_Perimeter,
01043          ZONE_SetCenter,
01044          ZONE_Rotate,
01045          };
01046       //! Tool settings
01047       MARKER m_marker;
01048       UINT16 m_markersize;
01049       double m_minradius;                 //!< Minimum radius
01050       double m_maxradius;                 //!< Maximum radius, 0 if no maximum
01051       bool m_anglevisible;             //!< Visibility of rotation angle indicator
01052       //! Tool position values
01053       DPOINT2D m_center;                  //!< Center
01054       double m_radius;
01055       double m_angle;
01056       //! Values used during interaction
01057       ZONE m_CursorZone;                  //!< Current cursor zone
01058       DPOINT2D m_prevpt;                  //!< Previous point during button-down
01059 
01060       //! Methods called by the GRTOOL base class
01061       virtual void DoDraw (CDC*);
01062       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
01063       //! Methods called directly by the equivalent GRTOOLVIEW method
01064       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
01065       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
01066 
01067       //! Methods
01068       void AdjustTool (const DPOINT2D&, bool firsttime=false);
01069       void ComputeCursorZone (const DPOINT2D&);
01070       void StartTool (const DPOINT2D&);
01071       void UpdateCursor (const DPOINT2D&) const;
01072    };
01073 
01074 
01075 //!
01076 //! GRTOOL_ELLIPSE - Ellipse tool
01077 //!
01078 class GRTOOL_ELLIPSE : public GRTOOL {
01079    public:
01080 
01081       //! Constructor.
01082       explicit GRTOOL_ELLIPSE (
01083          GRTOOLVIEW *view
01084          );
01085 
01086       //! Destructor.
01087       virtual ~GRTOOL_ELLIPSE ();
01088 
01089       //! Generate region from tool boundary.
01090       //! @return TRUE if region generated, FALSE if not, < 0 if error.
01091       virtual int GenerateRegion (
01092          REGION2D& region
01093          ) const;
01094 
01095       //! Get current rotation angle.
01096       double GetAngle (
01097          ) const { return (m_angle); }
01098 
01099       //! Get center position.
01100       const DPOINT2D& GetCenter (
01101          ) const { return (m_center); }
01102 
01103       //! Get radius.
01104       const DPOINT2D& GetRadius (
01105          ) const { return (m_radius); }
01106 
01107       //! Set rotation angle.
01108       void SetAngle (
01109          double angle                        //!< New rotation angle in RADIANS
01110          );
01111 
01112       //! Set whether rotation angle indicator is visible.
01113       //! The rotation angle is indicated by a line from the center to the boundary.
01114       void SetAngleVisible (
01115          bool anglevisible = true
01116          );
01117 
01118       //! Set center coordinates.
01119       void SetCenter (
01120          const DPOINT2D& center
01121          );
01122 
01123       //! Set marker type and size.
01124       //! The default marker is MARKER_Plus with a size of 9 pixels.
01125       void SetMarker (
01126          MARKER marker,                      //!< New marker type
01127          UINT16 size = 0                     //!< New marker size, 0 to retain current size
01128          );
01129 
01130       //! Set radius.
01131       void SetRadius (
01132          DPOINT2D& radius
01133          );
01134 
01135       //! Set allowed radius range.
01136       void SetRadiusRange (
01137          double minradius,                   //!< Minimum radius in tool units
01138          double maxradius                    //!< Maximum radius, <= 0 for no maximum
01139          );
01140 
01141    private:
01142       //! Enumeration constants
01143       enum ZONE {
01144          ZONE_NoFunction = 0,
01145          ZONE_Outside,
01146          ZONE_Inside,
01147          ZONE_ResizeX,
01148          ZONE_ResizeY,
01149          ZONE_Perimeter,
01150          ZONE_SetCenter,
01151          ZONE_Rotate,
01152          };
01153       //! Tool settings
01154       MARKER m_marker;
01155       UINT16 m_markersize;
01156       double m_minradius;                 //!< Minimum radius
01157       double m_maxradius;                 //!< Maximum radius, 0 if no maximum
01158       bool m_anglevisible;                //!< Visibility of rotation angle indicator
01159       //! Tool position values
01160       DPOINT2D m_center;                  //!< Center
01161       DPOINT2D m_radius;
01162       double m_angle;
01163       //! Values used during interaction
01164       ZONE m_CursorZone;                  //!< Current cursor zone
01165       DPOINT2D m_prevpt;                  //!< Previous point during button-down
01166       TRANS2D_AFFINE m_trans;             //!< Transformation to apply size,rotation,center
01167 
01168       //! Methods called by the GRTOOL base class
01169       virtual void DoDraw (CDC*);
01170       virtual void DoMove (double dx, double dy, ADJUSTFLAGS flags);
01171       //! Methods called directly by the equivalent GRTOOLVIEW method
01172       virtual void OnLButtonDown (UINT nFlags, const CPoint& mpoint);
01173       virtual void OnMouseMove (UINT nFlags, const CPoint& mpoint);
01174 
01175       //! Methods
01176       void AdjustTool (const DPOINT2D&, bool firsttime=false);
01177       void ComputeCursorZone (const DPOINT2D&);
01178       void StartTool (const DPOINT2D&);
01179       void UpdateCursor (const DPOINT2D&) const;
01180    };
01181 
01182 
01183 //!
01184 //! GRTOOL_ARC - Circular arc tool
01185 //!
01186 class GRTOOL_ARC : public GRTOOL {
01187    public:
01188 
01189       enum CLOSURE {
01190          CLOSURE_None,
01191          CLOSURE_Chord,
01192          CLOSURE_Wedge
01193          };
01194 
01195       //! Constructor.
01196       explicit GRTOOL_ARC (
01197          GRTOOLVIEW *view
01198          );
01199 
01200       //! Destructor.
01201       virtual ~GRTOOL_ARC ();
01202 
01203       //! Generate region from tool boundary.
01204       //! @return TRUE if region generated, FALSE if not, < 0 if error.
01205       virtual int GenerateRegion (
01206          REGION2D& region
01207          ) const;
01208 
01209       //! Get center position.
01210       const DPOINT2D& GetCenter (
01211          ) const { return (m_center); }
01212 
01213       //! Get closure type.
01214       CLOSURE GetClosure (
01215          ) const { return (m_closure); }
01216 
01217       //! Get radius.
01218       double GetRadius (
01219          ) const { return (m_radius); }
01220 
01221       //! Get starting angle.
01222       //! @return Starting angle in radians.
01223       double GetStartAngle (
01224          ) const { return (m_StartAngle); }
01225 
01226       //! Get sweep angle.
01227       //! @return Sweep angle in radians.
01228       double GetSweepAngle (
01229          ) const { return (m_SweepAngle); }
01230 
01231       //! Set center of arc.
01232       void SetCenter (
01233          const DPOINT2D& newcenter
01234          );
01235 
01236       //! Set closure type.
01237       void SetClosure (
01238          CLOSURE closure
01239          );
01240 
01241       //! Set marker type and size.
01242       //! The default marker is MARKER_Plus with a size of 9 pixels.
01243       void SetMarker (
01244          MARKER marker,                      //!< New marker type
01245          UINT16 size = 0                     //!< New marker size, 0 to retain current size
01246          );
01247 
01248       void SetRadius (
01249          double newradius
01250          );
01251 
01252       void SetRadiusRange (
01253          double newminradius,
01254          double newmaxradius
01255          );
01256 
01257       //! Set starting angle.
01258       void SetStartAngle (
01259          double startangle                   //!< Starting angle in radians
01260          );
01261 
01262       //! Set sweep angle
01263       void SetSweepAngle (
01264          double sweepangle                   //!< Sweep angle in radians
01265          );
01266 
01267    private:
01268       //! Enumeration constants
01269       enum ZONE {
01270          ZONE_NoFunction = 0,
01271          ZONE_Outside,
01272          ZONE_Inside,
01273          ZONE_Perimeter,
01274          ZONE_SetCenter,
01275          ZONE_Start,
01276          ZONE_End
01277          };
01278       //! Tool settings
01279       MARKER m_marker;
01280       UINT16 m_markersize;
01281       double m_minradius;                 //!< Minimum radius
01282       double m_maxradius;                 //!< Maximum radius, 0 if no maximum
01283       CLOSURE m_closure;
01284       //! Tool position values
01285       DPOINT2D m_center;                  //!< Center
01286       double m_radius;
01287       double m_StartAngle;
01288       double m_SweepAngle;
01289       //! Values used during interaction
01290       ZONE m_CursorZone;                  //!< Current cursor zone
01291       DPOINT2D m_prevpt;                  //!< Previous point during button-down
01292 
01293       //! Methods called by the GRTOOL base class
01294       virtual void