]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Avoid deletion of objects which do not have Delete context command
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 17 Apr 2015 09:34:45 +0000 (12:34 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 17 Apr 2015 09:34:45 +0000 (12:34 +0300)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h
src/XGUI/XGUI_Workshop.cpp

index 80fdfad7f07ece1ba1b23243e578fdf41ad8d9e6..494ecf28d011cf8dcf54d04dae64ac496ebd843e 100644 (file)
@@ -8,6 +8,7 @@
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_Selection.h"
 #include "XGUI_SalomeConnector.h"
+#include "XGUI_Tools.h"
 
 #include <AppElements_MainWindow.h>
 
@@ -154,18 +155,8 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
     bool hasResult = false;
     bool hasFeature = false;
     bool hasParameter = false;
-    foreach(ObjectPtr aObj, aObjects)
-    {
-      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
-      ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
-
-      hasResult = (aResult.get() != NULL);
-      hasFeature = (aFeature.get() != NULL);
-      hasParameter = (aConstruction.get() != NULL);
-      if (hasFeature && hasResult  && hasParameter)
-        break;
-    }
+    XGUI_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter);
+
     //Process Feature
     if (aSelected == 1) {
       ObjectPtr aObject = aObjects.first();
index 26672cd89bc4cdf295c2152632fe497bdb6c8048..4ffac6dc7ba28294cd40733b3bcc26344f92004d 100644 (file)
@@ -4,6 +4,9 @@
 
 #include <TopoDS_Shape.hxx>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_Feature.h>
 #include <GeomAPI_Shape.h>
 
 #include <QDir>
@@ -71,4 +74,24 @@ std::string featureInfo(FeaturePtr theFeature)
  }
  }*/
 
+
+void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter)
+{
+  hasResult = false;
+  hasFeature = false;
+  hasParameter = false;
+  foreach(ObjectPtr aObj, theObjects) {
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+    ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+
+    hasResult = (aResult.get() != NULL);
+    hasFeature = (aFeature.get() != NULL);
+    hasParameter = (aConstruction.get() != NULL);
+    if (hasFeature && hasResult  && hasParameter)
+      break;
+  }
+}
+
+
 }
index 7db64558ac26448911c1dd19bbbf343af1116f1f..e541ba2f0418e8fcef741ece0fd46eb62e0433f8 100644 (file)
@@ -8,6 +8,7 @@
 #include <QRect>
 
 #include <ModelAPI_Feature.h>
+#include <ModuleBase_Definitions.h>
 
 #include <memory>
 
@@ -63,6 +64,17 @@ bool XGUI_EXPORT isModelObject(FeaturePtr theFeature);
  \param theFeature a feature
  */
 std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
-}
+
+
+/*!
+Check types of objects which are in the given list
+\param theObjects the list of objects
+\param hasResult will be set to true if list contains Result objects
+\param hasFeature will be set to true if list contains Feature objects
+\param hasParameter will be set to true if list contains Parameter objects
+*/
+void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter);
+
+};
 
 #endif
index a824d664c740f1bcba914d2fdfb60a939b215dc8..42aa97e3000859a3b259ef7c55413428a5ca42b6 100644 (file)
@@ -1391,6 +1391,13 @@ void XGUI_Workshop::deleteObjects()
   if (!isActiveOperationAborted())
     return;
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  bool hasResult = false;
+  bool hasFeature = false;
+  bool hasParameter = false;
+  XGUI_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter);
+  if (!(hasFeature || hasParameter))
+    return;
+
   // 1. start operation
   QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
   aDescription += tr(" %1");