Salome HOME
39520d8af82f766a3ffe29a98001cbc0a0d531ca
[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(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       XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
298       XGUI_Workshop* aWorkshop = aConnector->workshop();
299       QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
300       theMenu->addAction(anAction);
301     }
302   }
303   bool isConstruction;
304   if (mySketchMgr->canChangeConstruction(isConstruction)) {
305     QAction* anAction = action("CONSTRUCTION_CMD");
306     theMenu->addAction(anAction);
307     anAction->setChecked(isConstruction);
308   }
309 }
310
311 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
312 {
313   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
314   if (PartSet_SketcherMgr::isSketchOperation(theOperation) &&  (theOperation->isEditOperation())) {
315     // we have to manually activate the sketch label in edit mode
316       aPanel->activateWidget(aPanel->modelWidgets().first());
317       return;
318   }
319
320   // Restart last operation type 
321   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
322     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
323     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
324       // Initialise new line with first point equal to end of previous
325       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
326       if (aPnt2dWgt) {
327         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
328         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
329           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
330         if (aPoint) {
331           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
332           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
333             aWgt->attributeID(), aPoint->x(), aPoint->y());
334           aPanel->activateNextWidget(aPnt2dWgt);
335         }
336       }
337     }
338   } else {
339     // Start editing constraint
340     if (theOperation->isEditOperation()) {
341       // TODO: #391 - to be removed
342       std::string aId = theOperation->id().toStdString();
343       if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
344           PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
345         // Find and activate widget for management of point for dimension line position
346         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
347         foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
348           PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
349           if (aPntWgt) {
350             aPanel->activateWidget(aPntWgt);
351             return;
352           }
353         }
354       }
355     }
356   }
357 }
358
359
360 void PartSet_Module::onSelectionChanged()
361 {
362   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
363   if (!aOperation)
364     return;
365
366   bool isSketcherOp = false;
367   // An edit operation is enable only if the current opeation is the sketch operation
368   if (mySketchMgr->activeSketch()) {
369     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
370       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
371   }
372   if (isSketcherOp) {
373     // Editing of constraints can be done on selection
374     ModuleBase_ISelection* aSelect = myWorkshop->selection();
375     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
376     if (aSelected.size() == 1) {
377       ModuleBase_ViewerPrs aPrs = aSelected.first();
378       ObjectPtr aObject = aPrs.object();
379       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
380       if (aFeature) {
381         std::string aId = aFeature->getKind();
382         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
383             (aId == SketchPlugin_ConstraintLength::ID()) || 
384             (aId == SketchPlugin_ConstraintDistance::ID())) {
385           editFeature(aFeature);
386         }
387       }
388     }
389   } 
390 }
391
392 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
393 {
394   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
395   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
396   anOpMgr->onKeyReleased(theEvent);
397 }
398
399 void PartSet_Module::onEnterReleased()
400 {
401   myRestartingMode = RM_EmptyFeatureUsed;
402 }
403
404 void PartSet_Module::onOperationActivatedByPreselection()
405 {
406   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
407   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
408     // Set final definitions if they are necessary
409     //propertyPanelDefined(aOperation);
410
411     /// Commit sketcher operations automatically
412     anOperation->commit();
413   }
414 }
415
416 void PartSet_Module::onNoMoreWidgets()
417 {
418   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
419   if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
420     if (anOperation) {
421       if (myRestartingMode != RM_Forbided)
422         myRestartingMode = RM_LastFeatureUsed;
423       anOperation->commit();
424     }
425   }
426 }
427
428 void PartSet_Module::onVertexSelected()
429 {
430   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
431   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
432     /// If last line finished on vertex the lines creation sequence has to be break
433     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
434     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
435     if (aWidgets.last() == aPanel->activeWidget()) {
436       myRestartingMode = RM_Forbided;
437     }
438   }
439 }
440
441 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
442                                             Config_WidgetAPI* theWidgetApi, std::string theParentId,
443                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
444 {
445   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
446   XGUI_Workshop* aWorkshop = aConnector->workshop();
447   ModuleBase_ModelWidget* aWgt = NULL;
448   if (theType == "sketch-start-label") {
449     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
450     aLabelWgt->setWorkshop(aWorkshop);
451     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
452       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
453     aWgt = aLabelWgt;
454   } else if (theType == "sketch-2dpoint_selector") {
455     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
456     aPointWgt->setWorkshop(aWorkshop);
457     aPointWgt->setSketch(mySketchMgr->activeSketch());
458     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
459     aWgt = aPointWgt;
460   } if (theType == "point2ddistance") {
461     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
462     aDistanceWgt->setWorkshop(aWorkshop);
463     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
464     aWgt = aDistanceWgt;
465   } if (theType == "sketch_shape_selector") {
466     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
467       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
468     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
469     aWgt = aShapeSelectorWgt;
470   } if (theType == "sketch_constraint_shape_selector") {
471     PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
472       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
473     aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
474     aWgt = aConstraintShapeSelectorWgt;
475   }
476   if(aWgt)
477     theModelWidgets.append(aWgt);
478   return aWgt;
479 }
480
481 void PartSet_Module::createActions()
482 {
483   QAction* anAction;
484
485   anAction = new QAction(tr("Construction"), this);
486   anAction->setCheckable(true);
487   addAction("CONSTRUCTION_CMD", anAction);
488 }
489
490 QAction* PartSet_Module::action(const QString& theId) const
491 {
492   if (myActions.contains(theId))
493     return myActions[theId];
494   return 0;
495 }
496
497 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
498 {
499   if (myActions.contains(theId))
500     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
501   theAction->setData(theId);
502   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
503   myActions[theId] = theAction;
504 }
505
506 void PartSet_Module::onAction(bool isChecked)
507 {
508   QAction* aAction = static_cast<QAction*>(sender());
509   QString anId = aAction->data().toString();
510
511   if (anId == "CONSTRUCTION_CMD") {
512     mySketchMgr->setConstruction(isChecked);
513   }
514 }
515
516 bool PartSet_Module::deleteObjects()
517 {
518   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
519   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
520        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
521   if (!isSketchOp && !isNestedOp)
522     return false;
523
524   // sketch feature should be skipped, only sub-features can be removed
525   // when sketch operation is active
526   CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
527
528   // selected objects should be collected before the current operation abort because
529   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
530   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
531   XGUI_Workshop* aWorkshop = aConnector->workshop();
532   ModuleBase_ISelection* aSel = aConnector->selection();
533   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
534
535   // if there are no selected objects in the viewer, that means that the selection in another
536   // place cased this method. It is necessary to return the false value to understande in above
537   // method that delete is not processed
538   if (aSelectedObj.count() == 0)
539     return false;
540
541   if (isNestedOp)
542     anOperation->abort();
543
544   // the active nested sketch operation should be aborted unconditionally
545   if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
546     anOperation->abort();
547
548   std::set<FeaturePtr> aRefFeatures;
549   foreach (ObjectPtr aObj, aSelectedObj)
550   {
551     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
552     //if (aPart) {
553       // TODO: check for what there is this condition. It is placed here historicaly because
554       // ther is this condition during remove features.
555     //} else {
556     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
557     if (aFeature.get() != NULL) {
558       aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
559     }
560     //}
561   }
562
563   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
564   /**
565   // according to #355 feature, it is not necessary to inform about dependencies during
566   // sketch delete operation
567   // 
568   if (!aRefFeatures.empty()) {
569     QStringList aRefNames;
570     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
571                                          aLast = aRefFeatures.end();
572     for (; anIt != aLast; anIt++) {
573       FeaturePtr aFeature = (*anIt);
574       if (aFeature == aSketch)
575         continue;
576       aRefNames.append((*anIt)->name().c_str());
577     }
578     if (!aRefNames.empty()) {
579       QString aNames = aRefNames.join(", ");
580       aDescription += aNames.prepend(" ");
581
582       QMainWindow* aDesktop = aWorkshop->desktop();
583       QMessageBox::StandardButton aRes = QMessageBox::warning(
584           aDesktop, tr("Delete features"),
585           QString(tr("Selected features are used in the following features: %1.\
586   These features will be deleted also. Would you like to continue?")).arg(aNames),
587           QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
588       if (aRes != QMessageBox::Yes)
589         return;
590     }
591   }*/
592
593   SessionPtr aMgr = ModelAPI_Session::get();
594   aMgr->startOperation(aDescription.toStdString());
595   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
596                                        aLast = aRefFeatures.end();
597   for (; anIt != aLast; anIt++) {
598     FeaturePtr aRefFeature = (*anIt);
599     if (aRefFeature == aSketch)
600       continue;
601     aRefFeature->document()->removeFeature(aRefFeature);
602   }
603
604   foreach (ObjectPtr aObj, aSelectedObj)
605   {
606     DocumentPtr aDoc = aObj->document();
607     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
608     //if (aPart) {
609     //  if (aDoc == aMgr->activeDocument()) {
610     //    aDoc->close();
611     //  }
612     //} else {
613       //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
614     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
615     if (aFeature.get() != NULL) {
616       aDoc->removeFeature(aFeature);
617     }
618     //}
619   }
620   aWorkshop->displayer()->updateViewer();
621   //myDisplayer->updateViewer();
622   aMgr->finishOperation();
623
624   return true;
625 }