Salome HOME
f3ccdf4f7d2dc0c570b1778f5f1d737252b2cfc4
[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     mySketchMgr->stopSketch(theOperation);
205   }
206   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
207     mySketchMgr->stopNestedSketch(theOperation);
208   }
209   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
210 }
211
212 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
213 {
214   bool aCanDisplay = false;
215   if (!mySketchMgr->canDisplayObject(theObject))
216     return aCanDisplay;
217   CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
218   if (aSketchFeature.get() != NULL) {
219     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
220
221     // MPV: the second and third conditions to avoid crash on exit for application
222     if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
223       if (aFeature == aSketchFeature) {
224         aCanDisplay = false;
225       }
226       else if (aSketchFeature.get() && aSketchFeature->data().get() &&
227                aSketchFeature->data()->isValid()) {
228         for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
229           FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
230           std::list<ResultPtr> aResults = aSubFeature->results();
231           std::list<ResultPtr>::const_iterator aIt;
232           for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
233             if (theObject == (*aIt))
234               aCanDisplay = true;
235           }
236           if (aSubFeature == theObject)
237             aCanDisplay = true;
238         }
239       }
240     }
241   }
242   else {
243     aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
244   }
245   return aCanDisplay;
246 }
247
248 void PartSet_Module::addViewerItems(QMenu* theMenu) const
249 {
250   if (!PartSet_SketcherMgr::isSketchOperation(myWorkshop->currentOperation()) &&
251       !isSketchFeatureOperationActive())
252     return;
253   ModuleBase_ISelection* aSelection = myWorkshop->selection();
254   QObjectPtrList aObjects = aSelection->selectedPresentations();
255   if (aObjects.size() > 0) {
256     bool hasFeature = false;
257     foreach(ObjectPtr aObject, aObjects)
258     {
259       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
260       if (aFeature.get() != NULL) {
261         hasFeature = true;
262       }
263     }
264     if (hasFeature)
265       theMenu->addAction(action("DELETE_PARTSET_CMD"));
266   }
267 }
268
269 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
270 {
271   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
272   if (PartSet_SketcherMgr::isSketchOperation(theOperation) &&  (theOperation->isEditOperation())) {
273     // we have to manually activate the sketch label in edit mode
274       aPanel->activateWidget(aPanel->modelWidgets().first());
275       return;
276   }
277
278   // Restart last operation type 
279   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
280     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
281     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
282       // Initialise new line with first point equal to end of previous
283       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
284       if (aPnt2dWgt) {
285         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
286         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
287           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
288         if (aPoint) {
289           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
290           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
291             aWgt->attributeID(), aPoint->x(), aPoint->y());
292           aPanel->activateNextWidget(aPnt2dWgt);
293         }
294       }
295     }
296   } else {
297     // Start editing constraint
298     if (theOperation->isEditOperation()) {
299       // TODO: #391 - to be removed
300       std::string aId = theOperation->id().toStdString();
301       if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
302           PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
303         // Find and activate widget for management of point for dimension line position
304         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
305         foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
306           PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
307           if (aPntWgt) {
308             aPanel->activateWidget(aPntWgt);
309             return;
310           }
311         }
312       }
313     }
314   }
315 }
316
317
318 void PartSet_Module::onSelectionChanged()
319 {
320   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
321   if (!aOperation)
322     return;
323
324   bool isSketcherOp = false;
325   // An edit operation is enable only if the current opeation is the sketch operation
326   if (mySketchMgr->activeSketch()) {
327     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
328       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
329   }
330   if (isSketcherOp) {
331     // Editing of constraints can be done on selection
332     ModuleBase_ISelection* aSelect = myWorkshop->selection();
333     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
334     if (aSelected.size() == 1) {
335       ModuleBase_ViewerPrs aPrs = aSelected.first();
336       ObjectPtr aObject = aPrs.object();
337       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
338       if (aFeature) {
339         std::string aId = aFeature->getKind();
340         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
341             (aId == SketchPlugin_ConstraintLength::ID()) || 
342             (aId == SketchPlugin_ConstraintDistance::ID())) {
343           editFeature(aFeature);
344         }
345       }
346     }
347   } 
348 }
349
350 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
351 {
352   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
353   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
354   anOpMgr->onKeyReleased(theEvent);
355 }
356
357 void PartSet_Module::onEnterReleased()
358 {
359   myRestartingMode = RM_EmptyFeatureUsed;
360 }
361
362 void PartSet_Module::onOperationActivatedByPreselection()
363 {
364   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
365   if(aOperation && isSketchFeatureOperationActive()) {
366     // Set final definitions if they are necessary
367     //propertyPanelDefined(aOperation);
368
369     /// Commit sketcher operations automatically
370     aOperation->commit();
371   }
372 }
373
374 void PartSet_Module::onNoMoreWidgets()
375 {
376   if (isSketchFeatureOperationActive()) {
377     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
378     if (aOperation) {
379       if (myRestartingMode != RM_Forbided)
380         myRestartingMode = RM_LastFeatureUsed;
381       aOperation->commit();
382     }
383   }
384 }
385
386 void PartSet_Module::onVertexSelected()
387 {
388   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
389   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
390     /// If last line finished on vertex the lines creation sequence has to be break
391     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
392     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
393     if (aWidgets.last() == aPanel->activeWidget()) {
394       myRestartingMode = RM_Forbided;
395     }
396   }
397 }
398
399 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
400                                             Config_WidgetAPI* theWidgetApi, std::string theParentId,
401                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
402 {
403   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
404   XGUI_Workshop* aWorkshop = aConnector->workshop();
405   if (theType == "sketch-start-label") {
406     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
407     aWgt->setWorkshop(aWorkshop);
408     connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)), 
409       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
410     theModelWidgets.append(aWgt);
411     return aWgt->getControl();
412
413   } else if (theType == "sketch-2dpoint_selector") {
414     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
415     aWgt->setWorkshop(aWorkshop);
416     aWgt->setSketch(mySketchMgr->activeSketch());
417
418     connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
419
420     theModelWidgets.append(aWgt);
421     return aWgt->getControl();
422
423   } if (theType == "point2ddistance") {
424     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
425     aWgt->setWorkshop(aWorkshop);
426     aWgt->setSketch(mySketchMgr->activeSketch());
427
428     theModelWidgets.append(aWgt);
429     return aWgt->getControl();
430
431   } if (theType == "sketch_shape_selector") {
432     PartSet_WidgetShapeSelector* aWgt = 
433       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
434     aWgt->setSketcher(mySketchMgr->activeSketch());
435
436     theModelWidgets.append(aWgt);
437     return aWgt->getControl();
438
439   } if (theType == "sketch_constraint_shape_selector") {
440     PartSet_WidgetConstraintShapeSelector* aWgt = 
441       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
442     aWgt->setSketcher(mySketchMgr->activeSketch());
443
444     theModelWidgets.append(aWgt);
445     return aWgt->getControl();
446
447   } else
448     return 0;
449 }
450
451 bool PartSet_Module::isSketchFeatureOperationActive() const
452 {
453   bool isCurrentSketchOp = false;
454   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
455   if (aOperation) {
456     FeaturePtr aFeature = aOperation->feature();
457     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
458               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
459     isCurrentSketchOp = aSPFeature.get() != NULL;
460   }
461   return isCurrentSketchOp;
462 }
463
464 void PartSet_Module::createActions()
465 {
466   QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
467   addAction("DELETE_PARTSET_CMD", aAction);
468 }
469
470 QAction* PartSet_Module::action(const QString& theId) const
471 {
472   if (myActions.contains(theId))
473     return myActions[theId];
474   return 0;
475 }
476
477 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
478 {
479   if (myActions.contains(theId))
480     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
481   theAction->setData(theId);
482   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
483   myActions[theId] = theAction;
484 }
485
486 void PartSet_Module::onAction(bool isChecked)
487 {
488   QAction* aAction = static_cast<QAction*>(sender());
489   QString anId = aAction->data().toString();
490
491   if (anId == "DELETE_PARTSET_CMD") {
492     deleteObjects();
493   }
494 }
495
496 void PartSet_Module::deleteObjects()
497 {
498   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(myWorkshop->currentOperation());
499   if (!isSketchOp && !isSketchFeatureOperationActive())
500     return;
501
502   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
503   XGUI_Workshop* aWorkshop = aConnector->workshop();
504
505   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
506   if (!isSketchOp && anOpMgr->canStopOperation()) {
507     ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation();
508     if (aCurrentOp) {
509       aCurrentOp->abort();
510     }
511   }
512   // sketch feature should be skipped, only sub-features can be removed
513   // when sketch operation is active
514   CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
515
516   ModuleBase_ISelection* aSel = aConnector->selection();
517   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
518
519   std::set<FeaturePtr> aRefFeatures;
520   foreach (ObjectPtr aObj, aSelectedObj)
521   {
522     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
523     //if (aPart) {
524       // TODO: check for what there is this condition. It is placed here historicaly because
525       // ther is this condition during remove features.
526     //} else {
527     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
528     if (aFeature.get() != NULL) {
529       aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
530     }
531     //}
532   }
533
534   if (!aRefFeatures.empty()) {
535     QStringList aRefNames;
536     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
537                                          aLast = aRefFeatures.end();
538     for (; anIt != aLast; anIt++) {
539       FeaturePtr aFeature = (*anIt);
540       if (aFeature == aSketch)
541         continue;
542       aRefNames.append((*anIt)->name().c_str());
543     }
544     if (!aRefNames.empty()) {
545       QString aNames = aRefNames.join(", ");
546
547       QMainWindow* aDesktop = aWorkshop->desktop();
548       QMessageBox::StandardButton aRes = QMessageBox::warning(
549           aDesktop, tr("Delete features"),
550           QString(tr("Selected features are used in the following features: %1.\
551   These features will be deleted also. Would you like to continue?")).arg(aNames),
552           QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
553       if (aRes != QMessageBox::Yes)
554         return;
555     }
556   }
557
558   SessionPtr aMgr = ModelAPI_Session::get();
559   aMgr->startOperation("DeletePartSet");
560   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
561                                        aLast = aRefFeatures.end();
562   for (; anIt != aLast; anIt++) {
563     FeaturePtr aRefFeature = (*anIt);
564     if (aRefFeature == aSketch)
565       continue;
566     aRefFeature->document()->removeFeature(aRefFeature);
567   }
568
569   foreach (ObjectPtr aObj, aSelectedObj)
570   {
571     DocumentPtr aDoc = aObj->document();
572     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
573     //if (aPart) {
574     //  if (aDoc == aMgr->activeDocument()) {
575     //    aDoc->close();
576     //  }
577     //} else {
578       //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
579     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
580     if (aFeature.get() != NULL) {
581       aDoc->removeFeature(aFeature);
582     }
583     //}
584   }
585   aWorkshop->displayer()->updateViewer();
586   //myDisplayer->updateViewer();
587   aMgr->finishOperation();
588 }