]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #355 Delete: elements of sketch and constraints
authornds <natalia.donis@opencascade.com>
Mon, 19 Jan 2015 09:28:05 +0000 (12:28 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 30 Jan 2015 08:26:45 +0000 (11:26 +0300)
Remove the deleted feature from the list of sketch sub-elements.

src/Model/Model_AttributeRefList.cpp
src/Model/Model_Document.cpp
src/PartSet/PartSet_Module.cpp
src/SketchPlugin/SketchPlugin_Feature.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index 9287cf0415079707b7ecfb17c91b01c51742deb4..effa56db232cb21a0989fc801baad662fcf283a1 100644 (file)
@@ -22,9 +22,25 @@ void Model_AttributeRefList::append(ObjectPtr theObject)
 
 void Model_AttributeRefList::remove(ObjectPtr theObject)
 {
-  std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
-  myRef->Remove(aData->label().Father());
-
+  std::shared_ptr<Model_Data> aData;
+  if (theObject.get() != NULL) {
+    aData = std::dynamic_pointer_cast<Model_Data>(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<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+        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);
 }
 
index d9905674765c0b51a5160b603ac36c6f21124c49..38ba4adf161b54135e7b033ce1ce9e987ea15b84 100644 (file)
@@ -605,7 +605,13 @@ void Model_Document::refsToFeature(FeaturePtr theFeature,
   std::shared_ptr<Model_Data> aData = 
       std::dynamic_pointer_cast<Model_Data>(theFeature->data());
   if (aData && !aData->refsToMe().empty()) {
-    theRefs.insert(theFeature);
+    const std::set<AttributePtr>& aRefs = aData->refsToMe();
+    std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin(), aRefLast = aRefs.end();
+    for(; aRefIt != aRefLast; aRefIt++) {
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
+      if (aFeature.get() != NULL)
+        theRefs.insert(aFeature);
+    }
   }
 
   if (!theRefs.empty() && isSendError) {
index df5d23f1ee0a0d52afeb7f68a0edc74c8bff1c07..b3f9f28f77709dd5accdea298fd2c88093a6e902 100644 (file)
@@ -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)
   {
index 6e0f7111d1c29125622aae6885db76c5e1003b5e..b89f5d42563a44a380f72f4cdbc9f7fd1c62c1af 100644 (file)
@@ -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) {
index 24a3c49e5785c4039f1c5cd12fa5ab619158ef0b..acf95e2a67554a19c01394ce5a55f7ceec15c8ad 100644 (file)
@@ -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:
index 024bda4b473b92fc0f3298be8a6d80b914894535..a3cbc24b5f0c49377501a2cd1939c6096558a4ca 100644 (file)
@@ -133,6 +133,24 @@ std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string th
   return aNew;
 }
 
+void SketchPlugin_Sketch::removeFeature(ModelAPI_Feature* theFeature)
+{
+  list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+  list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
+  bool isRemoved = false;
+  for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
+    std::shared_ptr<ModelAPI_Feature> aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*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();
index 51ac70496b266da567e9d7b086728f5ed0f03da7..84cda7dfba7a5604b83de15b59adb4ac64eb887c 100644 (file)
@@ -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<ModelAPI_Feature> 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;