From: nds Date: Wed, 27 May 2015 18:03:54 +0000 (+0300) Subject: Issue #355 Delete: elements of sketch and constraints: X-Git-Tag: V_1.2.0~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1b9dd3633d644c358424227423b330e9551be38f;p=modules%2Fshaper.git Issue #355 Delete: elements of sketch and constraints: 1. Search references in all documents if a feature from "PartSet" is removed 2. displayAllResults() is not used, so commented 3. !anObject->data() is removed because the data can not be empty in an object. --- diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 89d6e4b6a..9c9708688 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -517,8 +517,9 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptrdata() || !anObject->data()->isValid() || - anObject->isDisabled() || (!anObject->isDisplayed()); + bool aHide = !anObject->data()->isValid() || + anObject->isDisabled() || + !anObject->isDisplayed(); if (!aHide) { // setDisplayed has to be called in order to synchronize internal state of the object // with list of displayed objects @@ -1310,25 +1311,65 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, { // 1. find all referenced features std::set aRefFeatures; - foreach (ObjectPtr aObj, theList) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); - if (aFeature.get() != NULL) { - DocumentPtr aFeatureDoc = aObj->document(); + foreach (ObjectPtr aDeletedObj, theList) { + FeaturePtr aDeletedFeature = ModelAPI_Feature::feature(aDeletedObj); + if (aDeletedFeature.get() != NULL) { + DocumentPtr aDeletedFeatureDoc = aDeletedObj->document(); + // 1.1 find references in the current document + aDeletedFeatureDoc->refsToFeature(aDeletedFeature, aRefFeatures, false); + // 1.2 find references in all documents if the document of the feature is + // "PartSet". Features of this document can be used in all other documents SessionPtr aMgr = ModelAPI_Session::get(); DocumentPtr aModuleDoc = aMgr->moduleDocument(); - // objects from "Part" documents can refer to the the features of "PartSet". - // So, it the referenced features should be checked in these documents - if (aFeatureDoc == aModuleDoc) { - std::list aDocuments = aMgr->allOpenedDocuments(); + if (aDeletedFeatureDoc == aModuleDoc) { + // the deleted feature and results of the feature should be found in references + std::list aDeletedObjects; + aDeletedObjects.push_back(aDeletedFeature); + typedef std::list > ResultsList; + const ResultsList& aDeletedResults = aDeletedFeature->results(); + ResultsList::const_iterator aRIter = aDeletedResults.begin(); + for (; aRIter != aDeletedResults.cend(); aRIter++) { + ResultPtr aRes = *aRIter; + if (aRes.get()) + aDeletedObjects.push_back(aRes); + } + // get all opened documents; found features in the documents; + // get a list of objects where a feature refers; + // search in these objects the deleted objects. std::list anOpenedDocs = aMgr->allOpenedDocuments(); std::list::const_iterator anIt = anOpenedDocs.begin(), aLast = anOpenedDocs.end(); + std::list > > aRefs; for (; anIt != aLast; anIt++) { - (*anIt)->refsToFeature(aFeature, aRefFeatures, false); + DocumentPtr aDocument = *anIt; + if (aDocument == aDeletedFeatureDoc) + continue; // this document has been already processed in 1.1 + + int aFeaturesCount = aDocument->size(ModelAPI_Feature::group()); + for (int aId = 0; aId < aFeaturesCount; aId++) { + ObjectPtr anObject = aDocument->object(ModelAPI_Feature::group(), aId); + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + if (!aFeature.get()) + continue; + + aRefs.clear(); + aFeature->data()->referencesToObjects(aRefs); + std::list > >::iterator aRef = aRefs.begin(); + bool aHasReferenceToDeleted = false; + for(; aRef != aRefs.end() && !aHasReferenceToDeleted; aRef++) { + std::list::iterator aRefObj = aRef->second.begin(); + for(; aRefObj != aRef->second.end() && !aHasReferenceToDeleted; aRefObj++) { + std::list::const_iterator aDelIt = aDeletedObjects.begin(); + for(; aDelIt != aDeletedObjects.end() && !aHasReferenceToDeleted; aDelIt++) { + aHasReferenceToDeleted = *aDelIt == *aRefObj; + } + } + } + if (aHasReferenceToDeleted) + aRefFeatures.insert(aFeature); + } } } - else - aFeatureDoc->refsToFeature(aFeature, aRefFeatures, false); } } // 2. warn about the references remove, break the delete operation if the user chose it @@ -1545,7 +1586,7 @@ void XGUI_Workshop::registerValidators() const } //************************************************************** -void XGUI_Workshop::displayAllResults() +/*void XGUI_Workshop::displayAllResults() { SessionPtr aMgr = ModelAPI_Session::get(); DocumentPtr aRootDoc = aMgr->moduleDocument(); @@ -1556,7 +1597,7 @@ void XGUI_Workshop::displayAllResults() displayDocumentResults(aPart->partDoc()); } myDisplayer->updateViewer(); -} +}*/ //************************************************************** void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc) diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index d4fd4a368..8e5af0de4 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -321,7 +321,7 @@ signals: void onFeatureRedisplayMsg(const std::shared_ptr& ); /// Display all results - void displayAllResults(); + //void displayAllResults(); /// Displau results from document /// \param theDoc a document