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