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