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