+ //SessionPtr aMgr = ModelAPI_Session::get();
+ // 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) {
+ // 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
+ 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;
+
+ // avoid delete of the objects, which are not belong to the current sketch
+ // in order to do not delete results of other sketches
+ QObjectPtrList aSketchObjects;
+ QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
+ for ( ; anIt != aLast; anIt++) {
+ ObjectPtr anObject = *anIt;
+ if (mySketchMgr->isObjectOfSketch(anObject)) {
+ // sketch feature should be used in this list because workshop deletes features only
+ // results are skipped
+ FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
+ aSketchObjects.append(aSketchFeature);
+ }
+ }
+ // if the selection contains only local selected presentations from other sketches,
+ // the Delete operation should not be done at all
+ if (aSketchObjects.size() == 0)
+ return true;
+
+ // 3. start operation
+ QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
+ ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
+
+ // the active nested sketch operation should be aborted unconditionally
+ // the Delete action should be additionally granted for the Sketch operation
+ // in order to do not abort/commit it
+ if (!anOpMgr->canStartOperation(anOpAction->id(), isSketchOp/*granted*/))
+ return true; // the objects are processed but can not be deleted
+
+ anOpMgr->startOperation(anOpAction);
+
+ // 4. delete features
+ // sketch feature should be skipped, only sub-features can be removed
+ // when sketch operation is active
+ aWorkshop->deleteFeatures(aSketchObjects);
+ // 5. stop operation
+ anOpMgr->commitOperation();
+ }
+ else {
+ bool isPartRemoved = false;
+ // Delete part with help of PartSet plugin
+ // TODO: the deleted objects has to be processed by multiselection
+ QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
+ if (aObjects.size() == 1) {
+ ObjectPtr aObj = aObjects.first();
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
+ // Remove feature should be created in the document of the part results
+ ResultPtr aPartResult = aFeature->firstResult();
+ if (aPartResult.get()) {
+ std::shared_ptr<ModelAPI_ResultPart> aPart =
+ std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
+ DocumentPtr aPartDoc = aPart->partDoc();
+ if (aPartDoc.get()) {
+ ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
+ (PartSetPlugin_Remove::ID().c_str(), this);
+ if (!anOpMgr->canStartOperation(anOpAction->id()))
+ return true; // the objects are processed but can not be deleted
+
+ anOpMgr->startOperation(anOpAction);
+
+ FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
+ aFeature->execute();
+
+ anOpMgr->commitOperation();
+ isPartRemoved = true;
+ }
+ }
+ }
+ }
+ return isPartRemoved;
+ }
+ return true;
+}