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