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