]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
External edge to be removed with all references. The same mechanizm should be applied...
authornds <natalia.donis@opencascade.com>
Wed, 1 Apr 2015 07:29:05 +0000 (10:29 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 1 Apr 2015 07:29:05 +0000 (10:29 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 0fb0094978c30595b4ab7fc4efca8efb54ce5e9a..841387209216913943061197202e97cb03f22a97 100644 (file)
@@ -537,23 +537,20 @@ void PartSet_Module::onAction(bool isChecked)
 
 bool PartSet_Module::deleteObjects()
 {
+  // 1. check whether the delete should be processed in the module
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
   if (!isSketchOp && !isNestedOp)
     return false;
 
-  // sketch feature should be skipped, only sub-features can be removed
-  // when sketch operation is active
-  CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
-
+  // 2. find selected presentations
   // selected objects should be collected before the current operation abort because
   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
   XGUI_Workshop* aWorkshop = aConnector->workshop();
   ModuleBase_ISelection* aSel = aConnector->selection();
   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
-
   // if there are no selected objects in the viewer, that means that the selection in another
   // place cased this method. It is necessary to return the false value to understande in above
   // method that delete is not processed
@@ -564,80 +561,20 @@ bool PartSet_Module::deleteObjects()
   if (isNestedOp)
     anOperation->abort();
 
-  std::set<FeaturePtr> aRefFeatures;
-  foreach (ObjectPtr aObj, aSelectedObj)
-  {
-    //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
-    //if (aPart) {
-      // TODO: check for what there is this condition. It is placed here historicaly because
-      // ther is this condition during remove features.
-    //} else {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
-    if (aFeature.get() != NULL) {
-      aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
-    }
-    //}
-  }
-
+  // 3. start operation
   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
-  /**
-  // according to #355 feature, it is not necessary to inform about dependencies during
-  // sketch delete operation
-  // 
-  if (!aRefFeatures.empty()) {
-    QStringList aRefNames;
-    std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
-                                         aLast = aRefFeatures.end();
-    for (; anIt != aLast; anIt++) {
-      FeaturePtr aFeature = (*anIt);
-      if (aFeature == aSketch)
-        continue;
-      aRefNames.append((*anIt)->name().c_str());
-    }
-    if (!aRefNames.empty()) {
-      QString aNames = aRefNames.join(", ");
-      aDescription += aNames.prepend(" ");
-
-      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();
   aMgr->startOperation(aDescription.toStdString());
-  std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
-                                       aLast = aRefFeatures.end();
-  for (; anIt != aLast; anIt++) {
-    FeaturePtr aRefFeature = (*anIt);
-    if (aRefFeature == aSketch)
-      continue;
-    aRefFeature->document()->removeFeature(aRefFeature);
-  }
 
-  foreach (ObjectPtr aObj, aSelectedObj)
-  {
-    DocumentPtr aDoc = aObj->document();
-    //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
-    //if (aPart) {
-    //  if (aDoc == aMgr->activeDocument()) {
-    //    aDoc->close();
-    //  }
-    //} else {
-      //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-    FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
-    if (aFeature.get() != NULL) {
-      aDoc->removeFeature(aFeature);
-    }
-    //}
-  }
+  // 4. delete features
+  // sketch feature should be skipped, only sub-features can be removed
+  // when sketch operation is active
+  std::set<FeaturePtr> anIgnoredFeatures;
+  anIgnoredFeatures.insert(mySketchMgr->activeSketch());
+  aWorkshop->deleteFeatures(aSelectedObj, anIgnoredFeatures);
+  
+  // 5. stop operation
   aWorkshop->displayer()->updateViewer();
-  //myDisplayer->updateViewer();
   aMgr->finishOperation();
 
   return true;
index fdda90f35cfba242aab573574a7695c001917c08..7352c1344cb42c50241b3fea9b8a860804f78c07 100644 (file)
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <ModuleBase_Definitions.h>
+
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
+#include <XGUI_Workshop.h>
+
+PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
+                                                         ModuleBase_IWorkshop* theWorkshop,
+                                                         const Config_WidgetAPI* theData,
+                                                         const std::string& theParentId)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
+{
+}
+
 bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
   ObjectPtr aSelectedObject = theSelectedObject;
@@ -97,7 +109,12 @@ void PartSet_WidgetShapeSelector::removeExternal()
     DocumentPtr aDoc = myExternalObject->document();
     FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
     if (aFeature.get() != NULL) {
-      aDoc->removeFeature(aFeature);
+      QObjectPtrList anObjects;
+      anObjects.append(aFeature);
+      // the external feature should be removed with all references, sketch feature should be ignored
+      std::set<FeaturePtr> anIgnoredFeatures;
+      anIgnoredFeatures.insert(sketch());
+      XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
     }
     myExternalObject = NULL;
   }
index 1ad2f21974b2ca5590286efbfcf0a04aa1d6444b..e529e33ec5f45e122d69457f7739114cec4c4730 100644 (file)
@@ -30,8 +30,7 @@ Q_OBJECT
   /// \param theData the widget configuation. The attribute of the model widget is obtained from
   /// \param theParentId is Id of a parent of the current attribute
   PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
-    const Config_WidgetAPI* theData, const std::string& theParentId)
-    : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+    const Config_WidgetAPI* theData, const std::string& theParentId);
 
   virtual ~PartSet_WidgetShapeSelector() {}
 
index 0f02f7eb768d8bb91fde416a2b88073e9ece6e41..7498ab8317aadecd9375858cb631334984ddb6b4 100644 (file)
@@ -106,6 +106,8 @@ QString objectInfo(ObjectPtr theObj)
   }
   if (aFeature.get()) {
     aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
+    if (aFeature->data().get() && aFeature->data()->isValid())
+      aFeatureStr.append(QString("(name=%1)").arg(aFeature->data()->name().c_str()).toStdString().c_str());
   }
   return aFeatureStr;
 }
@@ -1303,7 +1305,7 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
   } else if (theId == "DEACTIVATE_PART_CMD")
     activatePart(ResultPartPtr());
   else if (theId == "DELETE_CMD")
-    deleteObjects(aObjects);
+    deleteObjects();
   else if (theId == "COLOR_CMD")
     changeColor(aObjects);
   else if (theId == "SHOW_CMD")
@@ -1353,90 +1355,106 @@ void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
 //}
 
 //**************************************************************
-void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
+void XGUI_Workshop::deleteObjects()
 {
   ModuleBase_IModule* aModule = module();
+  // 1. allow the module to delete objects, do nothing if it has succeed
   if (aModule->deleteObjects())
     return;
 
   if (!isActiveOperationAborted())
     return;
+  QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  // 1. start operation
+  QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
+  aDescription += tr(" %1");
+  QStringList aObjectNames;
+  foreach (ObjectPtr aObj, anObjects) {
+    if (!aObj->data().get())
+      continue;
+    aObjectNames << QString::fromStdString(aObj->data()->name());
+  }
+  aDescription = aDescription.arg(aObjectNames.join(", "));
 
-  QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
-  std::set<FeaturePtr> aRefFeatures;
-  foreach (ObjectPtr aObj, theList)
+  SessionPtr aMgr = ModelAPI_Session::get();
+  aMgr->startOperation(aDescription.toStdString());
+  // 2. close the documents of the removed parts if the result part is in a list of selected objects
+  foreach (ObjectPtr aObj, anObjects)
   {
     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
     if (aPart) {
-      // TODO: check for what there is this condition. It is placed here historicaly because
-      // ther is this condition during remove features.
-    } else {
-      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-      if (aFeature.get() != NULL) {
-        aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
+      DocumentPtr aDoc = aObj->document();
+      if (aDoc == aMgr->activeDocument()) {
+        aDoc->close();
       }
     }
   }
+  // 3. delete objects
+  QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
+  std::set<FeaturePtr> anIgnoredFeatures;
+  if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
+    myDisplayer->updateViewer();
+    aMgr->finishOperation();
+    updateCommandStatus();
+  }
+  else {
+    aMgr->abortOperation();
+  }
+}
 
-  if (!aRefFeatures.empty()) {
+//**************************************************************
+bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
+                                   std::set<FeaturePtr> theIgnoredFeatures,
+                                   QWidget* theParent,
+                                   const bool theAskAboutDeleteReferences)
+{
+  // 1. find all referenced features
+  std::set<FeaturePtr> aRefFeatures;
+  foreach (ObjectPtr aObj, theList) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+    if (aFeature.get() != NULL) {
+      aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
+    }
+  }
+  // 2. warn about the references remove, break the delete operation if the user chose it
+  if (theAskAboutDeleteReferences && !aRefFeatures.empty()) {
     QStringList aRefNames;
     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
                                          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();
       aRefNames.append((*anIt)->name().c_str());
     }
     QString aNames = aRefNames.join(", ");
 
     QMessageBox::StandardButton aRes = QMessageBox::warning(
-        aDesktop, tr("Delete features"),
+        theParent, 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;
+      return false;
   }
 
-  QString aDescription = tr("Delete %1");
-  QStringList aObjectNames;
-  foreach (ObjectPtr aObj, theList) {
-    if (!aObj->data().get())
-      continue;
-    aObjectNames << QString::fromStdString(aObj->data()->name());
-  }
-  aDescription = aDescription.arg(aObjectNames.join(", "));
-  SessionPtr aMgr = ModelAPI_Session::get();
-  aMgr->startOperation(aDescription.toStdString());
+  // 3. remove referenced features
   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
                                        aLast = aRefFeatures.end();
   for (; anIt != aLast; anIt++) {
-    FeaturePtr aRefFeature = (*anIt);
-    DocumentPtr aDoc = aRefFeature->document();
-    aDoc->removeFeature(aRefFeature);
-   }
-
+    FeaturePtr aFeature = (*anIt);
+    DocumentPtr aDoc = aFeature->document();
+    if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end())
+      aDoc->removeFeature(aFeature);
+  }
 
-  foreach (ObjectPtr aObj, theList)
-  {
-    DocumentPtr aDoc = aObj->document();
-    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
-    if (aPart) {
-      if (aDoc == aMgr->activeDocument()) {
-        aDoc->close();
-      }
-    } else {
-      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-      if (aFeature) {
+  // 4. remove the parameter features
+  foreach (ObjectPtr aObj, theList) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+    if (aFeature) {
+      DocumentPtr aDoc = aObj->document();
+      if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end())
         aDoc->removeFeature(aFeature);
-      }
     }
   }
-
-  myDisplayer->updateViewer();
-  aMgr->finishOperation();
-  updateCommandStatus();
+  return true;
 }
 
 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
index baeff44487730e7f95d5fa35b6693bf31deccc96..ff4a8708a336473849d6f8f4e0f2cdeb36e6103d 100644 (file)
@@ -164,7 +164,7 @@ Q_OBJECT
   void activatePart(std::shared_ptr<ModelAPI_ResultPart> theFeature);
 
   //! Delete features
-  void deleteObjects(const QObjectPtrList& theList);
+  void deleteObjects();
 
   //! Returns true if there is at least one selected body/construction/group result
   //! \return boolean value
@@ -213,6 +213,19 @@ Q_OBJECT
    */
   bool isActiveOperationAborted();
 
+  //! Delete features. Delete the referenced features. There can be a question with a list of referenced
+  //! objects.
+  //! \param theList an objects to be deleted
+  //! \param theIgnoredFeatures a list of features to be ignored during delete
+  //! \param theParent a parent widget for the question message box
+  //! \param theAskAboutDeleteReferences if true, the message box with a list of references to the
+  //! objects features appear. If the user chose do not continue, the deletion is not performed
+  //! \return the success of the delete 
+  static bool deleteFeatures(const QObjectPtrList& theList,
+                             std::set<FeaturePtr> theIgnoredFeatures = std::set<FeaturePtr>(),
+                             QWidget* theParent = 0,
+                             const bool theAskAboutDeleteReferences = false);
+
 signals:
   /// Emitted when selection happens in Salome viewer
   void salomeViewerSelection();