Salome HOME
Create mirror symbols
[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_WidgetEditor.h>
12 #include "PartSet_SketcherMgr.h"
13 #include "PartSet_MenuMgr.h"
14
15 #include <ModuleBase_Operation.h>
16 #include <ModuleBase_IViewer.h>
17 #include <ModuleBase_IViewWindow.h>
18 #include <ModuleBase_IPropertyPanel.h>
19 #include <ModuleBase_WidgetEditor.h>
20 #include <ModuleBase_FilterFactory.h>
21 #include <ModuleBase_FilterLinearEdge.h>
22 #include <ModuleBase_FilterFace.h>
23 #include <ModuleBase_FilterMulti.h>
24 #include <ModuleBase_FilterCustom.h>
25 #include <ModuleBase_FilterNoConsructionSubShapes.h>
26 #include <GeomValidators_Edge.h>
27 #include <GeomValidators_EdgeOrVertex.h>
28 #include <GeomValidators_Face.h>
29 #include <GeomValidators_ConstructionComposite.h>
30
31 #include <PartSet_FilterSketchEntity.h>
32
33 #include <ModelAPI_Object.h>
34 #include <ModelAPI_Events.h>
35 #include <ModelAPI_Validator.h>
36 #include <ModelAPI_Data.h>
37 #include <ModelAPI_Session.h>
38 #include <ModelAPI_ShapeValidator.h>
39
40 #include <GeomDataAPI_Point2D.h>
41 #include <GeomDataAPI_Point.h>
42 #include <GeomDataAPI_Dir.h>
43
44 #include <XGUI_Displayer.h>
45 #include <XGUI_Workshop.h>
46 #include <XGUI_OperationMgr.h>
47 #include <XGUI_PropertyPanel.h>
48 #include <XGUI_ModuleConnector.h>
49 #include <XGUI_ContextMenuMgr.h>
50 #include <XGUI_Tools.h>
51
52 #include <SketchPlugin_Feature.h>
53 #include <SketchPlugin_Sketch.h>
54 #include <SketchPlugin_Line.h>
55 #include <SketchPlugin_Arc.h>
56 #include <SketchPlugin_Circle.h>
57 #include <SketchPlugin_Point.h>
58 #include <SketchPlugin_ConstraintLength.h>
59 #include <SketchPlugin_ConstraintDistance.h>
60 #include <SketchPlugin_ConstraintParallel.h>
61 #include <SketchPlugin_ConstraintPerpendicular.h>
62 #include <SketchPlugin_ConstraintRadius.h>
63
64 #include <SketcherPrs_SymbolPrs.h>
65 #include <SketcherPrs_Tools.h>
66
67 #include <Events_Loop.h>
68 #include <Config_PropManager.h>
69 #include <Config_Keywords.h>
70
71 #include <StdSelect_TypeOfFace.hxx>
72 #include <TopoDS_Vertex.hxx>
73 #include <TopoDS.hxx>
74 #include <TopoDS_Shape.hxx>
75 #include <BRep_Tool.hxx>
76 #include <AIS_Dimension.hxx>
77
78 #include <QObject>
79 #include <QMouseEvent>
80 #include <QString>
81 #include <QTimer>
82 #include <QApplication>
83 #include <QMessageBox>
84 #include <QMainWindow>
85
86 #include <GeomAlgoAPI_FaceBuilder.h>
87 #include <GeomDataAPI_Dir.h>
88
89 #ifdef _DEBUG
90 #include <QDebug>
91 #endif
92
93 /*!Create and return new instance of XGUI_Module*/
94 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
95 {
96   return new PartSet_Module(theWshop);
97 }
98
99 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
100   : ModuleBase_IModule(theWshop), 
101   myRestartingMode(RM_None), myVisualLayerId(0)
102 {
103   mySketchMgr = new PartSet_SketcherMgr(this);
104
105   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
106   XGUI_Workshop* aWorkshop = aConnector->workshop();
107
108   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
109   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
110   connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
111           this, SLOT(onOperationActivatedByPreselection()));
112
113   ModuleBase_IViewer* aViewer = theWshop->viewer();
114   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
115           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
116   connect(aViewer, SIGNAL(viewTransformed(int)),
117           SLOT(onViewTransformed(int)));
118
119   myMenuMgr = new PartSet_MenuMgr(this);
120 }
121
122 PartSet_Module::~PartSet_Module()
123 {
124   if (!myDocumentShapeFilter.IsNull())
125     myDocumentShapeFilter.Nullify();
126 }
127
128 void PartSet_Module::registerValidators()
129 {
130   //Registering of validators
131   SessionPtr aMgr = ModelAPI_Session::get();
132   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
133   aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
134   aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
135   aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
136   aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
137   aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
138   aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
139   aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
140   aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
141   aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
142
143   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
144   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
145
146   aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
147   aFactory->registerValidator("GeomValidators_EdgeOrVertex",
148                               new GeomValidators_EdgeOrVertex);
149   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
150
151   aFactory->registerValidator("GeomValidators_ConstructionComposite",
152                               new GeomValidators_ConstructionComposite);
153
154   aFactory->registerValidator("PartSet_SketchEntityValidator",
155                               new PartSet_SketchEntityValidator);
156
157   aFactory->registerValidator("PartSet_SameTypeAttr",
158                               new PartSet_SameTypeAttrValidator);
159 }
160
161 void PartSet_Module::registerFilters()
162 {
163   //Registering of selection filters
164   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
165   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
166
167   //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
168   //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
169   //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
170   //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
171   //aFactory->registerFilter("NoConstructionSubShapesFilter",
172   //          new ModuleBase_FilterCustom(aSelectFilter));
173   //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
174   //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
175 }
176
177 void PartSet_Module::registerProperties()
178 {
179   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
180                                    PLANE_SIZE);
181   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
182                                    Config_Prop::Integer, SKETCH_WIDTH);
183 }
184
185 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
186 {
187   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
188     mySketchMgr->commitNestedSketch(theOperation);
189   }
190
191   if (theOperation->isEditOperation())
192     return;
193   // the selection is cleared after commit the create operation
194   // in order to do not use the same selected objects in the restarted operation
195   // for common behaviour, the selection is cleared even if the operation is not restarted
196   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
197   if (!aContext.IsNull())
198     aContext->ClearSelected();
199
200   /// Restart sketcher operations automatically
201   FeaturePtr aFeature = theOperation->feature();
202   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
203             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
204   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
205                      myRestartingMode == RM_EmptyFeatureUsed)) {
206     myLastOperationId = theOperation->id();
207     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
208     
209     launchOperation(myLastOperationId);
210   }
211   breakOperationSequence();
212 }
213
214 void PartSet_Module::breakOperationSequence()
215 {
216   myLastOperationId = "";
217   myLastFeature = FeaturePtr();
218   myRestartingMode = RM_None;
219 }
220
221 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
222 {
223   breakOperationSequence();
224 }
225
226 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
227 {
228   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
229     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
230     aViewer->AddZLayer(myVisualLayerId);
231     mySketchMgr->startSketch(theOperation);
232   }
233   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
234     mySketchMgr->startNestedSketch(theOperation);
235   }
236
237   if (myDocumentShapeFilter.IsNull())
238     myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
239   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
240 }
241
242 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
243 {
244   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
245     mySketchMgr->stopSketch(theOperation);
246     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
247     aViewer->RemoveZLayer(myVisualLayerId);
248     myVisualLayerId = 0;
249   }
250   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
251     mySketchMgr->stopNestedSketch(theOperation);
252   }
253   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
254 }
255
256 ModuleBase_Operation* PartSet_Module::currentOperation() const
257 {
258   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
259   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
260   return anOpMgr->currentOperation();
261 }
262
263 bool PartSet_Module::canUndo() const
264 {
265   bool aCanUndo = false;
266   SessionPtr aMgr = ModelAPI_Session::get();
267   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
268     aCanUndo = !aMgr->isOperation();
269     if (!aCanUndo) // check the enable state additionally by sketch manager
270       aCanUndo = aMgr->canUndo();
271   }
272   return aCanUndo;
273 }
274
275 bool PartSet_Module::canRedo() const
276 {
277   bool aCanRedo = false;
278   SessionPtr aMgr = ModelAPI_Session::get();
279   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
280     aCanRedo = !aMgr->isOperation();
281     if (!aCanRedo) // check the enable state additionally by sketch manager
282       aCanRedo = aMgr->canRedo();
283   }
284   return aCanRedo;
285 }
286
287 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
288 {
289   // the sketch manager put the restriction to the objects display
290   return mySketchMgr->canDisplayObject(theObject);
291 }
292
293
294 bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
295 {
296   return myMenuMgr->addViewerItems(theMenu, theStdActions);
297 }
298
299 bool PartSet_Module::isMouseOverWindow()
300 {
301   return mySketchMgr->isMouseOverWindow();
302 }
303
304 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
305 {
306   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
307   if (PartSet_SketcherMgr::isSketchOperation(theOperation) &&  (theOperation->isEditOperation())) {
308     // we have to manually activate the sketch label in edit mode
309       aPanel->activateWidget(aPanel->modelWidgets().first());
310       return;
311   }
312
313   // Restart last operation type 
314   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
315     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
316     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
317       // Initialise new line with first point equal to end of previous
318       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
319       if (aPnt2dWgt) {
320         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
321         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
322           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
323         if (aPoint) {
324           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
325           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
326             aWgt->attributeID(), aPoint->x(), aPoint->y());
327           aPanel->activateNextWidget(aPnt2dWgt);
328         }
329       }
330     }
331   } else {
332     // Start editing constraint
333     if (theOperation->isEditOperation()) {
334       // TODO: #391 - to be removed
335       std::string aId = theOperation->id().toStdString();
336       if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation) &&
337           PartSet_SketcherMgr::isDistanceOperation(theOperation)) {
338         // Find and activate widget for management of point for dimension line position
339         QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
340         foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
341           PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
342           if (aPntWgt) {
343             aPanel->activateWidget(aPntWgt);
344             return;
345           }
346         }
347       }
348     }
349   }
350 }
351
352
353 void PartSet_Module::onSelectionChanged()
354 {
355   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
356   if (!aOperation)
357     return;
358
359   bool isSketcherOp = false;
360   // An edit operation is enable only if the current opeation is the sketch operation
361   if (mySketchMgr->activeSketch()) {
362     if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
363       isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
364   }
365   if (isSketcherOp) {
366     // Editing of constraints can be done on selection
367     ModuleBase_ISelection* aSelect = myWorkshop->selection();
368     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
369     if (aSelected.size() == 1) {
370       ModuleBase_ViewerPrs aPrs = aSelected.first();
371       ObjectPtr aObject = aPrs.object();
372       FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
373       if (aFeature) {
374         std::string aId = aFeature->getKind();
375         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
376             (aId == SketchPlugin_ConstraintLength::ID()) || 
377             (aId == SketchPlugin_ConstraintDistance::ID())) {
378           editFeature(aFeature);
379         }
380       }
381     }
382   } 
383 }
384
385 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
386 {
387   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
388   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
389   anOpMgr->onKeyReleased(theEvent);
390 }
391
392 void PartSet_Module::onEnterReleased()
393 {
394   myRestartingMode = RM_EmptyFeatureUsed;
395 }
396
397 void PartSet_Module::onOperationActivatedByPreselection()
398 {
399   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
400   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
401     // Set final definitions if they are necessary
402     //propertyPanelDefined(aOperation);
403
404     /// Commit sketcher operations automatically
405     anOperation->commit();
406   }
407 }
408
409 void PartSet_Module::onNoMoreWidgets()
410 {
411   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
412   if (anOperation) {
413     if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
414       if (myRestartingMode != RM_Forbided)
415         myRestartingMode = RM_LastFeatureUsed;
416       anOperation->commit();
417     }
418   }
419 }
420
421 void PartSet_Module::onVertexSelected()
422 {
423   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
424   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
425     /// If last line finished on vertex the lines creation sequence has to be break
426     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
427     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
428     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
429     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
430     bool aFoundWidget = false;
431     bool aFoundObligatory = false;
432     for (; anIt != aLast && !aFoundObligatory; anIt++) {
433       if (!aFoundWidget)
434         aFoundWidget = *anIt == anActiveWidget;
435       else
436         aFoundObligatory = (*anIt)->isObligatory();
437     }
438     if (!aFoundObligatory)
439       myRestartingMode = RM_Forbided;
440   }
441 }
442
443 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
444                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
445 {
446   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
447   XGUI_Workshop* aWorkshop = aConnector->workshop();
448   ModuleBase_ModelWidget* aWgt = NULL;
449   if (theType == "sketch-start-label") {
450     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, 
451       theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
452     aLabelWgt->setWorkshop(aWorkshop);
453     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
454       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
455     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
456       mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
457     aWgt = aLabelWgt;
458   } else if (theType == "sketch-2dpoint_selector") {
459     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
460     aPointWgt->setWorkshop(aWorkshop);
461     aPointWgt->setSketch(mySketchMgr->activeSketch());
462     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
463     aWgt = aPointWgt;
464   } if (theType == "point2ddistance") {
465     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
466     aDistanceWgt->setWorkshop(aWorkshop);
467     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
468     aWgt = aDistanceWgt;
469   } if (theType == "sketch_shape_selector") {
470     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
471       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
472     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
473     aWgt = aShapeSelectorWgt;
474   } if (theType == "sketch_constraint_shape_selector") {
475     PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
476       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
477     aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
478     aWgt = aConstraintShapeSelectorWgt;
479   } if (theType == WDG_DOUBLEVALUE_EDITOR) {
480     aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
481   } 
482   return aWgt;
483 }
484
485
486 bool PartSet_Module::deleteObjects()
487 {
488   // 1. check whether the delete should be processed in the module
489   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
490   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
491        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
492   if (!isSketchOp && !isNestedOp)
493     return false;
494
495   // 2. find selected presentations
496   // selected objects should be collected before the current operation abort because
497   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
498   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
499   XGUI_Workshop* aWorkshop = aConnector->workshop();
500   ModuleBase_ISelection* aSel = workshop()->selection();
501   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
502   // if there are no selected objects in the viewer, that means that the selection in another
503   // place cased this method. It is necessary to return the false value to understande in above
504   // method that delete is not processed
505   if (aSelectedObj.count() == 0)
506     return false;
507
508   // the active nested sketch operation should be aborted unconditionally
509   if (isNestedOp)
510     anOperation->abort();
511
512   // 3. start operation
513   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
514   SessionPtr aMgr = ModelAPI_Session::get();
515   aMgr->startOperation(aDescription.toStdString());
516
517   // 4. delete features
518   // sketch feature should be skipped, only sub-features can be removed
519   // when sketch operation is active
520   std::set<FeaturePtr> anIgnoredFeatures;
521   anIgnoredFeatures.insert(mySketchMgr->activeSketch());
522   aWorkshop->deleteFeatures(aSelectedObj, anIgnoredFeatures);
523   
524   // 5. stop operation
525   aWorkshop->displayer()->updateViewer();
526   aMgr->finishOperation();
527
528   return true;
529 }
530
531
532 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
533 {
534   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
535   if (!anAIS.IsNull()) {
536     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
537     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
538     if (!aDim.IsNull()) {
539       aCtx->SetZLayer(aDim, myVisualLayerId);
540     } else {
541       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
542       if (!aCons.IsNull())
543         aCtx->SetZLayer(aCons, myVisualLayerId);
544     }
545   }
546 }
547
548 void PartSet_Module::onViewTransformed(int theTrsfType)
549 {
550   // Set length of arrows constant in pixel size
551   // if the operation is panning or rotate or panglobal then do nothing
552   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
553     return;
554
555   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
556   Handle(V3d_View) aView = aViewer->activeView();
557
558   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
559   XGUI_Workshop* aWorkshop = aConnector->workshop();
560   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
561   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
562
563   double aLen = aView->Convert(15);
564
565   SketcherPrs_Tools::setArrowSize(aLen);
566   bool isModified = false;
567   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
568   foreach (AISObjectPtr aAIS, aPrsList) {
569     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
570
571     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
572     if (!aDim.IsNull()) {
573       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
574       aContext->Redisplay(aDim, false);
575       isModified = true;
576     }
577   }
578   if (isModified)
579     aDisplayer->updateViewer();
580 }