- bool isCurrentSketchOp = false;
- ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- if (aOperation) {
- FeaturePtr aFeature = aOperation->feature();
- std::shared_ptr<SketchPlugin_Feature> aSPFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- isCurrentSketchOp = aSPFeature.get() != NULL;
- }
- return isCurrentSketchOp;
-}
+ // 1. check whether the delete should be processed in the module
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
+ isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+ if (!isSketchOp && !isNestedOp)
+ return false;
+
+ // 2. find selected presentations
+ // selected objects should be collected before the current operation abort because
+ // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ ModuleBase_ISelection* aSel = workshop()->selection();
+ QObjectPtrList aSelectedObj = aSel->selectedPresentations();
+ // if there are no selected objects in the viewer, that means that the selection in another
+ // place cased this method. It is necessary to return the false value to understande in above
+ // method that delete is not processed
+ if (aSelectedObj.count() == 0)
+ return false;
+
+ // the active nested sketch operation should be aborted unconditionally
+ if (isNestedOp)
+ anOperation->abort();
+
+ // 3. start operation
+ QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aMgr->startOperation(aDescription.toStdString());