Salome HOME
Multi-selection widget to be used in the extrusion feature.
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "PartSet_Module.h"
4 #include <PartSet_WidgetSketchLabel.h>
5 #include <PartSet_Validators.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_WidgetPoint2d.h>
8 #include <PartSet_WidgetPoint2dDistance.h>
9 #include <PartSet_WidgetShapeSelector.h>
10 #include <PartSet_WidgetConstraintShapeSelector.h>
11 #include <PartSet_SketcherMgr.h>
12
13 #include <ModuleBase_Operation.h>
14 #include <ModuleBase_IViewer.h>
15 #include <ModuleBase_IViewWindow.h>
16 #include <ModuleBase_IPropertyPanel.h>
17 #include <ModuleBase_WidgetEditor.h>
18 #include <ModuleBase_FilterFactory.h>
19 #include <ModuleBase_FilterLinearEdge.h>
20 #include <ModuleBase_FilterFace.h>
21 #include <ModuleBase_FilterMulti.h>
22 #include <ModuleBase_FilterCustom.h>
23 #include <ModuleBase_FilterNoConsructionSubShapes.h>
24 #include <PartSet_FilterSketchEntity.h>
25
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_Events.h>
28 #include <ModelAPI_Validator.h>
29 #include <ModelAPI_Data.h>
30 #include <ModelAPI_Session.h>
31 #include <ModelAPI_ShapeValidator.h>
32
33 #include <GeomDataAPI_Point2D.h>
34 #include <GeomDataAPI_Point.h>
35 #include <GeomDataAPI_Dir.h>
36
37 #include <XGUI_Displayer.h>
38 #include <XGUI_Workshop.h>
39 #include <XGUI_OperationMgr.h>
40 #include <XGUI_PropertyPanel.h>
41 #include <XGUI_ModuleConnector.h>
42 #include <XGUI_ContextMenuMgr.h>
43 #include <XGUI_Tools.h>
44
45 #include <SketchPlugin_Feature.h>
46 #include <SketchPlugin_Sketch.h>
47 #include <SketchPlugin_Line.h>
48 //#include <SketchPlugin_Arc.h>
49 //#include <SketchPlugin_Circle.h>
50 #include <SketchPlugin_ConstraintLength.h>
51 #include <SketchPlugin_ConstraintDistance.h>
52 #include <SketchPlugin_ConstraintParallel.h>
53 #include <SketchPlugin_ConstraintPerpendicular.h>
54 #include <SketchPlugin_ConstraintRadius.h>
55 //#include <SketchPlugin_ConstraintRigid.h>
56
57 #include <Events_Loop.h>
58 #include <Config_PropManager.h>
59
60 #include <StdSelect_TypeOfFace.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <BRep_Tool.hxx>
65
66 #include <QObject>
67 #include <QMouseEvent>
68 #include <QString>
69 #include <QTimer>
70 #include <QApplication>
71 #include <QMessageBox>
72 #include <QMainWindow>
73
74 #include <GeomAlgoAPI_FaceBuilder.h>
75 #include <GeomDataAPI_Dir.h>
76
77 #ifdef _DEBUG
78 #include <QDebug>
79 #endif
80
81 /*!Create and return new instance of XGUI_Module*/
82 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
83 {
84   return new PartSet_Module(theWshop);
85 }
86
87 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
88   : ModuleBase_IModule(theWshop), 
89   myRestartingMode(RM_None)
90 {
91   //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
92   mySketchMgr = new PartSet_SketcherMgr(this);
93
94   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
95   XGUI_Workshop* aWorkshop = aConnector->workshop();
96
97   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
98   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
99   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
100           this, SLOT(onOperationActivatedByPreselection()));
101
102   ModuleBase_IViewer* aViewer = theWshop->viewer();
103   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
104           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
105
106   createActions();
107 }
108
109 PartSet_Module::~PartSet_Module()
110 {
111   if (!myDocumentShapeFilter.IsNull())
112     myDocumentShapeFilter.Nullify();
113 }
114
115 void PartSet_Module::registerValidators()
116 {
117   //Registering of validators
118   SessionPtr aMgr = ModelAPI_Session::get();
119   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
120   aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
121   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
122   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
123   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
124   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
125   aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
126   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
127   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
128   aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
129 }
130
131 void PartSet_Module::registerFilters()
132 {
133   //Registering of selection filters
134   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
135   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
136
137   aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
138   aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
139   aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
140   Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
141   aFactory->registerFilter("NoConstructionSubShapesFilter",
142             new ModuleBase_FilterCustom(aSelectFilter));
143   aSelectFilter = new PartSet_FilterSketchEntity(workshop());
144   aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
145 }
146
147 void PartSet_Module::registerProperties()
148 {
149   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
150                                    PLANE_SIZE);
151   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
152                                    Config_Prop::Integer, SKETCH_WIDTH);
153 }
154
155 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
156 {
157   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
158     mySketchMgr->commitNestedSketch(theOperation);
159   }
160
161   if (theOperation->isEditOperation())
162     return;
163   // the selection is cleared after commit the create operation
164   // in order to do not use the same selected objects in the restarted operation
165   // for common behaviour, the selection is cleared even if the operation is not restarted
166   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
167   if (!aContext.IsNull())
168     aContext->ClearSelected();
169
170   /// Restart sketcher operations automatically
171   FeaturePtr aFeature = theOperation->feature();
172   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
173             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
174   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
175                      myRestartingMode == RM_EmptyFeatureUsed)) {
176     myLastOperationId = theOperation->id();
177     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
178     
179     launchOperation(myLastOperationId);
180   }
181   breakOperationSequence();
182 }
183
184 void PartSet_Module::breakOperationSequence()
185 {
186   myLastOperationId = "";
187   myLastFeature = FeaturePtr();
188   myRestartingMode = RM_None;
189 }
190
191 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
192 {
193   breakOperationSequence();
194 }
195
196 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
197 {
198   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
199     mySketchMgr->startSketch(theOperation);
200   }
201   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
202     mySketchMgr->startNestedSketch(theOperation);
203   }
204
205   if (myDocumentShapeFilter.IsNull())
206     myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
207   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
208 }
209
210 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
211 {
212   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
213     mySketchMgr->stopSketch(theOperation);
214   }
215   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
216     mySketchMgr->stopNestedSketch(theOperation);
217   }
218   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
219 }
220
221 bool PartSet_Module::canUndo() const
222 {
223   bool aCanUndo = false;
224   SessionPtr aMgr = ModelAPI_Session::get();
225   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
226     aCanUndo = !aMgr->isOperation();
227     if (!aCanUndo) // check the enable state additionally by sketch manager
228       aCanUndo = aMgr->canUndo();
229   }
230   return aCanUndo;
231 }
232
233 bool PartSet_Module::canRedo() const
234 {
235   bool aCanRedo = false;
236   SessionPtr aMgr = ModelAPI_Session::get();
237   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
238     aCanRedo = !aMgr->isOperation();
239     if (!aCanRedo) // check the enable state additionally by sketch manager
240       aCanRedo = aMgr->canRedo();
241   }
242   return aCanRedo;
243 }
244
245 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
246 {
247   bool aCanDisplay = false;
248   if (!mySketchMgr->canDisplayObject())
249     return aCanDisplay;
250   CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
251   if (aSketchFeature.get() != NULL) {
252     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
253
254     // MPV: the second and third conditions to avoid crash on exit for application
255     if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
256       if (aFeature == aSketchFeature) {
257         aCanDisplay = false;
258       }
259       else if (aSketchFeature.get() && aSketchFeature->data().get() &&
260                aSketchFeature->data()->isValid()) {
261         for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
262           FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
263           std::list<ResultPtr> aResults = aSubFeature->results();
264           std::list<ResultPtr>::const_iterator aIt;
265           for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
266             if (theObject == (*aIt))
267               aCanDisplay = true;
268           }
269           if (aSubFeature == theObject)
270             aCanDisplay = true;
271         }
272       }
273     }
274   }
275   else {
276     aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
277   }
278   return aCanDisplay;
279 }
280
281 void PartSet_Module::addViewerItems(QMenu* theMenu) const
282 {
283   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
284   if (!PartSet_SketcherMgr::isSketchOperation(anOperation) &&
285       !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
286     return;
287
288   ModuleBase_ISelection* aSelection = myWorkshop->selection();
289   QObjectPtrList aObjects = aSelection->selectedPresentations();
290   if (aObjects.size() > 0) {
291     bool hasFeature = false;
292     foreach(ObjectPtr aObject, aObjects)
293     {
294       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
295       if (aFeature.get() != NULL) {
296         hasFeature = true;
297       }
298     }
299     if (hasFeature) {
300       XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
301       XGUI_Workshop* aWorkshop = aConnector->workshop();
302       QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
303       theMenu->addAction(anAction);
304     }
305   }
306   bool isAuxiliary;
307   if (mySketchMgr->canSetAuxiliary(isAuxiliary)) {
308     QAction* anAction = action("AUXILIARY_CMD");
309     theMenu->addAction(anAction);
310     anAction->setChecked(isAuxiliary);
311   }
312 }
313
314 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
315 {
316   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
317   if (PartSet_SketcherMgr::isSketchOperation(theOperation) &&  (theOperation->isEditOperation())) {
318     // we have to manually activate the sketch label in edit mode
319       aPanel->activateWidget(aPanel->modelWidgets().first());
320       return;
321   }
322
323   // Restart last operation type 
324   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
325     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
326     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
327       // Initialise new line with first point equal to end of previous
328       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
329       if (aPnt2dWgt) {
330         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
331         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
332           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
333         if (aPoint) {
334           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
335           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
336             aWgt->attributeID(), aPoint->x(), aPoint->y());
337           aPanel->activateNextWidget(aPnt2dWgt);
338         }
339       }
340     }
341   } else {
342     // Start editing constraint
343     if (theOperation->isEditOperation()) {
344       // TODO: #391 - to be removed
345       std::string aId = theOperation->id().toStdString();
346       if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
347           PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
348         // Find and activate widget for management of point for dimension line position
349         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
350         foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
351           PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
352           if (aPntWgt) {
353             aPanel->activateWidget(aPntWgt);
354             return;
355           }
356         }
357       }
358     }
359   }
360 }
361
362
363 void PartSet_Module::onSelectionChanged()
364 {
365   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
366   if (!aOperation)
367     return;
368
369   bool isSketcherOp = false;
370   // An edit operation is enable only if the current opeation is the sketch operation
371   if (mySketchMgr->activeSketch()) {
372     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
373       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
374   }
375   if (isSketcherOp) {
376     // Editing of constraints can be done on selection
377     ModuleBase_ISelection* aSelect = myWorkshop->selection();
378     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
379     if (aSelected.size() == 1) {
380       ModuleBase_ViewerPrs aPrs = aSelected.first();
381       ObjectPtr aObject = aPrs.object();
382       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
383       if (aFeature) {
384         std::string aId = aFeature->getKind();
385         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
386             (aId == SketchPlugin_ConstraintLength::ID()) || 
387             (aId == SketchPlugin_ConstraintDistance::ID())) {
388           editFeature(aFeature);
389         }
390       }
391     }
392   } 
393 }
394
395 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
396 {
397   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
398   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
399   anOpMgr->onKeyReleased(theEvent);
400 }
401
402 void PartSet_Module::onEnterReleased()
403 {
404   myRestartingMode = RM_EmptyFeatureUsed;
405 }
406
407 void PartSet_Module::onOperationActivatedByPreselection()
408 {
409   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
410   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
411     // Set final definitions if they are necessary
412     //propertyPanelDefined(aOperation);
413
414     /// Commit sketcher operations automatically
415     anOperation->commit();
416   }
417 }
418
419 void PartSet_Module::onNoMoreWidgets()
420 {
421   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
422   if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
423     if (anOperation) {
424       if (myRestartingMode != RM_Forbided)
425         myRestartingMode = RM_LastFeatureUsed;
426       anOperation->commit();
427     }
428   }
429 }
430
431 void PartSet_Module::onVertexSelected()
432 {
433   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
434   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
435     /// If last line finished on vertex the lines creation sequence has to be break
436     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
437     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
438     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
439     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
440     bool aFoundWidget = false;
441     bool aFoundObligatory = false;
442     for (; anIt != aLast && !aFoundObligatory; anIt++) {
443       if (!aFoundWidget)
444         aFoundWidget = *anIt == anActiveWidget;
445       else
446         aFoundObligatory = (*anIt)->isObligatory();
447     }
448     if (!aFoundObligatory)
449       myRestartingMode = RM_Forbided;
450   }
451 }
452
453 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
454                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
455 {
456   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
457   XGUI_Workshop* aWorkshop = aConnector->workshop();
458   ModuleBase_ModelWidget* aWgt = NULL;
459   if (theType == "sketch-start-label") {
460     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
461     aLabelWgt->setWorkshop(aWorkshop);
462     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
463       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
464     aWgt = aLabelWgt;
465   } else if (theType == "sketch-2dpoint_selector") {
466     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
467     aPointWgt->setWorkshop(aWorkshop);
468     aPointWgt->setSketch(mySketchMgr->activeSketch());
469     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
470     aWgt = aPointWgt;
471   } if (theType == "point2ddistance") {
472     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
473     aDistanceWgt->setWorkshop(aWorkshop);
474     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
475     aWgt = aDistanceWgt;
476   } if (theType == "sketch_shape_selector") {
477     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
478       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
479     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
480     aWgt = aShapeSelectorWgt;
481   } if (theType == "sketch_constraint_shape_selector") {
482     PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
483       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
484     aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
485     aWgt = aConstraintShapeSelectorWgt;
486   }
487   return aWgt;
488 }
489
490 void PartSet_Module::createActions()
491 {
492   QAction* anAction;
493
494   anAction = new QAction(tr("Auxiliary"), this);
495   anAction->setCheckable(true);
496   addAction("AUXILIARY_CMD", anAction);
497 }
498
499 QAction* PartSet_Module::action(const QString& theId) const
500 {
501   if (myActions.contains(theId))
502     return myActions[theId];
503   return 0;
504 }
505
506 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
507 {
508   if (myActions.contains(theId))
509     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
510   theAction->setData(theId);
511   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
512   myActions[theId] = theAction;
513 }
514
515 void PartSet_Module::onAction(bool isChecked)
516 {
517   QAction* aAction = static_cast<QAction*>(sender());
518   QString anId = aAction->data().toString();
519
520   if (anId == "AUXILIARY_CMD") {
521     mySketchMgr->setAuxiliary(isChecked);
522   }
523 }
524
525 bool PartSet_Module::deleteObjects()
526 {
527   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
528   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
529        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
530   if (!isSketchOp && !isNestedOp)
531     return false;
532
533   // sketch feature should be skipped, only sub-features can be removed
534   // when sketch operation is active
535   CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
536
537   // selected objects should be collected before the current operation abort because
538   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
539   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
540   XGUI_Workshop* aWorkshop = aConnector->workshop();
541   ModuleBase_ISelection* aSel = aConnector->selection();
542   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
543
544   // if there are no selected objects in the viewer, that means that the selection in another
545   // place cased this method. It is necessary to return the false value to understande in above
546   // method that delete is not processed
547   if (aSelectedObj.count() == 0)
548     return false;
549
550   if (isNestedOp)
551     anOperation->abort();
552
553   // the active nested sketch operation should be aborted unconditionally
554   if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
555     anOperation->abort();
556
557   std::set<FeaturePtr> aRefFeatures;
558   foreach (ObjectPtr aObj, aSelectedObj)
559   {
560     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
561     //if (aPart) {
562       // TODO: check for what there is this condition. It is placed here historicaly because
563       // ther is this condition during remove features.
564     //} else {
565     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
566     if (aFeature.get() != NULL) {
567       aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
568     }
569     //}
570   }
571
572   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
573   /**
574   // according to #355 feature, it is not necessary to inform about dependencies during
575   // sketch delete operation
576   // 
577   if (!aRefFeatures.empty()) {
578     QStringList aRefNames;
579     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
580                                          aLast = aRefFeatures.end();
581     for (; anIt != aLast; anIt++) {
582       FeaturePtr aFeature = (*anIt);
583       if (aFeature == aSketch)
584         continue;
585       aRefNames.append((*anIt)->name().c_str());
586     }
587     if (!aRefNames.empty()) {
588       QString aNames = aRefNames.join(", ");
589       aDescription += aNames.prepend(" ");
590
591       QMainWindow* aDesktop = aWorkshop->desktop();
592       QMessageBox::StandardButton aRes = QMessageBox::warning(
593           aDesktop, tr("Delete features"),
594           QString(tr("Selected features are used in the following features: %1.\
595   These features will be deleted also. Would you like to continue?")).arg(aNames),
596           QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
597       if (aRes != QMessageBox::Yes)
598         return;
599     }
600   }*/
601
602   SessionPtr aMgr = ModelAPI_Session::get();
603   aMgr->startOperation(aDescription.toStdString());
604   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
605                                        aLast = aRefFeatures.end();
606   for (; anIt != aLast; anIt++) {
607     FeaturePtr aRefFeature = (*anIt);
608     if (aRefFeature == aSketch)
609       continue;
610     aRefFeature->document()->removeFeature(aRefFeature);
611   }
612
613   foreach (ObjectPtr aObj, aSelectedObj)
614   {
615     DocumentPtr aDoc = aObj->document();
616     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
617     //if (aPart) {
618     //  if (aDoc == aMgr->activeDocument()) {
619     //    aDoc->close();
620     //  }
621     //} else {
622       //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
623     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
624     if (aFeature.get() != NULL) {
625       aDoc->removeFeature(aFeature);
626     }
627     //}
628   }
629   aWorkshop->displayer()->updateViewer();
630   //myDisplayer->updateViewer();
631   aMgr->finishOperation();
632
633   return true;
634 }