Main Page   Class Hierarchy   Compound List   File List   Compound Members  

tool.h

00001 
00002 
00003 
00004 #ifndef _TOOLS
00005 #define _TOOLS
00006 
00007 #ifdef __GNUG__
00008 #pragma interface
00009 #endif
00010 
00011 #include "wxwin.h"
00012 #include "mainwin.h"
00013 #include "windrv.h"
00014 #include "units.h"
00015 class ToolControl;
00016 class CircleditDialog;
00017 enum ToolSet{ SELECT_TOOL, DESELECT_TOOL, ZOOMIN_TOOL , RECTANGLE_TOOL, POLYGON_TOOL,POLYLINE_TOOL,
00018                                   MOVE_TOOL, ZOOMOUT_TOOL, ZOOMBACK_TOOL,       COPY_TOOL,CIRCLE2_TOOL,CIRCLE_TOOL,
00019               EDIT_TOOL, EDITPOLYGON_TOOL,EDITPOLYLINE_TOOL,DELETE_TOOL,EDITPROPERTY_TOOL,
00020               ROTATE_TOOL , EDITCIRCLE_TOOL ,EDITREC_TOOL, TEXT_TOOL, SET_CURSOR,
00021               INSERTREF_TOOL,INSERTSTRUC_TOOL,EDITIMAGE_TOOL,EDITREF_TOOL,EDITLINE_TOOL
00022                                 };
00023 
00024 
00026 
00053 class BaseTool
00054 {
00055    public:
00056       // constructor and destructor
00057       BaseTool(ToolControl* controller);
00058       virtual ~BaseTool();
00059                 virtual void    OnMouseEvent(wxMouseEvent& event);
00060                 virtual void    OnChar(wxKeyEvent& event);
00061                 virtual void    OnKeyDown(wxKeyEvent& event);
00062                 virtual void    OnKeyUp(wxKeyEvent& event);
00063       ToolSet GetType();
00064                 void SetStatusBar();
00065                 virtual void   Draw()=0;
00066                 virtual void   Undo();
00067       void                              SetCursor(double x, double y);
00068       wxCursor                  GetCursor(){return _toolcursor;};
00069                 virtual void   AddPoint(double x,double y);
00070                 virtual void    RemovePoint(){};
00071       bool      GetOnlyOnce(){return _onlyonce;};
00072       void              SetOnlyOnce(bool onlyonce){_onlyonce = onlyonce;};
00073       bool         Get_Busy(){return _busy;};
00074       virtual void      Begin();
00075       virtual void      End();
00076       virtual wxString  GetToolInfo()=0;
00077                 ToolBarSet              GetToolBarType(){return m_toolbar;};
00078       //is the tool that wants to be started allowed within this tools context
00079                 virtual bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00080 
00081    protected:
00082                 void                     DrawHandle(wxDC& dc,double x,double y,int type=0);
00083                 virtual void EvRD();
00084                 virtual void EvLeftDClick();
00085                 virtual void EvDrag();
00086                 virtual void EvMove(int drag);
00087                 virtual void EvLD();
00088                 virtual void EvLU();
00089       void Grid();
00090 
00091                 void CalculateCurrent();
00092                 void CalcVirtual(long x,long y,double& xr,double& yr);
00093 
00094 
00095                 ToolControl*            _controller;
00096 
00097       wxMouseEvent              _event;
00098 
00099                 long                                    _grid_x;
00100                 long                                    _grid_y;
00101                 long                                    _currentX;
00102                 long                                    _currentY;
00103       double            _realcurrentX;
00104       double            _realcurrentY;
00105       ToolSet           _tooltype;
00106       long                                      _timeevent;
00107       bool              _onlyonce;
00108       bool              _busy;
00109       wxCursor          _toolcursor;
00110                 ToolBarSet                      m_toolbar;
00111       wxCoord                           m_maxx;
00112       wxCoord                           m_minx;
00113       wxCoord                           m_maxy;
00114       wxCoord                           m_miny;
00115       bool                                      m_valid_bbox;
00116 
00117       virtual void CalcBoundingBox(wxCoord x, wxCoord y)
00118       {
00119              if (m_valid_bbox)
00120         {
00121            if ( x < m_minx ) m_minx = x;
00122            if ( y < m_miny ) m_miny = y;
00123            if ( x > m_maxx ) m_maxx = x;
00124            if ( y > m_maxy ) m_maxy = y;
00125         }
00126         else
00127         {
00128            m_valid_bbox=true;
00129            m_minx = x;
00130            m_miny = y;
00131            m_maxx = x;
00132            m_maxy = y;
00133         }
00134       }
00135 
00136 
00137 };
00138 
00141 class BoxTool : public BaseTool
00142 
00143 {
00144    public:
00145       // constructor and destructor
00146       BoxTool(ToolControl* controller);
00147       ~BoxTool();
00148                 void  OnMouseEvent(wxMouseEvent& event);
00149 
00150    protected:
00151                 void EvDrag();
00152       void EvMove(int drag);
00153       void EvLD();
00154       void EvLU();
00155 
00156                 bool                            _boxdrawn;
00157                 struct ZoomRect {
00158                         double  left;
00159                         double  top;
00160                         double  right;
00161                         double  bottom;
00162                 };
00163                 ZoomRect                                _ZoomRect;
00164            bool  box;
00165                 double                          _firstX;
00166                 double                          _firstY;
00167 
00168 };
00169 
00172 class SelectTool : public BoxTool
00173 {
00174    public:
00175       // constructor and destructor
00176       SelectTool(ToolControl* controller);
00177       ~SelectTool();
00178                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00179                 void Draw();
00180       wxString  GetToolInfo();
00181 
00182    protected:
00183       void EvLU();
00184       void EvLD();
00185 };
00186 
00189 class DeSelectTool : public BoxTool
00190 {
00191    public:
00192       // constructor and destructor
00193       DeSelectTool(ToolControl* controller);
00194       ~DeSelectTool();
00195                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00196       void BeginTool();
00197       void EndTool();
00198                 void Draw();
00199       wxString  GetToolInfo();
00200 
00201    protected:
00202       void EvLU();
00203 
00204 };
00205 
00208 class ZoomTool : public BoxTool
00209 {
00210    public:
00211       // constructor and destructor
00212       ZoomTool(ToolControl* controller);
00213       ~ZoomTool();
00214                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00215                 void Draw();
00216       wxString  GetToolInfo();
00217 
00218    protected:
00219            bool _zooming;
00220       void EvLU();
00221                 void EvLD();
00222 };
00223 
00226 class RecTangleTool : public BoxTool
00227 {
00228    public:
00229       // constructor and destructor
00230       RecTangleTool(ToolControl* controller);
00231       ~RecTangleTool();
00232                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00233       void BeginTool();
00234       void EndTool();
00235                 void Draw();
00236                 void  AddPoint(double x,double y);
00237       wxString  GetToolInfo();
00238 
00239    protected:
00240       void EvLU();
00241                 void EvLD();
00242 };
00243 
00246 class PolyTool : public BaseTool
00247 {
00248    public:
00249       // constructor and destructor
00250       PolyTool(ToolControl* controller);
00251       ~PolyTool();
00252                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00253                 void  AddPoint(double x,double y);
00254                 void    RemovePoint();
00255                 void Draw();
00256       void End();
00257       wxString  GetToolInfo();
00258 
00259    protected:
00260                 void EvLeftDClick();
00261                 void EvDrag();
00262       void EvLD();
00263       void EvLU();
00264       void EvMove(int drag);
00265 
00266                 bool                            _firstpoint;
00267 
00268                 G_Polygon*                      _polygon;
00269       Line_Seg*         _segm;
00270       Line_Seg          _lastsegm;
00271 
00272                 Boundary*                       _boundary;
00273 };
00274 
00278 class TextTool : public BaseTool
00279 {
00280    public:
00281       // constructor and destructor
00282       TextTool(ToolControl* controller);
00283       ~TextTool();
00284                 void Draw();
00285       void End();
00286       wxString  GetToolInfo();
00287 
00288    protected:
00289                 void     EvDrag();
00290       void   EvLD();
00291       void   EvLU();
00292       void   EvMove(int drag);
00293                 Text*  _text;
00294       double _height;
00295       char       _unit[20];
00296 
00297 };
00298 
00301 class PolyLineTool : public BaseTool
00302 {
00303    public:
00304       // constructor and destructor
00305       PolyLineTool(ToolControl* controller);
00306       ~PolyLineTool();
00307                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00308                 void  AddPoint(double x,double y);
00309                 void    RemovePoint();
00310                 void Draw();
00311       void End();
00312       wxString  GetToolInfo();
00313 
00314    protected:
00315                 void EvLeftDClick();
00316                 void EvDrag();
00317       void EvLD();
00318       void EvLU();
00319       void EvMove(int drag);
00320 
00321       G_Polyline*               _polyline;
00322       bool                              _firstpoint;
00323       Line_Seg*         _segm;
00324       Line_Seg          _lastsegm;
00325                 Path*                                   _path;
00326 };
00327 
00330 class MoveTool : public BaseTool
00331 {
00332    public:
00333       // constructor and destructor
00334       MoveTool(ToolControl* controller);
00335       ~MoveTool();
00336                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00337                 void Draw();
00338                 void Undo();
00339       wxString  GetToolInfo();
00340 
00341    protected:
00342                 void EvLeftDClick();
00343                 void EvDrag();
00344       void EvMove(int drag);
00345       void EvLD();
00346       void EvLU();
00347 
00348       wxTransformMatrix*        _trans_matrix;
00349       long                                      _eventstamp;
00350 
00351                 ElementList* _elemlst;
00352                 ElementList* _elemlst_orig;
00353 
00354                 double                          _oldX;
00355                 double                          _oldY;
00356                 double                          _newX;
00357                 double                          _newY;
00358 };
00359 
00362 class RotateTool : public BaseTool
00363 {
00364    public:
00365       // constructor and destructor
00366       RotateTool(ToolControl* controller);
00367       ~RotateTool();
00368                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00369                 void Draw();
00370                 void Undo();
00371       wxString  GetToolInfo();
00372 
00373    protected:
00374                 void EvLeftDClick();
00375                 void EvDrag();
00376       void EvMove(int drag);
00377       void EvLD();
00378       void EvLU();
00379 
00380       wxTransformMatrix*        _trans_matrix;
00381                 ElementList* _elemlst;
00382                 ElementList* _elemlst_orig;
00383 
00384       long                                      _eventstamp;
00385 
00386                 double                                  _rotX;
00387                 double                          _rotY;
00388                 double                          _newX;
00389                 double                          _newY;
00390 };
00391 
00394 class CopyTool : public BaseTool
00395 {
00396    public:
00397       // constructor and destructor
00398       CopyTool(ToolControl* controller);
00399       ~CopyTool();
00400                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00401                 void Draw();
00402                 void Undo();
00403       wxString  GetToolInfo();
00404 
00405    protected:
00406                 void EvLeftDClick();
00407                 void EvDrag();
00408       void EvMove(int drag);
00409       void EvLD();
00410       void EvLU();
00411 
00412       wxTransformMatrix*        _trans_matrix;
00413                 ElementList* _elemlst;
00414 
00415                 double                          _oldX;
00416                 double                          _oldY;
00417                 double                          _newX;
00418                 double                          _newY;
00419       long                                      _eventstamp;
00420 };
00421 
00424 class CircleTool : public BaseTool
00425 {
00426    public:
00427       // constructor and destructor
00428       CircleTool(ToolControl* controller,bool mode);
00429       ~CircleTool();
00430                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00431                 void Draw();
00432       wxString  GetToolInfo();
00433 
00434    protected:
00435                 void EvDrag();
00436       void EvLD();
00437       void EvLU();
00438       void EvMove(int drag);
00439                 double                                  _firstX;
00440                 double                          _firstY;
00441       bool                              _started;
00442       bool                              _mode;
00443 
00444                 Circle*                                 _circle;
00445 };
00446 
00447 
00450 class EditCircleTool : public BaseTool
00451 {
00452    public:
00453       // constructor and destructor
00454       EditCircleTool(ToolControl* controller);
00455       ~EditCircleTool();
00456                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00457                 void Draw();
00458       wxString  GetToolInfo();
00459       wxUnit GetRadius();
00460       void SetRadius(wxUnit& rad);
00461 
00462    protected:
00463                 void EvLeftDClick();
00464                 void EvDrag();
00465       void EvLD();
00466       void EvLU();
00467 
00468                 bool                            _moving;
00469 
00470       CircleditDialog*   m_circle_dlg;
00471 
00472                 Circle*                                 _circle;
00473                 Circle*                                 _circle_orig;
00474 };
00475 
00478 class EditRectangleTool : public BaseTool
00479 {
00480    public:
00481       // constructor and destructor
00482       EditRectangleTool(ToolControl* controller);
00483       ~EditRectangleTool();
00484                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00485                 void Draw();
00486       wxString  GetToolInfo();
00487 
00488    protected:
00489                 void EvLeftDClick();
00490                 void EvDrag();
00491       void EvLD();
00492       void EvLU();
00493 
00494                 bool                            _moving;
00495                 int                                     _movedpoint;
00496                 wxTransformMatrix*      _inverse_mapping;
00497                 double                          _prevX;
00498                 double                          _prevY;
00499 
00500                 Box*                                    _box;
00501                 Box*                                    _box_orig;
00502 };
00503 
00506 class EditImageTool : public BaseTool
00507 {
00508    public:
00509       // constructor and destructor
00510       EditImageTool(ToolControl* controller);
00511       ~EditImageTool();
00512                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00513                 void Draw();
00514       wxString  GetToolInfo();
00515 
00516    protected:
00517                 void EvLeftDClick();
00518                 void EvDrag();
00519       void EvLD();
00520       void EvLU();
00521 
00522                 bool                                _moving;
00523                 int                                      _movedpoint;
00524                 wxTransformMatrix* _inverse_mapping;
00525                 double                           _prevX;
00526                 double                           _prevY;
00527 
00528                 Image*                           _image;
00529                 Image*                           _image_orig;
00530 };
00531 
00534 class EditReferenceTool : public BaseTool
00535 {
00536    public:
00537       // constructor and destructor
00538       EditReferenceTool(ToolControl* controller);
00539       ~EditReferenceTool();
00540                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00541                 void Draw();
00542       wxString  GetToolInfo();
00543 
00544    protected:
00545                 void EvLeftDClick();
00546                 void EvDrag();
00547       void EvLD();
00548       void EvLU();
00549 
00550                 bool                                _moving;
00551                 int                                      _movedpoint;
00552                 wxTransformMatrix* _inverse_mapping;
00553                 double                           _prevX;
00554                 double                           _prevY;
00555 
00556                 StructureReference*                              _sref;
00557                 StructureReference*                              _sref_orig;
00558 };
00559 
00562 class EditPolyTool : public BaseTool
00563 {
00564    public:
00565       // constructor and destructor
00566       EditPolyTool(ToolControl* controller);
00567       ~EditPolyTool();
00568                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00569                 void  XorDrawMoveLines();
00570                 void  XorRemoveMoveLines();
00571                 void  AddPoint(double x,double y);
00572                 void    RemovePoint();
00573                 void Draw();
00574       wxString  GetToolInfo();
00575 
00576    protected:
00577                 void EvLeftDClick();
00578                 void EvDrag();
00579       void EvLD();
00580       void EvLU();
00581 
00582                 bool                            _moving;
00583 
00584                 Boundary*                       _boundary;
00585                 Boundary*                       _boundary_orig;
00586 
00587                 double                          _prevX;
00588                 double                          _prevY;
00589                 double                                  _XN;
00590                 double                          _YN;
00591                 double                          _XP;
00592                 double                          _YP;
00593            TDLI<Segment>*    _AI;
00594            Segment*             _PM;
00595 };
00596 
00599 class EditPolyLineTool : public BaseTool
00600 {
00601    public:
00602       // constructor and destructor
00603       EditPolyLineTool(ToolControl* controller);
00604       ~EditPolyLineTool();
00605                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00606                 void  XorDrawMoveLines();
00607                 void  XorRemoveMoveLines();
00608                 void  AddPoint(double x,double y);
00609                 void    RemovePoint();
00610                 void Draw();
00611       wxString  GetToolInfo();
00612 
00613    protected:
00614                 void EvLeftDClick();
00615                 void EvDrag();
00616       void EvLD();
00617       void EvLU();
00618 
00619                 bool                            _moving;
00620 
00621                 Path*                                   _path;
00622                 Path*                                   _path_orig;
00623 
00624                 double                          _prevX;
00625                 double                          _prevY;
00626                 double                                  _XN;
00627                 double                          _YN;
00628                 double                          _XP;
00629                 double                          _YP;
00630            TDLI<Segment>*    _AI;
00631            Segment*             _PM;
00632 };
00633 
00636 class EditLineTool : public BaseTool
00637 {
00638    public:
00639       // constructor and destructor
00640       EditLineTool(ToolControl* controller);
00641       ~EditLineTool();
00642                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00643                 void Draw();
00644       wxString  GetToolInfo();
00645 
00646    protected:
00647                 void EvLeftDClick();
00648                 void EvDrag();
00649       void EvLD();
00650       void EvLU();
00651 
00652                 bool                               _moving;
00653       bool              m_one;
00654 
00655                 SLine*                                  _line;
00656                 SLine*                                  _line_orig;
00657 };
00658 
00661 class EditPropertyTool : public BaseTool
00662 {
00663    public:
00664       // constructor and destructor
00665       EditPropertyTool(ToolControl* controller);
00666       ~EditPropertyTool();
00667                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00668                 void Draw();
00669       wxString  GetToolInfo();
00670 
00671    protected:
00672       void EvLD();
00673 };
00674 
00677 class DeleteTool : public BaseTool
00678 {
00679    public:
00680       // constructor and destructor
00681       DeleteTool(ToolControl* controller);
00682       ~DeleteTool();
00683                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00684                 void Draw();
00685       wxString  GetToolInfo();
00686 
00687    protected:
00688       void EvLD();
00689 
00690                 ElementList* _elemlst;
00691 };
00692 
00696 class EditTool : public BaseTool
00697 {
00698    public:
00699       // constructor and destructor
00700       EditTool(ToolControl* controller);
00701       ~EditTool();
00702                 bool IsAllowedTool(ToolSet tool_to_start_next,bool onlyonce,int tools_on_stack);
00703                 void Draw();
00704       wxString  GetToolInfo();
00705 
00706    protected:
00707       void EvLD();
00708       char       _unit[20];
00709       G_Polyline*               _polyline;
00710       bool                              _firstpoint;
00711       Line_Seg*         _segm;
00712                 Path*                                   _path;
00713       Circle*                           _circle;
00714       bool                              _started;
00715 };
00716 
00719 class InsertReferenceTool : public BaseTool
00720 {
00721    public:
00722       // constructor and destructor
00723       InsertReferenceTool(ToolControl* controller);
00724       ~InsertReferenceTool();
00725                 void Draw();
00726       void End();
00727       wxString  GetToolInfo();
00728 
00729    protected:
00730                 void     EvDrag();
00731       void   EvLD();
00732       void   EvLU();
00733       void   EvMove(int drag);
00734 };
00735 
00738 class InsertStructureTool : public BaseTool
00739 {
00740    public:
00741       // constructor
00742       InsertStructureTool(ToolControl* controller);
00743       // destructor
00744       ~InsertStructureTool();
00745                 void Draw();
00746       void End();
00747       wxString  GetToolInfo();
00748 
00749    protected:
00750                 void     EvDrag();
00751       void   EvLD();
00752       void   EvLU();
00753       void   EvMove(int drag);
00754 };
00755 #endif
00756 
tool.h Source File -- Thu Nov 28 21:24:56 2002 -- 28 Nov 2002 -- 1.2.18 -- -- . -- Main Page