wxArt2D
cancom.h
1 /*! \file wx/canvas/cancom.h
2  \brief a2dCanvasCommandProcessor for do, undo and redo changes in a a2dCanvasDocument
3 
4  Each specific Command to change a document is wrapped into class. This class knows what to do,
5  in order to make the change to the document. The command procesor recieves such a command, stores
6  in the undo stack and tells it to do the command. Undo-ing is reversing the change done,
7  which the command class is able to do, since it stores the situation before the change, or it knows
8  how to get back in that state.
9 
10  \author Klaas Holwerda
11 
12  Copyright: 2000-2004 (c) Klaas Holwerda
13 
14  Licence: wxWidgets Licence
15 
16  RCS-ID: $Id: cancom.h,v 1.89 2009/10/01 19:22:35 titato Exp $
17 */
18 
19 #ifndef __WXCANCOM_H__
20 #define __WXCANCOM_H__
21 
22 #ifndef WX_PRECOMP
23 #include "wx/wx.h"
24 #endif
25 
26 #include "wx/cmdproc.h"
27 
28 #include "wx/canvas/canmod.h"
29 #include "wx/canextobj/imageioh.h"
30 #include "wx/editor/orderdlg.h"
31 #include "wx/editor/candoc.h"
32 #include "wx/docview/doccom.h"
33 #include <wx/tokenzr.h>
34 #include <wx/uri.h>
35 #include <wx/numdlg.h>
36 
37 #if wxART2D_USE_GDSIO
38 #include "wx/gdsio/gdsio.h"
39 #endif //wxART2D_USE_GDSIO
40 
41 #if wxART2D_USE_KEYIO
42 #include "wx/keyio/keyio.h"
43 #endif //wxART2D_USE_KEYIO
44 
45 class a2dCoordinateEntry;
46 
47 class A2DEDITORDLLEXP ExecDlg;
48 
49 class A2DEDITORDLLEXP a2dCentralCanvasCommandProcessor;
50 class A2DEDITORDLLEXP a2dPropertyEditorDlg;
51 class A2DEDITORDLLEXP a2dCanvasObjectsDocDialog;
52 
53 #define CMDP (((a2dCanvasDocument*)GetCurrentDocument())->GetCanvasCommandProcessor())
54 
55 DECLARE_MENU_ITEMID( CmdMenu_GdsIoSaveTextAsPolygon )
56 DECLARE_MENU_ITEMID( CmdMenu_KeyIoSaveTextAsPolygon )
57 DECLARE_MENU_ITEMID( CmdMenu_SetGdsIoSaveFromView )
58 DECLARE_MENU_ITEMID( CmdMenu_SetKeyIoSaveFromView )
59 
60 DECLARE_MENU_ITEMID( CmdMenu_SaveLayers )
61 DECLARE_MENU_ITEMID( CmdMenu_SaveLayersHome )
62 DECLARE_MENU_ITEMID( CmdMenu_SaveLayersLastDir )
63 DECLARE_MENU_ITEMID( CmdMenu_SaveLayersCurrentDir )
64 DECLARE_MENU_ITEMID( CmdMenu_LoadLayers )
65 DECLARE_MENU_ITEMID( CmdMenu_LoadLayersHome )
66 DECLARE_MENU_ITEMID( CmdMenu_LoadLayersLastDir )
67 DECLARE_MENU_ITEMID( CmdMenu_LoadLayersCurrentDir )
68 
69 DECLARE_MENU_ITEMID( CmdMenu_GdsIoSaveFromView )
70 DECLARE_MENU_ITEMID( CmdMenu_KeyIoSaveFromView )
71 DECLARE_MENU_ITEMID( CmdMenu_SetLayersProperty )
72 
73 DECLARE_MENU_ITEMID( CmdMenu_ShowDlgLayers )
74 DECLARE_MENU_ITEMID( CmdMenu_ShowDlgStructureDocument )
75 DECLARE_MENU_ITEMID( CmdMenu_ShowDlgStructureDocumentModal )
76 DECLARE_MENU_ITEMID( CmdMenu_ShowDlgLayersDocument )
77 DECLARE_MENU_ITEMID( CmdMenu_ShowDlgLayerOrderDocument )
78 
79 DECLARE_MENU_ITEMID( CmdMenu_ViewAsImage )
80 DECLARE_MENU_ITEMID( CmdMenu_ViewAsImage_Png )
81 DECLARE_MENU_ITEMID( CmdMenu_ViewAsImage_Bmp )
82 DECLARE_MENU_ITEMID( CmdMenu_ViewAsSvg )
83 
84 DECLARE_MENU_ITEMID( CmdMenu_DocumentAsImage_Png )
85 DECLARE_MENU_ITEMID( CmdMenu_DocumentAsImage_Bmp )
86 DECLARE_MENU_ITEMID( CmdMenu_DocumentAsOdbXml )
87 
88 DECLARE_MENU_ITEMID( CmdMenu_PushTool_Link_OneShot )
89 DECLARE_MENU_ITEMID( CmdMenu_PushTool_Link )
90 DECLARE_MENU_ITEMID( CmdMenu_PushTool_FollowLinkDocDrawCam )
91 DECLARE_MENU_ITEMID( CmdMenu_PushTool_Master3Link )
92 
93 
94 //! a command wrapper specially designed to work with wxArt2D docview classes and rest.
95 /*!
96  This class wraps command string into functions for a a2dDocumentCommandProcessor.
97 
98  \ingroup tools commands
99 */
101 {
102 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
103  a2dInitCurrentSmartPointerOwner m_initCurrentSmartPointerOwner;
104 #endif
105 
106  DECLARE_EVENT_TABLE()
107  DECLARE_CLASS( a2dCentralCanvasCommandProcessor )
108 
109 public:
110 
111  friend class a2dCommand_GroupAB;
112 
113  //! \see a2dDocumentCommandProcessor
114  a2dCentralCanvasCommandProcessor( long flags = a2dDEFAULT_DOCUMENT_FLAGS,
115  bool initialize = true,
116  int maxCommands = -1 );
117 
118  //! initilize with lower level command processor
119  a2dCentralCanvasCommandProcessor( a2dDocumentCommandProcessor* other );
120 
121  //! destructor
123 
124  void UpdateAllViews();
125 
126  void OnUpdateUndo( wxUpdateUIEvent& event );
127 
128  void OnUpdateRedo( wxUpdateUIEvent& event );
129 
130  //! reroutes events to the current active drawingPart when not handled here.
131  /*!
132  In general menu commands are handled here or in the a2dDrawingPart.
133  */
134  bool ProcessEvent( wxEvent& event );
135 
136  void OnPushToolUpdateMenu( wxUpdateUIEvent& event );
137 
138  void OnUpdateMenu( wxUpdateUIEvent& event );
139 
140  //! All menu's a2dMenuIdItem using can be intercepted here
141  void OnMenu( wxCommandEvent& event );
142 
143  //! Submit a command to the active drawing
144  bool SubmitToDrawing( a2dCommand* command, bool storeIt = true );
145 
146  //! return current document in the command processor
148 
149  //! Get UnitScale of current document if set else returns 1
150  double GetUnitsScaleOfDocument();
151 
152  //! grid setting X
153  void SetGridX( const a2dDoMu& gridX );
154  //! grid setting Y
155  void SetGridY( const a2dDoMu& gridY );
156 
157  //! refresh what is documents and shown on views
158  void Refresh();
159 
160  bool SaveLayers( const wxFileName& fileName );
161 
162  bool LoadLayers( const wxFileName& fileName );
163 
164  //! add the current canvas object to parent as child
165  /*! First the current style is to the currentobject, and then it is added to the document.
166 
167  \param objectToAdd this is the object to add to the current parentobject
168  \param withUndo if true a a2dCommand_AddObject will be used to have undo information
169  \param setStyles the object added will get these styles that are currently set in the command processor
170  \param parentObject when not NULL, this will become the current parent object.
171  */
172  a2dCanvasObject* AddCurrent( a2dCanvasObject* objectToAdd, bool withUndo = false, a2dPropertyIdList* setStyles = NULL, a2dCanvasObject* parentObject = NULL );
173 
174  bool CvgString( const wxString& cvgString );
175 
176  //! To set a property by to a certain object
177  /*!
178  \param objectname name of the object to set the property to.
179  object name is:
180  -# a2dBaseTool Sets a property on the a2dToolContr its FirstTool of the current a2dCanvasView.
181  -# a2dToolContr Sets a property on the a2dToolContr of the current a2dCanvasView.
182  -# a2dCanvasCommandProcessor Sets a property to this a2dCentralCanvasCommandProcessor
183  -# a2dCentralCanvasCommandProcessor Sets a property on the current a2dCanvasDocument its wxCommandProcessor
184  \param propertyname name of property
185  \param value
186  */
187  bool SetPropertyToObject( const wxString& objectname, const wxString& propertyname, const wxString& value = wxT( "" ) );
188 
189  //! To set a property by to a certain object
190  /*!
191  \param objectname name of the object to set the property to.
192  object name is:
193  -# a2dBaseTool Sets a property on the a2dToolContr its FirstTool of the current a2dCanvasView.
194  -# a2dToolContr Sets a property on the a2dToolContr of the current a2dCanvasView.
195  -# a2dCanvasCommandProcessor Sets a property to this a2dCentralCanvasCommandProcessor
196  -# a2dCentralCanvasCommandProcessor Sets a property on the current a2dCanvasDocument its wxCommandProcessor
197  \param property the property to set
198  */
199  bool SetPropertyToObject( const wxString& objectname, a2dNamedProperty* property );
200 
201  //! set a layer property via command "setlayerproperty"
202  /*!
203  \param layer layer to add property to
204  \param propertyname name of property
205  \param value
206  */
207  bool SetLayerProperty( long layer, const wxString& propertyname, const wxString& value );
208 
209  //! returns the current active tool in the current active view
210  /*! If the view is of type a2dCanvasView, then if a a2dToolContr is set for it,
211  the first tool on its tool stack is returned.
212  */
213  a2dBaseTool* GetActiveTool();
214 
215  //! pop a tool from the tool stack of the current active a2dCanvasView
216  /*!
217 
218  */
219  a2dBaseTool* PopTool();
220 
221  //! set show object using index of child
222  bool SetShowObject( int index );
223 
224  //! zoom into this area
225  bool Zoom( double x1, double y1, double x2, double y2, bool upp );
226 
227  //! force an update of information on the currently active view
228  bool Update();
229 
230  //! besides calling the base class, its connect to Current view (active or not) for some events
231  void SetCurrentView( a2dView* view );
232 
233  //! is a view with a2dCanvasView active
234  a2dCanvasView* CheckDrawer() const;
235 
236  //! is a view with a2dCanvasView active and does it have a document
237  a2dCanvasDocument* CheckCanvasDocument() const;
238 
239  //! get commandprocessor of document
241  {
243  if ( !drawer )
244  return NULL;
245  if ( !drawer->GetDrawing() )
246  return NULL;
247 
248  return drawer->GetDrawing()->GetCanvasCommandProcessor();
249 
250  //wxASSERT_MSG( CheckDrawer(), wxT( "current drawing needs to be set" ) );
251  //return CheckDrawer()->GetDrawingPart()->GetDrawing()->GetCanvasCommandProcessor();
252  }
253 
254  void FillLibraryPoints();
255 
256  a2dCanvasDocument* GetLibraryPoints() const { return m_librarypoints.Get(); }
257 
258  //! cleaup modeless dialogs created from here
259  virtual void OnExit();
260 
261  virtual bool ShowDlg( const a2dCommandId* comID, bool modal, bool onTop );
262 
263  void DeleteDlgs();
264 
265  bool IsShownStructureDlg();
266 
267  //! boolean engine setting
268  void SetBooleanEngineMarge( const a2dDoMu& marge );
269  //! boolean engine setting
270  void SetBooleanEngineGrid( long grid );
271  //! boolean engine setting
272  void SetBooleanEngineDGrid( double dgrid );
273  //! boolean engine setting
274  void SetBooleanEngineCorrectionAber( const a2dDoMu& aber ) ;
275  //! boolean engine setting
276  void SetBooleanEngineCorrectionFactor( const a2dDoMu& aber );
277  //! boolean engine setting
278  void SetBooleanEngineMaxlinemerge( const a2dDoMu& maxline );
279  //! boolean engine setting
280  void SetBooleanEngineWindingRule( bool rule );
281  //! boolean engine setting
282  void SetBooleanEngineRoundfactor( double roundfac ) ;
283  void SetBooleanEngineSmoothAber( const a2dDoMu& aber );
284  void SetBooleanEngineLinkHoles( bool doLinkHoles );
285  //! Polygon/polyline to Arc Minimum radius to test
286  void SetRadiusMin( const a2dDoMu& radiusMin );
287  //! Polygon/polyline to Arc Maximum radius to test
288  void SetRadiusMax( const a2dDoMu& radiusMax ) ;
289  //! Polygon/polyline to Arc Maximum abberation
290  void SetAberPolyToArc( const a2dDoMu& aber );
291  //! Arc to Polygon/polyline Maximum abberation
292  void SetAberArcToPoly( const a2dDoMu& aber );
293  //! detection of small object, smaller than this
294  void SetSmall( const a2dDoMu& smallest );
295 
296  bool GdsIoSaveTextAsPolygon( bool onOff );
297  bool KeyIoSaveTextAsPolygon( bool onOff );
298 
299  //! Polygon/polyline to Arc Minimum radius to test
300  const a2dDoMu& GetRadiusMin() const ;
301  //! Polygon/polyline to Arc Maximum radius to test
302  const a2dDoMu& GetRadiusMax() const ;
303  //! Polygon/polyline to Arc Maximum abberation
304  const a2dDoMu& GetAberPolyToArc() const;
305  //! Arc to Polygon/polyline Maximum abberation
306  const a2dDoMu& GetAberArcToPoly() const ;
307  //! detection of small object, smaller than this
308  const a2dDoMu& GetSmall() const;
309 
310  //! boolean engine setting
311  const a2dDoMu& GetBooleanEngineMarge() const;
312  //! boolean engine setting
313  long GetBooleanEngineGrid() const;
314  //! boolean engine setting
315  double GetBooleanEngineDGrid() const;
316  //! boolean engine setting
317  const a2dDoMu& GetBooleanEngineCorrectionAber() const ;
318  //! boolean engine setting
319  const a2dDoMu& GetBooleanEngineCorrectionFactor() const;
320  //! boolean engine setting
321  const a2dDoMu& GetBooleanEngineMaxlinemerge() const ;
322  //! boolean engine setting
323  bool GetBooleanEngineWindingRule() const ;
324  //! boolean engine setting
325  double GetBooleanEngineRoundfactor() const ;
326  //! boolean engine setting
327  const a2dDoMu& GetBooleanEngineSmoothAber() const;
328  //! boolean engine setting
329  bool GetBooleanEngineLinkHoles() const;
330 
331  //! Save current view as an image of the given type.
332  bool SaveViewAsImage( a2dCanvasDocument* doc, const wxString& file, wxBitmapType type, a2dCanvasObject* from );
333 
334 protected:
335 
336 /*
337  const a2dFill& MX_GetFill() const { return m_currentfill; }
338  void MX_SetFill( const a2dFill& value ) { m_currentfill = value; }
339  const a2dStroke& MX_GetStroke() const { return m_currentstroke; }
340  void MX_SetStroke( const a2dStroke& value ) { m_currentstroke = value; }
341  const a2dFont& MX_GetFont() const { return m_font; }
342  void MX_SetFont( const a2dFont& value ) { m_font = value; }
343 */
344  //! do this at command start
345  void OnBusyBegin( a2dCommandProcessorEvent& WXUNUSED( event ) );
346 
347  //! do this at command end
348  void OnBusyEnd( a2dCommandProcessorEvent& WXUNUSED( event ) );
349 
350  void OnChangedDocument( a2dCommandEvent& event );
351 
352  a2dSmrtPtr<a2dCanvasDocument> m_librarypoints;
353 
354  LayerPropertiesDialog* m_layersdlg;
355 
356  a2dLayerOrderDialog* m_layerOrderDlg;
357 
358  a2dCanvasObjectsDocDialog* m_structDlgDoc;
359 
360 public:
361  // member ids
362 /*
363  static a2dPropertyIdCanvasObject* PROPID_Begin;
364  static a2dPropertyIdCanvasObject* PROPID_End;
365  static a2dPropertyIdDouble* PROPID_EndScaleX;
366  static a2dPropertyIdDouble* PROPID_EndScaleY;
367  static a2dPropertyIdBool* PROPID_Spline;
368 
369  static a2dPropertyIdFill* PROPID_Fill;
370  static a2dPropertyIdStroke* PROPID_Stroke;
371  static a2dPropertyIdFont* PROPID_Font;
372  static a2dPropertyIdUint16* PROPID_Layer;
373 
374  static a2dPropertyIdBool* PROPID_PopBeforePush;
375  static a2dPropertyIdBool* PROPID_OneShotTools;
376  static a2dPropertyIdBool* PROPID_EditAtEndTools;
377  static a2dPropertyIdBool* PROPID_Snap;
378 */
380 };
381 
382 A2DCANVASDLLEXP extern a2dDrawer2D* a2dGetDrawer2D();
383 
384 A2DCANVASDLLEXP extern a2dCentralCanvasCommandProcessor* a2dGetCmdh();
385 
386 
387 
388 //! set
389 /*!
390  \ingroup commands
391 */
392 class A2DCANVASDLLEXP a2dCommand_GdsIoSaveTextAsPolygon: public a2dCommand
393 {
394  DECLARE_DYNAMIC_CLASS( a2dCommand_GdsIoSaveTextAsPolygon )
395 public:
396  static const a2dCommandId Id;
397 
398  a2dCommand_GdsIoSaveTextAsPolygon( bool set = true ): a2dCommand( false, Id )
399  { m_value = set; }
400 
401  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
402  {
403  return new a2dCommand_GdsIoSaveTextAsPolygon( m_value );
404  }
405 
406  bool m_value;
407 
408 protected:
409 
410  bool Do( void )
411  {
412  const_forEachIn( a2dDocumentTemplateList, &GetCanvasCmp()->GetDocTemplates() )
413  {
414  a2dDocumentTemplateList::value_type temp = *iter;
415  if ( temp->IsVisible() && wxT( "GDS-II" ) == temp->GetDescription() )
416  {
417 #if wxART2D_USE_GDSIO
418  wxStaticCast( temp->GetDocumentIOHandlerStrOut(), a2dIOHandlerGDSOut )->SetSaveTextAsVpath( m_value );
419 #endif //wxART2D_USE_GDSIO
420  }
421  }
422  return true;
423  }
424  bool Undo( void )
425  {
426  return false;
427  }
428 
429  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
430 
431 };
432 
433 //! set
434 /*!
435  \ingroup commands
436 */
437 class A2DCANVASDLLEXP a2dCommand_KeyIoSaveTextAsPolygon: public a2dCommand
438 {
439  DECLARE_DYNAMIC_CLASS( a2dCommand_KeyIoSaveTextAsPolygon )
440 public:
441  static const a2dCommandId Id;
442 
443  a2dCommand_KeyIoSaveTextAsPolygon( bool set = true ): a2dCommand( false, Id )
444  { m_value = set; }
445 
446  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
447  {
448  return new a2dCommand_KeyIoSaveTextAsPolygon( m_value );
449  }
450 
451  bool m_value;
452 
453 protected:
454 
455  bool Do( void )
456  {
457  const_forEachIn( a2dDocumentTemplateList, &GetCanvasCmp()->GetDocTemplates() )
458  {
459  a2dDocumentTemplateList::value_type temp = *iter;
460  if ( temp->IsVisible() && wxT( "KEY" ) == temp->GetDescription() )
461  {
462 #if wxART2D_USE_KEYIO
463  wxStaticCast( temp->GetDocumentIOHandlerStrOut(), a2dIOHandlerKeyOut )->SetSaveTextAsVpath( m_value );
464 #endif //wxART2D_USE_KEYIO
465  }
466  }
467  return true;
468  }
469  bool Undo( void )
470  {
471  return false;
472  }
473 
474  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
475 
476 };
477 
478 //! Export view as image
479 /*!
480  \ingroup commands
481 */
482 class A2DCANVASDLLEXP a2dCommand_ViewAsImage: public a2dCommand
483 {
484  DECLARE_DYNAMIC_CLASS( a2dCommand_ViewImage )
485 public:
486 
487  //! Export a document to a file
488  /*! \ingroup commandid
489  */
490  static const a2dCommandId Id;
491 
492  class A2DCANVASDLLEXP Args
493  {
494  public:
495  Args()
496  {
497  argSet.file = false;
498  argSet.btype = false;
499  argValue.btype = wxBITMAP_TYPE_PNG;
500  }
501 
502  A2D_ARGUMENT_SETTER( wxFileName, file )
503  A2D_ARGUMENT_SETTER( wxBitmapType, btype )
504 
505  struct argValue
506  {
507  wxFileName file;
508  wxBitmapType btype;
509  } argValue;
510 
511  struct argSet
512  {
513  bool file;
514  bool btype;
515  } argSet;
516  };
517 
518  a2dCommand_ViewAsImage( const Args& args = Args() ): a2dCommand( false, Id )
519  {
520  m_args = args;
521  if ( args.argSet.file )
522  m_args.file( args.argValue.file );
523  else
524  throw a2dCommandException( _( "file argument must be set" ) );
525  }
526 
527  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
528  {
529  return new a2dCommand_ViewAsImage( m_args );
530  }
531 
532  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
533 
534  Args m_args;
535 
536 protected:
537 
538  virtual bool Do()
539  {
540  a2dCanvasDocument* doc = GetCanvasCmp()->CheckCanvasDocument();
541  if ( !doc )
542  return false;
543  a2dCanvasView* drawer = GetCanvasCmp()->CheckDrawer();
544  if ( !drawer )
545  return false;
546 
547  a2dPathList path;
548  path.Add( wxT( "." ) );
549  wxString foundfile = m_args.argValue.file.GetFullPath();
550  if ( !path.ExpandPath( foundfile ) )
551  {
552  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), m_args.argValue.file.GetFullPath().c_str(), foundfile.c_str() );
553  return false;
554  }
555  if ( foundfile.IsEmpty() )
556  {
557  a2dDocviewGlobals->ReportErrorF( a2dError_NotSpecified, _( "Filename %s not in %s" ), foundfile.c_str(), path.GetAsString().c_str() );
558  return false;
559  }
560 
561  drawer->GetDrawingPart()->GetDrawer2D()->GetBuffer().SaveFile( foundfile, m_args.argValue.btype, ( wxPalette* )NULL );
562 
563  return true;
564  }
565 
566  virtual bool Undo()
567  {
568  return false;
569  }
570 };
571 
572 //! Export view as ViewAsSvg
573 /*!
574  \ingroup commands
575 */
576 class A2DCANVASDLLEXP a2dCommand_ViewAsSvg: public a2dCommand
577 {
578  DECLARE_DYNAMIC_CLASS( a2dCommand_ViewAsSvg )
579 public:
580 
581  //!
582  /*! \ingroup commandid
583  */
584  static const a2dCommandId Id;
585 
586  class A2DCANVASDLLEXP Args
587  {
588  public:
589  Args()
590  {
591  argSet.file = false;
592  }
593 
594  A2D_ARGUMENT_SETTER( wxFileName, file )
595 
596  struct argValue
597  {
598  wxFileName file;
599  } argValue;
600 
601  struct argSet
602  {
603  bool file;
604  } argSet;
605  };
606 
607  a2dCommand_ViewAsSvg( const Args& args = Args() ): a2dCommand( false, Id )
608  {
609  m_args = args;
610 
611  if ( args.argSet.file )
612  m_args.file( args.argValue.file );
613  else
614  throw a2dCommandException( _( "file argument must be set" ) );
615  }
616 
617  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
618  {
619  return new a2dCommand_ViewAsSvg( m_args );
620  }
621 
622  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
623 
624  Args m_args;
625 
626 private:
627 
628  virtual bool Do()
629  {
630  a2dCanvasDocument* doc = GetCanvasCmp()->CheckCanvasDocument();
631  if ( !doc )
632  return false;
633  a2dCanvasView* drawer = GetCanvasCmp()->CheckDrawer();
634  if ( !drawer )
635  return false;
636 
637  a2dPathList path;
638  path.Add( wxT( "." ) );
639  wxString foundfile = m_args.argValue.file.GetFullPath();
640  if ( !path.ExpandPath( foundfile ) )
641  {
642  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotEvaluatePath, _( "Could not expand %s resulted in %s" ), m_args.argValue.file.GetFullPath().c_str(), foundfile.c_str() );
643  return false;
644  }
645  if ( foundfile.IsEmpty() )
646  {
647  a2dDocviewGlobals->ReportErrorF( a2dError_NotSpecified, _( "Filename %s not in %s" ), foundfile.c_str(), path.GetAsString().c_str() );
648  return false;
649  }
650 
651  doc->WriteSVG( drawer, foundfile, drawer->GetDrawingPart()->GetShowObject(), 10, 10, _T( "cm" ) );
652 
653  return true;
654  }
655 
656  virtual bool Undo()
657  {
658  return false;
659  }
660 };
661 
662 //! set
663 /*!
664  \ingroup commands
665 */
666 class A2DCANVASDLLEXP a2dCommand_KeyIoSaveFromView: public a2dCommand
667 {
668  DECLARE_DYNAMIC_CLASS( a2dCommand_KeyIoSaveTextAsPolygon )
669 public:
670  static const a2dCommandId Id;
671 
672  a2dCommand_KeyIoSaveFromView( bool set = true ): a2dCommand( false, Id )
673  { m_value = set; }
674 
675  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
676  {
677  return new a2dCommand_KeyIoSaveFromView( m_value );
678  }
679 
680  bool m_value;
681 
682 protected:
683 
684  bool Do( void )
685  {
686  const_forEachIn( a2dDocumentTemplateList, &GetCanvasCmp()->GetDocTemplates() )
687  {
688  a2dDocumentTemplateList::value_type temp = *iter;
689  if ( temp->IsVisible() && wxT( "KEY" ) == temp->GetDescription() )
690  {
691 #if wxART2D_USE_KEYIO
692  a2dIOHandlerKeyOut* handler = wxStaticCast( temp->GetDocumentIOHandlerStrOut(), a2dIOHandlerKeyOut );
693  bool currentSetting = handler->GetFromViewAsTop();
694  handler->SetFromViewAsTop( m_value );
695  m_value = currentSetting;
696 #endif //wxART2D_USE_KEYIO
697  }
698  }
699  return true;
700  }
701  bool Undo( void )
702  {
703  return Do();
704  }
705 
706  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
707 
708 };
709 
710 //! set
711 /*!
712  \ingroup commands
713 */
714 class A2DCANVASDLLEXP a2dCommand_GdsIoSaveFromView: public a2dCommand
715 {
716  DECLARE_DYNAMIC_CLASS( a2dCommand_GdsIoSaveFromView )
717 public:
718  static const a2dCommandId Id;
719 
720  a2dCommand_GdsIoSaveFromView( bool set = true ): a2dCommand( false, Id )
721  { m_value = set; }
722 
723  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
724  {
725  return new a2dCommand_GdsIoSaveFromView( m_value );
726  }
727 
728  bool m_value;
729 
730 protected:
731 
732  bool Do( void )
733  {
734  const_forEachIn( a2dDocumentTemplateList, &GetCanvasCmp()->GetDocTemplates() )
735  {
736  a2dDocumentTemplateList::value_type temp = *iter;
737  if ( temp->IsVisible() && wxT( "GDS-II" ) == temp->GetDescription() )
738  {
739 #if wxART2D_USE_GDSIO
740  a2dIOHandlerGDSOut* handler = wxStaticCast( temp->GetDocumentIOHandlerStrOut(), a2dIOHandlerGDSOut );
741  bool currentSetting = handler->GetFromViewAsTop();
742  handler->SetFromViewAsTop( m_value );
743  m_value = currentSetting;
744 #endif //wxART2D_USE_GDSIO
745  }
746  }
747  return true;
748  }
749  bool Undo( void )
750  {
751  return Do();
752  }
753 
754  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
755 
756 };
757 
758 //! command to show a dialog
759 /*!
760  \ingroup commands
761 */
762 class A2DEDITORDLLEXP a2dCommand_ShowDlg: public a2dCommand
763 {
764  DECLARE_DYNAMIC_CLASS( a2dCommand_ShowDlg )
765 
766 public:
767 
768  //!
769  /*! \ingroup commandid
770  */
771  static const a2dCommandId Id;
772 
773  class A2DEDITORDLLEXP Args
774  {
775  public:
776  Args()
777  {
778  argSet.which = false;
779  argSet.modal = false;
780  argValue.modal = false;
781  argValue.onTop = false;
782  }
783 
784  Args& which( const a2dCommandId& arg )
785  {
786  this->argValue.which = &arg;
787  this->argSet.which = true;
788  return *this;
789  }
790 
791  A2D_ARGUMENT_SETTER( bool, modal )
792  A2D_ARGUMENT_SETTER( bool, onTop )
793 
794  struct argValue
795  {
796  const a2dCommandId* which;
797  bool modal;
798  bool onTop;
799  } argValue;
800 
801  struct argSet
802  {
803  bool which;
804  bool modal;
805  bool onTop;
806  } argSet;
807  };
808 
809  a2dCommand_ShowDlg( const a2dCommandId& which = a2dCanvasCommandProcessor::COMID_ShowDlgStyle, bool modal = false, bool onTop = true ): a2dCommand( false, Id )
810  {
811  m_args.argSet.which = true;
812  m_args.argValue.which = &which;
813  m_args.argSet.modal = true;
814  m_args.argValue.modal = modal;
815  m_args.argValue.onTop = onTop;
816  }
817 
818  a2dCommand_ShowDlg( const Args& args ): a2dCommand( false, Id )
819  {
820  m_args = args;
821  }
822 
823  virtual a2dObject* Clone( CloneOptions options = clone_deep ) const
824  {
825  return new a2dCommand_ShowDlg( m_args );
826  }
827 
828  inline a2dCentralCanvasCommandProcessor* GetCanvasCmp() { return wxStaticCast( m_cmp, a2dCentralCanvasCommandProcessor ); }
829 
830 private:
831 
832  Args m_args;
833 
834  virtual bool Do()
835  {
836  return GetCanvasCmp()->ShowDlg( m_args.argValue.which, m_args.argValue.modal, m_args.argValue.onTop );
837  }
838 
839  virtual bool Undo()
840  {
841  return false;
842  }
843 };
844 
845 #endif
846 
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
static const a2dCommandId Id
Export a document to a file.
Definition: cancom.h:490
The a2dBaseTool is used to derive tools from that are controlled by.
Definition: tools.h:379
bool Undo(void)
Override this to undo a command.
Definition: cancom.h:469
a2dCanvasCommandProcessor * GetDrawingCmdProcessor()
get commandprocessor of document
Definition: cancom.h:240
View on a a2dCanvasDocument.
Definition: candoc.h:212
virtual bool Do()=0
Override this to perform a command.
const a2dError a2dError_CouldNotEvaluatePath
Ref Counted base object.
Definition: gen.h:1045
a2dObject * Clone(CloneOptions options, a2dRefMap *refs=NULL) const
create an exact copy of this property
Definition: gen.cpp:1199
see a2dCommandEvent
Definition: doccom.h:79
Path searching.
Definition: gen.h:2926
a command processor specially designed to work with a a2dCanvasDocument
Definition: drawing.h:1046
#define DECLARE_PROPERTIES()
check if class has the given id as a valid id for this object
Definition: gen.h:835
bool GetFromViewAsTop()
/see SetFromViewAsTop()
Definition: keyio.h:210
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
Docview framework its controlling class.
void SetFromViewAsTop(bool fromViewAsTop)
if set, the current view its ShowObject will be saved top down.
Definition: keyio.h:207
KEY input and output.
virtual bool Undo()
Override this to undo a command.
Definition: cancom.h:566
store and convert number to number with unit and visa versa. e.g. 1.23e-6 =&gt; 1.23 * 1e-6 ...
Definition: artglob.h:208
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
bool WriteSVG(a2dCanvasView *drawer, const wxString &filename, a2dCanvasObject *top, double Width, double Height, wxString unit)
write as SVG to a file starting at given object
Definition: candoc.cpp:1242
bool Do(void)
Override this to perform a command.
Definition: cancom.h:455
Holds a view on a a2dDocument.
Definition: docviewref.h:1804
void SetFromViewAsTop(bool fromViewAsTop)
if set, the current view its ShowObject will be saved top down.
Definition: gdsio.h:374
a2dCanvasDocument * GetCanvasDocument()
return current document in the command processor
Definition: cancom.h:147
Export view as ViewAsSvg.
Definition: cancom.h:576
bool Undo(void)
Override this to undo a command.
Definition: cancom.h:701
One object of this class may be created in an application, to manage all the templates and documents...
Definition: doccom.h:242
edit properties of a2dCanvasObject&#39;s
Definition: canpropedit.h:148
Export view as image.
Definition: cancom.h:482
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
Drawing context abstraction.
Definition: drawer2d.h:177
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the drawer.
Definition: drawer.h:680
virtual bool Do()
Override this to perform a command.
Definition: cancom.h:538
bool Do(void)
Override this to perform a command.
Definition: cancom.h:732
a2dDrawer2D * GetDrawer2D()
get the internal m_drawer2D that is used for rendering the document
Definition: drawer.h:1125
bool Undo(void)
Override this to undo a command.
Definition: cancom.h:424
Each a2dCommand is given a command id at construction.
Definition: comevt.h:99
a2dCommand(bool canUndo=false, const a2dCommandId &commandId=sm_noCommandId, const a2dCommandId &commandTypeId=sm_noCommandTypeId, const wxString &menuString=wxEmptyString)
constructor
Definition: comevt.cpp:103
Dialog for displaying/editing layers and properties of layers.
Definition: layerdlg.h:30
a2dDocviewGlobal * a2dDocviewGlobals
a global pointer to get to global instance of important classes.
Definition: doccom.cpp:2348
Output driver for KEY files.
Definition: keyio.h:175
bool Do(void)
Override this to perform a command.
Definition: cancom.h:684
virtual wxBitmap GetBuffer() const =0
Return the buffer as a bitmap.
Each a2dCanvasView needs to have a a2dCanvasDocument set in order to render data. ...
Definition: candoc.h:374
a2dCanvasCommandProcessor * GetCanvasCommandProcessor()
get a pointer to the command processor
Definition: drawing.cpp:375
Output driver for GDSII files.
Definition: gdsio.h:347
Definition of class for dialog to specify the layerorder.
virtual void ReportErrorF(const a2dError &error, const wxChar *Format,...)
concatenate to the the error report the given error.
Definition: comevt.cpp:1312
Event sent to a2dCommandProcessor.
Definition: comevt.h:701
const a2dError a2dError_NotSpecified
command to show a dialog
Definition: cancom.h:762
a2dDrawing * GetDrawing() const
get drawing via top object
Definition: drawer.cpp:726
wxString GetAsString()
Get all search paths as one string.
Definition: gen.cpp:4470
#define const_forEachIn(listtype, list)
easy const iteration for a2dlist
Definition: a2dlist.h:118
bool GetFromViewAsTop()
/see SetFromViewAsTop()
Definition: gdsio.h:377
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
all headers of the canvas module
a command wrapper specially designed to work with wxArt2D docview classes and rest.
Definition: cancom.h:100
command on selected objects
Definition: drawing.h:2589
bool Do(void)
Override this to perform a command.
Definition: cancom.h:410
GdsII format input and output.
CloneOptions
options for cloning
Definition: gen.h:1200
bool Undo(void)
Override this to undo a command.
Definition: cancom.h:749
For exceptions thrown from commands.
Definition: comevt.h:294
a base command for the a2dCommandProcessor
Definition: comevt.h:140
cancom.h Source File -- Sun Oct 12 2014 17:04:13 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation