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