]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #662 Warning on remove or rename of (may be) used object in PartSet
authornds <natalia.donis@opencascade.com>
Fri, 10 Jul 2015 07:07:18 +0000 (10:07 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 10 Jul 2015 07:08:06 +0000 (10:08 +0300)
There also was a crash when remove sketch(in PartSet), which is used in the Part_1. Edit extrusion ->crash in OperationPrs. The null object should be skipped like it is done in not simple selection attribute(not a list).

src/PartSet/PartSet_OperationPrs.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h
src/XGUI/XGUI_Workshop.cpp

index b4a5fb5a1636340eb50db3325d5a2bb74c082ce2..5e7d2f2ec834c288d6b849888a1d143f4c0ec165 100755 (executable)
@@ -125,14 +125,25 @@ bool isSubObject(const ObjectPtr& theObject, const FeaturePtr& theFeature)
 }
 
 void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape,
+              const FeaturePtr& theFeature,
               QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
 {
-  if (theObjectShapes.contains(theObject))
-    theObjectShapes[theObject].append(theShape);
-  else {
-    QList<GeomShapePtr> aShapes;
-    aShapes.append(theShape);
-    theObjectShapes[theObject] = aShapes;
+  if (theObject.get()) {
+    GeomShapePtr aShape = theShape;
+    if (!aShape.get()) {
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+      if (aResult.get())
+        aShape = aResult->shape();
+    }
+    if (!isSubObject(theObject, theFeature)) {
+      if (theObjectShapes.contains(theObject))
+        theObjectShapes[theObject].append(theShape);
+      else {
+        QList<GeomShapePtr> aShapes;
+        aShapes.append(theShape);
+        theObjectShapes[theObject] = aShapes;
+      }
+    }
   }
 }
 
@@ -158,10 +169,7 @@ void PartSet_OperationPrs::getFeatureShapes(QMap<ObjectPtr, QList<GeomShapePtr>
         std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
         ResultPtr aResult = aSelAttribute->context();
         GeomShapePtr aShape = aSelAttribute->value();
-        if (!aShape.get())
-          aShape = aResult->shape();
-        if (!isSubObject(aResult, myFeature))
-          addValue(aResult, aShape, theObjectShapes);
+        addValue(aResult, aShape, myFeature, theObjectShapes);
       }
     }
     else {
@@ -190,16 +198,7 @@ void PartSet_OperationPrs::getFeatureShapes(QMap<ObjectPtr, QList<GeomShapePtr>
         AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
         anObject = anAttr->value();
       }
-
-      if (anObject.get()) {
-        if (!aShape.get()) {
-          ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-          if (aResult.get())
-            aShape = aResult->shape();
-        }
-        if (!isSubObject(anObject, myFeature))
-          addValue(anObject, aShape, theObjectShapes);
-      }
+      addValue(anObject, aShape, myFeature, theObjectShapes);
     }
   }
 }
index 81e5b9d4cb344c9509625a8641f527beb08c2f12..448f47dbd0af79320cca73cb1dd202d8f7cef988 100644 (file)
@@ -266,6 +266,12 @@ void XGUI_ObjectsBrowser::onEditItem()
   if (aSelectedData.size() > 0) {
     ObjectPtr aFeature = aSelectedData.first();
     if (aFeature) {  // Selection happens in TreeView
+      QObjectPtrList aList;
+      aList.append(aFeature);
+      // check whether the object can be deleted. There should not be parts which are not loaded
+      if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aList))
+        return;
+
       // Find index which corresponds the feature
       QModelIndex aIndex;
       foreach(QModelIndex aIdx, selectedIndexes()) {
index 42ddf7318fdcc02e4f6521763f192386bd5dc4b9..47de402703e2f0cc611ff9659b1ac3bca33a5a01 100644 (file)
@@ -7,9 +7,14 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultPart.h>
+
 #include <GeomAPI_Shape.h>
 
 #include <QDir>
+#include <QMessageBox>
 
 #include <iostream>
 #include <sstream>
@@ -74,6 +79,48 @@ std::string featureInfo(FeaturePtr theFeature)
  }
  }*/
 
+//******************************************************************
+bool canRemoveOrRename(QWidget* theParent, const QObjectPtrList& theObjects)
+{
+  bool aResult = true;
+  QString aNotActivatedNames;
+  if (!XGUI_Tools::allDocumentsActivated(aNotActivatedNames)) {
+    DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
+    bool aFoundPartSetObject = false;
+    foreach (ObjectPtr aObj, theObjects) {
+      if (aObj->groupName() == ModelAPI_ResultPart::group())
+        continue;
+      aFoundPartSetObject = aObj->document() == aModuleDoc;
+    }
+    if (aFoundPartSetObject) {
+      QMessageBox::StandardButton aRes = QMessageBox::warning(theParent, QObject::tr("Warning"),
+               QObject::tr("Selected objects can be used in Part documents which are not loaded: \
+%1. Whould you like to continue?").arg(aNotActivatedNames),
+               QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+      aResult = aRes == QMessageBox::Yes;
+    }
+  }
+  return aResult;
+}
+
+//******************************************************************
+bool allDocumentsActivated(QString& theNotActivatedNames)
+{
+  bool anAllPartActivated = true;
+  QStringList aRefNames;
 
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+  int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
+  for (int i = 0; i < aSize; i++) {
+    ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+    if (!aPart->isActivated()) {
+      anAllPartActivated = false;
+      aRefNames.append(aObject->data()->name().c_str());
+    }
+  }
+  theNotActivatedNames = aRefNames.join(", ");
+  return anAllPartActivated;
+}
 
 }
index 1a5c7b05f2b2103dc91e33dcc25025ef9a47742f..a3fba88c90fdebba52e6216ab9ef44de3cab117c 100644 (file)
@@ -9,8 +9,12 @@
 
 #include <ModelAPI_Feature.h>
 
+#include <ModuleBase_Definitions.h>
+
 #include <memory>
 
+class QWidget;
+
 /*!
  \ingroup GUI
  \brief Return directory part of the file path.
@@ -64,7 +68,21 @@ bool XGUI_EXPORT isModelObject(FeaturePtr theFeature);
  */
 std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
 
+/*!
+ Returns true if there are no parts in the document, which are not activated or
+ all objects in the list are not PartSet document.
+ It shows the warning control if the result is false.
+ \param theParent a parent for the warning control
+ \param theList a list of object
+ \return a boolean value
+ */
+bool XGUI_EXPORT canRemoveOrRename(QWidget* theParent, const QObjectPtrList& aList);
 
+/*!
+ Returns true if there are no parts in the document, which are not activated
+ \return a boolean value
+ */
+bool XGUI_EXPORT allDocumentsActivated(QString& theNotActivatedNames);
 };
 
 #endif
index 556fe4e7909080865abdc8049caca723dc187ced..3f044f918a247debc6135b072a2395a1321cc827 100644 (file)
@@ -1011,29 +1011,9 @@ void XGUI_Workshop::deleteObjects()
   if (!isActiveOperationAborted())
     return;
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
-  // check whether the object can be deleted
-  bool anAllPartActivated = true;
-  {
-    DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
-    int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
-    for (int i = 0; i < aSize && anAllPartActivated; i++) {
-      ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
-      ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
-      anAllPartActivated = aPart->isActivated();
-    }
-  }
-  if (!anAllPartActivated) {
-    SessionPtr aMgr = ModelAPI_Session::get();
-    DocumentPtr aModuleDoc = aMgr->moduleDocument();
-
-    bool aFoundPartSetObject = false;
-    foreach (ObjectPtr aObj, anObjects) {
-      aFoundPartSetObject = aObj->document() == aModuleDoc;
-    }
-    if (aFoundPartSetObject)
-      QMessageBox::critical(myMainWindow, tr("Warning"), tr("Some Part documents are not loaded. It is not possible to perform the operation because the selected objects can be used in the documents."));
-  }
-
+  // check whether the object can be deleted. There should not be parts which are not loaded
+  if (!XGUI_Tools::canRemoveOrRename(myMainWindow, anObjects))
+    return;
 
   bool hasResult = false;
   bool hasFeature = false;