00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "a2dprec.h"
00012
00013 #ifdef __BORLANDC__
00014 #pragma hdrstop
00015 #endif
00016
00017 #ifndef WX_PRECOMP
00018 #include "wx/wx.h"
00019 #endif
00020
00021 #include <wx/wfstream.h>
00022 #include <math.h>
00023 #include <wx/tokenzr.h>
00024 #include <locale.h>
00025
00026
00027 #if wxUSE_STD_IOSTREAM
00028 #include "wx/ioswrap.h"
00029 #if wxUSE_IOSTREAMH
00030 #include <fstream.h>
00031 #else
00032 #include <fstream>
00033 #endif
00034 #else
00035 #include "wx/wfstream.h"
00036 #endif
00037
00038
00039 #include "wx/canvas/candoc.h"
00040 #include "wx/canvas/cancom.h"
00041
00042 #include "wx/canvas/xmlpars.h"
00043 #include "wx/canvas/drawer.h"
00044 #include "wx/canvas/canglob.h"
00045 #include "wx/canvas/algos.h"
00046
00047 #if defined(__WXMSW__) && defined(__MEMDEBUG__)
00048 #include <wx/msw/msvcrt.h>
00049 #endif
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 DEFINE_EVENT_TYPE( a2dCanvasDocument::sm_layersetupChanged )
00060
00061 IMPLEMENT_DYNAMIC_CLASS(a2dCanvasDocument, a2dDocument)
00062
00063 A2D_BEGIN_EVENT_TABLE( a2dCanvasDocument, a2dDocument )
00064 A2D_EVT_IDLE( a2dCanvasDocument::OnIdle )
00065 A2D_EVT_OPEN_DOCUMENT( a2dCanvasDocument::OnOpenDocument )
00066 A2D_END_EVENT_TABLE()
00067
00068 a2dCanvasDocument::a2dCanvasDocument(): a2dDocument()
00069 {
00070 m_rootobject = new a2dCanvasObject();
00071
00072 m_askSaveWhenOwned = false;
00073
00074 m_layersetup = (a2dLayers*) a2dCanvasGlobals->GetLayerSetup()->Clone( clone_deep );
00075
00076 m_rootobject->SetCanvasDocument( this );
00077
00078 m_ignorePendingObjects = false;
00079 m_updatespending = false;
00080
00081 m_units_accuracy = 0.001;
00082 m_units_scale = 1.0;
00083 m_normalize_scale = 1.0;
00084
00085 m_units = wxT("non");
00086 m_units_measure = wxT("non");
00087
00088 m_initialSizeX = 100;
00089 m_initialSizeY = 100;
00090
00091 m_description = wxT("a2dCanvasDocument generated by wxArt2D");
00092 m_libraryname = wxT("Not specified");
00093
00094 m_modificationtime = wxDateTime::Now();
00095 m_accesstime = wxDateTime::Now();
00096 m_changedInternalAccesstime = wxDateTime::Now();
00097
00098 m_documentTypeName = wxT("a2dCanvasDocument");
00099
00100 m_multiRoot = false;
00101 }
00102
00103 a2dCanvasDocument::a2dCanvasDocument( const a2dCanvasDocument &other)
00104 :a2dDocument( other )
00105 {
00106 if ( other.m_rootobject )
00107 {
00108 m_rootobject = other.m_rootobject->TClone( clone_deep );
00109 m_rootobject->SetCanvasDocument( this );
00110 }
00111 if ( other.m_layersetup )
00112 {
00113 m_layersetup = (a2dLayers*) other.m_layersetup->Clone( clone_deep );
00114 m_layersetup->SetCanvasDocument( this );
00115 }
00116 m_ignorePendingObjects = false;
00117 m_updatespending = false;
00118 m_units_accuracy = other.m_units_accuracy;
00119 m_units = other.m_units;
00120 m_units_scale = other.m_units_scale;
00121 m_normalize_scale = other.m_normalize_scale;
00122 m_units_measure = other.m_units_measure;
00123 m_description = other.m_description;
00124 m_libraryname = other.m_libraryname;
00125 m_modificationtime = other.m_modificationtime;
00126 m_accesstime = other.m_accesstime;
00127 m_documentTypeName = other.m_documentTypeName;
00128 m_multiRoot = other.m_multiRoot;
00129
00130 m_initialSizeX = other.m_initialSizeX;
00131 m_initialSizeY = other.m_initialSizeY;
00132
00133 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG)
00134
00135 CurrentSmartPointerOwner = this;
00136 #endif
00137 }
00138
00139 a2dObject* a2dCanvasDocument::Clone( CloneOptions WXUNUSED(options) ) const
00140 {
00141 a2dCanvasDocument* a = new a2dCanvasDocument( *this );
00142 return a;
00143 }
00144
00145 a2dCanvasDocument::~a2dCanvasDocument()
00146 {
00147
00148
00149
00150 if ( m_rootobject )
00151 m_rootobject->SetCanvasDocument( NULL );
00152 if ( m_layersetup )
00153 m_layersetup->SetCanvasDocument( this );
00154 }
00155
00156
00157
00158
00159
00160
00161 void a2dCanvasDocument::DeleteContents()
00162 {
00163 m_rootobject->ReleaseChildObjects();
00164 }
00165
00166 a2dCanvasCommandProcessor* a2dCanvasDocument::GetCanvasCommandProcessor()
00167 {
00168 return wxStaticCastNull( GetCommandProcessor(), a2dCanvasCommandProcessor);
00169 }
00170
00171 void a2dCanvasDocument::Update( a2dCanvasObject::UpdateMode mode )
00172 {
00173 m_layersetup->SetAllLayersAvailable( false );
00174
00175 m_layersetup->SetAvailable( wxLAYER_DEFAULT, TRUE );
00176
00177 m_rootobject->Update( mode );
00178 }
00179
00180 void a2dCanvasDocument::SetRootObject( a2dCanvasObject* newRoot )
00181 {
00182 wxASSERT_MSG( newRoot, wxT("a2dCanvasDocument its root object can not be NULL") );
00183 m_rootobject = newRoot;
00184 SetCanvasDocumentRecursive();
00185 }
00186
00187 void a2dCanvasDocument::DependencyPending()
00188 {
00189 if ( !m_ignorePendingObjects )
00190 {
00191
00192 while ( m_updatespending )
00193 {
00194 m_updatespending = false;
00195 a2dWalker_CallMemberFuncW walker;
00196 walker.Start( m_rootobject, &a2dCanvasObject::DependencyPending );
00197 }
00198 m_updatespending = true;
00199 }
00200 }
00201
00202 void a2dCanvasDocument::SetUpdatesPending(bool onoff)
00203 {
00204 if ( !m_ignorePendingObjects )
00205 {
00206 m_changedInternalAccesstime = wxDateTime::Now();
00207 if ( !onoff )
00208 {
00209 a2dWalker_SetSpecificFlagsCanvasObjects setflags( a2dCanvasOFlags::PENDING );
00210 setflags.Start( m_rootobject, false );
00211
00212
00213
00214 setflags.Start( m_layersetup, false );
00215 }
00216 m_updatespending=onoff;
00217 }
00218 }
00219
00220 bool a2dCanvasDocument::GetUpdatesPending()
00221 {
00222 if ( m_ignorePendingObjects )
00223 return false;
00224 return m_updatespending;
00225 }
00226
00227 void a2dCanvasDocument::SetIgnorePendingObjects( bool onoff )
00228 {
00229 m_ignorePendingObjects = onoff;
00230 }
00231
00232 void a2dCanvasDocument::SetLayerSetup( a2dLayers* layersetup )
00233 {
00234 m_layersetup = layersetup;
00235 if ( m_layersetup )
00236 m_layersetup->SetCanvasDocument( this );
00237
00238 a2dComEvent changedlayers( this, m_layersetup, &sm_layersetupChanged );
00239 a2dDocviewGlobals->GetEventDistributer()->ProcessEvent( changedlayers );
00240 };
00241
00242 void a2dCanvasDocument::SetCanvasDocumentRecursive()
00243 {
00244 if ( m_rootobject )
00245 m_rootobject->SetCanvasDocument(this);
00246 if ( m_layersetup )
00247 m_layersetup->SetCanvasDocument(this);
00248
00249
00250
00251
00252
00253 a2dComEvent changedlayers( this, m_layersetup, &a2dCanvasView::sm_changedLayers );
00254 a2dDocviewGlobals->GetEventDistributer()->ProcessEvent( changedlayers );
00255 }
00256
00257 void a2dCanvasDocument::OnOpenDocument( a2dDocumentEvent& event )
00258 {
00259 a2dDocument::OnOpenDocument( event );
00260
00261 UpdateAllViews( NULL, a2dCANVIEW_UPDATE_ALL );
00262 }
00263
00264 a2dDocumentInputStream& a2dCanvasDocument::LoadObject( a2dDocumentInputStream& stream, a2dIOHandlerStrIn* handler )
00265 {
00266
00267
00268
00269
00270
00271 wxString oldLocale = wxSetlocale( LC_NUMERIC, NULL );
00272 wxSetlocale( LC_NUMERIC, wxString(wxT("English")) );
00273
00274 bool ownhandler = false;
00275 if (! handler )
00276 {
00277 #if wxART2D_USE_CVGIO
00278
00279 handler = new a2dIOHandlerCVGIn();
00280 ownhandler = true;
00281 #else
00282 a2dDocviewGlobals->ReportErrorF( a2dError_NoDocTemplateRef, _("No template defined in a2dDocument::LoadObject") );
00283 #endif //wxART2D_USE_CVGIO
00284 }
00285
00286 #if wxUSE_STD_IOSTREAM
00287 bool isOK = (stream.fail() || stream.bad()) == 0;
00288 #else
00289 bool isOK = stream.IsOk ();
00290 #endif
00291
00292 bool oke = false;
00293 if (isOK)
00294 {
00295 if ( handler )
00296 {
00297 if ( handler->CanLoad( stream, this, m_documentTemplate ? m_documentTemplate->GetDocumentClassInfo(): NULL ) )
00298 {
00299 if ( !handler->Load(stream, this) )
00300 {
00301 a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotLoad, _("I/O handler error during loading this format."));
00302 m_lastError = a2dError_CouldNotLoad;
00303 }
00304 else
00305 oke = true;
00306 }
00307 else
00308 {
00309 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("I/O handler not capable of loading in this format."));
00310 m_lastError = a2dError_IOHandler;
00311 }
00312 }
00313 else
00314 {
00315 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("I/O handler must be != NULL, maybe template I/O handler not available in document template.") );
00316 m_lastError = a2dError_IOHandler;
00317 }
00318
00319
00320 if ( ownhandler )
00321 delete handler;
00322 }
00323 else
00324 a2dDocviewGlobals->ReportErrorF( a2dError_ImportObject, _("bad stream"));
00325
00326
00327 if ( oke )
00328 {
00329
00330 SetCanvasDocumentRecursive();
00331
00332 Update( a2dCanvasObject::updatemask_force );
00333
00334 a2dDocumentEvent event( wxEVT_POST_LOAD_DOCUMENT );
00335 event.SetEventObject( this );
00336 DistributeEvent( event );
00337 }
00338 else
00339 {
00340 a2dDocviewGlobals->ReportErrorF( a2dError_CouldNotLoad, _("bad stream"));
00341 m_lastError = a2dError_CouldNotLoad;
00342 }
00343
00344 wxSetlocale( LC_NUMERIC, oldLocale );
00345 return stream;
00346 }
00347
00348 bool a2dCanvasDocument::Load(const wxString& filename, a2dIOHandlerStrIn* handler )
00349 {
00350 m_lastError = a2dError_NoError;
00351 #if wxUSE_STD_IOSTREAM
00352 a2dDocumentFileInputStream stream( filename.mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
00353 if (stream.fail() || stream.bad())
00354 #else
00355 wxFileInputStream stream( filename );
00356 if ( !stream.IsOk() )
00357 #endif
00358 {
00359 a2dDocviewGlobals->ReportErrorF( a2dError_FileCouldNotOpen, _("Sorry, could not open file %s for loading"), filename.c_str() );
00360 return false;
00361 }
00362
00363 if ( handler )
00364 {
00365 if ( handler->CanLoad(stream, this, m_documentTemplate ? m_documentTemplate->GetDocumentClassInfo(): NULL ) )
00366 {
00367 if ( !handler->Load(stream, this) )
00368 {
00369 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler failed loading from stream.") );
00370 m_lastError = a2dError_CouldNotLoad;
00371 }
00372 else
00373 {
00374 UpdateAllViews( NULL, a2dCANVIEW_UPDATE_ALL );
00375 return true;
00376 }
00377 }
00378 else
00379 {
00380 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler not capable of loading this format.") );
00381 m_lastError = a2dError_IOHandler;
00382 }
00383 }
00384 else
00385 {
00386 a2dDocviewGlobals->ReportErrorF( a2dError_LoadObject, _("I/O handler not set in document template.") );
00387 m_lastError = a2dError_NoDocTemplateRef;
00388 }
00389 return false;
00390 }
00391
00392 #if wxART2D_USE_CVGIO
00393 void a2dCanvasDocument::Load( wxObject* WXUNUSED(parent), a2dIOHandlerXmlSerIn& parser )
00394 {
00395 a2dWalker_SetBoolProperty setp( PROPID_Check, false );
00396 setp.Start( m_rootobject );
00397 setp.Start( m_layersetup );
00398
00399 parser.Next();
00400 parser.Require( START_TAG, wxT("cvg") );
00401 parser.Next();
00402 if ( parser.GetTagName() == wxT("title") )
00403 {
00404 m_documentTitle = parser.GetContent();
00405 parser.Next();
00406 parser.Require( END_TAG, wxT("title") );
00407 parser.Next();
00408 }
00409 if ( parser.GetTagName() == wxT("desc") )
00410 {
00411 m_description = parser.GetContent();
00412 parser.Next();
00413 parser.Require( END_TAG, wxT("desc") );
00414 parser.Next();
00415 }
00416
00417 if ( parser.GetTagName() == wxT("o") && parser.GetAttributeValue( wxT("classname") ) == wxT("a2dLayers") )
00418 {
00419 if (m_layersetup)
00420 m_layersetup->ReleaseChildObjects();
00421 else
00422 {
00423 m_layersetup = new a2dLayers();
00424 }
00425 m_layersetup->Load( NULL, parser );
00426 m_layersetup->GetLayerIndex();
00427 }
00428
00429 UpdateLoadedLayerSetup();
00430
00431 if ( parser.GetTagName() == wxT("o") )
00432 m_rootobject->Load( NULL, parser );
00433
00434 parser.Require( END_TAG, wxT("cvg") );
00435 }
00436 #endif //wxART2D_USE_CVGIO
00437
00438 bool a2dCanvasDocument::SaveLayers( const wxString& filename )
00439 {
00440 return m_layersetup->SaveLayers( filename );
00441 }
00442
00443 bool a2dCanvasDocument::LoadLayers( const wxString& filename )
00444 {
00445 m_lastError = a2dError_NoError;
00446 #if wxUSE_STD_IOSTREAM
00447 a2dDocumentFileInputStream stream( filename.mb_str(), wxSTD ios_base::in | wxSTD ios_base::binary );
00448 if (stream.fail() || stream.bad())
00449 #else
00450 wxFileInputStream stream( filename );
00451 if ( !stream.Ok() )
00452 #endif
00453 {
00454 a2dDocviewGlobals->ReportErrorF( a2dError_LoadLayers, _("Sorry, could not open file %s for loading"), filename.c_str() );
00455 m_lastError = a2dError_LoadLayers;
00456 return false;
00457 }
00458
00459 m_layersetup->SetFileName( filename );
00460 m_layersetup->ReleaseChildObjects();
00461
00462 bool done = true;
00463
00464 #if wxART2D_USE_CVGIO
00465
00466 a2dIOHandlerCVGIn* handler = new a2dIOHandlerCVGIn();
00467
00468 if ( handler && handler->CanLoad(stream, m_layersetup, NULL ) )
00469 {
00470 if ( !handler->LoadLayers(stream, m_layersetup ) )
00471 {
00472 a2dDocviewGlobals->ReportErrorF( a2dError_LoadLayers, _("template I/O handler not capable of loading this format."));
00473 m_lastError = a2dError_LoadLayers;
00474 done = false;
00475 }
00476 }
00477 else
00478 {
00479 a2dDocviewGlobals->ReportErrorF( a2dError_LoadLayers, _("template I/O handler not capable of loading this format."));
00480 m_lastError = a2dError_LoadLayers;
00481 done = false;
00482 }
00483 #else
00484 wxFAIL_MSG( wxT("wxART2D_USE_CVGIO is needed to load layers from a file CVG file") );
00485 #endif //wxART2D_USE_CVGIO
00486
00487 #if wxART2D_USE_CVGIO
00488 delete handler;
00489 #endif //wxART2D_USE_CVGIO
00490 return done;
00491 }
00492
00493 void a2dCanvasDocument::UpdateLoadedLayerSetup()
00494 {
00495 }
00496
00497 a2dDocumentOutputStream& a2dCanvasDocument::SaveObject(a2dDocumentOutputStream& stream, a2dIOHandlerStrOut* handler )
00498 {
00499
00500
00501
00502
00503
00504 wxString oldLocale = wxSetlocale( LC_NUMERIC, NULL );
00505 wxSetlocale( LC_NUMERIC, wxString( wxT("English") ) );
00506
00507 #if wxUSE_STD_IOSTREAM
00508 bool isOK = (stream.fail() || stream.bad()) == 0;
00509 #else
00510 bool isOK = stream.IsOk ();
00511 #endif
00512
00513 if (! handler )
00514 {
00515 #if wxART2D_USE_CVGIO
00516
00517 handler = new a2dIOHandlerCVGOut();
00518 #else
00519 wxFAIL_MSG( wxT("wxART2D_USE_CVGIO is needed to load object from a file CVG file") );
00520 #endif //wxART2D_USE_CVGIO
00521 }
00522
00523 if (isOK)
00524 {
00525 if ( handler )
00526 {
00527 if ( handler->CanSave( this ) )
00528 {
00529 if ( !handler->Save(stream, this) )
00530 {
00531 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler error during saving in this format") );
00532 m_lastError = a2dError_IOHandler;
00533 }
00534 }
00535 else
00536 {
00537 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler not capable of saving in this format."));
00538 m_lastError = a2dError_IOHandler;
00539 }
00540 }
00541 else
00542 {
00543 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler not set in document template"));
00544 m_lastError = a2dError_IOHandler;
00545 }
00546 }
00547 else
00548 {
00549 a2dDocviewGlobals->ReportErrorF( a2dError_SaveObject, _("bad stream") );
00550 m_lastError = a2dError_SaveObject;
00551 }
00552
00553 if (! m_documentTemplate )
00554 delete handler;
00555
00556 wxSetlocale( LC_NUMERIC, oldLocale );
00557
00558 return stream;
00559 }
00560
00561 bool a2dCanvasDocument::Save(const wxString& filename, a2dIOHandlerStrOut* handler ) const
00562 {
00563 #if wxUSE_STD_IOSTREAM
00564 a2dDocumentFileOutputStream stream(filename.mb_str(), wxSTD ios_base::out | wxSTD ios_base::binary );
00565 if (stream.fail() || stream.bad())
00566 #else
00567 wxFileOutputStream stream( filename );
00568 if (stream.GetLastError() != wxSTREAM_NO_ERROR)
00569 #endif
00570 {
00571 a2dDocviewGlobals->ReportErrorF( a2dError_SaveFile, _("Sorry, could not open file %s for saving"), filename.c_str() );
00572
00573
00574 return false;
00575 }
00576
00577 if ( handler )
00578 {
00579 if ( handler->CanSave( this ) )
00580 {
00581 if ( handler->Save(stream, this) )
00582 return true;
00583
00584 a2dDocviewGlobals->ReportErrorF( a2dError_SaveFile, _("template I/O handler not succeeded to save in this format to file %s"), filename.c_str() );
00585 }
00586 else
00587 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler not capable of saving in this format."));
00588 }
00589 else
00590 a2dDocviewGlobals->ReportErrorF( a2dError_IOHandler, _("template I/O handler not set in document template"));
00591 return false;
00592 }
00593
00594
00595 #if wxART2D_USE_CVGIO
00596 void a2dCanvasDocument::Save( wxObject* WXUNUSED(parent), a2dIOHandlerXmlSerOut &out, a2dObjectList* WXUNUSED(towrite) )
00597 {
00598 Save( (a2dIOHandlerCVGOut&) out, m_rootobject );
00599 }
00600
00601 void a2dCanvasDocument::Save( a2dIOHandlerCVGOut &out, a2dCanvasObject* start )
00602 {
00603
00604 a2dWalker_SetBoolProperty setp( PROPID_Check, false );
00605 setp.Start( m_rootobject );
00606 setp.Start( m_layersetup );
00607
00608 out.WriteStartDocument( wxT("1.0"), wxT("UTF-8") , true );
00609
00610 out.WriteStartElementAttributes( wxT("cvg") );
00611 out.WriteAttribute( wxT("classname"), GetClassInfo()->GetClassName() );
00612 out.WriteEndAttributes();
00613
00614 out.WriteElement( wxT("title"), GetPrintableName() );
00615 out.WriteElement( wxT("desc"), m_description );
00616
00617 a2dObjectList towritelayer;
00618 m_layersetup->Save( NULL, out, &towritelayer );
00619
00620 a2dObjectList towrite;
00621 if ( start )
00622 towrite.push_back( start );
00623 else
00624 towrite.push_back( m_rootobject.Get() );
00625
00626 a2dObjectList::iterator iter = towrite.begin();
00627 while ( towrite.size() )
00628 {
00629 a2dObject *obj = *iter;
00630 obj->Save( NULL, out, &towrite );
00631 towrite.erase( iter );
00632 iter = towrite.begin();
00633 }
00634
00635 out.WriteEndElement();
00636 out.WriteEndDocument();
00637 }
00638
00639 void a2dCanvasDocument::DoSave( a2dIOHandlerCVGOut &out, a2dCanvasObjectList* WXUNUSED(towrite) )
00640 {
00641 out.WriteEndAttributes();
00642 }
00643 #endif //wxART2D_USE_CVGIO
00644
00645 bool a2dCanvasDocument::WriteSVG( a2dCanvasView* drawer, const wxString& filename, a2dCanvasObject* WXUNUSED(top), double WXUNUSED(Width), double WXUNUSED(Height), wxString unit)
00646 {
00647 wxASSERT_MSG( drawer, wxT("no a2dCanvasView set for a2dCanvasDocument") );
00648
00649 a2dWalker_SetBoolProperty setp( PROPID_Check, false );
00650 setp.Start( m_rootobject );
00651 setp.Start( m_layersetup );
00652
00653 bool done = false;
00654 #if wxART2D_USE_SVGIO
00655 a2dIOHandlerSVGOut* handler = new a2dIOHandlerSVGOut();
00656 a2dIterC ic( drawer );
00657
00658 handler->SetIterC( ic );
00659
00660 done = Save( filename, handler );
00661
00662 delete handler;
00663 #else
00664 wxFAIL_MSG( wxT("wxART2D_USE_SVGIO is needed to write doc into SVG file") );
00665 #endif //wxART2D_USE_SVGIO
00666
00667 return done;
00668 }
00669
00670 a2dCanvasObject* a2dCanvasDocument::Find( a2dCanvasObject* obj )
00671 {
00672 a2dWalker_FindCanvasObject finder( obj );
00673
00674 if ( finder.Start( m_rootobject ) )
00675 return obj;
00676 return NULL;
00677 }
00678
00679 a2dCanvasObject* a2dCanvasDocument::Find( const wxString& objectname, const wxString& classname, wxInt64 id )
00680 {
00681 a2dWalker_CollectCanvasObjects finder( a2dCanvasOFlags::ALL );
00682 finder.SetObjectName( objectname );
00683 finder.AddClassName( classname );
00684 finder.SetUniqueSerializationId( id );
00685 finder.Start( m_rootobject );
00686
00687 if ( finder.m_found.size() )
00688 return finder.m_found.front();
00689 return NULL;
00690 }
00691
00692 void a2dCanvasDocument::SetSpecificFlags( bool setOrClear, a2dCanvasObjectFlagsMask which, const wxString& classname, a2dCanvasObjectFlagsMask whichobjects )
00693 {
00694 a2dWalker_SetSpecificFlagsCanvasObjects setflags( which, whichobjects );
00695 setflags.Start( m_rootobject, setOrClear );
00696 }
00697
00698 void a2dCanvasDocument::OnIdle( wxIdleEvent &event )
00699 {
00700 if ( AddPendingUpdatesOldNew() )
00701 {
00702
00703
00704
00705
00706 UpdateAllViews( NULL, a2dCANVIEW_UPDATE_AREAS | a2dCANVIEW_UPDATE_BLIT );
00707 }
00708 else
00709 event.Skip();
00710 }
00711
00712 void a2dCanvasDocument::UpdateAllViews( a2dView *sender, unsigned int hint, wxObject *WXUNUSED(objecthint) )
00713 {
00714
00715
00716 if ( ( hint & a2dCANVIEW_UPDATE_ALL ) && GetUpdatesPending() )
00717 {
00718 a2dDocumentEvent event( wxEVT_UPDATE_VIEWS, (a2dView*) NULL );
00719 event.SetEventObject(this);
00720 event.SetUpdateHint( a2dCANVIEW_UPDATE_VIEWDEPENDENT );
00721 DistributeEvent( event );
00722
00723
00724 Update( a2dCanvasObject::updatemask_normal );
00725
00726 SetUpdatesPending(false);
00727 }
00728
00729
00730 a2dDocument::UpdateAllViews(sender, hint, NULL );
00731 }
00732
00733 bool a2dCanvasDocument::AddPendingUpdatesOldNew()
00734 {
00735 if ( !GetUpdatesPending() )
00736 return false;
00737
00738
00739
00740 if ( m_layersetup && m_layersetup->GetPending() )
00741 {
00742 a2dComEvent changedlayers( this, m_layersetup, &sm_layersetupChanged );
00743 a2dDocviewGlobals->GetEventDistributer()->ProcessEvent( changedlayers );
00744
00745 Update( a2dCanvasObject::updatemask_normal );
00746
00747 SetUpdatesPending(false);
00748
00749 UpdateAllViews( NULL, a2dCANVIEW_UPDATE_ALL );
00750
00751
00752 return true;
00753 }
00754
00755
00756 if ( m_layersetup )
00757 {
00758 unsigned int j;
00759 for ( j=0; j< wxMAXLAYER; j++ )
00760 {
00761 if ( m_layersetup->GetLayerIndex()[j]->GetPending() )
00762 {
00763 Update( a2dCanvasObject::updatemask_normal );
00764
00765 SetUpdatesPending(false);
00766
00767 UpdateAllViews( NULL, a2dCANVIEW_UPDATE_ALL );
00768 return true;
00769 }
00770 }
00771 }
00772
00773 DependencyPending();
00774
00775
00776
00777
00778 a2dDocumentEvent eventPreUpdate( wxEVT_UPDATE_VIEWS, (a2dView*) NULL );
00779 eventPreUpdate.SetEventObject(this);
00780
00781
00782 eventPreUpdate.SetUpdateHint( a2dCANVIEW_UPDATE_PENDING );
00783 DistributeEvent( eventPreUpdate );
00784
00785 Update( a2dCanvasObject::updatemask_normal );
00786
00787
00788
00789
00790
00791 a2dDocumentEvent eventPostUpdate( wxEVT_UPDATE_VIEWS, (a2dView*) NULL );
00792 eventPostUpdate.SetEventObject(this);
00793 eventPostUpdate.SetUpdateHint( a2dCANVIEW_UPDATE_PENDING );
00794 DistributeEvent( eventPostUpdate );
00795
00796
00797 SetUpdatesPending(false);
00798
00799
00800
00801
00802
00803
00804
00805 a2dWalker_RemovePropertyCandoc removep( a2dCanvasObject::PROPID_BoundingBox );
00806 removep.SetMakePending( true );
00807 removep.Start( GetRootObject() );
00808
00809 return true;
00810 }
00811
00812 void a2dCanvasDocument::Freeze()
00813 {
00814
00815
00816
00817
00818
00819
00820 }
00821
00822 void a2dCanvasDocument::Thaw(bool WXUNUSED(update) )
00823 {
00824
00825
00826
00827
00828
00829
00830
00831 }
00832
00833 void a2dCanvasDocument::CreateCommandProcessor()
00834 {
00835 m_commandProcessor = new a2dCanvasCommandProcessor( this );
00836 }
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846