From: vsv Date: Fri, 17 Apr 2015 09:34:45 +0000 (+0300) Subject: Avoid deletion of objects which do not have Delete context command X-Git-Tag: V_1.1.0~13^2~1^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1e4ee8e223432f35f5f48325c1d02a53987b6b69;p=modules%2Fshaper.git Avoid deletion of objects which do not have Delete context command --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 80fdfad7f..494ecf28d 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -8,6 +8,7 @@ #include "XGUI_ViewerProxy.h" #include "XGUI_Selection.h" #include "XGUI_SalomeConnector.h" +#include "XGUI_Tools.h" #include @@ -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(aObj); - ResultPtr aResult = std::dynamic_pointer_cast(aObj); - ResultParameterPtr aConstruction = std::dynamic_pointer_cast(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(); diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 26672cd89..4ffac6dc7 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include #include @@ -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(aObj); + ResultPtr aResult = std::dynamic_pointer_cast(aObj); + ResultParameterPtr aConstruction = std::dynamic_pointer_cast(aResult); + + hasResult = (aResult.get() != NULL); + hasFeature = (aFeature.get() != NULL); + hasParameter = (aConstruction.get() != NULL); + if (hasFeature && hasResult && hasParameter) + break; + } +} + + } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 7db64558a..e541ba2f0 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -8,6 +8,7 @@ #include #include +#include #include @@ -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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index a824d664c..42aa97e30 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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");