From: mpv Date: Tue, 22 Dec 2015 14:08:00 +0000 (+0300) Subject: For the issue #1156 : do not cause Placement error on activation of previous Part... X-Git-Tag: V_2.1.0~106 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=54be9b4cb34b76e64da83faff84f04880a37537d;p=modules%2Fshaper.git For the issue #1156 : do not cause Placement error on activation of previous Part. THe Placement should be disabled at that time. --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index c38a70f53..ec071b403 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -870,6 +870,8 @@ const int Model_Document::index(std::shared_ptr theObject) int Model_Document::size(const std::string& theGroupID) { + if (myObjs == 0) // may be on close + return 0; return myObjs->size(theGroupID); } diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 431576afb..772cbb384 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -97,6 +97,8 @@ std::shared_ptr Model_ResultPart::original() bool Model_ResultPart::isActivated() { if (myTrsf.get()) { + if (!baseRef().get()) // may be on close + return false; return baseRef()->isActivated(); } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 4f95c72cc..1bb0cebd2 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -252,6 +252,18 @@ void Model_Session::setActiveDocument( std::shared_ptr aPrevious = myCurrentDoc; myCurrentDoc = theDoc; if (theDoc.get() && theSendSignal) { + // this must be before the synchronisation call because features in PartSet lower than this + // part feature must be disabled and don't recomputed anymore (issue 1156, + // translation feature is failed on activation of Part 2) + if (isOperation()) { // do it only in transaction, not on opening of document + DocumentPtr aRoot = moduleDocument(); + if (myCurrentDoc != aRoot) { + FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, myCurrentDoc); + if (aPartFeat.get()) { + aRoot->setCurrentFeature(aPartFeat, false); + } + } + } // syncronize the document: it may be just opened or opened but removed before std::shared_ptr aDoc = std::dynamic_pointer_cast(theDoc); if (aDoc.get()) { @@ -275,14 +287,6 @@ void Model_Session::setActiveDocument( } else { // make the current feature the latest in sub, root current feature becomes this sub makeCurrentLast(myCurrentDoc); - DocumentPtr aRoot = moduleDocument(); - ResultPtr aPartRes = ModelAPI_Tools::findPartResult(aRoot, myCurrentDoc); - if (aPartRes.get()) { - FeaturePtr aPartFeat = aRoot->feature(aPartRes); - if (aPartFeat.get()) { - aRoot->setCurrentFeature(aPartFeat, false); - } - } } } } diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 442549557..1b618562d 100755 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -209,6 +209,28 @@ ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub) return ResultPtr(); } +FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub) +{ + if (theMain != theSub) { // to optimize and avoid of crash on partset document close (don't touch the sub-document structure) + for (int a = theMain->size(ModelAPI_Feature::group()) - 1; a >= 0; a--) { + FeaturePtr aPartFeat = std::dynamic_pointer_cast( + theMain->object(ModelAPI_Feature::group(), a)); + if (aPartFeat.get()) { + const std::list >& aResList = aPartFeat->results(); + std::list >::const_iterator aRes = aResList.begin(); + for(; aRes != aResList.end(); aRes++) { + ResultPartPtr aPart = std::dynamic_pointer_cast(*aRes); + if (aPart.get()) { + if (aPart->isActivated() && aPart->partDoc() == theSub) + return aPartFeat; + } else break; // if the first is not Part, others are also not + } + } + } + } + return FeaturePtr(); +} + CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature) { if (theFeature.get() && theFeature->data()->isValid()) { diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 0b3f965b7..1d86a03cc 100755 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -53,12 +53,22 @@ MODELAPI_EXPORT void findRandomColor(std::vector& theValues); /*! * Searches for Part result that contains the reference to the given document. + * The result must be presented in the tree. * \param theMain document that contains the searched feature * \param theSub document that is searched, the resulting feature references to it * \returns null if not found */ MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub); +/*! + * Searches for Part the feature that contains in result the reference to the given document. + * The result may be disabled. + * \param theMain document that contains the searched feature + * \param theSub document that is searched, the resulting feature references to it + * \returns null if not found + */ +MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub); + /*! * Returns the composite feature - parent of this feature. * \param theFeature the sub-element of composite