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