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