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