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