+bool PartSet_Module::deleteObjects()
+{
+ 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
+ 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;
+
+ // 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;
+
+ // the active nested sketch operation should be aborted unconditionally
+ if (isNestedOp)
+ anOperation->abort();
+
+ // 3. start operation
+ QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
+ aMgr->startOperation(aDescription.toStdString());
+
+ // 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
+ aWorkshop->displayer()->updateViewer();
+ aMgr->finishOperation();
+ } 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()) {
+ aMgr->startOperation(PartSetPlugin_Remove::ID());
+ FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
+ aFeature->execute();
+ aMgr->finishOperation();
+ isPartRemoved = true;
+ }
+ }
+ }
+ }
+ return isPartRemoved;
+ }
+ return true;
+}