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).
}
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;
+ }
+ }
}
}
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 {
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);
}
}
}
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()) {
#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>
}
}*/
+//******************************************************************
+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;
+}
}
#include <ModelAPI_Feature.h>
+#include <ModuleBase_Definitions.h>
+
#include <memory>
+class QWidget;
+
/*!
\ingroup GUI
\brief Return directory part of the file path.
*/
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
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;