00001 /*! \file wx/editor/sttool2.h 00002 \brief stack based tools for drawing and editing in a faster manner, but with less document feedback. 00003 00004 Tools here are drawn directly via the drawing context, and not by first adding them to the document. 00005 This makes certain feadback drawing from the document impossible, but is much faster. 00006 00007 \author Klaas Holwerda 00008 00009 Copyright: 2001-2004 (c) Klaas Holwerda 00010 00011 Licence: wxWidgets Licence 00012 00013 RCS-ID: $Id: sttool2.h,v 1.15 2009/05/31 23:37:29 titato Exp $ 00014 */ 00015 00016 #ifndef __A2DSTTOOL2_H__ 00017 #define __A2DSTTOOL2_H__ 00018 00019 #ifndef WX_PRECOMP 00020 #include "wx/wx.h" 00021 #endif 00022 00023 #include <wx/listimpl.cpp> 00024 00025 #include "wx/editor/sttool.h" 00026 00027 //! base for tools that draw and are stack based. 00028 class A2DEDITORDLLEXP a2dStDrawToolFast: public a2dStDrawTool 00029 { 00030 public: 00031 //!\param controller Pointer to a a2dStToolContr controller. 00032 a2dStDrawToolFast(a2dStToolContr* controller); 00033 00034 //!destructor 00035 virtual ~a2dStDrawToolFast(); 00036 00037 //! template adepts to style change from outside or not 00038 void SetAllowModifyTemplate( bool allowModifyTemplate ) { m_AllowModifyTemplate = allowModifyTemplate; } 00039 00040 //! template adepts to style change from outside or not 00041 bool GetAllowModifyTemplate() { return m_AllowModifyTemplate; } 00042 00043 00044 protected: 00045 00046 //!Create the editcopy and other tool objects (e.g. decorations) 00047 /*! m_original must be set before this function is called */ 00048 virtual bool CreateToolObjects(); 00049 virtual void CleanupToolObjects(); 00050 void Render(); 00051 00052 public: 00053 00054 DECLARE_CLASS(a2dStDrawToolFast) 00055 A2D_DECLARE_EVENT_TABLE() 00056 }; 00057 00058 00059 //!Interactive Zooming. 00060 /*! Use mouse to drag a rectangle to zoom into area. 00061 00062 \remark Left Click and/or drag. 00063 \remark Right Click for zoom popup. 00064 \remark Double Left Click for zoom out. 00065 00066 \sa a2dStToolContr 00067 00068 \ingroup tools 00069 */ 00070 class A2DEDITORDLLEXP a2dZoomFast: public a2dStTool 00071 { 00072 public: 00073 00074 //! push this tool on the tools stack 00075 /*! \ingroup commandid 00076 */ 00077 static const a2dCommandId COMID_PushTool_ZoomFast; 00078 00079 //! constructor 00080 a2dZoomFast(a2dStToolContr* controller); 00081 00082 //! constructor 00083 a2dZoomFast( const a2dZoomFast& other, CloneOptions options ); 00084 00085 //! destructor 00086 ~a2dZoomFast(); 00087 00088 00089 virtual a2dObject* Clone( CloneOptions options = clone_deep ) const; 00090 00091 bool ZoomSave(){return true;}; 00092 00093 bool m_draggingCanvas; 00094 00095 protected: 00096 00097 virtual void GenerateAnotation(); 00098 void Render(); 00099 00100 //! character handling 00101 void OnChar(wxKeyEvent& event); 00102 00103 void OnMouseEvent(wxMouseEvent& event); 00104 00105 virtual wxString GetCommandGroupName() { return _("Zoom objects"); } 00106 00107 public: 00108 00109 DECLARE_CLASS(a2dZoomFast) 00110 A2D_DECLARE_EVENT_TABLE() 00111 00112 }; 00113 00114 00115 //!Interactive Selection of an Object. 00116 /*!Either with just one click or draging a rectangle to select many. 00117 00118 \remark Left Click and/or drag. 00119 \remark Shift Down to Un select. 00120 00121 \sa a2dStToolContr 00122 00123 */ 00124 class A2DEDITORDLLEXP a2dFastSelect: public a2dStTool 00125 { 00126 public: 00127 00128 //! push this tool on the tools stack 00129 /*! \ingroup commandid 00130 */ 00131 static const a2dCommandId COMID_PushTool_FastSelect; 00132 00133 a2dFastSelect(a2dStToolContr* controller); 00134 ~a2dFastSelect(); 00135 bool ZoomSave(){return true;}; 00136 void SetShiftIsAdd() { m_shift_is_add = true; } 00137 00138 protected: 00139 void DeselectAll(); 00140 00141 virtual void GenerateAnotation(); 00142 00143 //! character handling 00144 void OnChar(wxKeyEvent& event); 00145 00146 void OnMouseEvent(wxMouseEvent& event); 00147 00148 void Render(); 00149 00150 virtual wxString GetCommandGroupName() { return _("Fast Select objects"); } 00151 00152 public: 00153 00154 DECLARE_CLASS(a2dFastSelect) 00155 A2D_DECLARE_EVENT_TABLE() 00156 00157 //! false: shift key will unselect, true: shift will add to selection 00158 bool m_shift_is_add; 00159 00160 }; 00161 00162 //!Interactive (De)selection Selection of an Object(s). 00163 /*!Either with just one click or dragging a rectangle to (de)select many. 00164 00165 \remark Left Click and/or drag. 00166 00167 \sa a2dStToolContr 00168 00169 */ 00170 class A2DEDITORDLLEXP a2dFastSelect2: public a2dStTool 00171 { 00172 public: 00173 00174 //! push this tool on the tools stack 00175 /*! \ingroup commandid 00176 */ 00177 static const a2dCommandId COMID_PushTool_FastSelect2; 00178 00179 a2dFastSelect2(a2dStToolContr* controller); 00180 ~a2dFastSelect2(); 00181 bool ZoomSave(){return true;}; 00182 00183 //! if set true selection is done, when false it is deselect. 00184 void SetSelectMode( bool select) { m_selectMode = select; } 00185 00186 protected: 00187 00188 void SelectAll( bool select ); 00189 00190 virtual void GenerateAnotation(); 00191 00192 //! character handling 00193 void OnChar(wxKeyEvent& event); 00194 00195 void OnMouseEvent(wxMouseEvent& event); 00196 00197 virtual wxString GetCommandGroupName() { return _("Fast Select objects"); } 00198 00199 public: 00200 00201 DECLARE_CLASS(a2dFastSelect2) 00202 A2D_DECLARE_EVENT_TABLE() 00203 00204 bool m_selectMode; 00205 00206 }; 00207 00208 //!Drag Selected canvasObjects 00209 /*! \sa a2dStToolContr 00210 \ingroup tools 00211 */ 00212 class A2DEDITORDLLEXP a2dFastDragMultiTool: public a2dStTool 00213 { 00214 public: 00215 00216 //! push this tool on the tools stack 00217 /*! \ingroup commandid 00218 */ 00219 static const a2dCommandId COMID_PushTool_FastDragMulti; 00220 00221 a2dFastDragMultiTool(a2dStToolContr* controller); 00222 ~a2dFastDragMultiTool(); 00223 bool ZoomSave(){ return !GetBusy(); }; 00224 00225 void SetMode( int mode ); 00226 00227 protected: 00228 00229 void GenerateAnotation(); 00230 00231 void OnChar(wxKeyEvent& event); 00232 00233 void OnMouseEvent(wxMouseEvent& event); 00234 00235 void OnIdle( wxIdleEvent &event ); 00236 00237 virtual bool EnterBusyMode(); 00238 virtual void FinishBusyMode(); 00239 virtual void AbortBusyMode(); 00240 00241 //!redirect all mouse events for the canvas to this object 00242 void CaptureMouse(); 00243 //!release the mouse capture for this object 00244 void ReleaseMouse(); 00245 00246 //!called for incremental keyboard shifts 00247 virtual void DragRelative( double x, double y ); 00248 //!render in drag style 00249 virtual void Render(); 00250 //!This is overriden by copy tools to have a minimum distance between original and copy 00251 virtual void AdjustShift( double *x, double *y ); 00252 00253 virtual wxString GetCommandGroupName() { return _("Move multiple objects") ; } 00254 virtual bool CreateToolObjects(); 00255 virtual void CleanupToolObjects(); 00256 00257 //!the list of selected objects 00258 a2dCanvasObjectList m_objects; 00259 a2dCanvasObjectList m_copies; 00260 00261 double m_startObjectx; 00262 double m_startObjecty; 00263 double m_startMousexw; 00264 double m_startMouseyw; 00265 00266 public: 00267 DECLARE_CLASS(a2dFastDragMultiTool) 00268 A2D_DECLARE_EVENT_TABLE() 00269 00270 }; 00271 00272 //!Drag and Copy Selected canvasObjects 00273 /*!\sa a2dStToolContr 00274 \ingroup tools 00275 */ 00276 class A2DEDITORDLLEXP a2dFastCopyMultiTool: public a2dFastDragMultiTool 00277 { 00278 public: 00279 00280 //! push this tool on the tools stack 00281 /*! \ingroup commandid 00282 */ 00283 static const a2dCommandId COMID_PushTool_FastCopyMulti; 00284 00285 a2dFastCopyMultiTool(a2dStToolContr* controller); 00286 00287 protected: 00288 00289 void OnChar(wxKeyEvent& event); 00290 00291 void OnMouseEvent(wxMouseEvent& event); 00292 00293 void FinishBusyMode(); 00294 00295 void AdjustShift( double *x, double *y ); 00296 00297 virtual wxString GetCommandGroupName() { return _("Copy multiple objects") ; } 00298 00299 // minimum distance of the copy from the original 00300 double m_mindist; 00301 public: 00302 DECLARE_CLASS(a2dFastCopyMultiTool) 00303 A2D_DECLARE_EVENT_TABLE() 00304 00305 }; 00306 00307 //!Interactive drawing of a Rectangle. 00308 /*! 00309 \remark Left Click and drag. 00310 \remark Cursor keys to shift object. 00311 \remark Or Spacebar to end rectangle. 00312 00313 \sa a2dStToolContr 00314 00315 \ingroup tools 00316 */ 00317 class A2DEDITORDLLEXP a2dDrawRectangleToolFast: public a2dStDrawToolFast 00318 { 00319 public: 00320 00321 //! push this tool on the tools stack 00322 /*! \ingroup commandid 00323 */ 00324 static const a2dCommandId COMID_PushTool_DrawRectangleFast; 00325 00326 a2dDrawRectangleToolFast(a2dStToolContr* controller); 00327 ~a2dDrawRectangleToolFast(); 00328 00329 void SetRadius(double radius) { m_radius = radius; } 00330 00331 bool ZoomSave(){ return true; } 00332 00333 protected: 00334 00335 void OnComEvent( a2dComEvent& event ); 00336 00337 void OnMouseEvent(wxMouseEvent& event); 00338 00339 virtual wxString GetCommandGroupName() { return _("Draw Rectangle Fast"); } 00340 00341 bool CreateToolObjects(); 00342 00343 double m_radius; 00344 double m_xwlast; 00345 double m_ywlast; 00346 bool m_didDraw; 00347 00348 public: 00349 DECLARE_CLASS(a2dDrawRectangleToolFast) 00350 A2D_DECLARE_EVENT_TABLE() 00351 00352 }; 00353 00354 //!Interactive drawing of a Circle. 00355 /*! 00356 \remark Left Click and drag. 00357 \remark Cursor keys to shift object. 00358 \remark Or Spacebar to end line. 00359 00360 \sa a2dStToolContr 00361 */ 00362 class A2DEDITORDLLEXP a2dDrawCircleToolFast: public a2dStDrawToolFast 00363 { 00364 public: 00365 00366 //! push this tool on the tools stack 00367 /*! \ingroup commandid 00368 */ 00369 static const a2dCommandId COMID_PushTool_DrawCircleFast; 00370 00371 a2dDrawCircleToolFast(a2dStToolContr* controller); 00372 bool ZoomSave(){ return true;}; 00373 00374 void SetMode( int mode ); 00375 00376 protected: 00377 00378 //! tool specific statusbar 00379 void OnComEvent( a2dComEvent& event ); 00380 00381 void OnChar(wxKeyEvent& event); 00382 00383 void OnMouseEvent(wxMouseEvent& event); 00384 00385 bool CreateToolObjects(); 00386 00387 double m_start_x; 00388 double m_start_y; 00389 double m_radius; 00390 00391 public: 00392 DECLARE_CLASS(a2dDrawCircleToolFast) 00393 A2D_DECLARE_EVENT_TABLE() 00394 00395 }; 00396 00397 //!Interactive drawing of a polygon. 00398 /*! 00399 \remark Left Click to add points. 00400 \remark Space bar or Double click to end drawing. 00401 \remark Cursor keys to shift object. 00402 \remark Cursor keys + control to shift point. 00403 \remark Right Click to zoom. 00404 00405 \sa a2dStToolContr 00406 00407 \ingroup tools 00408 */ 00409 class A2DEDITORDLLEXP a2dDrawPolygonLToolFast: public a2dStDrawToolFast 00410 { 00411 public: 00412 00413 //! push this tool on the tools stack 00414 /*! \ingroup commandid 00415 */ 00416 static const a2dCommandId COMID_PushTool_DrawPolygonLFast; 00417 //! push this tool on the tools stack 00418 /*! \ingroup commandid 00419 */ 00420 static const a2dCommandId COMID_PushTool_DrawPolygonLFast_Splined; 00421 00422 //! constructor 00423 /*! 00424 \param controller tool controller one which this tool is pushed. 00425 \param templateObject when not NULL, this object is cloned and used for the new drawn object. 00426 */ 00427 a2dDrawPolygonLToolFast(a2dStToolContr* controller, a2dPolygonL* templateObject = NULL ); 00428 00429 ~a2dDrawPolygonLToolFast(); 00430 00431 //! save to zoom while drawing 00432 bool ZoomSave(){ return true;}; 00433 00434 //! mode of drawing, can be swicthed with Tab key. 00435 void SetMode( int mode ); 00436 00437 //!certain drawing tools like polygon drawing use this setting 00438 /*! You might want to reset m_newObjectsGetCommandProcStyle also. 00439 Otherwise the command processor will overwrite what you set here 00440 */ 00441 void SetSpline(bool spline); 00442 00443 //!certain drawing tools like polygon drawing use this setting 00444 bool GetSpline(){return m_spline;} 00445 00446 protected: 00447 00448 void OnIdle( wxIdleEvent &event ); 00449 00450 void OnChar(wxKeyEvent& event); 00451 00452 void OnMouseEvent(wxMouseEvent& event); 00453 00454 void OnUndoEvent( a2dCommandProcessorEvent& event ); 00455 void OnRedoEvent( a2dCommandProcessorEvent& event ); 00456 00457 bool CreateToolObjects(); 00458 00459 void AddPoint( a2dLineSegment* point ); 00460 00461 virtual wxString GetCommandGroupName() { return _("Draw polygon") ; } 00462 00463 //! object to clone to use as start 00464 a2dSmrtPtr<a2dPolygonL> m_templateObject; 00465 00466 //! previous x 00467 double m_prev_x; 00468 //! previous y 00469 double m_prev_y; 00470 00471 //! points sofar 00472 a2dVertexList* m_points; 00473 00474 //! last point 00475 a2dLineSegment* m_point; 00476 00477 //! spline polygons 00478 bool m_spline; 00479 00480 //! end to begin wire. 00481 bool m_reverse; 00482 00483 public: 00484 DECLARE_CLASS(a2dDrawPolygonLToolFast) 00485 A2D_DECLARE_EVENT_TABLE() 00486 00487 }; 00488 00489 //!Interactive drawing of a polyline. 00490 /*! 00491 \remark Left Click to add points. 00492 \remark Space bar or Double click to end drawing. 00493 \remark Cursor keys to shift object. 00494 \remark Cursor keys + control to shift point. 00495 \remark Right Click to zoom. 00496 00497 \sa a2dStToolContr 00498 00499 \ingroup tools 00500 */ 00501 class A2DEDITORDLLEXP a2dDrawPolylineLToolFast: public a2dDrawPolygonLToolFast 00502 { 00503 public: 00504 00505 //! push this tool on the tools stack 00506 /*! \ingroup commandid 00507 */ 00508 static const a2dCommandId COMID_PushTool_DrawPolylineLFast; 00509 //! push this tool on the tools stack 00510 /*! \ingroup commandid 00511 */ 00512 static const a2dCommandId COMID_PushTool_DrawPolylineLFast_Splined; 00513 00514 //! constructor 00515 /*! 00516 \param controller tool controller one which this tool is pushed. 00517 \param templateObject when not NULL, this object is cloned and used for the new drawn object. 00518 */ 00519 a2dDrawPolylineLToolFast(a2dStToolContr* controller, a2dPolylineL* templateObject = NULL ); 00520 00521 ~a2dDrawPolylineLToolFast(); 00522 00523 //!defines line begin object for line and polyline drawing tools 00524 /*! You might want to reset m_newObjectsGetCommandProcStyle also. 00525 Otherwise the command processor will overwrite what you set here 00526 */ 00527 void SetLineBegin(a2dCanvasObject* begin); 00528 00529 //!defines line end object for line and polyline drawing tools 00530 /*! You might want to reset m_newObjectsGetCommandProcStyle also. 00531 Otherwise the command processor will overwrite what you set here 00532 */ 00533 void SetLineEnd(a2dCanvasObject* end); 00534 00535 //!get current line begin object for line and polyline drawing tools. 00536 /*!\return Null if not set. */ 00537 a2dCanvasObject* GetLineBegin(){return m_begin;} 00538 00539 //!get current line end object for line and polyline drawing tools 00540 /*!return: Null if not set. */ 00541 a2dCanvasObject* GetLineEnd(){return m_end;} 00542 00543 //!scaling in X for begin and end objects of linres and polylines 00544 void SetEndScaleX(double xs) { m_xscale = xs; } 00545 00546 //!scaling in Y for begin and end objects of linres and polylines 00547 void SetEndScaleY(double ys) { m_yscale = ys; } 00548 00549 //!get scaling in X for begin and end objects of lines and polylines 00550 double GetEndScaleX(){return m_xscale;} 00551 00552 //!get scaling in Y for begin and end objects of lines and polylines 00553 double GetEndScaleY(){return m_yscale;} 00554 00555 //! Set when m_contourwidth != 0 what is the end of the line should be. 00556 void SetPathType( a2dPATH_END_TYPE pathtype ); 00557 00558 //! get when m_contourwidth != 0 what is the end of the line looks like. 00559 a2dPATH_END_TYPE GetPathType() { return m_pathtype; } 00560 00561 protected: 00562 00563 bool CreateToolObjects(); 00564 00565 void OnMouseEvent(wxMouseEvent& event); 00566 00567 void OnDoEvent( a2dCommandProcessorEvent& event ); 00568 00569 //! begin point object for lines and polylines 00570 a2dCanvasObjectPtr m_begin; 00571 00572 //! end point object for lines and polylines 00573 a2dCanvasObjectPtr m_end; 00574 00575 //!begin point scaling 00576 double m_xscale; 00577 00578 //!end point scaling 00579 double m_yscale; 00580 00581 //! when m_contourwidth != 0 what is the end of the line looking like. 00582 a2dPATH_END_TYPE m_pathtype; 00583 00584 public: 00585 DECLARE_CLASS(a2dDrawPolylineLToolFast) 00586 A2D_DECLARE_EVENT_TABLE() 00587 00588 }; 00589 00590 #endif /* __A2DSTTOOL2_H__ */ 00591 00592 00593