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