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