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