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