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