Salome HOME
a6ae7a8a5bcb4f656210a239a4d08275dbb4878f
[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     /// The operation should not be aborted here, because the method does not changed
784     /// the auxilliary state, but checks the possibility to perform this
785     ///if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
786     ///  anOperation->abort();
787     // 2. change auxiliary type of selected sketch entities
788     ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
789     anObjects = aSelection->selectedPresentations();
790   }
791   anEnabled = anObjects.size() > 0;
792
793   bool isNotAuxiliaryFound = false;
794   if (anObjects.size() > 0) {
795     QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
796     for (; anIt != aLast && !isNotAuxiliaryFound; anIt++) {
797       FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
798       if (aFeature.get() != NULL) {
799         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
800                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
801         if (aSketchFeature.get() != NULL) {
802           std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
803
804           std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr = 
805             std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
806           if (anAuxiliaryAttr)
807             isNotAuxiliaryFound = !anAuxiliaryAttr->value();
808         }
809       }
810     }
811   }
812   theValue = anObjects.size() && !isNotAuxiliaryFound;
813   return anEnabled;
814 }
815   
816 void PartSet_SketcherMgr::setAuxiliary(const bool isChecked)
817 {
818   ModuleBase_Operation* anOperation = getCurrentOperation();
819
820   bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
821                         PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
822   if (!isActiveSketch)
823     return;
824
825   QObjectPtrList anObjects;
826   bool isUseTransaction = false;
827   // 1. change auxiliary type of a created feature
828   if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
829       PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
830     anObjects.append(anOperation->feature());
831   }
832   else {
833     isUseTransaction = true;
834     // 2. change auxiliary type of selected sketch entities
835     ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
836     anObjects = aSelection->selectedPresentations();
837   }
838
839   QAction* anAction = myModule->action("AUXILIARY_CMD");
840   SessionPtr aMgr = ModelAPI_Session::get();
841   if (isUseTransaction) {
842     if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
843       anOperation->abort();
844     aMgr->startOperation(anAction->text().toStdString());
845   }
846   storeSelection();
847
848   if (anObjects.size() > 0) {
849     QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
850     for (; anIt != aLast; anIt++) {
851       FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
852       if (aFeature.get() != NULL) {
853         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
854                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
855         if (aSketchFeature.get() != NULL) {
856           std::string anAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
857
858           std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr = 
859             std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
860           if (anAuxiliaryAttr)
861             anAuxiliaryAttr->setValue(isChecked);
862         }
863       }
864     }
865   }
866   if (isUseTransaction) {
867     aMgr->finishOperation();
868   }
869   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
870   restoreSelection();
871 }
872
873 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
874 {
875   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
876 }
877
878 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
879                                               const FeaturePtr& theSketch,
880                                               ModuleBase_IWorkshop* theWorkshop,
881                                               FeatureToSelectionMap& theSelection)
882 {
883   if (theFeature.get() == NULL)
884     return;
885
886   std::set<AttributePtr> aSelectedAttributes;
887   std::set<ResultPtr> aSelectedResults;
888
889   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
890   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
891   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
892   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
893
894   std::list<ResultPtr> aResults = theFeature->results();
895   std::list<ResultPtr>::const_iterator aIt;
896   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
897   {
898     ResultPtr aResult = *aIt;
899     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
900     if (aAISObj.get() == NULL)
901       continue;
902     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
903     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
904     {
905       Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
906                                                                       aContext->SelectedOwner());
907       if (aBRepOwner.IsNull())
908         continue;
909       Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
910                                                                         aBRepOwner->Selectable());
911       if (anIO != anAISIO)
912         continue;
913
914       if (aBRepOwner->HasShape()) {
915         const TopoDS_Shape& aShape = aBRepOwner->Shape();
916         TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
917         if (aShapeType == TopAbs_VERTEX) {
918           AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
919                                                                         aShape, theSketch);
920           if (aPntAttr.get() != NULL)
921             aSelectedAttributes.insert(aPntAttr);
922         }
923         else if (aShapeType == TopAbs_EDGE &&
924                  aSelectedResults.find(aResult) == aSelectedResults.end()) {
925           aSelectedResults.insert(aResult);
926         }
927       }
928     }
929   }
930   theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
931 }
932
933 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
934                                              const FeaturePtr& theSketch,
935                                              ModuleBase_IWorkshop* theWorkshop,
936                                              const FeatureToSelectionMap& theSelection,
937                                              SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
938 {
939   if (theFeature.get() == NULL)
940     return;
941
942   FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
943   std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
944   std::set<ResultPtr> aSelectedResults = anIt.value().second;
945
946   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
947   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
948   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
949   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
950
951   // 1. found the feature's owners. Check the AIS objects of the constructions
952   AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
953   if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
954     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
955
956     SelectMgr_IndexedMapOfOwner aSelectedOwners;  
957     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
958     for  (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
959       Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
960       if (!anOwner.IsNull())
961         anOwnersToSelect.Add(anOwner);
962     }
963   }
964
965   // 2. found the feature results's owners
966   std::list<ResultPtr> aResults = theFeature->results();
967   std::list<ResultPtr>::const_iterator aIt;
968   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
969   {
970     ResultPtr aResult = *aIt;
971     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
972     if (aAISObj.get() == NULL)
973       continue; 
974     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
975
976     SelectMgr_IndexedMapOfOwner aSelectedOwners;  
977     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
978     for  ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
979       Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
980       if ( anOwner.IsNull() || !anOwner->HasShape() )
981         continue;
982       const TopoDS_Shape& aShape = anOwner->Shape();
983       TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
984       if (aShapeType == TopAbs_VERTEX) {
985         AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
986         if (aPntAttr.get() != NULL &&
987             aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
988           anOwnersToSelect.Add(anOwner);
989         }
990       }
991       else if (aShapeType == TopAbs_EDGE) {
992         bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
993         if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
994             anOwnersToSelect.FindIndex(anOwner) <= 0)
995           anOwnersToSelect.Add(anOwner);
996       }
997     }
998   }
999 }
1000
1001 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1002 {
1003   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1004   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1005   XGUI_Workshop* aWorkshop = aConnector->workshop();
1006   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1007   if (aPropertyPanel) {
1008     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1009     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1010       if (isToConnect) {
1011         connect(aWidget, SIGNAL(beforeValuesChanged()),
1012                 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1013         connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1014         connect(aWidget, SIGNAL(afterValuesChanged()),
1015                 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1016       }
1017       else {
1018         disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1019                    this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1020         disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1021         disconnect(aWidget, SIGNAL(afterValuesChanged()),
1022                    this, SLOT(onAfterValuesChangedInPropertyPanel()));
1023       }
1024     }
1025   }
1026 }
1027
1028 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1029 {
1030   return myModule->workshop()->currentOperation();
1031 }
1032
1033 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1034                                            const bool isToDisplay)
1035 {
1036   if (!theOperation || theOperation->isEditOperation())
1037     return;
1038
1039   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1040   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1041   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1042
1043   // 1. change visibility of the object itself, here the presentable object is processed,
1044   // e.g. constraints features
1045   FeaturePtr aFeature = theOperation->feature();
1046   std::list<ResultPtr> aResults = aFeature->results();
1047   if (isToDisplay)
1048     aDisplayer->display(aFeature, false);
1049   else
1050     aDisplayer->erase(aFeature, false);
1051
1052   // change visibility of the object results, e.g. non-constraint features
1053   std::list<ResultPtr>::const_iterator aIt;
1054   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1055     if (isToDisplay) {
1056       aDisplayer->display(*aIt, false);
1057     }
1058     else {
1059       aDisplayer->erase(*aIt, false);
1060     }
1061   }
1062   aDisplayer->updateViewer();
1063 }
1064
1065 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1066 {
1067   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1068   ModuleBase_ISelection* aSelect = aWorkshop->selection();
1069   QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1070     
1071   QMap<FeaturePtr, QList<AttributePtr> > aFeature2AttributeMap;
1072   if (theHighlightedOnly) {
1073     fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
1074   }
1075   else {
1076     fillFeature2Attribute(aHighlighted, aFeature2AttributeMap, myCurrentSketch);
1077
1078     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
1079     fillFeature2Attribute(aSelected, aFeature2AttributeMap, myCurrentSketch);
1080   }
1081
1082   // 1. it is necessary to save current selection in order to restore it after the features moving
1083   myCurrentSelection.clear();
1084   QMap<FeaturePtr, QList<AttributePtr> >::const_iterator anIt = aFeature2AttributeMap.begin(),
1085                                                          aLast = aFeature2AttributeMap.end();
1086   for (; anIt != aLast; anIt++) {
1087     FeaturePtr aFeature = anIt.key();
1088     getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection);
1089   }
1090   //qDebug(QString("  storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1091 }
1092
1093 void PartSet_SketcherMgr::restoreSelection()
1094 {
1095   //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1096   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1097   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1098   FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1099                                         aSLast = myCurrentSelection.end();
1100   SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1101   for (; aSIt != aSLast; aSIt++) {
1102     anOwnersToSelect.Clear();
1103     getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1104                         anOwnersToSelect);
1105     aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1106   }
1107 }