X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Document.cpp;h=4ff65b48c699da6b4d07e62764f267cd22fdebf1;hb=77b93142eb8ba33bfb9a42040c2fd8926ffea5c8;hp=d85fb7b292b9abcbdddf464d43ece287587726ac;hpb=a48ce23147176e95a71738cd1aeab5ff79a58b3a;p=modules%2Fshaper.git diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index d85fb7b29..4ff65b48c 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -105,8 +105,9 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis) } TCollection_ExtendedString aPath(DocFileName(theFileName, myID)); PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1; + Handle(TDocStd_Document) aLoaded; try { - aStatus = anApp->Open(aPath, myDoc); + aStatus = anApp->Open(aPath, aLoaded); } catch (Standard_Failure) { Handle(Standard_Failure) aFail = Standard_Failure::Caught(); Events_Error::send( @@ -168,6 +169,7 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis) } } if (!isError) { + myDoc = aLoaded; myDoc->SetUndoLimit(UNDO_LIMIT); // to avoid the problem that feature is created in the current, not this, document std::shared_ptr aSession = @@ -184,7 +186,13 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis) aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false); // this is done in Part result "activate", so no needed here. Causes not-blue active part. // aSession->setActiveDocument(anApp->getDocument(myID), true); - } + } else { // open failed, but new documnet was created to work with it: inform the model + static std::shared_ptr aMsg( + new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED))); + Events_Loop::loop()->send(aMsg); + TDF_LabelList anEmpty; + myObjs->synchronizeFeatures(anEmpty, true, true); + } return !isError; } @@ -607,6 +615,7 @@ FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurre FeaturePtr aFeature = aSession->createFeature(theID, this); if (!aFeature) return aFeature; + aFeature->init(); Model_Document* aDocToAdd; if (!aFeature->documentToAdd().empty()) { // use the customized document to add if (aFeature->documentToAdd() != kind()) { // the root document by default @@ -745,7 +754,7 @@ std::shared_ptr Model_Document::currentFeature(const bool theV } void Model_Document::setCurrentFeature(std::shared_ptr theCurrent, - const bool theVisible) + const bool theVisible, const bool theFlushUpdates) { // blocks the flush signals to avoid each objects visualization in the viewer // they should not be shown once after all modifications are performed @@ -840,9 +849,11 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr // unblock the flush signals and up them after this aLoop->activateFlushes(isActive); - aLoop->flush(aCreateEvent); - aLoop->flush(aRedispEvent); - aLoop->flush(aDeleteEvent); + if (theFlushUpdates) { + aLoop->flush(aCreateEvent); + aLoop->flush(aRedispEvent); + aLoop->flush(aDeleteEvent); + } } void Model_Document::setCurrentFeatureUp() @@ -852,7 +863,8 @@ void Model_Document::setCurrentFeatureUp() FeaturePtr aCurrent = currentFeature(false); if (aCurrent.get()) { // if not, do nothing because null is the upper FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true); - setCurrentFeature(aPrev, false); + // do not flush: it is called only on remove, it will be flushed in the end of transaction + setCurrentFeature(aPrev, false, false); } } @@ -1000,7 +1012,27 @@ std::shared_ptr Model_Document::internalFeature(const int theI return myObjs->internalFeature(theIndex); } -// Feature that is used for selection in the Part document by the external request +void Model_Document::synchronizeTransactions() +{ + Model_Document* aRoot = + std::dynamic_pointer_cast(ModelAPI_Session::get()->moduleDocument()).get(); + if (aRoot == this) + return; // don't need to synchronise root with root + + std::shared_ptr aSession = + std::dynamic_pointer_cast(Model_Session::get()); + while(myRedos.size() > aRoot->myRedos.size()) { // remove redos in this + aSession->setCheckTransactions(false); + redo(); + aSession->setCheckTransactions(true); + } + /* this case can not be reproduced in any known case for the current moment, so, just comment + while(myRedos.size() < aRoot->myRedos.size()) { // add more redos in this + undoInternal(false, true); + }*/ +} + +/// Feature that is used for selection in the Part document by the external request class Model_SelectionInPartFeature : public ModelAPI_Feature { public: /// Nothing to do in constructor