]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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_DistanceValidator", new PartSet_DistanceValidator);
134   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
135   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
136   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
137   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
138   aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
139   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
140   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
141
142   aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
143   aFactory->registerValidator("GeomValidators_EdgeOrVertex",
144                               new GeomValidators_EdgeOrVertex);
145   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
146
147   aFactory->registerValidator("GeomValidators_ConstructionComposite",
148                               new GeomValidators_ConstructionComposite);
149
150   aFactory->registerValidator("PartSet_SketchEntityValidator",
151                               new PartSet_SketchEntityValidator);
152
153   aFactory->registerValidator("PartSet_SameTypeAttr",
154                               new PartSet_SameTypeAttrValidator);
155 }
156
157 void PartSet_Module::registerFilters()
158 {
159   //Registering of selection filters
160   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
161   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
162
163   //aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
164   //aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
165   //aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
166   //Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
167   //aFactory->registerFilter("NoConstructionSubShapesFilter",
168   //          new ModuleBase_FilterCustom(aSelectFilter));
169   //Handle(SelectMgr_Filter) aSelectFilter = new PartSet_FilterSketchEntity(workshop());
170   //aFactory->registerFilter("SketchEntityFilter", new ModuleBase_FilterCustom(aSelectFilter));
171 }
172
173 void PartSet_Module::registerProperties()
174 {
175   Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
176                                    PLANE_SIZE);
177   Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
178                                    Config_Prop::Integer, SKETCH_WIDTH);
179 }
180
181 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
182 {
183   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
184     mySketchMgr->commitNestedSketch(theOperation);
185   }
186
187   if (theOperation->isEditOperation())
188     return;
189   // the selection is cleared after commit the create operation
190   // in order to do not use the same selected objects in the restarted operation
191   // for common behaviour, the selection is cleared even if the operation is not restarted
192   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
193   if (!aContext.IsNull())
194     aContext->ClearSelected();
195
196   /// Restart sketcher operations automatically
197   FeaturePtr aFeature = theOperation->feature();
198   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
199             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
200   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
201                      myRestartingMode == RM_EmptyFeatureUsed)) {
202     myLastOperationId = theOperation->id();
203     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
204     
205     launchOperation(myLastOperationId);
206   }
207   breakOperationSequence();
208 }
209
210 void PartSet_Module::breakOperationSequence()
211 {
212   myLastOperationId = "";
213   myLastFeature = FeaturePtr();
214   myRestartingMode = RM_None;
215 }
216
217 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
218 {
219   breakOperationSequence();
220 }
221
222 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
223 {
224   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
225     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
226     aViewer->AddZLayer(myVisualLayerId);
227     mySketchMgr->startSketch(theOperation);
228   }
229   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
230     mySketchMgr->startNestedSketch(theOperation);
231   }
232
233   if (myDocumentShapeFilter.IsNull())
234     myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
235   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
236 }
237
238 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
239 {
240   if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
241     mySketchMgr->stopSketch(theOperation);
242     Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer();
243     aViewer->RemoveZLayer(myVisualLayerId);
244     myVisualLayerId = 0;
245   }
246   else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
247     mySketchMgr->stopNestedSketch(theOperation);
248   }
249   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
250 }
251
252 ModuleBase_Operation* PartSet_Module::currentOperation() const
253 {
254   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
255   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
256   return anOpMgr->currentOperation();
257 }
258
259 bool PartSet_Module::canUndo() const
260 {
261   bool aCanUndo = false;
262   SessionPtr aMgr = ModelAPI_Session::get();
263   if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
264     aCanUndo = !aMgr->isOperation();
265     if (!aCanUndo) // check the enable state additionally by sketch manager
266       aCanUndo = aMgr->canUndo();
267   }
268   return aCanUndo;
269 }
270
271 bool PartSet_Module::canRedo() const
272 {
273   bool aCanRedo = false;
274   SessionPtr aMgr = ModelAPI_Session::get();
275   if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
276     aCanRedo = !aMgr->isOperation();
277     if (!aCanRedo) // check the enable state additionally by sketch manager
278       aCanRedo = aMgr->canRedo();
279   }
280   return aCanRedo;
281 }
282
283 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
284 {
285   // the sketch manager put the restriction to the objects display
286   return mySketchMgr->canDisplayObject(theObject);
287 }
288
289
290 bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
291 {
292   return myMenuMgr->addViewerItems(theMenu, theStdActions);
293 }
294
295 bool PartSet_Module::isMouseOverWindow()
296 {
297   return mySketchMgr->isMouseOverWindow();
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 (anOperation) {
409     if (PartSet_SketcherMgr::isNestedSketchOperation(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     ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
424     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
425     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
426     bool aFoundWidget = false;
427     bool aFoundObligatory = false;
428     for (; anIt != aLast && !aFoundObligatory; anIt++) {
429       if (!aFoundWidget)
430         aFoundWidget = *anIt == anActiveWidget;
431       else
432         aFoundObligatory = (*anIt)->isObligatory();
433     }
434     if (!aFoundObligatory)
435       myRestartingMode = RM_Forbided;
436   }
437 }
438
439 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
440                                             Config_WidgetAPI* theWidgetApi, std::string theParentId)
441 {
442   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
443   XGUI_Workshop* aWorkshop = aConnector->workshop();
444   ModuleBase_ModelWidget* aWgt = NULL;
445   if (theType == "sketch-start-label") {
446     PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, 
447       theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
448     aLabelWgt->setWorkshop(aWorkshop);
449     connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
450       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
451     connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
452       mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
453     aWgt = aLabelWgt;
454   } else if (theType == "sketch-2dpoint_selector") {
455     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
456     aPointWgt->setWorkshop(aWorkshop);
457     aPointWgt->setSketch(mySketchMgr->activeSketch());
458     connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
459     aWgt = aPointWgt;
460   } if (theType == "point2ddistance") {
461     PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
462     aDistanceWgt->setWorkshop(aWorkshop);
463     aDistanceWgt->setSketch(mySketchMgr->activeSketch());
464     aWgt = aDistanceWgt;
465   } if (theType == "sketch_shape_selector") {
466     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
467       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
468     aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
469     aWgt = aShapeSelectorWgt;
470   } if (theType == "sketch_constraint_shape_selector") {
471     PartSet_WidgetConstraintShapeSelector* aConstraintShapeSelectorWgt =
472       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
473     aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
474     aWgt = aConstraintShapeSelectorWgt;
475   } if (theType == WDG_DOUBLEVALUE_EDITOR) {
476     aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
477   } 
478   return aWgt;
479 }
480
481
482 bool PartSet_Module::deleteObjects()
483 {
484   // 1. check whether the delete should be processed in the module
485   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
486   bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
487        isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
488   if (!isSketchOp && !isNestedOp)
489     return false;
490
491   // 2. find selected presentations
492   // selected objects should be collected before the current operation abort because
493   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
494   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
495   XGUI_Workshop* aWorkshop = aConnector->workshop();
496   ModuleBase_ISelection* aSel = workshop()->selection();
497   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
498   // if there are no selected objects in the viewer, that means that the selection in another
499   // place cased this method. It is necessary to return the false value to understande in above
500   // method that delete is not processed
501   if (aSelectedObj.count() == 0)
502     return false;
503
504   // the active nested sketch operation should be aborted unconditionally
505   if (isNestedOp)
506     anOperation->abort();
507
508   // 3. start operation
509   QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
510   SessionPtr aMgr = ModelAPI_Session::get();
511   aMgr->startOperation(aDescription.toStdString());
512
513   // 4. delete features
514   // sketch feature should be skipped, only sub-features can be removed
515   // when sketch operation is active
516   std::set<FeaturePtr> anIgnoredFeatures;
517   anIgnoredFeatures.insert(mySketchMgr->activeSketch());
518   aWorkshop->deleteFeatures(aSelectedObj, anIgnoredFeatures);
519   
520   // 5. stop operation
521   aWorkshop->displayer()->updateViewer();
522   aMgr->finishOperation();
523
524   return true;
525 }
526
527
528 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) 
529 {
530   Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
531   if (!anAIS.IsNull()) {
532     Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
533     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
534     if (!aDim.IsNull()) {
535       aCtx->SetZLayer(aDim, myVisualLayerId);
536     } else {
537       Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
538       if (!aCons.IsNull())
539         aCtx->SetZLayer(aCons, myVisualLayerId);
540     }
541   }
542 }
543
544 void PartSet_Module::onViewTransformed(int theTrsfType)
545 {
546   // Set length of arrows constant in pixel size
547   // if the operation is panning or rotate or panglobal then do nothing
548   if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
549     return;
550
551   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
552   Handle(V3d_View) aView = aViewer->activeView();
553
554   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
555   XGUI_Workshop* aWorkshop = aConnector->workshop();
556   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
557   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
558
559   double aLen = aView->Convert(15);
560
561   SketcherPrs_Tools::setArrowSize(aLen);
562   bool isModified = false;
563   QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
564   foreach (AISObjectPtr aAIS, aPrsList) {
565     Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
566
567     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
568     if (!aDim.IsNull()) {
569       aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
570       aContext->Redisplay(aDim, false);
571       isModified = true;
572     }
573   }
574   if (isModified)
575     aDisplayer->updateViewer();
576 }