From: nds Date: Mon, 19 Jan 2015 09:28:05 +0000 (+0300) Subject: Issue #355 Delete: elements of sketch and constraints X-Git-Tag: V_1.0.0~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2e5353958b8e5a0a7d8bc3903f522b5564df8d48;p=modules%2Fshaper.git Issue #355 Delete: elements of sketch and constraints Remove the deleted feature from the list of sketch sub-elements. --- diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index 9287cf041..effa56db2 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -22,9 +22,25 @@ void Model_AttributeRefList::append(ObjectPtr theObject) void Model_AttributeRefList::remove(ObjectPtr theObject) { - std::shared_ptr aData = std::dynamic_pointer_cast(theObject->data()); - myRef->Remove(aData->label().Father()); - + std::shared_ptr aData; + if (theObject.get() != NULL) { + aData = std::dynamic_pointer_cast(theObject->data()); + myRef->Remove(aData->label().Father()); + } + else { // in case of empty object remove, the first empty object is removed from the list + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); + if (aDoc) { + const TDF_LabelList& aList = myRef->List(); + for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) { + ObjectPtr anObj = aDoc->object(aLIter.Value()); + if (anObj.get() == NULL) { + myRef->Remove(aLIter.Value()); + break; + } + } + } + } owner()->data()->sendAttributeUpdated(this); } diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index d99056747..38ba4adf1 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -605,7 +605,13 @@ void Model_Document::refsToFeature(FeaturePtr theFeature, std::shared_ptr aData = std::dynamic_pointer_cast(theFeature->data()); if (aData && !aData->refsToMe().empty()) { - theRefs.insert(theFeature); + const std::set& aRefs = aData->refsToMe(); + std::set::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end(); + for(; aRefIt != aRefLast; aRefIt++) { + FeaturePtr aFeature = std::dynamic_pointer_cast((*aRefIt)->owner()); + if (aFeature.get() != NULL) + theRefs.insert(aFeature); + } } if (!theRefs.empty() && isSendError) { diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index df5d23f1e..b3f9f28f7 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -479,6 +479,9 @@ void PartSet_Module::deleteObjects() aCurrentOp->abort(); } } + // sketch feature should be skipped, only sub-features can be removed + // when sketch operation is active + CompositeFeaturePtr aSketch = mySketchMgr->activeSketch(); ModuleBase_ISelection* aSel = aConnector->selection(); QObjectPtrList aSelectedObj = aSel->selectedPresentations(); @@ -504,20 +507,22 @@ void PartSet_Module::deleteObjects() aLast = aRefFeatures.end(); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = (*anIt); - std::string aFName = aFeature->data()->name().c_str(); - std::string aName = (*anIt)->name().c_str(); + if (aFeature == aSketch) + continue; aRefNames.append((*anIt)->name().c_str()); } - QString aNames = aRefNames.join(", "); - - QMainWindow* aDesktop = aWorkshop->desktop(); - QMessageBox::StandardButton aRes = QMessageBox::warning( - aDesktop, tr("Delete features"), - QString(tr("Selected features are used in the following features: %1.\ -These features will be deleted also. Would you like to continue?")).arg(aNames), - QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (aRes != QMessageBox::Yes) - return; + if (!aRefNames.empty()) { + QString aNames = aRefNames.join(", "); + + QMainWindow* aDesktop = aWorkshop->desktop(); + QMessageBox::StandardButton aRes = QMessageBox::warning( + aDesktop, tr("Delete features"), + QString(tr("Selected features are used in the following features: %1.\ + These features will be deleted also. Would you like to continue?")).arg(aNames), + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); + if (aRes != QMessageBox::Yes) + return; + } } SessionPtr aMgr = ModelAPI_Session::get(); @@ -526,9 +531,10 @@ These features will be deleted also. Would you like to continue?")).arg(aNames), aLast = aRefFeatures.end(); for (; anIt != aLast; anIt++) { FeaturePtr aRefFeature = (*anIt); - DocumentPtr aDoc = aRefFeature->document(); - aDoc->removeFeature(aRefFeature); - } + if (aRefFeature == aSketch) + continue; + aRefFeature->document()->removeFeature(aRefFeature); + } foreach (ObjectPtr aObj, aSelectedObj) { diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 6e0f7111d..b89f5d425 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -13,6 +13,15 @@ SketchPlugin_Feature::SketchPlugin_Feature() mySketch = 0; } +void SketchPlugin_Feature::erase() +{ + SketchPlugin_Sketch* aSketch = sketch(); + if (aSketch) + aSketch->removeFeature(this); + + ModelAPI_Feature::erase(); +} + SketchPlugin_Sketch* SketchPlugin_Feature::sketch() { if (!mySketch) { diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 24a3c49e5..acf95e2a6 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -75,6 +75,9 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs // thePrs->setPointMarker(6, 2.); } + /// removes also all sub-sketch elements + SKETCHPLUGIN_EXPORT virtual void erase(); + /// Returns the sketch of this feature SketchPlugin_Sketch* sketch(); protected: diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 024bda4b4..a3cbc24b5 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -133,6 +133,24 @@ std::shared_ptr SketchPlugin_Sketch::addFeature(std::string th return aNew; } +void SketchPlugin_Sketch::removeFeature(ModelAPI_Feature* theFeature) +{ + list aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); + list::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end(); + bool isRemoved = false; + for(; aSubIt != aLastIt && !isRemoved; aSubIt++) { + std::shared_ptr aFeature = std::dynamic_pointer_cast(*aSubIt); + if (aFeature.get() != NULL || aFeature.get() == theFeature) { + data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature); + isRemoved = true; + } + } + // if the object is not found in the sketch sub-elements, that means that the object is removed already. + // Find the first empty element and remove it + if (!isRemoved) + data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(NULL); +} + int SketchPlugin_Sketch::numberOfSubs() const { return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size(); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 51ac70496..84cda7dfb 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -116,8 +116,12 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I /// removes also all sub-sketch elements SKETCHPLUGIN_EXPORT virtual void erase(); + /// appends a feature to the sketch sub-elements container SKETCHPLUGIN_EXPORT virtual std::shared_ptr addFeature(std::string theID); + /// appends a feature from the sketch sub-elements container + SKETCHPLUGIN_EXPORT virtual void removeFeature(ModelAPI_Feature* theFeature); + /// Returns the number of sub-elements SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;