Salome HOME
It corrects the validator parameter from the entrity to viewerprs in order to validat...
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_SketcherMgr.cpp
4 // Created:     19 Dec 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_WidgetPoint2d.h"
10 #include "PartSet_WidgetPoint2dDistance.h"
11 #include "PartSet_Tools.h"
12 #include "PartSet_WidgetSketchLabel.h"
13
14 #include <ModuleBase_WidgetEditor.h>
15
16 #include <XGUI_ModuleConnector.h>
17 #include <XGUI_Displayer.h>
18 #include <XGUI_Workshop.h>
19 #include <XGUI_ContextMenuMgr.h>
20 #include <XGUI_Selection.h>
21 #include <XGUI_SelectionMgr.h>
22 #include <ModuleBase_ModelWidget.h>
23 #include <XGUI_ModuleConnector.h>
24 #include <XGUI_PropertyPanel.h>
25 #include <XGUI_ViewerProxy.h>
26
27 #include <AppElements_MainWindow.h>
28
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IWorkshop.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_Operation.h>
33 #include <ModuleBase_ISelection.h>
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_Operation.h>
36
37 #include <GeomDataAPI_Point2D.h>
38
39 #include <Events_Loop.h>
40
41 #include <SketchPlugin_Line.h>
42 #include <SketchPlugin_Sketch.h>
43 #include <SketchPlugin_Point.h>
44 #include <SketchPlugin_Arc.h>
45 #include <SketchPlugin_Circle.h>
46 #include <SketchPlugin_ConstraintLength.h>
47 #include <SketchPlugin_ConstraintDistance.h>
48 #include <SketchPlugin_ConstraintParallel.h>
49 #include <SketchPlugin_ConstraintPerpendicular.h>
50 #include <SketchPlugin_ConstraintRadius.h>
51 #include <SketchPlugin_ConstraintRigid.h>
52 #include <SketchPlugin_ConstraintHorizontal.h>
53 #include <SketchPlugin_ConstraintVertical.h>
54 #include <SketchPlugin_ConstraintEqual.h>
55 #include <SketchPlugin_ConstraintTangent.h>
56 #include <SketchPlugin_ConstraintCoincidence.h>
57 #include <SketchPlugin_ConstraintFillet.h>
58 #include <SketchPlugin_ConstraintMirror.h>
59
60 #include <SketcherPrs_Tools.h>
61
62 #include <SelectMgr_IndexedMapOfOwner.hxx>
63 #include <StdSelect_BRepOwner.hxx>
64
65 //#include <AIS_DimensionSelectionMode.hxx>
66 #include <AIS_Shape.hxx>
67
68 #include <ModelAPI_Events.h>
69 #include <ModelAPI_Session.h>
70
71 #include <QMouseEvent>
72 #include <QApplication>
73
74 //#define DEBUG_DO_NOT_BY_ENTER
75
76 /// Returns list of unique objects by sum of objects from List1 and List2
77 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
78                                        const QList<ModuleBase_ViewerPrs>& theList2)
79 {
80   QList<ModuleBase_ViewerPrs> aRes;
81   foreach (ModuleBase_ViewerPrs aPrs, theList1) {
82     if (!aRes.contains(aPrs))
83       aRes.append(aPrs);
84   }
85   foreach (ModuleBase_ViewerPrs aPrs, theList2) {
86     if (!aRes.contains(aPrs))
87       aRes.append(aPrs);
88   }
89   return aRes;
90 }*/
91
92 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
93                            QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
94                            const FeaturePtr theSketch)
95 {
96   QList<ModuleBase_ViewerPrs> aRes;
97
98   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
99                                               aLast = theList.end();
100   for (; anIt != aLast; anIt++)
101   {
102     ModuleBase_ViewerPrs aPrs = *anIt;
103     FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
104     if (aFeature.get() == NULL)
105       continue;
106
107     QList<AttributePtr> anAttributes;
108     if (theFeature2AttributeMap.contains(aFeature)) {
109       anAttributes = theFeature2AttributeMap[aFeature];
110     }
111     AttributePtr anAttr;
112     TopoDS_Shape aShape = aPrs.shape();
113     if (!aShape.IsNull()) {
114       if (aShape.ShapeType() == TopAbs_VERTEX) {
115         anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
116         if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
117           anAttributes.push_back(anAttr);
118       }
119     }
120     theFeature2AttributeMap[aFeature] = anAttributes;
121   }
122 }
123
124
125
126
127 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
128   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
129     myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false),
130     myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
131     myIsPopupMenuActive(false), myIsConstraintsShown(true)
132 {
133   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
134   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
135
136   myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
137
138   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
139           this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
140
141   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
142           this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
143
144   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
145           this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
146
147   connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
148           this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
149
150   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
151   XGUI_Workshop* aWorkshop = aConnector->workshop();
152   connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
153 }
154
155 PartSet_SketcherMgr::~PartSet_SketcherMgr()
156 {
157   if (!myPlaneFilter.IsNull())
158     myPlaneFilter.Nullify();
159 }
160
161 void PartSet_SketcherMgr::onEnterViewPort()
162 {
163   // 1. if the mouse over window, update the next flag. Do not perform update visibility of
164   // created feature because it should be done in onMouseMove(). Some widgets watch
165   // the mouse move and use the cursor position to update own values. If the presentaion is
166   // redisplayed before this update, the feature presentation jumps from reset value to current.
167   myIsMouseOverWindow = true;
168   myIsPropertyPanelValueChanged = false;
169
170   #ifdef DEBUG_DO_NOT_BY_ENTER
171   return;
172   #endif
173   //if (!isNestedCreateOperation(getCurrentOperation()))
174   //  return;
175 }
176
177 void PartSet_SketcherMgr::onLeaveViewPort()
178 {
179   myIsMouseOverViewProcessed = false;
180   myIsMouseOverWindow = false;
181   myIsPropertyPanelValueChanged = false;
182
183   #ifdef DEBUG_DO_NOT_BY_ENTER
184   return;
185   #endif
186
187   if (!isNestedCreateOperation(getCurrentOperation()))
188     return;
189   // the method should be performed if the popup menu is called,
190   // the reset of the current widget should not happen
191   if (myIsPopupMenuActive)
192     return;
193
194   // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
195   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
196   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
197   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
198   // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
199   // obtained after reset value
200   bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
201   ModuleBase_Operation* aOperation = getCurrentOperation();
202   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
203   ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
204   if (aActiveWgt) {
205     aActiveWgt->reset();
206   }
207   aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
208
209   // hides the presentation of the current operation feature
210   //myIsPropertyPanelValueChanged = false;
211   // the feature is to be erased here, but it is correct to call canDisplayObject because
212   // there can be additional check (e.g. editor widget in distance constraint)
213   FeaturePtr aFeature = getCurrentOperation()->feature();
214   visualizeFeature(aOperation, canDisplayObject(aFeature));
215 }
216
217 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
218 {
219   if (isNestedCreateOperation(getCurrentOperation()))
220     return;
221   // it is necessary to save current selection in order to restore it after the values are modifed
222   storeSelection();
223
224   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
225   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
226   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
227   myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
228 }
229
230 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
231 {
232   if (isNestedCreateOperation(getCurrentOperation()))
233     return;
234   // it is necessary to restore current selection in order to restore it after the values are modified
235   restoreSelection();
236   myCurrentSelection.clear();
237
238   // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
239   // viewer happens by deselect/select the modified objects. The flag should be restored after
240   // the selection processing. The update viewer should be also called.
241   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
242   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
243   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
244   aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
245   aDisplayer->updateViewer();
246 }
247
248 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
249 {
250   if (!isNestedCreateOperation(getCurrentOperation()))
251     return;
252
253   // visualize the current operation feature
254   myIsPropertyPanelValueChanged = true;
255   ModuleBase_Operation* aOperation = getCurrentOperation();
256   // the feature is to be erased here, but it is correct to call canDisplayObject because
257   // there can be additional check (e.g. editor widget in distance constraint)
258   FeaturePtr aFeature = getCurrentOperation()->feature();
259   visualizeFeature(aOperation, canDisplayObject(aFeature));
260 }
261
262 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
263 {
264   get2dPoint(theWnd, theEvent, myClickedPoint);
265
266   if (!(theEvent->buttons() & Qt::LeftButton))
267     return;
268
269   // Clear dragging mode
270   myIsDragging = false;
271
272   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
273   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
274   if (!aViewer->canDragByMouse())
275     return;
276
277   ModuleBase_Operation* aOperation = getCurrentOperation();
278   if (aOperation && aOperation->isEditOperation()) {
279     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
280     ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
281     // If the current widget is a selector, do do nothing, it processes the mouse press
282     if(aActiveWgt && aActiveWgt->isViewerSelector()) {
283       return;
284     }
285   }
286
287   // Use only for sketch operations
288   if (aOperation && myCurrentSketch) {
289     if (!PartSet_Tools::sketchPlane(myCurrentSketch))
290       return;
291
292     bool isSketcher = isSketchOperation(aOperation);
293     bool isSketchOpe = isNestedSketchOperation(aOperation);
294
295     // Avoid non-sketch operations
296     if ((!isSketchOpe) && (!isSketcher))
297       return;
298
299     bool isEditing = aOperation->isEditOperation();
300
301     // Ignore creation sketch operation
302     if ((!isSketcher) && (!isEditing))
303       return;
304
305     // MoveTo in order to highlight current object
306     aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
307
308     // Remember highlighted objects for editing
309     ModuleBase_ISelection* aSelect = aWorkshop->selection();
310
311     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
312     storeSelection(!aHasShift);
313
314     if (myCurrentSelection.empty()) {
315       if (isSketchOpe && (!isSketcher))
316         // commit previous operation
317         if (!aOperation->commit())
318           aOperation->abort();
319       return;
320     }
321
322     if (isSketcher) {
323       myIsDragging = true;
324       get2dPoint(theWnd, theEvent, myCurrentPoint);
325       myDragDone = false;
326       launchEditing();
327
328     } else if (isSketchOpe && isEditing) {
329       // If selected another object commit current result
330       aOperation->commit();
331
332       myIsDragging = true;
333       get2dPoint(theWnd, theEvent, myCurrentPoint);
334       myDragDone = false;
335
336       // This is necessary in order to finalize previous operation
337       QApplication::processEvents();
338       launchEditing();
339     }
340   }
341 }
342
343 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
344 {
345   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
346   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
347   if (!aViewer->canDragByMouse())
348     return;
349   ModuleBase_Operation* aOp = getCurrentOperation();
350   if (aOp) {
351     if (isNestedSketchOperation(aOp)) {
352       get2dPoint(theWnd, theEvent, myClickedPoint);
353
354       // Only for sketcher operations
355       if (myIsDragging) {
356         if (myDragDone) {
357           //aOp->commit();
358           myCurrentSelection.clear();
359           // Reselect edited object
360           /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
361           if (theEvent->modifiers() & Qt::ShiftModifier)
362             aViewer->AISContext()->ShiftSelect();
363           else
364             aViewer->AISContext()->Select();
365             */
366         }
367       }
368     }
369   }
370   aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
371   myIsDragging = false;
372 }
373
374 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
375 {
376   if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
377     myIsMouseOverViewProcessed = true;
378     // 1. perform the widget mouse move functionality and display the presentation
379     ModuleBase_Operation* aOperation = getCurrentOperation();
380     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
381     ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
382     // the mouse move should be processed in the widget, if it can in order to visualize correct
383     // presentation. These widgets correct the feature attribute according to the mouse position
384     PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
385     if (aPoint2DWdg) {
386       aPoint2DWdg->onMouseMove(theWnd, theEvent);
387     }
388     PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
389                                                                 (anActiveWdg);
390     if (aDistanceWdg) {
391       aDistanceWdg->onMouseMove(theWnd, theEvent);
392     }
393     // the feature is to be erased here, but it is correct to call canDisplayObject because
394     // there can be additional check (e.g. editor widget in distance constraint)
395     FeaturePtr aFeature = getCurrentOperation()->feature();
396     visualizeFeature(aOperation, canDisplayObject(aFeature));
397   }
398
399   myClickedPoint.clear();
400
401   if (myIsDragging) {
402     // 1. the current selection is saved in the mouse press method in order to restore it after moving
403     // 2. the enable selection in the viewer should be temporary switched off in order to ignore
404     // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
405     // deselected). This flag should be restored in the slot, processed the mouse release signal.
406     ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
407     aViewer->enableSelection(false);
408
409     ModuleBase_Operation* aOperation = getCurrentOperation();
410     if (!aOperation)
411       return;
412     if (isSketchOperation(aOperation))
413       return; // No edit operation activated
414
415     Handle(V3d_View) aView = theWnd->v3dView();
416     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
417     double aX, aY;
418     PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
419     double dX =  aX - myCurrentPoint.myCurX;
420     double dY =  aY - myCurrentPoint.myCurY;
421
422     ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
423     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
424     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
425     // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
426     // viewer happens by deselect/select the modified objects. The flag should be restored after
427     // the selection processing. The update viewer should be also called.
428     bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
429
430     static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
431     //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
432     FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
433                                           aLast = myCurrentSelection.end();
434     // 4. the features and attributes modification(move)
435     for (; anIt != aLast; anIt++) {
436       FeaturePtr aFeature = anIt.key();
437
438       std::set<AttributePtr> anAttributes = anIt.value().first;
439       // Process selection by attribute: the priority to the attribute
440       if (!anAttributes.empty()) {
441         std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
442                                                anAttLast = anAttributes.end();
443         for (; anAttIt != anAttLast; anAttIt++) {
444           AttributePtr anAttr = *anAttIt;
445           if (anAttr.get() == NULL)
446             continue;
447           std::string aAttrId = anAttr->id();
448           DataPtr aData = aFeature->data();
449           if (aData.get() != NULL) {
450             std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
451               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
452             if (aPoint.get() != NULL) {
453               bool isImmutable = aPoint->setImmutable(true);
454               aPoint->move(dX, dY);
455               ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
456               aPoint->setImmutable(isImmutable);
457             }
458           }
459         }
460       } else {
461         // Process selection by feature
462         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
463           std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
464         if (aSketchFeature) {
465           aSketchFeature->move(dX, dY);
466           ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
467         }
468       }
469     }
470     Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
471     //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
472
473     // 5. it is necessary to save current selection in order to restore it after the features moving
474     restoreSelection();
475     // 6. restore the update viewer flag and call this update
476     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
477     aDisplayer->updateViewer();
478
479     myDragDone = true;
480     myCurrentPoint.setValue(aX, aY);
481   }
482 }
483
484 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
485 {
486   ModuleBase_Operation* aOperation = getCurrentOperation();
487   if (aOperation && aOperation->isEditOperation()) {
488     std::string aId = aOperation->id().toStdString();
489     if (isDistanceOperation(aOperation))
490     {
491       // Activate dimension value editing on double click
492       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
493       QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
494       // Find corresponded widget to activate value editing
495       foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
496         if (aWgt->attributeID() == "ConstraintValue") {
497           aWgt->focusTo();
498           return;
499         }
500       }
501     }
502   }
503 }
504
505 void PartSet_SketcherMgr::onApplicationStarted()
506 {
507   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
508   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
509   XGUI_Workshop* aWorkshop = aConnector->workshop();
510   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
511   if (aPropertyPanel) {
512     connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
513             this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
514   }
515
516   XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
517   connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
518   connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
519
520   XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
521   connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
522   connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
523 }
524
525 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
526 {
527   if (!myClickedPoint.myIsInitialized)
528     return;
529
530   ModuleBase_Operation* aOperation = getCurrentOperation();
531   // the distance constraint feature should not use the clickedd point
532   // this is workaround in order to don't throw down the flyout point value,
533   // set by execute() method of these type of features
534   if (isDistanceOperation(aOperation))
535     return;
536
537   PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
538   if (aPnt2dWgt) {
539     aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
540   }
541 }
542
543 void PartSet_SketcherMgr::onBeforeContextMenu()
544 {
545   myIsPopupMenuActive = true;
546 }
547
548 void PartSet_SketcherMgr::onAfterContextMenu()
549 {
550   myIsPopupMenuActive = false;
551 }
552
553 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
554                                      Point& thePoint)
555 {
556   Handle(V3d_View) aView = theWnd->v3dView();
557   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
558   double aX, anY;
559   PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
560   thePoint.setValue(aX, anY);
561 }
562
563 void PartSet_SketcherMgr::launchEditing()
564 {
565   // there should be activate the sketch selection mode because the edit can happens
566   // by any sketch entity or consttant selected
567   activateObjectsInSketchMode(true);
568
569   if (!myCurrentSelection.empty()) {
570     FeaturePtr aFeature = myCurrentSelection.begin().key();
571     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
572               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
573     if (aSPFeature) {
574       myModule->editFeature(aSPFeature);
575     }
576   }
577  
578 }
579
580
581 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
582 {
583   static QStringList aIds;
584   if (aIds.size() == 0) {
585     aIds << SketchPlugin_Line::ID().c_str();
586     aIds << SketchPlugin_Point::ID().c_str();
587     aIds << SketchPlugin_Arc::ID().c_str();
588     aIds << SketchPlugin_Circle::ID().c_str();
589     aIds << SketchPlugin_ConstraintLength::ID().c_str();
590     aIds << SketchPlugin_ConstraintDistance::ID().c_str();
591     aIds << SketchPlugin_ConstraintRigid::ID().c_str();
592     aIds << SketchPlugin_ConstraintRadius::ID().c_str();
593     aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
594     aIds << SketchPlugin_ConstraintParallel::ID().c_str();
595     aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
596     aIds << SketchPlugin_ConstraintVertical::ID().c_str();
597     aIds << SketchPlugin_ConstraintEqual::ID().c_str();
598     aIds << SketchPlugin_ConstraintTangent::ID().c_str();
599     aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
600     aIds << SketchPlugin_ConstraintFillet::ID().c_str();
601     aIds << SketchPlugin_ConstraintMirror::ID().c_str();
602   }
603   return aIds;
604 }
605
606 const QStringList& PartSet_SketcherMgr::constraintsIdList()
607 {
608   static QStringList aIds;
609   if (aIds.size() == 0) {
610     aIds << SketchPlugin_ConstraintLength::ID().c_str();
611     aIds << SketchPlugin_ConstraintDistance::ID().c_str();
612     aIds << SketchPlugin_ConstraintRigid::ID().c_str();
613     aIds << SketchPlugin_ConstraintRadius::ID().c_str();
614     aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
615     aIds << SketchPlugin_ConstraintParallel::ID().c_str();
616     aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
617     aIds << SketchPlugin_ConstraintVertical::ID().c_str();
618     aIds << SketchPlugin_ConstraintEqual::ID().c_str();
619     aIds << SketchPlugin_ConstraintTangent::ID().c_str();
620     aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
621     aIds << SketchPlugin_ConstraintMirror::ID().c_str();
622   }
623   return aIds;
624 }
625
626
627 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
628 {
629   return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
630 }
631
632 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
633 {
634   return theOperation &&
635          PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
636 }
637
638 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
639 {
640   return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
641 }
642
643 bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation)
644 {
645   std::string aId = theOperation ? theOperation->id().toStdString() : "";
646
647   return (aId == SketchPlugin_Line::ID()) ||
648          (aId == SketchPlugin_Point::ID()) ||
649          (aId == SketchPlugin_Arc::ID()) ||
650          (aId == SketchPlugin_Circle::ID());
651 }
652
653 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
654 {
655   std::string aId = theOperation ? theOperation->id().toStdString() : "";
656
657   return (aId == SketchPlugin_ConstraintLength::ID()) ||
658          (aId == SketchPlugin_ConstraintDistance::ID()) ||
659          (aId == SketchPlugin_ConstraintRadius::ID());
660 }
661
662 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
663 {
664   // Display all sketcher sub-Objects
665   myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
666   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
667   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
668
669   // Hide sketcher result
670   std::list<ResultPtr> aResults = myCurrentSketch->results();
671   std::list<ResultPtr>::const_iterator aIt;
672   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
673     aDisplayer->erase((*aIt), false);
674   }
675   aDisplayer->erase(myCurrentSketch, false);
676
677   // Display sketcher objects
678   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
679     FeaturePtr aFeature = myCurrentSketch->subFeature(i);
680     std::list<ResultPtr> aResults = aFeature->results();
681     std::list<ResultPtr>::const_iterator aIt;
682     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
683       aDisplayer->display((*aIt), false);
684     }
685     aDisplayer->display(aFeature, false);
686   }
687
688   if (myPlaneFilter.IsNull()) 
689     myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
690
691   myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
692   if (theOperation->isEditOperation()) {
693     // If it is editing of sketch then it means that plane is already defined
694     std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
695     myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
696   }
697   aDisplayer->updateViewer();
698 }
699
700 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
701 {
702   myIsMouseOverWindow = false;
703   myIsConstraintsShown = true;
704   // the objects activated in the sketch should be deactivated in order to do not have the specific
705   // sketch selection mode activated on objects in neutral point of the application(no started operation)
706   activateObjectsInSketchMode(false);
707
708   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
709   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
710
711   DataPtr aData = myCurrentSketch->data();
712   if ((!aData) || (!aData->isValid())) {
713     // The sketch was aborted
714     myCurrentSketch = CompositeFeaturePtr();
715     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
716
717     // Erase all sketcher objects
718     QStringList aSketchIds = sketchOperationIdList();
719     QObjectPtrList aObjects = aDisplayer->displayedObjects();
720     foreach (ObjectPtr aObj, aObjects) {
721       DataPtr aObjData = aObj->data();
722       if ((!aObjData) || (!aObjData->isValid()))
723         aDisplayer->erase(aObj);
724     }
725     return; 
726   }
727   // Hide all sketcher sub-Objects
728   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
729     FeaturePtr aFeature = myCurrentSketch->subFeature(i);
730     std::list<ResultPtr> aResults = aFeature->results();
731     std::list<ResultPtr>::const_iterator aIt;
732     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
733       aDisplayer->erase((*aIt), false);
734     }
735     aDisplayer->erase(aFeature, false);
736   }
737   // Display sketcher result
738   std::list<ResultPtr> aResults = myCurrentSketch->results();
739   std::list<ResultPtr>::const_iterator aIt;
740   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
741     aDisplayer->display((*aIt), false);
742   }
743   aDisplayer->display(myCurrentSketch);
744     
745   myCurrentSketch = CompositeFeaturePtr();
746   myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
747   aDisplayer->updateViewer();
748 }
749
750 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
751 {
752   if (constraintsIdList().contains(theOperation->id())) {
753     // Show constraints if a constraint was created
754     onShowConstraintsToggle(true);
755   }
756   connectToPropertyPanel(true);
757 }
758
759 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
760 {
761   connectToPropertyPanel(false);
762   myIsPropertyPanelValueChanged = false;
763   myIsMouseOverViewProcessed = true;
764
765   // the sketch objects selection should be activated in order to select any sketch
766   // object
767   activateObjectsInSketchMode(true);
768 }
769
770 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
771 {
772   if (isNestedCreateOperation(theOperation))
773     visualizeFeature(theOperation, true);
774
775 }
776
777 bool PartSet_SketcherMgr::canUndo() const
778 {
779   return isNestedCreateOperation(getCurrentOperation());
780 }
781
782 bool PartSet_SketcherMgr::canRedo() const
783 {
784   return isNestedCreateOperation(getCurrentOperation());
785 }
786
787 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
788 {
789   bool aCanDisplay = true;
790
791   bool aHasActiveSketch = activeSketch().get() != NULL;
792   if (aHasActiveSketch) {
793     // 1. the sketch feature should not be displayed during the sketch active operation
794     // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch 
795     // nested features can be visualized
796     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
797     if (aFeature.get() != NULL && aFeature == activeSketch())
798       aCanDisplay = false;
799   }
800   else { // there are no an active sketch
801     // 2. sketch sub-features should not visualized if the sketch operation is not active
802     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
803     if (aFeature.get() != NULL) {
804       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
805                               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
806       if (aSketchFeature.get())
807         aCanDisplay = false;
808     }
809   }
810
811   // 3. For created nested feature operation do not display the created feature if
812   // the mouse curstor leaves the OCC window.
813   // The correction cases, which ignores this condition:
814   // a. the property panel values modification
815   // b. the popup menu activated
816   // c. widget editor control
817   #ifndef DEBUG_DO_NOT_BY_ENTER
818   if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
819     ModuleBase_Operation* aOperation = getCurrentOperation();
820     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
821     ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
822     ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
823     // the active widget editor should not influence here. The presentation should be visible always
824     // when this widget is active.
825     if (!anEditorWdg && !myIsPopupMenuActive) {
826       // during a nested create operation, the feature is redisplayed only if the mouse over view
827       // of there was a value modified in the property panel after the mouse left the view
828       aCanDisplay = myIsPropertyPanelValueChanged || myIsMouseOverWindow;
829     }
830   }
831   #endif
832   return aCanDisplay;
833 }
834
835
836 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
837 {
838   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
839
840   // after the plane is selected in the sketch, the sketch selection should be activated
841   // it can not be performed in the sketch label widget because, we don't need to switch off
842   // the selection by any label deactivation, but need to switch it off by stop the sketch
843   activateObjectsInSketchMode(true);
844 }
845
846 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
847                                               const FeaturePtr& theSketch,
848                                               ModuleBase_IWorkshop* theWorkshop,
849                                               FeatureToSelectionMap& theSelection)
850 {
851   if (theFeature.get() == NULL)
852     return;
853
854   std::set<AttributePtr> aSelectedAttributes;
855   std::set<ResultPtr> aSelectedResults;
856
857   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
858   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
859   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
860   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
861
862   std::list<ResultPtr> aResults = theFeature->results();
863   std::list<ResultPtr>::const_iterator aIt;
864   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
865   {
866     ResultPtr aResult = *aIt;
867     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
868     if (aAISObj.get() == NULL)
869       continue;
870     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
871     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
872     {
873       Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
874                                                                       aContext->SelectedOwner());
875       if (aBRepOwner.IsNull())
876         continue;
877       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
878                                                                         aBRepOwner->Selectable());
879       if (anIO != anAISIO)
880         continue;
881
882       if (aBRepOwner->HasShape()) {
883         const TopoDS_Shape& aShape = aBRepOwner->Shape();
884         TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
885         if (aShapeType == TopAbs_VERTEX) {
886           AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
887                                                                         aShape, theSketch);
888           if (aPntAttr.get() != NULL)
889             aSelectedAttributes.insert(aPntAttr);
890         }
891         else if (aShapeType == TopAbs_EDGE &&
892                  aSelectedResults.find(aResult) == aSelectedResults.end()) {
893           aSelectedResults.insert(aResult);
894         }
895       }
896     }
897   }
898   theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
899 }
900
901 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
902                                              const FeaturePtr& theSketch,
903                                              ModuleBase_IWorkshop* theWorkshop,
904                                              const FeatureToSelectionMap& theSelection,
905                                              SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
906 {
907   if (theFeature.get() == NULL)
908     return;
909
910   FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
911   std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
912   std::set<ResultPtr> aSelectedResults = anIt.value().second;
913
914   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
915   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
916   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
917   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
918
919   // 1. found the feature's owners. Check the AIS objects of the constructions
920   AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
921   if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
922     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
923
924     SelectMgr_IndexedMapOfOwner aSelectedOwners;  
925     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
926     for  (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
927       Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
928       if (!anOwner.IsNull())
929         anOwnersToSelect.Add(anOwner);
930     }
931   }
932
933   // 2. found the feature results's owners
934   std::list<ResultPtr> aResults = theFeature->results();
935   std::list<ResultPtr>::const_iterator aIt;
936   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
937   {
938     ResultPtr aResult = *aIt;
939     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
940     if (aAISObj.get() == NULL)
941       continue; 
942     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
943
944     SelectMgr_IndexedMapOfOwner aSelectedOwners;  
945     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
946     for  ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
947       Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
948       if ( anOwner.IsNull() || !anOwner->HasShape() )
949         continue;
950       const TopoDS_Shape& aShape = anOwner->Shape();
951       TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
952       if (aShapeType == TopAbs_VERTEX) {
953         AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
954         if (aPntAttr.get() != NULL &&
955             aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
956           anOwnersToSelect.Add(anOwner);
957         }
958       }
959       else if (aShapeType == TopAbs_EDGE) {
960         bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
961         if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
962             anOwnersToSelect.FindIndex(anOwner) <= 0)
963           anOwnersToSelect.Add(anOwner);
964       }
965     }
966   }
967 }
968
969 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
970 {
971   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
972   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
973   XGUI_Workshop* aWorkshop = aConnector->workshop();
974   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
975   if (aPropertyPanel) {
976     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
977     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
978       if (isToConnect) {
979         connect(aWidget, SIGNAL(beforeValuesChanged()),
980                 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
981         connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
982         connect(aWidget, SIGNAL(afterValuesChanged()),
983                 this, SLOT(onAfterValuesChangedInPropertyPanel()));
984       }
985       else {
986         disconnect(aWidget, SIGNAL(beforeValuesChanged()),
987                    this, SLOT(onBeforeValuesChangedInPropertyPanel()));
988         disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
989         disconnect(aWidget, SIGNAL(afterValuesChanged()),
990                    this, SLOT(onAfterValuesChangedInPropertyPanel()));
991       }
992     }
993   }
994 }
995
996 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
997 {
998   return myModule->workshop()->currentOperation();
999 }
1000
1001 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1002                                            const bool isToDisplay)
1003 {
1004   #ifdef DEBUG_DO_NOT_BY_ENTER
1005   return;
1006   #endif
1007
1008   if (!theOperation || theOperation->isEditOperation())
1009     return;
1010
1011   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1012   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1013   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1014
1015   // 1. change visibility of the object itself, here the presentable object is processed,
1016   // e.g. constraints features
1017   FeaturePtr aFeature = theOperation->feature();
1018   std::list<ResultPtr> aResults = aFeature->results();
1019   if (isToDisplay)
1020     aDisplayer->display(aFeature, false);
1021   else
1022     aDisplayer->erase(aFeature, false);
1023
1024   // change visibility of the object results, e.g. non-constraint features
1025   std::list<ResultPtr>::const_iterator aIt;
1026   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1027     if (isToDisplay) {
1028       aDisplayer->display(*aIt, false);
1029     }
1030     else {
1031       aDisplayer->erase(*aIt, false);
1032     }
1033   }
1034   aDisplayer->updateViewer();
1035 }
1036
1037 void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive)
1038 {
1039   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1040   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1041   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1042
1043   QIntList aModes;
1044   if (isActive) {
1045     aModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
1046     aModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
1047     aModes.append(SketcherPrs_Tools::Sel_Constraint);
1048     aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
1049     aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
1050   }
1051   aDisplayer->activateObjects(aModes);
1052 }
1053
1054 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1055 {
1056   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1057   ModuleBase_ISelection* aSelect = aWorkshop->selection();
1058   QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1059     
1060   QMap<FeaturePtr, QList<AttributePtr> > aFeature2AttributeMap;
1061   if (theHighlightedOnly) {
1062     fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
1063   }
1064   else {
1065     fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
1066
1067     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
1068     fillFeature2Attribute(aSelected, aFeature2AttributeMap, myCurrentSketch);
1069   }
1070
1071   // 1. it is necessary to save current selection in order to restore it after the features moving
1072   myCurrentSelection.clear();
1073   QMap<FeaturePtr, QList<AttributePtr> >::const_iterator anIt = aFeature2AttributeMap.begin(),
1074                                                          aLast = aFeature2AttributeMap.end();
1075   for (; anIt != aLast; anIt++) {
1076     FeaturePtr aFeature = anIt.key();
1077     getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection);
1078   }
1079   //qDebug(QString("  storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1080 }
1081
1082 void PartSet_SketcherMgr::restoreSelection()
1083 {
1084   //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1085   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1086   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1087   FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1088                                         aSLast = myCurrentSelection.end();
1089   SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1090   for (; aSIt != aSLast; aSIt++) {
1091     anOwnersToSelect.Clear();
1092     getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1093                         anOwnersToSelect);
1094     aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1095   }
1096 }
1097
1098 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1099 {
1100   if (myIsConstraintsShown == theOn)
1101     return;
1102   if (myCurrentSketch.get() == NULL)
1103     return;
1104
1105   myIsConstraintsShown = theOn;
1106
1107   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1108   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1109   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1110
1111   const QStringList& aConstrIds = constraintsIdList();
1112   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1113     FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1114     if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1115       if (myIsConstraintsShown) 
1116         aDisplayer->display(aSubFeature, false);
1117       else
1118         aDisplayer->erase(aSubFeature, false);
1119     }
1120   }
1121   aDisplayer->updateViewer();
1122 }