wxArt2D
candoc.cpp
1 /*! \file canvas/src/candoc.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2001-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: candoc.cpp,v 1.190 2009/09/02 19:46:07 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include <wx/wfstream.h>
22 #include <math.h>
23 #include <wx/tokenzr.h>
24 #include <wx/metafile.h>
25 #include <locale.h>
26 
27 
28 #if wxUSE_STD_IOSTREAM
29 #include "wx/ioswrap.h"
30 #if wxUSE_IOSTREAMH
31 #include <fstream.h>
32 #else
33 #include <fstream>
34 #endif
35 #else
36 #include "wx/wfstream.h"
37 #endif
38 
39 
40 #include "wx/editor/candoc.h"
41 #include "wx/editor/cancom.h"
42 
43 #include "wx/canvas/xmlpars.h"
44 #include "wx/canvas/drawer.h"
45 #include "wx/canvas/canglob.h"
46 #include "wx/canvas/algos.h"
47 
48 #if defined(__WXMSW__) && defined(__MEMDEBUG__)
49 #include <wx/msw/msvcrt.h>
50 #endif
51 
52 //----------------------------------------------------------------------------
53 // globals
54 //----------------------------------------------------------------------------
55 
56 //----------------------------------------------------------------------------
57 // a2dViewPrintout
58 //----------------------------------------------------------------------------
59 
60 #if wxUSE_PRINTING_ARCHITECTURE
61 
63 
64 /* print out for drawer */
65 a2dViewPrintout::a2dViewPrintout( const wxPageSetupDialogData& pageSetupData, a2dCanvasView* drawingView, const wxString& title, const wxString& filename, a2dPrintWhat typeOfPrint, bool drawframe, double scalelimit, bool fitToPage ) :
66  m_pageSetupData( pageSetupData ),
67  a2dDocumentPrintout( drawingView, title )
68 {
69  m_typeOfPrint = typeOfPrint;
70  m_drawingView = drawingView;
71  m_title = title;
72  m_filename = filename;
73  m_scalelimit = scalelimit;
74  m_drawframe = drawframe;
75  m_fitToPage = fitToPage;
76 }
77 
79 {
80 }
81 
83 {
84 
85  wxDC* dc;
86  dc = GetDC();
87 
88  // We get the paper size in device units and the margins in mm,
89  // so we need to calculate the conversion with this trick
90  wxCoord pw, ph;
91  dc->GetSize( &pw, &ph );
92  wxCoord mw, mh;
93  GetPageSizeMM(&mw, &mh);
94  float mmToDeviceX = float(pw) / mw;
95  float mmToDeviceY = float(ph) / mh;
96 
97  // paper size in device units
98  wxRect paperRect = wxRect( 0,0,pw,ph);
99 
100  // margins in mm
101  wxPoint topLeft = m_pageSetupData.GetMarginTopLeft();
102  wxPoint bottomRight = m_pageSetupData.GetMarginBottomRight();
103 
104  // calculate margins in device units
105  wxRect pageMarginsRect(
106  paperRect.x + wxRound(mmToDeviceX * topLeft.x),
107  paperRect.y + wxRound(mmToDeviceY * topLeft.y),
108  paperRect.width - wxRound(mmToDeviceX * (topLeft.x + bottomRight.x)),
109  paperRect.height - wxRound(mmToDeviceY * (topLeft.y + bottomRight.y)));
110 
111  //! needed ?
112  dc->SetBrush( *wxWHITE_BRUSH );
113  dc->SetBackground( *wxWHITE_BRUSH );
114  dc->Clear();
115  dc->SetBackgroundMode( wxTRANSPARENT );
116  dc->SetTextForeground( *wxBLACK );
117  dc->SetBrush( *wxTRANSPARENT_BRUSH );
118 
119 
120  int marginX = ( int )( ph * 0.015 );
121  int marginY = marginX;
122  int fontMarginYTop = 0;
123  int fontMarginYBottom = 0;
124  wxFont fontTitle = wxFont( marginY, wxDEFAULT, wxNORMAL, wxNORMAL );
125  wxFont fontFilename = wxFont( int( marginY / 2. + 0.5 ), wxDEFAULT, wxNORMAL, wxNORMAL );
126 
127  if ( !m_title.IsEmpty() )
128  {
129  dc->SetFont( fontTitle );
130  fontMarginYTop += 2 * fontTitle.GetPointSize();
131  wxCoord xExtent, yExtent;
132  dc->GetTextExtent( m_title, &xExtent, &yExtent );
133  dc->DrawText( m_title, pw / 2 - xExtent / 2, marginY );
134  }
135 
136  if ( !m_filename.IsEmpty() )
137  {
138  dc->SetFont( fontFilename );
139  fontMarginYBottom += 2 * fontFilename.GetPointSize();
140  dc->DrawText( m_filename, marginX, ph - marginY - fontMarginYBottom );
141  }
142 
143 
144  int widthX = pageMarginsRect.GetWidth();
145  int widthY = pageMarginsRect.GetHeight();
146  int orgX = pageMarginsRect.GetTopLeft().x;
147  int orgY = pageMarginsRect.GetTopLeft().y;
148 
149  dc->SetBackgroundMode( wxSOLID );
150  dc->SetFont( wxNullFont );
151 
152 /* todo
153  double scaleX = ( widthX / ( double ) pw );
154  double scaleY = ( widthY / ( double ) ph );
155 // double scaleX = (w/widthX);
156 // double scaleY = (h/widthY);
157 
158  if( !m_fitToPage )
159  {
160  double actualScale = wxMax( scaleX, scaleY );
161 
162  if( actualScale < m_scalelimit )
163  actualScale = m_scalelimit;
164  scaleX = scaleY = actualScale;
165  }
166 
167  //if scale in X and Y did change, adjust incoming Dc to draw on that exact area.
168  // Calculate the position on the DC for centering the graphic
169  orgX = orgX + Round( ( pw - ( widthX / scaleX ) ) / 2.0 );
170  orgY = orgY + fontMarginYTop + Round( ( ph - ( widthY / scaleY ) ) / 2.0 );
171 */
172 
173  wxDC* memprint = wxDynamicCast( dc, wxMemoryDC );
174 
175  a2dDcDrawer* dcdrawer = NULL;
176  if (!memprint && !m_printAsBitmap)
177  dcdrawer = new a2dDcDrawer( widthX, widthY );
178  else
179  dcdrawer = new a2dMemDcDrawer( widthX, widthY );
180 
181  dcdrawer->SetPrintMode( true );
182  dcdrawer->SetRealScale( !m_fitToPage );
183  //dcdrawer->SetSmallTextThreshold( 10000 );
184 
185  // initialize with the view to print, but scaling will be changed later.
186  a2dSmrtPtr<a2dDrawingPart> drawPart = new a2dDrawingPart( *m_drawingView->GetDrawingPart() );
187 
188  //drawView is a a2dView and therefore gets events, but this is not wanted here.
189  drawPart->SetEvtHandlerEnabled( false );
190  drawPart->SetDrawer2D( dcdrawer );
191  drawPart->SetShowOrigin( false );
192  drawPart->SetGrid( false );
193 
194  // take some important settings from the view where this a2dViewPrintout was created:
195  // see a2dCanvasView::OnCreatePrintout()
196  a2dCanvasDocument* doc = wxStaticCastNull( m_drawingView->GetDocument(), a2dCanvasDocument );
197  drawPart->SetShowObjectAndRender( m_drawingView->GetDrawingPart()->GetShowObject() );
198  drawPart->SetDocumentDrawStyle( m_drawingView->GetDrawingPart()->GetDocumentDrawStyle() );
199  drawPart->SetAvailable();
200  a2dDrawer2D* drawcont = m_drawingView->GetDrawingPart()->GetDrawer2D();
201  dcdrawer->SetYaxis( drawcont->GetYaxis() );
202 
203  if ( memprint || (!memprint && !m_printAsBitmap) )
204  {
205  //is wxPrinterDc, and we draw on it;
206 
207  if ( m_typeOfPrint == a2dPRINT_Print )
208  {
209  dcdrawer->SetMappingWidthHeight( drawcont->GetVisibleMinX(),
210  drawcont->GetVisibleMinY(),
211  drawcont->GetVisibleWidth(),
212  drawcont->GetVisibleHeight() );
213  }
214  else if ( m_typeOfPrint == a2dPRINT_PrintView ||
216  {
217  dcdrawer->SetMappingWidthHeight( drawcont->GetVisibleMinX(),
218  drawcont->GetVisibleMinY(),
219  drawcont->GetVisibleWidth(),
220  drawcont->GetVisibleHeight() );
221  }
222  else //default do all of document
223  {
224  drawPart->SetMappingShowAll();
225  }
226 
227  //now start drawing the document on our created view
228  // Set the scale and origin
229  // dc->SetUserScale(scaleX, scaleY);
230  dc->SetDeviceOrigin( orgX, orgY );
231  dcdrawer->SetRenderDC( dc ); //a trick to set the drawers internal dc.
232  drawPart->UpdateArea( 0, 0, widthX, widthY );
233  dcdrawer->SetRenderDC( NULL );
234  }
235  else if ( !memprint && m_printAsBitmap )
236  {
237  if ( m_typeOfPrint == a2dPRINT_Print )
238  {
239  dcdrawer->SetMappingWidthHeight( drawcont->GetVisibleMinX(),
240  drawcont->GetVisibleMinY(),
241  drawcont->GetVisibleWidth(),
242  drawcont->GetVisibleHeight() );
243  }
244  else if ( m_typeOfPrint == a2dPRINT_PrintView ||
246  {
247  dcdrawer->SetMappingWidthHeight( drawcont->GetVisibleMinX(),
248  drawcont->GetVisibleMinY(),
249  drawcont->GetVisibleWidth(),
250  drawcont->GetVisibleHeight() );
251  }
252  else //default do all of document
253  {
254  drawPart->SetMappingShowAll();
255  }
256 
257  //now start drawing the document on our created view
258  drawPart->UpdateArea( 0, 0, widthX, widthY );
259 
260  wxBitmap buffer(dcdrawer->GetBuffer());
261  drawPart = NULL; // Delete the 2nd reference to the bitmap. Otherwise dcb.SelectObject( buffer ); causes an exception
262 
263  //buffer.SaveFile( "c:/soft/aap.png", wxBITMAP_TYPE_PNG );
264  wxMemoryDC dcb;
265  dcb.SelectObject( buffer );
266  dc->Blit( orgX, orgY, widthX, widthY, &dcb, 0, 0, wxCOPY, false );
267  dcb.SelectObject( wxNullBitmap );
268 /* if above does not work, this will!
269  wxMemoryDC dcb;
270  dcb.SelectObject( buffer );
271  int stripHeight = 1000;
272  int i, strips = widthY / stripHeight;
273  int rest = widthY - strips * stripHeight;
274  for ( i = 0; i < strips; i++ )
275  {
276  dc->Blit( 0 , stripHeight * i, widthX, stripHeight, &dcb, 0, stripHeight*i, wxCOPY, false );
277  }
278  dc->Blit( 0 , stripHeight * i, widthX, rest, &dcb, 0, stripHeight*i , wxCOPY, false );
279  dcb.SelectObject( wxNullBitmap );
280 */
281  //dc->DrawBitmap( buffer , 0,0 );
282  }
283 
284  if( m_drawframe )
285  {
286  dc->SetDeviceOrigin( 0, 0 );
287  dc->SetBrush( *wxTRANSPARENT_BRUSH );
288  dc->SetPen( *wxRED_PEN );
289  dc->DrawRectangle( orgX, orgY, widthX, widthY );
290  const wxPen& aPenForFrame = dc->GetPen();
291  }
292 
293 
294  /* debug
295  dc->SetDeviceOrigin( 0, 0 );
296  dc->SetPen( *wxBLACK_PEN );
297  dc->SetBrush( *wxTRANSPARENT_BRUSH );
298  dc->DrawRectangle( orgX, orgY, widthX, widthY);
299  */
300  return true;
301 }
302 #endif //wxUSE_PRINTING_ARCHITECTURE
303 
304 
305 BEGIN_EVENT_TABLE( a2dViewCanvas, a2dCanvas )
306  EVT_SET_DOCUMENT( a2dViewCanvas::OnSetDocument )
307  EVT_ACTIVATE_VIEW( a2dViewCanvas::OnActivate )
308  EVT_CLOSE_VIEW( a2dViewCanvas::OnCloseView )
309  EVT_UPDATE_VIEWS( a2dViewCanvas::OnUpdate )
310  //EVT_DISCONNECT_ALLVIEWS( a2dCanvasView::OnDisConnectView )
311 END_EVENT_TABLE()
312 
313 a2dViewCanvas::a2dViewCanvas( a2dCanvasView* view, wxWindow* parent, wxWindowID id,
314  const wxPoint& pos, const wxSize& size, long style, a2dDrawer2D* drawer2D )
315 :
316  a2dCanvas( parent, id, pos, size, style, drawer2D )
317 {
318  SetView( view );
319 }
320 
321 a2dViewCanvas::a2dViewCanvas( a2dCanvasView* view, a2dDrawingPart* drawingpart, wxWindow* parent, wxWindowID id,
322  const wxPoint& pos, const wxSize& size, long style )
323 :
324  a2dCanvas( drawingpart, parent, id, pos, size, style )
325 {
326  SetView( view );
327 }
328 
329 void a2dViewCanvas::SetView( a2dCanvasView* view )
330 {
331  m_view = view;
332  if ( m_view )
333  {
335  m_view->SetDisplayWindow( this );
336  if ( m_drawingPart && doc )
337  m_drawingPart->SetShowObject( doc->GetDrawing()->GetRootObject() );
338  }
339 }
340 
341 void a2dViewCanvas::OnCloseView( a2dCloseViewEvent& event )
342 {
343  a2dCanvasView* theView = wxDynamicCast( event.GetEventObject(), a2dCanvasView );
344  if ( m_drawingPart && theView->GetDrawingPart() == m_drawingPart )
345  {
346  if ( m_drawingPart->GetCanvasToolContr() )
347  m_drawingPart->GetCanvasToolContr()->StopAllTools();
348  m_drawingPart->SetShowObject( NULL );
349  if ( a2dCanvasGlobals->GetActiveDrawingPart() == m_drawingPart )
351  }
352  event.Skip();
353 }
354 
355 void a2dViewCanvas::OnActivate( a2dViewEvent& viewevent )
356 {
357  a2dCanvasView* view = (a2dCanvasView*) viewevent.GetEventObject();
358  bool activate = viewevent.GetActive();
359 
360  if ( activate && wxStaticCastNull( m_view->GetDocument(), a2dCanvasDocument ) && view == m_view )
361  {
362  if ( !HasFocus() )
363  {
364  // WARNING doing a setfocus here ruins it in wxAuiNotebook (Tab gets the END focus instead of this window here).
365  // wxLogDebug( "a2dCanvasView::OnActivate set focus %p", GetDrawingPart() );
366  // GetDisplayWindow()->SetFocus();
367  }
368  }
369 
370  activate = viewevent.GetActive();
371 
372  if ( activate && m_drawingPart && m_drawingPart->GetDrawing() && view == m_view )
373  {
374  a2dCanvasGlobals->SetActiveDrawingPart( m_drawingPart );
375  }
376 
377  viewevent.Skip();
378 }
379 
381 {
382  if ( m_drawingPart )
383  {
384  m_drawingPart->Update();
385  }
386 }
387 
389 {
390  a2dCanvasDocument* canvasdoc = wxDynamicCast( ( ( a2dView* )event.GetEventObject() )->GetDocument(), a2dCanvasDocument );
391  if ( canvasdoc && m_view->GetDocument() )
392  {
393  a2dCanvasView* view = wxDynamicCast( ( ( a2dView* )event.GetEventObject() ), a2dCanvasView );
394 
395  if ( m_drawingPart && view->GetDrawingPart() == m_drawingPart )
396  {
397  //why? view->GetDocument()->ConnectEvent( a2dEVT_COM_EVENT, this );
398  m_drawingPart->SetShowObject( canvasdoc->GetDrawing()->GetRootObject() );
399  }
400  }
401 }
402 
403 //----------------------------------------------------------------------------
404 // a2dCanvasView
405 //----------------------------------------------------------------------------
406 
407 IMPLEMENT_DYNAMIC_CLASS( a2dCanvasView, a2dView )
408 
409 BEGIN_EVENT_TABLE( a2dCanvasView, a2dView )
410  EVT_CREATE_VIEW( a2dCanvasView::OnCreateView )
411 END_EVENT_TABLE()
412 
413 a2dCanvasView::a2dCanvasView( const wxSize& size ): a2dView()
414 {
415  Init();
416 }
417 
418 a2dCanvasView::a2dCanvasView( int width, int height ): a2dView()
419 {
420  Init();
421 }
422 
423 void a2dCanvasView::Init()
424 {
425  m_printtitle = true;
426  m_printfilename = true;
427  m_printscalelimit = 0;
428  m_printframe = true;
429  m_printfittopage = false;
430 }
431 
433 {
434  //prevent event handling from now one ( else problem from event distribution can happen ).
435  //Unregister is done in a2dView.
436  SetEvtHandlerEnabled( false );
437 
438  m_display = NULL; //is used to test inside controllers.
439 }
440 
442  : a2dView( other )
443 {
444  Init();
445 }
446 
448 {
449  return wxDynamicCast( m_display, a2dCanvas );
450 }
451 
452 a2dCanvasDocument* a2dCanvasView::GetCanvasDocument() const
453 {
454  return wxStaticCastNull( GetDocument(), a2dCanvasDocument );
455 }
456 
457 void a2dCanvasView::OnCreateView( a2dViewEvent& event )
458 {
459  event.Skip();
460  //m_display = new a2dCanvas(); THIS would be one way of doing it in a derived/any view. But more flexible is to create windows/GUI in a a2dConnector Class, where this event goes also.
461 }
462 
463 a2dDrawingPart* a2dCanvasView::GetDrawingPart() const
464 {
465  if ( GetCanvas() )
466  return GetCanvas()->GetDrawingPart();
467  return NULL;
468 }
469 
470 bool a2dCanvasView::ProcessEvent( wxEvent& event )
471 {
472  bool processed = false;
473 
474  // An event handler can be enabled or disabled
475  if ( ( GetEvtHandlerEnabled() && m_viewEnabled ) ||
476  ( event.GetEventType() == wxEVT_ENABLE_VIEW ) ||
477  ( event.GetEventType() == wxEVT_ENABLE_VIEWS )
478  )
479  {
480  // via a2dCanvas
481  if ( m_display )
482  processed = m_display->GetEventHandler()->ProcessEvent( event );
483  if ( ! processed )
484  {
485  processed = a2dView::ProcessEvent( event );
486  }
487  return processed;
488  }
489 
490  return false;
491 }
492 
493 
494 void a2dCanvasView::OnDraw( wxDC* WXUNUSED( dc ) )
495 {
496  wxFAIL_MSG( wxT( "a2dCanvasView::OnDraw is not implemented, see a2dViewPrintout::OnPrintPage(int)" ) );
497 }
498 
499 #if wxUSE_PRINTING_ARCHITECTURE
500 wxPrintout* a2dCanvasView::OnCreatePrintout( a2dPrintWhat typeOfPrint, const wxPageSetupDialogData& pageSetupData )
501 {
503  return new a2dViewPrintout( pageSetupData, this, m_printtitle ? doc->GetDescription() : ( const wxString& )wxEmptyString, m_printfilename ? doc->GetFilename().GetFullPath() : wxString( wxT( "" ) ), typeOfPrint, m_printframe, m_printscalelimit, m_printfittopage );
504 }
505 #endif
506 
507 IMPLEMENT_CLASS( a2dZoomedView, wxWindow )
508 
509 BEGIN_EVENT_TABLE( a2dZoomedView, wxWindow )
510  EVT_UPDATE_VIEWS( a2dZoomedView::OnUpdate )
511  EVT_COM_EVENT( a2dZoomedView::OnComEvent )
512  EVT_PAINT( a2dZoomedView::OnPaint )
513  EVT_SIZE( a2dZoomedView::OnSize )
514  EVT_REMOVE_VIEW( a2dZoomedView::OnRemoveView )
515 END_EVENT_TABLE()
516 
517 a2dZoomedView::a2dZoomedView( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, a2dCanvasView* canvasview ):
518  wxWindow( parent, id, pos, size, style )
519 {
520  m_canvasDocview = canvasview;
521 }
522 
524 {
525 }
526 
527 void a2dZoomedView::OnUpdate( a2dDocumentEvent& event )
528 {
530  if ( !m_canvasDocview || doc != event.GetEventObject() )
531  return;
532 
533  if ( !GetEvtHandlerEnabled() )
534  return;
535 
536  if ( !m_canvasDocview || doc )
537  return;
538 
539  //update totalbbox or set dirty.
540 }
541 
542 void a2dZoomedView::OnPaint( wxPaintEvent& WXUNUSED( event ) )
543 {
545  {
546  wxPaintDC dc( this ); //needed to prevent looping
547  return;
548  }
549 
550  wxPaintDC dc( this );
551 
552  int dvx, dvy;
553  GetClientSize( &dvx, &dvy );
554  if ( dvx == 0 ) dvx = 1;
555  if ( dvy == 0 ) dvy = 1;
556 
558  double w = doc->GetDrawing()->GetRootObject()->GetBboxWidth();
559  double h = doc->GetDrawing()->GetRootObject()->GetBboxHeight();
560  double xview = m_canvasDocview->GetDrawingPart()->GetDrawer2D()->GetVisibleMinX();
561  double yview = m_canvasDocview->GetDrawingPart()->GetDrawer2D()->GetVisibleMinY();
562  double wview = m_canvasDocview->GetDrawingPart()->GetDrawer2D()->GetVisibleWidth();
563  double hview = m_canvasDocview->GetDrawingPart()->GetDrawer2D()->GetVisibleHeight();
564 
565  if ( h * dvx / w < dvy )
566  {
567  //Do draw two rectangles, one of size document and one of size m_canvasDocview.
568  dc.DrawRectangle( 0, 0, dvx, ( int ) ( h * dvx / w ) );
569  dc.DrawRectangle( ( int ) ( xview * dvx / w ), ( int ) ( yview * dvx / w ), ( int ) ( wview * dvx / w ), ( int ) ( hview * dvx / w ) );
570  }
571  else
572  {
573  //Do draw two rectangles, one of size document and one of size m_canvasDocview.
574  dc.DrawRectangle( 0, 0, ( int ) ( w * dvx / h ), dvy );
575  dc.DrawRectangle( ( int ) ( xview * dvy / h ), ( int ) ( yview * dvy / h ), ( int ) ( wview * dvy / h ), ( int ) ( hview * dvy / h ) );
576  }
577 
578 }
579 
580 void a2dZoomedView::OnSize( wxSizeEvent& WXUNUSED( event ) )
581 {
582  Refresh();
583 }
584 
585 
587 {
588  if ( event.GetId() == a2dDrawer2D::sig_changedZoom )
589  {
590  Refresh();
591  }
592 }
593 
594 void a2dZoomedView::OnRemoveView( a2dDocumentEvent& event )
595 {
596  a2dView* viewremoved = ( a2dView* ) event.GetView();
597  if ( viewremoved == m_canvasDocview )
598  m_canvasDocview = NULL;
599 }
600 
601 //----------------------------------------------------------------------------
602 // a2dCanvasDocument
603 //----------------------------------------------------------------------------
604 
605 const a2dSignal a2dCanvasDocument::sig_layersetupChanged = wxNewId();
606 const a2dSignal a2dCanvasDocument::sig_changedLayer = wxNewId();
607 
608 IMPLEMENT_DYNAMIC_CLASS( a2dCanvasDocument, a2dDocument )
609 
610 BEGIN_EVENT_TABLE( a2dCanvasDocument, a2dDocument )
611  EVT_IDLE( a2dCanvasDocument::OnIdle )
612  EVT_OPEN_DOCUMENT( a2dCanvasDocument::OnOpenDocument )
613  EVT_DO( a2dCanvasDocument::OnDoEvent )
614  EVT_UNDO( a2dCanvasDocument::OnUndoEvent )
615  EVT_REDO( a2dCanvasDocument::OnRedoEvent )
616  EVT_CHANGEDMODIFY_DRAWING( a2dCanvasDocument::OnChangeDrawings )
617 END_EVENT_TABLE()
618 
619 a2dCanvasDocument::a2dCanvasDocument(): a2dDocument()
620 {
621  m_documentModified = 0;
622  if ( a2dCanvasGlobals->GetHabitat()->GetLayerSetup() )
623  m_layersetup = ( a2dLayers* ) a2dCanvasGlobals->GetHabitat()->GetLayerSetup()->Clone( clone_deep );
624 
625  m_drawing = (a2dDrawing*) a2dCanvasGlobals->GetHabitat()->GetDrawingTemplate()->Clone( clone_deep );
626  m_drawing->SetName( wxT("top") );
627  m_drawing->SetDrawingId( a2dDrawing::sm_physical );
628  m_drawing->SetParent( this );
629 
630  if ( m_layersetup )
631  {
632  m_layersetup->SetRoot( NULL ); //these layers do not belong to a drawing.
633  }
634  m_askSaveWhenOwned = false;
635 
636  m_units_accuracy = 0.001;
637  m_units_scale = 1.0;
638  m_normalize_scale = 1.0;
639 
640  m_units = wxT( "non" );
641  m_units_measure = wxT( "non" );
642 
643  m_description = wxT( "a2dCanvasDocument generated by wxArt2D" );
644  m_libraryname = wxT( "Not specified" );
645  m_version = wxT( "1" );
646 
647  m_accesstime = wxDateTime::Now();
648  m_changedInternalAccesstime = wxDateTime::Now();
649 
650  m_documentTypeName = wxT( "a2dCanvasDocument" );
651 
652  m_multiRoot = false;
653 
654  m_show = NULL;
655  m_main = NULL;
656 }
657 
659  : a2dDocument( other )
660 {
661  if ( other.m_drawing )
662  {
663  m_drawing = other.m_drawing->TClone( clone_deep );
664  m_drawing->SetParent( this );
665  }
666  if ( other.m_layersetup )
667  {
668  m_layersetup = ( a2dLayers* ) other.m_layersetup->Clone( clone_deep );
669  m_layersetup->SetRoot( NULL );
670  }
672  m_units = other.m_units;
678  m_accesstime = other.m_accesstime;
680  m_multiRoot = other.m_multiRoot;
681  m_show = other.m_show;
682  m_main = other.m_main;
683 
684  m_documentModified = 0;
685 
686 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
687  //klion: it is because the CurrentSmartPointerOwner can change in Clone ( )
688  CurrentSmartPointerOwner = this;
689 #endif
690 }
691 
693 {
694  a2dCanvasDocument* a = new a2dCanvasDocument( *this );
695  return a;
696 }
697 
699 {
701  m_commandProcessor = NULL;
702 }
703 
705 {
706  if ( event.GetCommand()->Modifies() )
708  event.Skip();
709 }
710 
712 {
713  if ( event.GetCommand()->Modifies() )
715  event.Skip();
716 }
717 
719 {
720  if ( event.GetCommand()->Modifies() )
722  event.Skip();
723 }
724 
726 {
727  // lower drawing ( of a2dCameleons for instance )
728  m_documentModified += event.GetModified();
729 }
730 
732 {
735 
736  if ( m_drawing )
737  m_drawing->DisconnectEventAll( this );
738 }
739 
740 //void a2dCanvasDocument::operator delete(void* recordptr)
741 //{
742 // ::delete recordptr;
743 //}
744 
746 {
747  if ( m_drawing )
748  {
749  // the command processor holds smart pointers to the m_drawing.
752  }
753 }
754 
756 {
757  if ( m_layersetup )
758  {
760  m_layersetup->SetAllLayersAvailable( true );
761  //this one always available because editing handles are on it.
762  m_layersetup->SetAvailable( wxLAYER_DEFAULT, TRUE );
763  }
764  if ( m_drawing )
765  {
766  m_drawing->GetRootObject()->Update( mode );
767 
768  //todo what if more drawings
770  m_layersetup->SetAvailable( m_drawing->GetLayerSetup() );
771  }
772 }
773 
775 {
776  wxASSERT_MSG( newRoot, wxT( "a2dCanvasDocument its root object can not be NULL" ) );
777  m_drawing = newRoot;
778 }
779 
781 {
782  m_layersetup = layersetup;
783  if ( m_layersetup )
785 
786  a2dComEvent changedlayers( this, m_layersetup, sig_layersetupChanged );
787  ProcessEvent( changedlayers );
788 };
789 
791 {
793 
795 }
796 
798 {
799  // Set the locale to english for this I/O operation
800  // !!!! It would be better to set the locale of the stream itself,
801  // but this does not work for two reasons:
802  // 1. wxWindows streams don't support this
803  // 2. CVG-IO uses e.g. wxString::ToDouble, which is independent of the stream
804  wxString oldLocale = wxSetlocale( LC_NUMERIC, NULL );
805 #ifdef __WXMSW__
806  wxSetlocale( LC_NUMERIC, wxString( wxT( "English" ) ) );
807 #else
808  wxSetlocale( LC_NUMERIC, wxString( wxT( "en_US" ) ) );
809 #endif
810 
811  bool ownhandler = false;
812  if ( ! handler )
813  {
814 #if wxART2D_USE_CVGIO
815  //assume it is the default CVG format.
816  handler = new a2dIOHandlerCVGIn();
817  ownhandler = true;
818 #else
819  a2dDocviewGlobals->ReportErrorF( a2dError_NoDocTemplateRef, _( "No template defined in a2dDocument::LoadObject" ) );
820 #endif //wxART2D_USE_CVGIO
821  }
822 
823 #if wxUSE_STD_IOSTREAM
824  bool isOK = ( stream.fail() || stream.bad() ) == 0;
825 #else
826  bool isOK = stream.IsOk ();
827 #endif
828 
829  bool oke = false;
830  if ( isOK )
831  {
832  if ( handler )
833  {
834  if ( handler->CanLoad( stream, this, m_documentTemplate ? m_documentTemplate->GetDocumentClassInfo() : NULL ) )
835  {
836  if ( !handler->Load( stream, this ) )
837  {
838  a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotLoad, _( "I/O handler error during loading this format." ) );
840  }
841  else
842  oke = true;
843  }
844  else
845  {
846  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "I/O handler not capable of loading in this format." ) );
848  }
849  }
850  else
851  {
852  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "I/O handler must be != NULL, maybe template I/O handler not available in document template." ) );
854  }
855  }
856  else
858 
859  if ( ownhandler )
860  delete handler;
861 
862  // now we are ready to prepare the document for rendering
863  if ( oke )
864  {
865  Update( a2dCanvasObject::updatemask_force_and_count );
866 
867  a2dDocumentEvent event( wxEVT_POST_LOAD_DOCUMENT );
868  event.SetEventObject( this );
869  ProcessEvent( event );
870  }
871  else
872  {
875  }
876 
877  wxSetlocale( LC_NUMERIC, oldLocale );
878  return stream;
879 }
880 
881 bool a2dCanvasDocument::Load( const wxString& filename, a2dIOHandlerStrIn* handler )
882 {
884 #if wxUSE_STD_IOSTREAM
885  a2dDocumentFileInputStream stream( filename.mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
886  if ( stream.fail() || stream.bad() )
887 #else
888  wxFileInputStream stream( filename );
889  if ( !stream.IsOk() )
890 #endif
891  {
892  a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _( "Sorry, could not open file %s for loading" ), filename.c_str() );
893  return false;
894  }
895 
896  if ( handler )
897  {
898  if ( handler->CanLoad( stream, this, m_documentTemplate ? m_documentTemplate->GetDocumentClassInfo() : NULL ) )
899  {
900  if ( !handler->Load( stream, this ) )
901  {
902  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler failed loading from stream." ) );
904  }
905  else
906  {
908  return true;
909  }
910  }
911  else
912  {
913  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler not capable of loading this format." ) );
915  }
916  }
917  else
918  {
919  a2dDocviewGlobals->ReportErrorF( a2dError_LoadObject, _( "I/O handler not set in document template." ) );
921  }
922  return false;
923 }
924 
925 #if wxART2D_USE_CVGIO
926 void a2dCanvasDocument::Load( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerIn& parser )
927 {
928  a2dWalker_SetCheck setp( false );
929  setp.Start( m_drawing );
930  if ( m_layersetup )
931  setp.Start( m_layersetup );
932 
933  parser.Next();
934  parser.Require( START_TAG, wxT( "cvg" ) );
935  if ( parser.HasAttribute( wxT( "main" ) ) )
936  {
937  parser.ResolveOrAdd( ( a2dSmrtPtr<class a2dObject>* ) &m_main, parser.GetAttributeValue( wxT( "main" ) ) );
938  }
939  if ( parser.HasAttribute( wxT( "show" ) ) )
940  {
941  parser.ResolveOrAdd( ( a2dSmrtPtr<class a2dObject>* ) &m_show, parser.GetAttributeValue( wxT( "show" ) ) );
942  }
943 
944  parser.Next();
945  if ( parser.GetTagName() == wxT( "title" ) )
946  {
947  m_documentTitle = parser.GetContent();
948  parser.Next();
949  parser.Require( END_TAG, wxT( "title" ) );
950  parser.Next();
951  }
952  if ( parser.GetTagName() == wxT( "desc" ) )
953  {
954  m_description = parser.GetContent();
955  parser.Next();
956  parser.Require( END_TAG, wxT( "desc" ) );
957  parser.Next();
958  }
959 
960  if ( parser.GetTagName() == wxT( "version" ) )
961  {
962  m_version = parser.GetContent();
963  parser.Next();
964  parser.Require( END_TAG, wxT( "version" ) );
965  parser.Next();
966  }
967  else
968  m_version = wxT( "1" );
969 
970  // now define format version in parser for nested object to test
971  parser.SetFormatVersion( m_version );
972 
973  if ( parser.GetTagName() == wxT( "o" ) && parser.GetAttributeValue( wxT( "classname" ) ) == wxT( "a2dLayers" ) )
974  {
975  if ( m_layersetup )
977  else
978  {
979  m_layersetup = new a2dLayers();
980  }
981  m_layersetup->Load( NULL, parser );
983  }
984 
986 
987  //old CVG did not have drawings, make it compatible
988  if ( parser.GetTagName() == wxT( "o" ) && parser.GetAttributeValue( wxT( "classname" ) ) == wxT( "a2dDrawing" ) )
989  {
990  m_drawing->Load( (wxObject*) this, parser );
991  }
992  else if ( parser.GetTagName() == wxT( "o" ) )
993  {
994  m_drawing = new a2dDrawing( wxT("") );
996  m_drawing->GetRootObject()->Load( this, parser );
997  }
998  //m_drawing->SetRootRecursive(); Is done inside a2dDrawing when after loading
999 
1000  parser.Require( END_TAG, wxT( "cvg" ) );
1001 }
1002 #endif //wxART2D_USE_CVGIO
1003 
1004 bool a2dCanvasDocument::SaveLayers( const wxString& filename )
1005 {
1006  wxASSERT_MSG( m_layersetup, wxT( "no a2dLayers set for a2dCanvasDocument" ) );
1007  return m_layersetup->SaveLayers( filename );
1008 }
1009 
1010 bool a2dCanvasDocument::LoadLayers( const wxString& filename )
1011 {
1013 #if wxUSE_STD_IOSTREAM
1014  a2dDocumentFileInputStream stream( filename.mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
1015  if ( stream.fail() || stream.bad() )
1016 #else
1017  wxFileInputStream stream( filename );
1018  if ( !stream.Ok() )
1019 #endif
1020  {
1021  a2dDocviewGlobals->ReportErrorF( a2dError_LoadLayers, _( "Sorry, could not open file %s for loading" ), filename.c_str() );
1023  return false;
1024  }
1025 
1026  if ( !m_layersetup )
1027  {
1028  m_layersetup = new a2dLayers();
1029  }
1030  m_layersetup->SetFileName( filename );
1032 
1033  bool done = true;
1034 
1035 #if wxART2D_USE_CVGIO
1036  //layers or in CVG format.
1037  a2dIOHandlerCVGIn* handler = new a2dIOHandlerCVGIn();
1038 
1039  if ( handler && handler->CanLoad( stream, m_layersetup, NULL ) )
1040  {
1041  if ( !handler->LoadLayers( stream, m_layersetup ) )
1042  {
1043  a2dDocviewGlobals->ReportErrorF( a2dError_LoadLayers, _( "template I/O handler not capable of loading this format." ) );
1045  done = false;
1046  }
1047  }
1048  else
1049  {
1050  a2dDocviewGlobals->ReportErrorF( a2dError_LoadLayers, _( "template I/O handler not capable of loading this format." ) );
1052  done = false;
1053  }
1054 #else
1055  wxFAIL_MSG( wxT( "wxART2D_USE_CVGIO is needed to load layers from a file CVG file" ) );
1056 #endif //wxART2D_USE_CVGIO
1057 
1058 #if wxART2D_USE_CVGIO
1059  delete handler;
1060 #endif //wxART2D_USE_CVGIO
1061  return done;
1062 }
1063 
1065 {
1066 }
1067 
1069 {
1070  // Set the locale to english for this I/O operation
1071  // !!!! It would be better to set the locale of the stream itself,
1072  // but this does not work for two reasons:
1073  // 1. wxWindows streams don't support this
1074  // 2. CVG-IO uses e.g. wxString::ToDouble, which is independent of the stream
1075  wxString oldLocale = wxSetlocale( LC_NUMERIC, NULL );
1076 #ifdef __WXMSW__
1077  wxSetlocale( LC_NUMERIC, wxString( wxT( "English" ) ) );
1078 #else
1079  wxSetlocale( LC_NUMERIC, wxString( wxT( "en_US" ) ) );
1080 #endif
1081 
1082 #if wxUSE_STD_IOSTREAM
1083  bool isOK = ( stream.fail() || stream.bad() ) == 0;
1084 #else
1085  bool isOK = stream.IsOk ();
1086 #endif
1087 
1088  bool ownhandler = false;
1089  if ( ! handler )
1090  {
1091 #if wxART2D_USE_CVGIO
1092  //assume it is the default CVG format.
1093  handler = new a2dIOHandlerCVGOut();
1094  ownhandler = true;
1095 #else
1096  wxFAIL_MSG( wxT( "wxART2D_USE_CVGIO is needed to load object from a file CVG file" ) );
1097 #endif //wxART2D_USE_CVGIO
1098  }
1099 
1100  if ( isOK )
1101  {
1102  if ( handler )
1103  {
1104  if ( handler->CanSave( this ) )
1105  {
1106  if ( !handler->Save( stream, this ) )
1107  {
1108  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler error during saving in this format" ) );
1110  }
1111  }
1112  else
1113  {
1114  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler not capable of saving in this format." ) );
1116  }
1117  }
1118  else
1119  {
1120  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler not set in document template" ) );
1122  }
1123  }
1124  else
1125  {
1126  a2dDocviewGlobals->ReportErrorF( a2dError_SaveObject, _( "bad stream" ) );
1128  }
1129 
1130  if ( ownhandler )
1131  delete handler;
1132 
1133  wxSetlocale( LC_NUMERIC, oldLocale );
1134 
1135  return stream;
1136 }
1137 
1138 bool a2dCanvasDocument::Save( const wxString& filename, a2dIOHandlerStrOut* handler ) const
1139 {
1140 #if wxUSE_STD_IOSTREAM
1141  a2dDocumentFileOutputStream stream( filename.mb_str(), wxSTD ios_base::out | wxSTD ios_base::binary );
1142  if ( stream.fail() || stream.bad() )
1143 #else
1144  wxFileOutputStream stream( filename );
1145  if ( stream.GetLastError() != wxSTREAM_NO_ERROR )
1146 #endif
1147  {
1148  a2dDocviewGlobals->ReportErrorF( a2dError_SaveFile, _( "Sorry, could not open file %s for saving" ), filename.c_str() );
1149 
1150  // Saving error
1151  return false;
1152  }
1153 
1154  if ( handler )
1155  {
1156  if ( handler->CanSave( this ) )
1157  {
1158  if ( handler->Save( stream, this ) )
1159  return true;
1160 
1161  a2dDocviewGlobals->ReportErrorF( a2dError_SaveFile, _( "template I/O handler not succeeded to save in this format to file %s" ), filename.c_str() );
1162  }
1163  else
1164  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler not capable of saving in this format." ) );
1165  }
1166  else
1167  a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _( "template I/O handler not set in document template" ) );
1168  return false;
1169 }
1170 
1171 
1172 #if wxART2D_USE_CVGIO
1173 void a2dCanvasDocument::Save( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dObjectList* WXUNUSED( towrite ) )
1174 {
1175  //check flag is used for writing once an object which is referenced many times
1176  a2dWalker_SetCheck setp( false );
1177  setp.Start( m_drawing );
1178  setp.Start( m_layersetup );
1179 
1180  out.WriteStartDocument( wxT( "1.0" ), wxT( "UTF-8" ) , true );
1181 
1182  out.WriteStartElementAttributes( wxT( "cvg" ) );
1183  out.WriteAttribute( wxT( "classname" ), GetClassInfo()->GetClassName() );
1184  if ( m_main )
1185  out.WriteAttribute( wxT( "main" ), m_main->GetUniqueSerializationId() );
1186  if ( m_show )
1187  out.WriteAttribute( wxT( "show" ), m_show->GetUniqueSerializationId() );
1188  out.WriteEndAttributes();
1189 
1190  out.WriteElement( wxT( "title" ), GetPrintableName() );
1191  out.WriteElement( wxT( "desc" ), m_description );
1192  out.WriteElement( wxT( "version" ), m_version );
1193 
1194  a2dObjectList towritelayer;
1195  if ( m_layersetup )
1196  m_layersetup->Save( NULL, out, &towritelayer );
1197 
1198  m_drawing->Save( this, ( a2dIOHandlerCVGOut& ) out, NULL, NULL );
1199 
1200  out.WriteEndElement();
1201  out.WriteEndDocument();
1202 
1203 }
1204 
1206 {
1207  //check flag is used for writing once an object which is referenced many times
1208  a2dWalker_SetCheck setp( false );
1209  setp.Start( m_drawing );
1210  setp.Start( m_layersetup );
1211 
1212  out.WriteStartDocument( wxT( "1.0" ), wxT( "UTF-8" ) , true );
1213 
1214  out.WriteStartElementAttributes( wxT( "cvg" ) );
1215  out.WriteAttribute( wxT( "classname" ), GetClassInfo()->GetClassName() );
1216  if ( m_main )
1217  out.WriteAttribute( wxT( "main" ), m_main->GetUniqueSerializationId() );
1218  if ( m_show )
1219  out.WriteAttribute( wxT( "show" ), m_show->GetUniqueSerializationId() );
1220  out.WriteEndAttributes();
1221 
1222  out.WriteElement( wxT( "title" ), GetPrintableName() );
1223  out.WriteElement( wxT( "desc" ), m_description );
1224  out.WriteElement( wxT( "version" ), m_version );
1225 
1226  a2dObjectList towritelayer;
1227  if ( m_layersetup )
1228  m_layersetup->Save( NULL, out, &towritelayer );
1229 
1230  m_drawing->Save( this, ( a2dIOHandlerCVGOut& ) out, NULL, start );
1231 
1232  out.WriteEndElement();
1233  out.WriteEndDocument();
1234 }
1235 
1237 {
1238  out.WriteEndAttributes();
1239 }
1240 #endif //wxART2D_USE_CVGIO
1241 
1242 bool a2dCanvasDocument::WriteSVG( a2dCanvasView* drawer, const wxString& filename, a2dCanvasObject* WXUNUSED( top ), double WXUNUSED( Width ), double WXUNUSED( Height ), wxString unit )
1243 {
1244  wxASSERT_MSG( drawer, wxT( "no a2dCanvasView set for a2dCanvasDocument" ) );
1245 
1246  a2dWalker_SetCheck setp( false );
1247  setp.Start( m_drawing );
1248  if ( m_layersetup )
1249  setp.Start( m_layersetup );
1250 
1251  bool done = false;
1252 #if wxART2D_USE_SVGIO
1253  a2dIOHandlerSVGOut* handler = new a2dIOHandlerSVGOut();
1254  a2dIterC ic( drawer->GetDrawingPart() );
1255 
1256  handler->SetIterC( ic );
1257 
1258  done = Save( filename, handler );
1259 
1260  delete handler;
1261 #else
1262  wxFAIL_MSG( wxT( "wxART2D_USE_SVGIO is needed to write doc into SVG file" ) );
1263 #endif //wxART2D_USE_SVGIO
1264 
1265  return done;
1266 }
1267 
1268 void a2dCanvasDocument::OnIdle( wxIdleEvent& event )
1269 {
1270  event.Skip();
1271  //m_drawing->ProcessEvent( event );
1272 }
1273 
1274 
#define EVT_UPDATE_VIEWS(func)
event from a document when its views need to be updated
Definition: docviewref.h:979
virtual void SetYaxis(bool up)
set if the Yaxis goes up or down
Definition: drawer2d.cpp:438
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
set check on a2dObject flag false or true
Definition: algos.h:665
a2dObject * DoClone(a2dObject::CloneOptions options, a2dRefMap *refs) const
Clone document.
Definition: candoc.cpp:692
a2dSmrtPtr< a2dCommandProcessor > m_commandProcessor
A pointer to the command processor associated with this document.
Definition: docviewref.h:1643
void SetDrawing(a2dDrawing *newRoot)
set new root object ( may not ne NULL )
Definition: candoc.cpp:774
a2dError m_lastError
error code used when LoadObject is returning.
Definition: docviewref.h:1656
~a2dViewPrintout(void)
destructor
Definition: candoc.cpp:78
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
void SetRoot(a2dDrawing *root, bool recurse=true)
Sets this object to a a2dCanvasDocument.
Definition: canobj.cpp:5933
#define EVT_OPEN_DOCUMENT(func)
event for document when a document has been opened
Definition: docviewref.h:963
void WriteElement(const wxString &name, const wxString &content=wxT(""), bool newLine=true)
Writes start and end tag.
Definition: genxmlpars.cpp:794
const a2dError a2dError_NoDocTemplateRef
wxString m_units_measure
measuring unit (e.g. Meters Inch Microns etc.)
Definition: candoc.h:733
bool HasAttribute(const wxString &attrib)
Does the current tag have this attribute?
Definition: genxmlpars.cpp:560
double m_printscalelimit
Set the scaling limit for printing, so that small stuff is not zoomed to full page.
Definition: candoc.h:311
see a2dDrawingEvent
Definition: drawing.h:933
wxString m_description
description for document
Definition: candoc.h:751
void SetFileName(const wxFileName &filename)
set filename based on file where layers were read from
Definition: layerinf.h:392
wxString m_units
unit (e.g. Meters Inch Microns etc.)
Definition: candoc.h:730
wxString m_documentTypeName
The document type name given to the a2dDocumentTemplate constructor,.
Definition: docviewref.h:1631
double m_units_scale
scaling factor (how many &quot;m_units_measure&quot; is one unit)
Definition: candoc.h:724
#define EVT_ACTIVATE_VIEW(func)
event sent to view and document manager
Definition: docviewref.h:999
a2dCanvasDocument()
Construct a a2dCanvasDocument to store a complete drawing in.
Definition: candoc.cpp:619
virtual void OnDraw(wxDC *)
Not implemented, use a2dViewPrintout to print.
Definition: candoc.cpp:494
output handler for the SVG format
Definition: parssvg.h:104
XMLeventType Next()
Walks to next element and returns event type.
Definition: genxmlpars.cpp:422
void SetRealScale(bool realScale)
If true use real scale else different scale by x and y.
Definition: drawer2d.h:656
virtual bool Load(a2dDocumentInputStream &stream, wxObject *obj)=0
override to read the stream and store (part of) the contents in to a specific a2dDocument or othere o...
bool m_multiRoot
multi root document
Definition: candoc.h:718
double GetVisibleMinX() const
get Minimal X of the visible part in world coordinates
Definition: drawer2d.cpp:403
bool m_printtitle
if true, a printout is done with title (document name (description?)), otherwise not ...
Definition: candoc.h:305
bool ResolveOrAdd(a2dSmrtPtr< a2dObject > *storedHere, const wxString &id=wxT(""))
try to resolve the object that is in storedHere when it is a reference.
Definition: gen.cpp:4760
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
View on a a2dCanvasDocument.
Definition: candoc.h:212
a2dCommand * GetCommand()
the command ( if there was one ) that did it.
Definition: comevt.h:759
wxBitmap GetBuffer() const
Return the buffer as a bitmap.
Definition: dcdrawer.h:60
a2dView * GetView()
Gives the a2dView in case of event types concerning a view.
Definition: docviewref.h:774
a2dCanvasObject * GetRootObject() const
get the root object, which holds the objects in the document
Definition: drawing.h:521
void WriteStartElementAttributes(const wxString &name, bool newLine=true)
Writes start tag which has attributes.
Definition: genxmlpars.cpp:757
a2dSmrtPtr< a2dCameleon > m_main
what is the root a2dcameleon in the drawing to display after opening a document, when m_show is not s...
Definition: candoc.h:705
a2dCanvasObjectPtr m_show
what to display when document is openened
Definition: candoc.h:708
#define EVT_CHANGEDMODIFY_DRAWING(func)
event from a drawing when changed by commands
Definition: drawing.h:991
virtual bool ProcessEvent(wxEvent &event)
Special event handling for a2dCanvasView class.
Definition: candoc.cpp:470
virtual void UpdateLoadedLayerSetup()
Update a loaded layer setup.
Definition: candoc.cpp:1064
Ref Counted base object.
Definition: gen.h:1045
virtual void SetDisplayWindow(wxWindow *display)
Set the display window.
a2dIOHandlerCVGIn and a2dIOHandlerCVGOut - XML I/O classes for the CVG format.
void SetRenderDC(wxDC *dc)
set the DC that is used for rendering
Definition: dcdrawer.cpp:248
#define EVT_DO(func)
event sent from a2DocumentCommandProcessor when a command is initially done
Definition: comevt.h:795
const a2dError a2dError_NoError
void OnSetDocument(a2dViewEvent &event)
called when document of the a2dView has changed.
Definition: candoc.cpp:388
a2dObject * Clone(CloneOptions options, a2dRefMap *refs=NULL) const
create an exact copy of this property
Definition: gen.cpp:1199
wxString m_version
version of library or document
Definition: candoc.h:754
wxOutputStream a2dDocumentOutputStream
output stream based wxStreams
Definition: gen.h:3458
virtual bool Update(UpdateMode mode)
Update the state of the object according to its current position etc.
Definition: canobj.cpp:5149
const a2dError a2dError_FileCouldNotOpen
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
UpdateMode
Various mode flags for Update.
Definition: canobj.h:1091
#define EVT_SET_DOCUMENT(func)
event sent to view when a new document is ser for it.
Definition: docviewref.h:997
This class implements drawing functions for wxDC based drawing.
Definition: dcdrawer.h:43
void Load(wxObject *parent, a2dIOHandlerXmlSerIn &parser)
used by CVG parser
Definition: candoc.cpp:926
void Update(unsigned int how=(a2dCANVIEW_UPDATE_ALL|a2dCANVIEW_UPDATE_BLIT), wxObject *hintObject=NULL)
see OnUpdate
Definition: drawer.cpp:1744
#define EVT_REDO(func)
event sent from a2DocumentCommandProcessor when a command is redone
Definition: comevt.h:799
bool GetYaxis() const
get y axis orientation
Definition: drawer2d.h:280
This class implements drawing functions for wxDC based drawing.
Definition: dcdrawer.h:203
a2dDrawing * GetDrawing() const
get the root object, which holds the objects in the document.
Definition: candoc.h:418
void SetGrid(bool grid)
Set grid on/off.
Definition: drawer.h:905
double m_normalize_scale
normalization factor to scale normalized objects.
Definition: candoc.h:727
double GetVisibleMinY() const
get Minimal X of the visible part in world coordinates
Definition: drawer2d.cpp:408
a2dCanvas * GetCanvas() const
Get the Display window of the a2dView. But casted to a a2dCanvas.
Definition: candoc.cpp:447
using a file stream for input, stream the file into a a2dDocument or other object ...
Definition: gen.h:3632
void SetDocumentDrawStyle(wxUint32 drawstyle)
set drawstyles to use for drawing the document
Definition: drawer.cpp:1016
static const a2dSignal sig_changedLayer
when an object is removed from a layer,
Definition: candoc.h:760
virtual a2dDocumentInputStream & LoadObject(a2dDocumentInputStream &stream, a2dIOHandlerStrIn *handler)
load form a file containing the a2dCanvas specific XML called CVG format
Definition: candoc.cpp:797
virtual void UpdateArea(int x, int y, int width, int height, wxUint8 id=0)
update/redraw part of the buffer, using the given a2dDrawing and ShowObject within that root...
Definition: drawer.cpp:1999
a2dView event, to report events in the a2dView class
Definition: docviewref.h:424
virtual bool CanLoad(a2dDocumentInputStream &stream, const wxObject *obj=NULL, wxClassInfo *docClassInfo=NULL)=0
Should return true if the handler can read from the stream.
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
std::vector< a2dLayerInfoPtr > & GetLayerIndex()
return array index on Layer
Definition: layerinf.cpp:555
wxString GetContent()
Returns the current content.
Definition: genxmlpars.cpp:570
a2dPrintWhat m_typeOfPrint
type of print requested
Definition: candoc.h:131
output handler for the CVG format.
Definition: xmlpars.h:103
a2dLayers * GetLayerSetup()
Get the layersettings for the canvas.
Definition: drawing.h:506
bool GetActive()
when ::wxEVT_ACTIVATE_VIEW get activation value of the event
Definition: docviewref.h:521
bool SaveLayers(const wxString &filename)
save layer object to CVG file
Definition: layerinf.cpp:615
bool m_viewEnabled
Is the view enabled?
Definition: docviewref.h:2241
void OnOpenDocument(a2dDocumentEvent &event)
load a document from a file into this document
Definition: docviewref.cpp:874
void Update(a2dCanvasObject::UpdateMode mode)
update all pending objects in the document
Definition: candoc.cpp:755
virtual void SetName(const wxString &name)
Creates the a2dStringProperty PROPID_Name.
Definition: gen.cpp:1305
void CreateCommandProcessor()
create a command processor and set it for the document.
Definition: candoc.cpp:698
void WriteEndElement(bool newLine=true)
Writes correspondending end tag for the current start tag.
Definition: genxmlpars.cpp:862
a2dDocumentOutputStream & SaveObject(a2dDocumentOutputStream &stream, a2dIOHandlerStrOut *handler)
save as the a2dCanvas specific XML called CVG format
Definition: candoc.cpp:1068
#define EVT_CREATE_VIEW(func)
event sent to view from template when a view has been created
Definition: docviewref.h:995
a2dDrawingPart * GetActiveDrawingPart()
return the currently/last active drawing part.
Definition: canglob.h:1262
double GetBboxWidth()
get width of the boundingbox in world coordinates relative to its parents
Definition: canobj.h:700
const a2dError a2dError_IOHandler
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
void WriteStartDocument(const wxString &version, const wxString &encoding, bool standalone)
Writes the XML header declaration.
Definition: genxmlpars.cpp:723
virtual double GetVisibleHeight() const
get Height of visible part in world coordinates
Definition: drawer2d.cpp:428
virtual void UpdateAllViews(a2dView *sender=(a2dView *) NULL, unsigned int hint=a2dVIEW_UPDATE_ALL, wxObject *objecthint=(wxObject *) NULL)
sent Update events to all a2dView which display or use this document.
bool IsClosed()
A closed flag is set when a view is closed.
Definition: docviewref.h:1829
void OnUpdate(a2dDocumentEvent &event)
calls a2dDrawingpart::Update()
Definition: candoc.cpp:380
Holds a view on a a2dDocument.
Definition: docviewref.h:1804
double m_scalelimit
limit scaling to this value (world/pixel)
Definition: candoc.h:143
~a2dCanvasDocument()
destructor
Definition: candoc.cpp:731
void OnRedoEvent(a2dCommandProcessorEvent &event)
track modification of document
Definition: candoc.cpp:711
virtual bool CanLoad(a2dDocumentInputStream &stream, const wxObject *obj=NULL, wxClassInfo *docClassInfo=NULL)
test header of the file to see if its CVG format
Definition: xmlpars.cpp:52
bool m_drawframe
draw a frame around the page
Definition: candoc.h:146
static const a2dSignal sig_layersetupChanged
layer info changed id sent around when m_layersetup is changed.
Definition: candoc.h:757
void OnDoEvent(a2dCommandProcessorEvent &event)
track modification of document
Definition: candoc.cpp:704
The document class can be used to model an application&#39;s file-based data.
Definition: docviewref.h:1066
wxDateTime m_accesstime
when was the document last accessed.
Definition: candoc.h:736
const a2dError a2dError_SaveFile
wxString m_documentTitle
Document title.
Definition: docviewref.h:1614
void SetParent(a2dObject *parent)
set parent object of the drawing ( in case there is always only one )
Definition: drawing.h:461
wxUint16 a2dPrintWhat
defines what to print
Definition: gen.h:4052
long m_documentModified
modified flag
Definition: docviewref.h:1637
#define EVT_COM_EVENT(func)
static wxEvtHandler for communication event
Definition: gen.h:564
void SetAvailable()
check which layers do contain objects as seen from the ShowObject()
Definition: drawer.cpp:1641
virtual double GetVisibleWidth() const
get Width of visible part in world coordinates
Definition: drawer2d.cpp:423
#define wxStaticCast(obj, className)
The wxWindows 2.4.2 wxStaticCast is buggy. It evaluates its argument twice.
Definition: gen.h:123
const a2dError a2dError_CouldNotLoad
Drawing context abstraction.
Definition: drawer2d.h:177
void StopAllTools(bool abort=true)
all tools currently on the tool stack will be terminated and poped ( forced )
Definition: tools.cpp:123
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the drawer.
Definition: drawer.h:680
void SetActiveDrawingPart(a2dDrawingPart *part)
get the drawing part that has the focus/is active in a window.
Definition: canglob.cpp:1220
#define EVT_CLOSE_VIEW(func)
event sent to document and view when a view needs to be closed ( can veto)
Definition: docviewref.h:993
void SetCommandProcessor(a2dCommandProcessor *proc)
Sets the command processor to be used for this document.
Definition: drawing.h:562
a2dCanvas and a2dCanvasView meet eachother here.
Definition: candoc.h:774
to print what is displayed on a a2dCanvasView or the whole document as seen from the showobject of th...
Definition: candoc.h:71
a2dCanvasView(int width=1000, int height=1000)
constructor
Definition: candoc.cpp:418
void SetShowObjectAndRender(a2dCanvasObject *obj)
Used temporarely in rendering bitmas or in printing, to Set the show object and redraw the whole part...
Definition: drawer.cpp:3069
a2dDrawer2D * GetDrawer2D()
get the internal m_drawer2D that is used for rendering the document
Definition: drawer.h:1125
const a2dError a2dError_LoadObject
void OnIdle(wxIdleEvent &event)
Called by ProcessEvent(wxEvent&amp; event) of document.
Definition: candoc.cpp:1268
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
view to display the size of a2dCanvasView compared to the whole of the a2dCanvasDocument that is view...
Definition: candoc.h:161
virtual void CreateCommandProcessor()
create a command processor and set it for the document.
Definition: drawing.cpp:380
bool LoadLayers(a2dDocumentInputStream &stream, a2dLayers *layers)
load a layer definition from a CVG file.
Definition: xmlpars.cpp:93
virtual bool Save(a2dDocumentOutputStream &stream, const wxObject *obj)=0
Override to write to the stream and store (part of) of the document contents in the stream...
void WriteEndAttributes(bool close=false)
&quot;Closes&quot; the start tag after writing all attributes (writes the &quot;&gt;&quot; or &quot;/&gt;&quot; bracket).
Definition: genxmlpars.cpp:837
bool m_fitToPage
Definition: candoc.h:150
const a2dPrintWhat a2dPRINT_Print
general print
Definition: docviewref.cpp:190
wxFileName GetFilename() const
Get the file name in use for this document.
Definition: docviewref.h:1103
using a file stream for output, stream a a2dDocument or other wxObject into a stream.
Definition: gen.h:3751
wxString m_title
title put above printout
Definition: candoc.h:137
const a2dError a2dError_SaveObject
const a2dError a2dError_ImportObject
a2dCanvas is used to display one of the a2dCanvasObjects which are part of a a2dCanvasDocument object...
Definition: canvas.h:68
void OnOpenDocument(a2dDocumentEvent &event)
uses wxBufferedInputStream instead of a2dDocumentInputStream
Definition: candoc.cpp:790
virtual wxPrintout * OnCreatePrintout(a2dPrintWhat typeOfPrint, const wxPageSetupDialogData &pageSetupData)
to create a a2dViewPrintout, used to print a view or its document
Definition: candoc.cpp:500
a2dSmrtPtr< a2dLayers > m_layersetup
setup for layers in this document
Definition: candoc.h:715
double m_units_accuracy
how many decimal places in fraction are valid
Definition: candoc.h:721
bool LoadLayers(const wxString &filename)
load layers from another file
Definition: candoc.cpp:1010
void OnChangeDrawings(a2dDrawingEvent &event)
called when a drawing in a document did change.
Definition: candoc.cpp:725
static const a2dSignal sig_changedZoom
Definition: drawer2d.h:1232
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
wxInputStream a2dDocumentInputStream
input stream based wxStreams
Definition: gen.h:3456
wxString m_libraryname
name of library or document
Definition: candoc.h:748
virtual bool CanSave(const wxObject *obj=NULL)=0
Should return true if the handler can write this document to a stream.
a2dWalker based algorithms
wxString & GetDescription()
Returns the description of the document.
Definition: candoc.h:438
bool ReleaseChildObjects(a2dCanvasObjectFlagsMask mask=a2dCanvasOFlags::ALL)
removes and release only from the childobjects the objects with the given mask
Definition: canobj.cpp:6296
static bool m_printAsBitmap
if set print a bitmap that was drawn into
Definition: candoc.h:153
a2dDocument * GetDocument() const
get the document of the view
Definition: docviewref.h:1882
a2dDocviewGlobal * a2dDocviewGlobals
a global pointer to get to global instance of important classes.
Definition: doccom.cpp:2348
bool Modifies()
Definition: comevt.h:214
virtual void Load(wxObject *parent, a2dIOHandlerXmlSerIn &parser)
load object from CVG file
Definition: gen.cpp:1396
wxString GetAttributeValue(const wxString &attrib, const wxString &defaultv=wxT(""))
Returns the value of an attribute.
Definition: genxmlpars.cpp:450
virtual void Load(wxObject *parent, a2dIOHandlerXmlSerIn &parser)
load object from CVG file
Definition: drawing.cpp:730
a2dCanvasView * m_canvasDocview
the view to view zoomed
Definition: candoc.h:193
a2dLayers * GetLayerSetup()
Get the central layersettings for the canvas library.
Definition: canglob.h:478
Each a2dCanvasView needs to have a a2dCanvasDocument set in order to render data. ...
Definition: candoc.h:374
void SetPrintMode(bool onOff)
to modify drawing feature when used as context for printing
Definition: drawer2d.h:696
void WriteEndDocument()
Checks if all open tags are closed.
Definition: genxmlpars.cpp:730
bool m_printfilename
if true, a printout is done with filename (document file path), otherwise not
Definition: candoc.h:308
a2dCanvasView * m_drawingView
maping defined by this canvas
Definition: candoc.h:134
a2dCanvasObject * SetShowObject(const wxString &name)
set object available in the a2dDrawing to be shown on the drawer
Definition: drawer.cpp:2947
const a2dError a2dError_LoadLayers
void Require(const XMLeventType &type, wxString name)
Forces a special tag.
Definition: genxmlpars.cpp:390
bool OnPrintPage(int)
called for every page to print, for a2dCanvasDocument in general just one.
Definition: candoc.cpp:82
wxString GetTagName()
Returns name of the current XML tag.
Definition: genxmlpars.cpp:565
virtual bool ProcessEvent(wxEvent &event)
Extend event processing to search the view&#39;s event table.
print a document
Definition: docviewref.h:3311
void DoSave(a2dIOHandlerCVGOut &out, a2dCanvasObjectList *towrite)
do not use directly, part of CVG format writing
Definition: candoc.cpp:1236
virtual void ReportErrorF(const a2dError &error, const wxChar *Format,...)
concatenate to the the error report the given error.
Definition: comevt.cpp:1312
void OnUndoEvent(a2dCommandProcessorEvent &event)
track modification of document
Definition: candoc.cpp:718
wxString GetPrintableName() const
Get title, or filename if no title, else [unnamed].
double GetBboxHeight()
get height of the boundingbox in world coordinates relative to its parents
Definition: canobj.h:706
bool SaveLayers(const wxString &filename)
save layer settings to CVG file
Definition: candoc.cpp:1004
Event sent to a2dCommandProcessor.
Definition: comevt.h:701
see a2dComEvent
Definition: gen.h:371
see a2dDocumentEvent
Definition: docviewref.h:356
bool DisconnectEventAll(wxEvtHandler *eventSink)
Remove all dynamic events in classA, going to classB (eventSink)
Definition: gen.cpp:1021
a2dViewPrintout(const wxPageSetupDialogData &pageSetupData, a2dCanvasView *drawer, const wxString &title, const wxString &filename, a2dPrintWhat typeOfPrint, bool drawframe, double scalelimit, bool fitToPage)
initialize mapping based on an existing canvas
Definition: candoc.cpp:65
bool m_printfittopage
If true, draw a view on all page without real scale.
Definition: candoc.h:317
used to report a2dDocument events
Definition: docviewref.h:591
void SetLayerSetup(a2dLayers *layersetup)
set the layersettings for the canvas.
Definition: drawing.cpp:280
a2dDrawing * GetDrawing() const
get drawing via top object
Definition: drawer.cpp:726
virtual ~a2dCanvasView()
destructor
Definition: candoc.cpp:432
the a2dDrawingPart is a a2dView specially designed for displaying parts of a a2dDrawing. It uses a a2dDrawer2D to actually redraw things from the document, by giving that a2dDrawer2D as drawing context to the document, and telling the document to redraw a certain rectangular area. At that last is what this class is for. It optimizes the areas to be redrawn after object in the document were changed. To do that it combines redraw areas to a minimal set of redrawing areas. All the administration for this and the way things will be redrawn is from this view.
Input handler for the CVG format.
Definition: xmlpars.h:59
virtual ~a2dZoomedView()
destructor
Definition: candoc.cpp:523
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
virtual void Save(wxObject *parent, a2dIOHandlerXmlSerOut &out, a2dObjectList *towrite)
write all needed to an XML type of file called the CVG format
Definition: gen.cpp:1343
#define EVT_UNDO(func)
event sent from a2DocumentCommandProcessor when a command is undone
Definition: comevt.h:797
const a2dPrintWhat a2dPRINT_PreviewView
preview print a2dView
Definition: docviewref.cpp:193
wxUint32 GetDocumentDrawStyle()
get drawstyles used for drawing the document
Definition: drawer.h:1141
const a2dPrintWhat a2dPRINT_PrintView
print a2dView
Definition: docviewref.cpp:192
bool Save()
Saves the document by sending a a2dDocumentEvent ::wxEVT_SAVE_DOCUMENT event.
Definition: docviewref.cpp:517
void SetShowOrigin(bool show)
Set showorigin on/off.
Definition: drawer.h:925
void SetDrawer2D(a2dDrawer2D *drawer2d, bool noDelete=false)
set the internal m_drawer2D to be used for rendering the document
Definition: drawer.cpp:765
wxWindow * m_display
In case of using a window for displaying the view, this holds the window.
Definition: docviewref.h:2244
virtual void DeleteContents()
delete all object in this document (also nested groups etc.)
Definition: candoc.cpp:745
list of a2dObject&#39;s
Definition: gen.h:3157
bool Start(a2dObject *object)
start removing properties from the object given, and down.
Definition: algos.h:634
a2dDocumentTemplatePtr m_documentTemplate
A pointer to the template from which this document was created.
Definition: docviewref.h:1634
wxString m_filename
filename put below printout
Definition: candoc.h:140
void SetFormatVersion(wxString formatVersion)
set version of library or document being parsed for
Definition: genxmlpars.h:844
CloneOptions
options for cloning
Definition: gen.h:1200
virtual void SetMappingWidthHeight(double vx1, double vy1, double width, double height)
Give the virtual size to be displayed, the mapping matrix will be calculated.
Definition: drawer2d.cpp:333
#define EVT_REMOVE_VIEW(func)
event sent to document when a view will be removed from the document
Definition: docviewref.h:1007
a2dDrawingPtr m_drawing
start a2dCanvasObject containing all primitives
Definition: candoc.h:702
Contain one drawing as hierarchical tree of a2dCanvasObject&#39;s.
Definition: drawing.h:434
void SetMappingShowAll()
use the boundingbox of the ShowObject to set the mapping such that it will be displayed completely on...
Definition: drawer.cpp:3149
wxInt64 GetUniqueSerializationId() const
return a unique id for this object
Definition: gen.cpp:1450
void OnComEvent(a2dComEvent &event)
called for a2dComEvent events.
Definition: candoc.cpp:586
void SetLayerSetup(a2dLayers *layersetup)
set the layersettings for the canvas.
Definition: candoc.cpp:780
general canvas module declarations and classes
bool m_printframe
If true, draw a frame around printouts.
Definition: candoc.h:314
candoc.cpp Source File -- Sun Oct 12 2014 17:04:13 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation