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