00001 /*! \file wx/editor/edit.h 00002 \brief editing tool for a2dCanvasObject's 00003 \author Klaas Holwerda 00004 00005 Copyright: 2000-2004 (c) Klaas Holwerda 00006 00007 Licence: wxWidgets Licence 00008 00009 RCS-ID: $Id: edit.h,v 1.23 2009/06/03 17:38:13 titato Exp $ 00010 */ 00011 00012 #ifndef __WXCANEDITOBJ_H__ 00013 #define __WXCANEDITOBJ_H__ 00014 00015 #ifndef WX_PRECOMP 00016 #include "wx/wx.h" 00017 #endif 00018 00019 #include "wx/canvas/canmod.h" 00020 00021 #include "wx/editor/sttool.h" 00022 00023 //---------------------------------------------------------------------------- 00024 // decls 00025 //---------------------------------------------------------------------------- 00026 00027 class a2dCanvas; 00028 class a2dCanvasDocument; 00029 class a2dLayers; 00030 00031 //!This tool is for editing a single object. 00032 /*! 00033 The object its EditStart member is called, this generates a Clone of the object 00034 to be edited. And event processing is redirected to the Cloned object to edit it. 00035 00036 The cloned edit copy, issues commands to the command processor of the document, and this changes 00037 the original a2dCanvasObject that is being edited. 00038 This then changes to make it in sync with editing clone. 00039 Undo is possible because of this, but it is possible to not use commands and choose to directly 00040 modify the original object. 00041 00042 After editing is done a double click will call the EditEnd member of the a2dCanvasObject. 00043 In the end the Cloned editing object is Released. 00044 00045 If SetSingleClickToEnd() is set, a Left Down mouse event outside the object being edited, 00046 also stops editing of the current object, and if subediting it even ends this tool. 00047 This makes it easy to go to sublevel editing and back with just one click. 00048 00049 The object itself is in control of all editing facilities of that specific object. 00050 This might mean that other tools will be pushed on the tool stack, for editing of subobjects. 00051 00052 The EditStart member initializes the a2dCanvasObject for editing, but only if editing is allowed by it. 00053 00054 The editing Clone will have as children editing handles, which can be dragged in order to modify the object. 00055 Those handles depend on the object its editing implementation. 00056 Rendering of the Cloned editing object can be changed on the basis of the m_editingCopy flag if needed. 00057 00058 The default editing functionality of a2dCanvasObject, is just editing its local matrix. 00059 00060 The TAB charecter should be used to switch between this mode and the object specific editing mode. 00061 00062 Adding editing functionality to an object is implemented by intercepting events using a static event table. 00063 When the m_editingCopy is set, we know it is the cloned edit copy we are dealing with. 00064 The events in this case should be handled in such a manner that the edit clone and the original object 00065 will be modified. 00066 Hits on child objects of the editing clone ( e.g a2dHandle ), may generate new events for 00067 the editng clone object itself. a2dHandleMouseEvent is such an event. You can intercept this event 00068 in the parent event table like this EVT_CANVASHANDLE_MOUSE_EVENT( OnHandleEvent ). 00069 In the OnHandleEvent you can define what change a specific handle will have on the object that is edited. 00070 00071 \ingroup tools 00072 */ 00073 class A2DEDITORDLLEXP a2dObjectEditTool: public a2dStTool 00074 { 00075 public: 00076 00077 //! push this tool on the tools stack 00078 /*! \ingroup commandid 00079 */ 00080 static const a2dCommandId COMID_PushTool_ObjectEdit; 00081 00082 //! when starting editing an object, this event is sent to tool 00083 static const wxEventType sm_toolStartEditObject; 00084 00085 //! constructor 00086 /*! 00087 \param controller controller to which the editing tool was pushed. 00088 \param editmode starting editing mode for objects 00089 \param SingleClickToEnd stop editing with a single Left Down, else double click. 00090 */ 00091 a2dObjectEditTool( a2dStToolContr* controller, int editmode = 1, bool SingleClickToEnd = true ); 00092 00093 //! constructor 00094 /*! 00095 \param controller controller to which the editing tool was pushed. 00096 \param ic iteration context to setup the corridor 00097 \param editmode starting editing mode for objects 00098 \param SingleClickToEnd stop editing with a single Left Down, else double click. 00099 */ 00100 a2dObjectEditTool( a2dStToolContr* controller, a2dIterC& ic, int editmode = 1, bool SingleClickToEnd = true ); 00101 00102 //! destuctor 00103 ~a2dObjectEditTool(); 00104 00105 //! start editing object within the given iteration context its coordinate system 00106 /*! 00107 Start editing the object within the coordinate system defined by ic (iterative context). 00108 Parent of startobject is defined in ic. 00109 00110 The ic is used to calculate the editworld matrix, meaning relative to what coordinates system 00111 the editing takes place. This becomes important when editing children of objects directly. 00112 00113 \remark at the top level (ShowObject of view) the editorWorld is always a2dIDENTITY_MATRIX 00114 else it depends on the structure of the document. 00115 */ 00116 bool SetContext( a2dIterC& ic, a2dCanvasObject* startObject ); 00117 00118 //! start editing this object 00119 void StartToEdit( a2dCanvasObject* startObject ); 00120 00121 //! restart editing (after undo event or when changing editing mode ) 00122 bool ReStartEdit( wxUint16 editmode ); 00123 00124 //! trigger restart editing (after undo event or when changing editing mode ) 00125 virtual void TriggerReStartEdit( wxUint16 editmode ); 00126 00127 //! save to zoom 00128 bool ZoomSave(){ return true;}; 00129 00130 //! set editing mode to start editing objects 00131 void SetMode( int mode ); 00132 00133 //! used extarnal by controller to activate or deactivate this tool. 00134 /*! If deactivated this tool, m_halted is set true. */ 00135 void SetActive(bool active); 00136 00137 //! a single non hit Left Down click is enough to end editing of an object. 00138 /*! If set false, a double click is needed. */ 00139 void SetSingleClickToEnd( bool SingleClickToEnd ) { m_SingleClickToEnd = SingleClickToEnd; } 00140 00141 //! when set true, other views on the document are disabled when editing a object. 00142 /*! 00143 This option is default set true, this prevents from showing editing handles in other views while 00144 editing an object in a view. 00145 */ 00146 void SetDisableOtherViews( bool disableOtherViews ) { m_disableOtherViews = disableOtherViews; } 00147 00148 void Render(); 00149 00150 00151 protected: 00152 00153 //! To stop this tools from inside or from the outside, sets m_stop = true 00154 /*! The a2dStToolContr will test this with GetStopTool() */ 00155 void DoStopTool( bool abort ); 00156 00157 void OnUndoEvent( a2dCommandProcessorEvent& WXUNUSED(event) ); 00158 00159 void OnRedoEvent( a2dCommandProcessorEvent& event ); 00160 00161 void OnKeyDown(wxKeyEvent& event); 00162 00163 void OnKeyUp(wxKeyEvent& event); 00164 00165 void OnChar(wxKeyEvent& event); 00166 00167 virtual void AdjustRenderOptions(); 00168 virtual bool EnterBusyMode(); 00169 virtual void FinishBusyMode(); 00170 virtual void AbortBusyMode(); 00171 00172 //! send an event with id sm_toolComEventSetEditObject to this tool. 00173 /*! 00174 Use this event to do actions when a specific object was clicked for editing. 00175 */ 00176 void SetEditObject( a2dCanvasObject* objectToEdit ); 00177 00178 //! redirect event to editng object or to a captured object ( handle or object itself. ) 00179 /*! return if event is processed or not. */ 00180 bool RedirectToEditObject( wxMouseEvent& event ); 00181 00182 //! start editing at m_canvasobject 00183 virtual bool CreateToolObjects(); 00184 00185 //! stop editing of m_canvasobject if busy editing 00186 virtual void CleanupToolObjects(); 00187 00188 void OnIdle( wxIdleEvent &event ); 00189 00190 void OnComEvent( a2dComEvent& event ); 00191 00192 void OnMouseEvent(wxMouseEvent& event); 00193 00194 void OnDoEvent( a2dCommandProcessorEvent& event ); 00195 00196 virtual wxString GetCommandGroupName() { return _("Edit object"); } 00197 00198 //! preserve the a2dCANVAS_SELECT flag after editing. 00199 bool m_preserve_select; 00200 00201 //! a single non hit Left Down click is enough to end editing of an object. 00202 bool m_SingleClickToEnd; 00203 00204 bool m_disableOtherViews; 00205 00206 bool m_triggerRestart; 00207 00208 //! List of wires connected to the draged object 00209 a2dCanvasObjectList m_connectedwirecopies; 00210 00211 public: 00212 DECLARE_CLASS(a2dObjectEditTool) 00213 A2D_DECLARE_EVENT_TABLE() 00214 00215 }; 00216 00217 00218 //!This tool does do a hit test on objects to edit, and then starts editing the object. 00219 /*! 00220 When an object is hit, the object its EditStart member is called, this generates a Clone of the object 00221 to be edited. And event processing is redirected to the Cloned object to edit it. 00222 00223 See a2dObjectEditTool for more details on editing. 00224 00225 \ingroup tools 00226 */ 00227 class A2DEDITORDLLEXP a2dRecursiveEditTool: public a2dObjectEditTool 00228 { 00229 public: 00230 00231 //! push this tool on the tools stack 00232 /*! \ingroup commandid 00233 */ 00234 static const a2dCommandId COMID_PushTool_RecursiveEdit; 00235 00236 //! constructor 00237 /*! 00238 \param controller controller to which the editing tool was pushed. 00239 \param editmode starting editing mode for objects 00240 \param SingleClickToEnd stop editing with a single Left Down, else double click. 00241 */ 00242 a2dRecursiveEditTool( a2dStToolContr* controller, int editmode = 1, bool SingleClickToEnd = true ); 00243 00244 //! constructor 00245 /*! 00246 \param controller controller to which the editing tool was pushed. 00247 \param ic iteration context to setup the corridor 00248 \param editmode starting editing mode for objects 00249 \param SingleClickToEnd stop editing with a single Left Down, else double click. 00250 */ 00251 a2dRecursiveEditTool( a2dStToolContr* controller, a2dIterC& ic, int editmode = 1, bool SingleClickToEnd = true ); 00252 00253 //! destuctor 00254 ~a2dRecursiveEditTool(); 00255 00256 protected: 00257 00258 void OnComEvent( a2dComEvent& event ); 00259 00260 void OnMouseEvent(wxMouseEvent& event); 00261 00262 virtual wxString GetCommandGroupName() { return _("Edit"); } 00263 00264 public: 00265 DECLARE_CLASS(a2dRecursiveEditTool) 00266 A2D_DECLARE_EVENT_TABLE() 00267 00268 }; 00269 00270 //!This tool does do a hit test on objects to edit, and then starts editing the object. 00271 /*! 00272 When an object is hit, the object its EditStart member is called, and event processing is redirected to the 00273 object to edit. 00274 The EditStart member sets the m_editing flag and initializes the a2dCanvasObject for editing. 00275 This normally means adding handles which can be dragged in order to modify the object. 00276 Rendering can also be chnaged on the basis of the m_editing flag if needed. 00277 The default editing functionality is just editing the a2dCanvasObject its local matrix. 00278 The TAB charecter should be used to switch between this mode and the object specific editing mode. 00279 There are several modes to edit an object, the main mode makes a copy of the object first and editing takes 00280 place on that copy. Updating the original object when needed. 00281 After editing is done a double click will call the EditEnd member of the object. 00282 Adding editing functionality to an object is implemented by intercepting event using a static event table. 00283 When the m_editing of a a2dCanvasObject is set, the events are handled in such a maner that the object will be modified. 00284 00285 \ingroup tools 00286 */ 00287 class A2DEDITORDLLEXP a2dMultiEditTool: public a2dObjectEditTool 00288 { 00289 public: 00290 00291 //! push this tool on the tools stack 00292 /*! \ingroup commandid 00293 */ 00294 static const a2dCommandId COMID_PushTool_MultiEdit; 00295 00296 a2dMultiEditTool(a2dStToolContr* controller ); 00297 ~a2dMultiEditTool(); 00298 00299 bool ZoomSave(){ return true;}; 00300 00301 void OnChar(wxKeyEvent& event); 00302 00303 //! start editing object 00304 bool StartEditing( a2dCanvasObject* startobject ); 00305 00306 bool StartEditingSelected(); 00307 00308 void SetActive(bool active); 00309 00310 bool AddToGroup( a2dCanvasObject* canvasobject ); 00311 00312 bool RemoveFromGroup( a2dCanvasObject* canvasobject, int index = 0 ); 00313 00314 protected: 00315 00316 void DoStopTool( bool abort ); 00317 00318 bool RedirectToEditObject( wxMouseEvent& event ); 00319 00320 bool EditStart(); 00321 00322 void CleanupToolObjects(); 00323 00324 void OnIdle( wxIdleEvent &event ); 00325 00326 void OnComEvent( a2dComEvent& event ); 00327 00328 void OnMouseEvent(wxMouseEvent& event); 00329 00330 void OnUndoEvent( a2dCommandProcessorEvent& event ); 00331 00332 void OnRedoEvent( a2dCommandProcessorEvent& event ); 00333 00334 //! this is intentioanally not a smart pointer (would create a reference loop) 00335 a2dCanvasDocument* m_doc; 00336 00337 public: 00338 DECLARE_CLASS(a2dMultiEditTool) 00339 A2D_DECLARE_EVENT_TABLE() 00340 00341 }; 00342 00343 00344 00345 #endif /* __WXCANEDITOBJ_H__ */ 00346 00347