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