]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
Issue #353 constraint on 2 segments from not acive sketches
[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   if (theType == "sketch-start-label") {
437     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
438     aWgt->setWorkshop(aWorkshop);
439     connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)), 
440       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
441     theModelWidgets.append(aWgt);
442     return aWgt->getControl();
443
444   } else if (theType == "sketch-2dpoint_selector") {
445     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
446     aWgt->setWorkshop(aWorkshop);
447     aWgt->setSketch(mySketchMgr->activeSketch());
448
449     connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
450
451     theModelWidgets.append(aWgt);
452     return aWgt->getControl();
453
454   } if (theType == "point2ddistance") {
455     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
456     aWgt->setWorkshop(aWorkshop);
457     aWgt->setSketch(mySketchMgr->activeSketch());
458
459     theModelWidgets.append(aWgt);
460     return aWgt->getControl();
461
462   } if (theType == "sketch_shape_selector") {
463     PartSet_WidgetShapeSelector* aWgt = 
464       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
465     aWgt->setSketcher(mySketchMgr->activeSketch());
466
467     theModelWidgets.append(aWgt);
468     return aWgt->getControl();
469
470   } if (theType == "sketch_constraint_shape_selector") {
471     PartSet_WidgetConstraintShapeSelector* aWgt = 
472       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
473     aWgt->setSketcher(mySketchMgr->activeSketch());
474
475     theModelWidgets.append(aWgt);
476     return aWgt->getControl();
477
478   } else
479     return 0;
480 }
481
482 void PartSet_Module::createActions()
483 {
484   QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
485   addAction("DELETE_PARTSET_CMD", aAction);
486 }
487
488 QAction* PartSet_Module::action(const QString& theId) const
489 {
490   if (myActions.contains(theId))
491     return myActions[theId];
492   return 0;
493 }
494
495 void PartSet_Module::addAction(const QString& theId, QAction* theAction)
496 {
497   if (myActions.contains(theId))
498     qCritical("A command with Id = '%s' already defined!", qPrintable(theId));
499   theAction->setData(theId);
500   connect(theAction, SIGNAL(triggered(bool)), this, SLOT(onAction(bool)));
501   myActions[theId] = theAction;
502 }
503
504 void PartSet_Module::onAction(bool isChecked)
505 {
506   QAction* aAction = static_cast<QAction*>(sender());
507   QString anId = aAction->data().toString();
508
509   if (anId == "DELETE_PARTSET_CMD") {
510     deleteObjects();
511   }
512 }
513
514 void PartSet_Module::deleteObjects()
515 {
516   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
517   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
518   if (!isSketchOp && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
519     return;
520
521   // sketch feature should be skipped, only sub-features can be removed
522   // when sketch operation is active
523   CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
524
525   // selected objects should be collected before the current operation abort because
526   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
527   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
528   ModuleBase_ISelection* aSel = aConnector->selection();
529   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
530
531   XGUI_Workshop* aWorkshop = aConnector->workshop();
532   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
533   if (!isSketchOp && anOpMgr->canStopOperation()) {
534     ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation();
535     if (aCurrentOp) {
536       aCurrentOp->abort();
537     }
538   }
539   std::set<FeaturePtr> aRefFeatures;
540   foreach (ObjectPtr aObj, aSelectedObj)
541   {
542     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
543     //if (aPart) {
544       // TODO: check for what there is this condition. It is placed here historicaly because
545       // ther is this condition during remove features.
546     //} else {
547     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
548     if (aFeature.get() != NULL) {
549       aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
550     }
551     //}
552   }
553   QString aDescription = tr("Delete");
554   /**
555   // according to #355 feature, it is not necessary to inform about dependencies during
556   // sketch delete operation
557   // 
558   if (!aRefFeatures.empty()) {
559     QStringList aRefNames;
560     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
561                                          aLast = aRefFeatures.end();
562     for (; anIt != aLast; anIt++) {
563       FeaturePtr aFeature = (*anIt);
564       if (aFeature == aSketch)
565         continue;
566       aRefNames.append((*anIt)->name().c_str());
567     }
568     if (!aRefNames.empty()) {
569       QString aNames = aRefNames.join(", ");
570       aDescription += aNames.prepend(" ");
571
572       QMainWindow* aDesktop = aWorkshop->desktop();
573       QMessageBox::StandardButton aRes = QMessageBox::warning(
574           aDesktop, tr("Delete features"),
575           QString(tr("Selected features are used in the following features: %1.\
576   These features will be deleted also. Would you like to continue?")).arg(aNames),
577           QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
578       if (aRes != QMessageBox::Yes)
579         return;
580     }
581   }*/
582
583   SessionPtr aMgr = ModelAPI_Session::get();
584   aMgr->startOperation(aDescription.toStdString());
585   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
586                                        aLast = aRefFeatures.end();
587   for (; anIt != aLast; anIt++) {
588     FeaturePtr aRefFeature = (*anIt);
589     if (aRefFeature == aSketch)
590       continue;
591     aRefFeature->document()->removeFeature(aRefFeature);
592   }
593
594   foreach (ObjectPtr aObj, aSelectedObj)
595   {
596     DocumentPtr aDoc = aObj->document();
597     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
598     //if (aPart) {
599     //  if (aDoc == aMgr->activeDocument()) {
600     //    aDoc->close();
601     //  }
602     //} else {
603       //FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
604     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
605     if (aFeature.get() != NULL) {
606       aDoc->removeFeature(aFeature);
607     }
608     //}
609   }
610   aWorkshop->displayer()->updateViewer();
611   //myDisplayer->updateViewer();
612   aMgr->finishOperation();
613 }