From: nds Date: Fri, 10 Jul 2015 07:07:18 +0000 (+0300) Subject: Issue #662 Warning on remove or rename of (may be) used object in PartSet X-Git-Tag: V_1.3.0~42 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=298b1a92be5d10083ad22bcd0a5e7dc7a7c0398f;p=modules%2Fshaper.git Issue #662 Warning on remove or rename of (may be) used object in PartSet 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). --- diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index b4a5fb5a1..5e7d2f2ec 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -125,14 +125,25 @@ bool isSubObject(const ObjectPtr& theObject, const FeaturePtr& theFeature) } void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape, + const FeaturePtr& theFeature, QMap >& theObjectShapes) { - if (theObjectShapes.contains(theObject)) - theObjectShapes[theObject].append(theShape); - else { - QList aShapes; - aShapes.append(theShape); - theObjectShapes[theObject] = aShapes; + if (theObject.get()) { + GeomShapePtr aShape = theShape; + if (!aShape.get()) { + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) + aShape = aResult->shape(); + } + if (!isSubObject(theObject, theFeature)) { + if (theObjectShapes.contains(theObject)) + theObjectShapes[theObject].append(theShape); + else { + QList aShapes; + aShapes.append(theShape); + theObjectShapes[theObject] = aShapes; + } + } } } @@ -158,10 +169,7 @@ void PartSet_OperationPrs::getFeatureShapes(QMap std::shared_ptr 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 AttributeReferencePtr anAttr = std::dynamic_pointer_cast(anAttribute); anObject = anAttr->value(); } - - if (anObject.get()) { - if (!aShape.get()) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - aShape = aResult->shape(); - } - if (!isSubObject(anObject, myFeature)) - addValue(anObject, aShape, theObjectShapes); - } + addValue(anObject, aShape, myFeature, theObjectShapes); } } } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 81e5b9d4c..448f47dbd 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -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()) { diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 42ddf7318..47de40270 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -7,9 +7,14 @@ #include #include #include +#include +#include +#include + #include #include +#include #include #include @@ -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(aObject); + if (!aPart->isActivated()) { + anAllPartActivated = false; + aRefNames.append(aObject->data()->name().c_str()); + } + } + theNotActivatedNames = aRefNames.join(", "); + return anAllPartActivated; +} } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 1a5c7b05f..a3fba88c9 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -9,8 +9,12 @@ #include +#include + #include +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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 556fe4e79..3f044f918 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(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;