]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_SketcherMgr.cpp
Salome HOME
#1334 Show dimensional constraint check-box does not work
[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_SketcherReetntrantMgr.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_WidgetPoint2d.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_Tools.h"
13 #include "PartSet_WidgetSketchLabel.h"
14 #include "PartSet_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 <XGUI_ModuleConnector.h>
23 #include <XGUI_PropertyPanel.h>
24 #include <XGUI_ViewerProxy.h>
25 #include <XGUI_OperationMgr.h>
26
27 #include <ModuleBase_IPropertyPanel.h>
28 #include <ModuleBase_ISelection.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IWorkshop.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_ModelWidget.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationFeature.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_WidgetEditor.h>
37
38 #include <GeomDataAPI_Point2D.h>
39
40 #include <Events_Loop.h>
41
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Sketch.h>
44 #include <SketchPlugin_Point.h>
45 #include <SketchPlugin_Arc.h>
46 #include <SketchPlugin_Circle.h>
47 #include <SketchPlugin_ConstraintLength.h>
48 #include <SketchPlugin_ConstraintDistance.h>
49 #include <SketchPlugin_ConstraintParallel.h>
50 #include <SketchPlugin_ConstraintPerpendicular.h>
51 #include <SketchPlugin_ConstraintRadius.h>
52 #include <SketchPlugin_ConstraintRigid.h>
53 #include <SketchPlugin_ConstraintHorizontal.h>
54 #include <SketchPlugin_ConstraintVertical.h>
55 #include <SketchPlugin_ConstraintEqual.h>
56 #include <SketchPlugin_ConstraintTangent.h>
57 #include <SketchPlugin_ConstraintCoincidence.h>
58 #include <SketchPlugin_ConstraintFillet.h>
59 #include <SketchPlugin_ConstraintMirror.h>
60 #include <SketchPlugin_ConstraintAngle.h>
61 #include <SketchPlugin_ConstraintCollinear.h>
62 #include <SketchPlugin_ConstraintMiddle.h>
63 #include <SketchPlugin_MultiRotation.h>
64 #include <SketchPlugin_MultiTranslation.h>
65 #include <SketchPlugin_IntersectionPoint.h>
66
67 #include <SketcherPrs_Tools.h>
68
69 #include <SelectMgr_IndexedMapOfOwner.hxx>
70 #include <StdSelect_BRepOwner.hxx>
71
72 //#include <AIS_DimensionSelectionMode.hxx>
73 #include <AIS_Shape.hxx>
74 #include <AIS_Dimension.hxx>
75
76 #include <ModelAPI_Events.h>
77 #include <ModelAPI_Session.h>
78 #include <ModelAPI_AttributeString.h>
79
80 #include <QMouseEvent>
81 #include <QApplication>
82 #include <QCursor>
83 #include <QMessageBox>
84
85 //#define DEBUG_DO_NOT_BY_ENTER
86
87 //#define DEBUG_CURSOR
88
89 /// Returns list of unique objects by sum of objects from List1 and List2
90 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
91                                        const QList<ModuleBase_ViewerPrs>& theList2)
92 {
93   QList<ModuleBase_ViewerPrs> aRes;
94   foreach (ModuleBase_ViewerPrs aPrs, theList1) {
95     if (!aRes.contains(aPrs))
96       aRes.append(aPrs);
97   }
98   foreach (ModuleBase_ViewerPrs aPrs, theList2) {
99     if (!aRes.contains(aPrs))
100       aRes.append(aPrs);
101   }
102   return aRes;
103 }*/
104
105 // Fills the list of features the list of selected presentations.
106 // \param theList a list of selected presentations
107 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
108 // and find the corresponded attribute
109 // \param theFeatureList  an output list of features
110 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
111                      const FeaturePtr theSketch,
112                      QList<FeaturePtr>& theFeatureList)
113 {
114   QList<ModuleBase_ViewerPrs> aRes;
115
116   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
117                                               aLast = theList.end();
118   for (; anIt != aLast; anIt++)
119   {
120     ModuleBase_ViewerPrs aPrs = *anIt;
121     FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
122     if (aFeature.get()  && !theFeatureList.contains(aFeature))
123       theFeatureList.append(aFeature);
124   }
125 }
126
127 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
128 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
129 /// result as is to the list of results.
130 /// \param theOwner a viewer selected owner
131 /// \param theFeature a feature, where the attribute is searched
132 /// \param theSketch a current sketch
133 /// \param theSelectedAttribute an output list of attributes
134 /// \param theSelectedResults an output list of edge results
135 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
136                             const FeaturePtr& theFeature, const FeaturePtr& theSketch,
137                             const ResultPtr& theResult,
138                             std::set<AttributePtr>& aSelectedAttributes,
139                             std::set<ResultPtr>& aSelectedResults)
140 {
141   Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
142   if (aBRepOwner.IsNull())
143     return;
144   Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
145                                                                     aBRepOwner->Selectable());
146   if (aBRepOwner->HasShape()) {
147     const TopoDS_Shape& aShape = aBRepOwner->Shape();
148     TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
149     if (aShapeType == TopAbs_VERTEX) {
150       AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
151                                                                     aShape, theSketch);
152       if (aPntAttr.get() != NULL)
153         aSelectedAttributes.insert(aPntAttr);
154     }
155     else if (aShapeType == TopAbs_EDGE &&
156              aSelectedResults.find(theResult) == aSelectedResults.end()) {
157       aSelectedResults.insert(theResult);
158     }
159   }
160 }
161
162 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
163   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
164     myIsMouseOverWindow(false),
165     myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
166     myIsPopupMenuActive(false)
167 {
168   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
169   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
170
171   myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
172
173   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
174           this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
175
176   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
177           this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
178
179   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
180           this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
181
182   connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
183           this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
184
185   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
186   XGUI_Workshop* aWorkshop = aConnector->workshop();
187   connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
188
189   myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
190   myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
191 }
192
193 PartSet_SketcherMgr::~PartSet_SketcherMgr()
194 {
195   if (!myPlaneFilter.IsNull())
196     myPlaneFilter.Nullify();
197 }
198
199 void PartSet_SketcherMgr::onEnterViewPort()
200 {
201   // 1. if the mouse over window, update the next flag. Do not perform update visibility of
202   // created feature because it should be done in onMouseMove(). Some widgets watch
203   // the mouse move and use the cursor position to update own values. If the presentaion is
204   // redisplayed before this update, the feature presentation jumps from reset value to current.
205   myIsMouseOverWindow = true;
206
207   #ifdef DEBUG_DO_NOT_BY_ENTER
208   return;
209   #endif
210
211   if (canChangeCursor(getCurrentOperation())) {
212     QCursor* aCurrentCursor = QApplication::overrideCursor();
213     if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
214       QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
215 #ifdef DEBUG_CURSOR
216       qDebug("onEnterViewPort() : Qt::CrossCursor");
217 #endif
218     }
219   }
220
221   if (!isNestedCreateOperation(getCurrentOperation()))
222     return;
223
224   operationMgr()->onValidateOperation();
225
226   // we need change displayed state of the current operation feature
227   // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
228   // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
229   // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
230   // presentation becomes valid and redisplay happens
231   //ModuleBase_Operation* aOperation = getCurrentOperation();
232   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
233                                                                            (getCurrentOperation());
234   if (aFOperation) {
235     FeaturePtr aFeature = aFOperation->feature();
236     if (aFeature.get() && aFeature->data()->isValid()) {
237       visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
238     }
239   }
240 }
241
242 void PartSet_SketcherMgr::onLeaveViewPort()
243 {
244   myIsMouseOverViewProcessed = false;
245   myIsMouseOverWindow = false;
246   // it is important to validate operation here only if sketch entity create operation is active
247   // because at this operation we reacts to the mouse leave/enter view port
248   //operationMgr()->onValidateOperation();
249
250   #ifdef DEBUG_DO_NOT_BY_ENTER
251   return;
252   #endif
253
254   if (canChangeCursor(getCurrentOperation())) {
255     QApplication::restoreOverrideCursor();
256 #ifdef DEBUG_CURSOR
257     qDebug("onLeaveViewPort() : None");
258 #endif
259   }
260
261   if (!isNestedCreateOperation(getCurrentOperation()))
262     return;
263
264   // the method should be performed if the popup menu is called,
265   // the reset of the current widget should not happen
266   if (myIsPopupMenuActive)
267     return;
268
269   operationMgr()->onValidateOperation();
270
271   // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
272   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
273   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
274   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
275   // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
276   // obtained after reset value
277   bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
278   ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
279   if (anActiveWidget)
280     anActiveWidget->reset();
281
282   // hides the presentation of the current operation feature
283   // the feature is to be erased here, but it is correct to call canDisplayObject because
284   // there can be additional check (e.g. editor widget in distance constraint)
285   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
286                                                                            (getCurrentOperation());
287   if (aFOperation) {
288     FeaturePtr aFeature = aFOperation->feature();
289     visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
290   }
291   // we should update viewer after the presentation are hidden in the viewer
292   // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
293   aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
294 }
295
296 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
297 {
298   if (!isNestedEditOperation(getCurrentOperation()) ||
299       myModule->sketchReentranceMgr()->isInternalEditActive())
300     return;
301   // it is necessary to save current selection in order to restore it after the values are modifed
302   storeSelection();
303
304   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
305   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
306   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
307   myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
308 }
309
310 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
311 {
312   if (!isNestedEditOperation(getCurrentOperation()) ||
313       myModule->sketchReentranceMgr()->isInternalEditActive())
314     return;
315   // it is necessary to restore current selection in order to restore it after the values are modified
316   restoreSelection();
317   myCurrentSelection.clear();
318
319   // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
320   // viewer happens by deselect/select the modified objects. The flag should be restored after
321   // the selection processing. The update viewer should be also called.
322   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
323   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
324   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
325   aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
326   aDisplayer->updateViewer();
327 }
328
329 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
330 {
331   if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
332     return;
333
334   //get2dPoint(theWnd, theEvent, myClickedPoint);
335
336   if (!(theEvent->buttons() & Qt::LeftButton))
337     return;
338
339   // Clear dragging mode
340   myIsDragging = false;
341
342   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
343   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
344   if (!aViewer->canDragByMouse())
345     return;
346
347   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
348                                                                (getCurrentOperation());
349   if (!aFOperation)
350     return;
351
352   if (aFOperation->isEditOperation()) {
353     // If the current widget is a selector, do nothing, it processes the mouse press
354     ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
355     if(anActiveWidget && anActiveWidget->isViewerSelector()) {
356       return;
357     }
358   }
359
360   // Use only for sketch operations
361   if (myCurrentSketch) {
362     if (!PartSet_Tools::sketchPlane(myCurrentSketch))
363       return;
364
365     bool isSketcher = isSketchOperation(aFOperation);
366     bool isSketchOpe = isNestedSketchOperation(aFOperation);
367
368     // Avoid non-sketch operations
369     if ((!isSketchOpe) && (!isSketcher))
370       return;
371
372     bool isEditing = aFOperation->isEditOperation();
373
374     // Ignore creation sketch operation
375     if ((!isSketcher) && (!isEditing))
376       return;
377
378     Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
379     if (!aContext.IsNull()) {
380       // MoveTo in order to highlight current object
381       aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
382     }
383     // Remember highlighted objects for editing
384     ModuleBase_ISelection* aSelect = aWorkshop->selection();
385
386     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
387     storeSelection(!aHasShift);
388
389     if (myCurrentSelection.empty()) {
390       if (isSketchOpe && (!isSketcher))
391         // commit previous operation
392         if (!aFOperation->commit())
393           aFOperation->abort();
394       return;
395     }
396     // Init flyout point for radius rotation
397     FeaturePtr aFeature = myCurrentSelection.begin().key();
398
399     if (isSketcher) {
400       myIsDragging = true;
401       get2dPoint(theWnd, theEvent, myCurrentPoint);
402       myDragDone = false;
403
404       myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
405       launchEditing();
406       if (aFeature.get() != NULL) {
407         std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
408                   std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
409       if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
410           DataPtr aData = aSPFeature->data();
411           AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
412           std::shared_ptr<GeomDataAPI_Point2D> aFPAttr = 
413             std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
414           aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
415         }
416       }
417     } else if (isSketchOpe && isEditing) {
418       // If selected another object commit current result
419       aFOperation->commit();
420
421       myIsDragging = true;
422       get2dPoint(theWnd, theEvent, myCurrentPoint);
423       myDragDone = false;
424
425       myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
426
427       // this is temporary commented in order to avoid the following wrong case:
428       // Distance constraint is under edition, double click on the digit -> nothing happens
429       // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
430       // but as the prev edit is commited an new one is not started, editor is not shown.
431       // This is necessary in order to finalize previous operation
432       //QApplication::processEvents();
433       launchEditing();
434     }
435   }
436 }
437
438 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
439 {
440   if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
441     return;
442
443   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
444   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
445   if (!aViewer->canDragByMouse())
446     return;
447   ModuleBase_Operation* aOp = getCurrentOperation();
448   if (aOp) {
449     if (isNestedSketchOperation(aOp)) {
450       //get2dPoint(theWnd, theEvent, myClickedPoint);
451
452       // Only for sketcher operations
453       if (myIsDragging) {
454         if (myDragDone) {
455           //aOp->commit();
456           myCurrentSelection.clear();
457           /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
458           if (!aContext.IsNull()) {
459           // Reselect edited object
460           aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
461           if (theEvent->modifiers() & Qt::ShiftModifier)
462             aContext->ShiftSelect();
463           else
464             aContext->Select();
465           */
466         }
467       }
468     }
469   }
470
471   aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
472   myIsDragging = false;
473 }
474
475 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
476 {
477   if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
478     return;
479
480   if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
481     myIsMouseOverViewProcessed = true;
482     // 1. perform the widget mouse move functionality and display the presentation
483     // the mouse move should be processed in the widget, if it can in order to visualize correct
484     // presentation. These widgets correct the feature attribute according to the mouse position
485     ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
486     PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
487     if (aPoint2DWdg) {
488       aPoint2DWdg->onMouseMove(theWnd, theEvent);
489     }
490     PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
491                                                                 (anActiveWidget);
492     if (aDistanceWdg) {
493       aDistanceWdg->onMouseMove(theWnd, theEvent);
494     }
495     // the feature is to be erased here, but it is correct to call canDisplayObject because
496     // there can be additional check (e.g. editor widget in distance constraint)
497     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
498                                                                              (getCurrentOperation());
499     if (aFOperation) {
500       FeaturePtr aFeature = aFOperation->feature();
501       visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
502     }
503   }
504
505   //myClickedPoint.clear();
506
507   if (myIsDragging) {
508     // 1. the current selection is saved in the mouse press method in order to restore it after moving
509     // 2. the enable selection in the viewer should be temporary switched off in order to ignore
510     // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
511     // deselected). This flag should be restored in the slot, processed the mouse release signal.
512
513     ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
514     if (!aCurrentOperation)
515       return;
516     if (isSketchOperation(aCurrentOperation))
517       return; // No edit operation activated
518
519     Handle(V3d_View) aView = theWnd->v3dView();
520     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
521     double aX, aY;
522     PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
523     double dX =  aX - myCurrentPoint.myCurX;
524     double dY =  aY - myCurrentPoint.myCurY;
525
526     ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
527     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
528     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
529     // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
530     // viewer happens by deselect/select the modified objects. The flag should be restored after
531     // the selection processing. The update viewer should be also called.
532     bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
533
534     static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
535     //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
536     FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
537                                           aLast = myCurrentSelection.end();
538     // 4. the features and attributes modification(move)
539     bool isModified = false;
540     for (; anIt != aLast; anIt++) {
541       FeaturePtr aFeature = anIt.key();
542
543       std::set<AttributePtr> anAttributes = anIt.value().first;
544       // Process selection by attribute: the priority to the attribute
545       if (!anAttributes.empty()) {
546         std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
547                                                anAttLast = anAttributes.end();
548         for (; anAttIt != anAttLast; anAttIt++) {
549           AttributePtr anAttr = *anAttIt;
550           if (anAttr.get() == NULL)
551             continue;
552           std::string aAttrId = anAttr->id();
553           DataPtr aData = aFeature->data();
554           if (aData->isValid()) {
555             std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
556               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
557             if (aPoint.get() != NULL) {
558               bool isImmutable = aPoint->setImmutable(true);
559               aPoint->move(dX, dY);
560               isModified = true;
561               ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
562               aPoint->setImmutable(isImmutable);
563             }
564           }
565         }
566       } else {
567         // Process selection by feature
568         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
569           std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
570         if (aSketchFeature) {
571           aSketchFeature->move(dX, dY);
572           isModified = true;
573           ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
574         }
575       }
576     }
577     // the modified state of the current operation should be updated if there are features, which
578     // were changed here
579     if (isModified) {
580       aCurrentOperation->onValuesChanged();
581     }
582     Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
583     //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
584
585     // 5. it is necessary to save current selection in order to restore it after the features moving
586     restoreSelection();
587     // 6. restore the update viewer flag and call this update
588     aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
589     aDisplayer->updateViewer();
590
591     myDragDone = true;
592     myCurrentPoint.setValue(aX, aY);
593   }
594 }
595
596 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
597 {
598   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
599                                                                (getCurrentOperation());
600   if (aFOperation && aFOperation->isEditOperation()) {
601     std::string aId = aFOperation->id().toStdString();
602     if (isDistanceOperation(aFOperation))
603     {
604       // Activate dimension value editing on double click
605       ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
606       QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
607       // Find corresponded widget to activate value editing
608       foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
609         if (aWgt->attributeID() == "ConstraintValue") {
610           PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
611           if (anEditor)
612             anEditor->showPopupEditor();
613           return;
614         }
615       }
616     }
617   }
618 }
619
620 void PartSet_SketcherMgr::onApplicationStarted()
621 {
622   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
623   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
624   XGUI_Workshop* aWorkshop = aConnector->workshop();
625   PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
626
627   XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
628   if (aPropertyPanel) {
629     //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
630     //        this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
631
632     connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
633             aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
634     connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
635             aReentranceMgr, SLOT(onWidgetActivated()));
636   }
637
638   XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
639   connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
640   connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
641
642   XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
643   connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
644   connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
645 }
646
647 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
648 //{
649   //if (!myClickedPoint.myIsInitialized)
650   //  return;
651
652   //ModuleBase_Operation* aOperation = getCurrentOperation();
653   // the distance constraint feature should not use the clickedd point
654   // this is workaround in order to don't throw down the flyout point value,
655   // set by execute() method of these type of features
656   //if (isDistanceOperation(aOperation))
657   //  return;
658
659   //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
660   //if (aPnt2dWgt) {
661   //  aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
662   //}
663 //}
664
665 void PartSet_SketcherMgr::onBeforeContextMenu()
666 {
667   myIsPopupMenuActive = true;
668 }
669
670 void PartSet_SketcherMgr::onAfterContextMenu()
671 {
672   myIsPopupMenuActive = false;
673 }
674
675 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
676                                      Point& thePoint)
677 {
678   Handle(V3d_View) aView = theWnd->v3dView();
679   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
680   double aX, anY;
681   PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
682   thePoint.setValue(aX, anY);
683 }
684
685 void PartSet_SketcherMgr::launchEditing()
686 {
687   if (!myCurrentSelection.empty()) {
688     FeaturePtr aFeature = myCurrentSelection.begin().key();
689     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
690               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
691     if (aSPFeature) {
692       myModule->editFeature(aSPFeature);
693     }
694   }
695 }
696
697 bool PartSet_SketcherMgr::sketchSolverError()
698 {
699   bool anError = false;
700   CompositeFeaturePtr aSketch = activeSketch();
701   if (aSketch.get()) {
702     AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
703     anError = !aAttributeString->value().empty();
704   }
705   return anError;
706 }
707
708 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
709 {
710   QString anError = "";
711   if (!theFeature.get() || !theFeature->data()->isValid())
712     return anError;
713
714   CompositeFeaturePtr aSketch = activeSketch();
715   if (aSketch.get() && aSketch == theFeature) {
716     AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
717     anError = aAttributeString->value().c_str();
718   }
719   return anError;
720 }
721
722 void PartSet_SketcherMgr::clearClickedFlags()
723 {
724   //myClickedPoint.clear();
725   myCurrentPoint.clear();
726 }
727
728 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
729 {
730   static QStringList aIds;
731   if (aIds.size() == 0) {
732     aIds << SketchPlugin_Line::ID().c_str();
733     aIds << SketchPlugin_Point::ID().c_str();
734     aIds << SketchPlugin_Arc::ID().c_str();
735     aIds << SketchPlugin_Circle::ID().c_str();
736     aIds << SketchPlugin_ConstraintFillet::ID().c_str();
737     aIds << SketchPlugin_IntersectionPoint::ID().c_str();
738     // TODO
739     // SketchRectangle is a python feature, so its ID is passed just as a string
740     aIds << "SketchRectangle";
741     aIds.append(constraintsIdList());
742   }
743   return aIds;
744 }
745
746 const QStringList& PartSet_SketcherMgr::constraintsIdList()
747 {
748   static QStringList aIds;
749   if (aIds.size() == 0) {
750     aIds << SketchPlugin_ConstraintLength::ID().c_str();
751     aIds << SketchPlugin_ConstraintDistance::ID().c_str();
752     aIds << SketchPlugin_ConstraintRigid::ID().c_str();
753     aIds << SketchPlugin_ConstraintRadius::ID().c_str();
754     aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
755     aIds << SketchPlugin_ConstraintParallel::ID().c_str();
756     aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
757     aIds << SketchPlugin_ConstraintVertical::ID().c_str();
758     aIds << SketchPlugin_ConstraintEqual::ID().c_str();
759     aIds << SketchPlugin_ConstraintTangent::ID().c_str();
760     aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
761     aIds << SketchPlugin_ConstraintMirror::ID().c_str();
762     aIds << SketchPlugin_ConstraintAngle::ID().c_str();
763     aIds << SketchPlugin_MultiRotation::ID().c_str();
764     aIds << SketchPlugin_MultiTranslation::ID().c_str();
765     aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
766     aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
767   }
768   return aIds;
769 }
770
771 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
772 {
773   theModes.clear();
774
775   theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
776   theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
777   theModes.append(SketcherPrs_Tools::Sel_Constraint);
778   theModes.append(TopAbs_VERTEX);
779   theModes.append(TopAbs_EDGE);
780 }
781
782 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
783 {
784   return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
785 }
786
787 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
788 {
789   return theOperation &&
790          PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
791 }
792
793 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
794 {
795   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
796                                                                (theOperation);
797   return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
798 }
799
800 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
801 {
802   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
803                                                                (theOperation);
804   return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
805 }
806
807 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
808 {
809   return (theId == SketchPlugin_Line::ID()) ||
810          (theId == SketchPlugin_Point::ID()) ||
811          (theId == SketchPlugin_Arc::ID()) ||
812          (theId == SketchPlugin_Circle::ID());
813 }
814
815 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
816 {
817   std::string anId = theOperation ? theOperation->id().toStdString() : "";
818
819   return isDistanceKind(anId);
820 }
821
822 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
823 {
824   return (theKind == SketchPlugin_ConstraintLength::ID()) ||
825          (theKind == SketchPlugin_ConstraintDistance::ID()) ||
826          (theKind == SketchPlugin_ConstraintRadius::ID()) ||
827          (theKind == SketchPlugin_ConstraintAngle::ID());
828 }
829
830 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
831 {
832   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
833                                                                (getCurrentOperation());
834   if (!aFOperation)
835     return;
836
837   myModule->onViewTransformed();
838
839   // Display all sketcher sub-Objects
840   myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
841   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
842   aConnector->workshop()->displayer()->activateTrihedron(true);
843
844   // Hide sketcher result
845   std::list<ResultPtr> aResults = myCurrentSketch->results();
846   std::list<ResultPtr>::const_iterator aIt;
847   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
848     (*aIt)->setDisplayed(false);
849   }
850   myCurrentSketch->setDisplayed(false);
851
852   // Display sketcher objects
853   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
854     FeaturePtr aFeature = myCurrentSketch->subFeature(i);
855     std::list<ResultPtr> aResults = aFeature->results();
856     std::list<ResultPtr>::const_iterator aIt;
857     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
858       (*aIt)->setDisplayed(true);
859     }
860     aFeature->setDisplayed(true);
861   }
862
863   if (myPlaneFilter.IsNull()) 
864     myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
865
866   myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
867   bool aHasPlane = false;
868   std::shared_ptr<GeomAPI_Pln> aPln;
869   if (aFOperation->isEditOperation()) {
870     // If it is editing of sketch then it means that plane is already defined
871     aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
872     if (aPln.get())
873       aHasPlane = true;
874   }
875   myPlaneFilter->setPlane(aPln);
876
877   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
878   // all sketch objects should be activated in the sketch selection modes by edit operation start
879   // in case of creation operation, there is an active widget, which activates own selection mode
880   if (aFOperation->isEditOperation() && aHasPlane)
881     aConnector->activateModuleSelectionModes();
882 }
883
884 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
885 {
886   myIsMouseOverWindow = false;
887   myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
888   myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
889
890   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
891
892   DataPtr aData = myCurrentSketch->data();
893   if (!aData->isValid()) {
894     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
895     // The sketch was aborted
896     myCurrentSketch = CompositeFeaturePtr();
897     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
898
899     // Erase all sketcher objects
900     QStringList aSketchIds = sketchOperationIdList();
901     QObjectPtrList aObjects = aDisplayer->displayedObjects();
902     foreach (ObjectPtr aObj, aObjects) {
903       DataPtr aObjData = aObj->data();
904       if (!aObjData->isValid())
905         aObj->setDisplayed(false);
906     }
907   }
908   else {
909     // Hide all sketcher sub-Objects
910     for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
911       FeaturePtr aFeature = myCurrentSketch->subFeature(i);
912       std::list<ResultPtr> aResults = aFeature->results();
913       std::list<ResultPtr>::const_iterator aIt;
914       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
915         (*aIt)->setDisplayed(false);
916       }
917       aFeature->setDisplayed(false);
918     }
919     // Display sketcher result
920     std::list<ResultPtr> aResults = myCurrentSketch->results();
921     std::list<ResultPtr>::const_iterator aIt;
922     Events_Loop* aLoop = Events_Loop::loop();
923     static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
924
925     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
926                                                                            (theOperation);
927     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
928       if (!aFOperation->isDisplayedOnStart(*aIt)) {
929         (*aIt)->setDisplayed(true);
930         // this display event is needed because sketch already may have "displayed" state,
931         // but not displayed while it is still active (issue 613, abort of existing sketch)
932         ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
933       }
934     }
935     if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
936       myCurrentSketch->setDisplayed(true);
937     
938     myCurrentSketch = CompositeFeaturePtr();
939     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
940
941     Events_Loop::loop()->flush(aDispEvent);
942   }
943   // restore the module selection modes, which were changed on startSketch
944   aConnector->activateModuleSelectionModes();
945   aConnector->workshop()->displayer()->activateTrihedron(false);
946 }
947
948 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
949 {
950   if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
951     QCursor* aCurrentCursor = QApplication::overrideCursor();
952     if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
953       QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
954 #ifdef DEBUG_CURSOR
955       qDebug("startNestedSketch() : Qt::CrossCursor");
956 #endif
957     }
958   }
959 }
960
961 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
962 {
963   myIsMouseOverViewProcessed = true;
964   operationMgr()->onValidateOperation();
965   if (canChangeCursor(theOperation)) {
966     QApplication::restoreOverrideCursor();
967 #ifdef DEBUG_CURSOR
968     qDebug("stopNestedSketch() : None");
969 #endif
970   }
971 }
972
973 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
974 {
975   if (isNestedCreateOperation(theOperation)) {
976     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
977                                                                              (theOperation);
978     if (aFOperation) {
979       FeaturePtr aFeature = aFOperation->feature();
980       // it is necessary to check the the feature data validity because
981       // some kind of features are removed by an operation commit(the macro state of a feature)
982       if (aFeature.get() && aFeature->data()->isValid()) {
983         visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
984       }
985     }
986   }
987 }
988
989 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
990 {
991   if (toActivate)
992     myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
993   else
994     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
995 }
996
997 void PartSet_SketcherMgr::operationActivatedByPreselection()
998 {
999   ModuleBase_Operation* anOperation = getCurrentOperation();
1000   if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1001     // Set final definitions if they are necessary
1002     //propertyPanelDefined(aOperation);
1003     /// Commit sketcher operations automatically
1004     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1005                                                                             (anOperation);
1006     if (aFOperation) {
1007       if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1008         FeaturePtr aFeature = aFOperation->feature();
1009         // editor is shown only if all attribute references are filled by preseletion
1010         bool anAllRefAttrInitialized = true;
1011
1012         std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1013                                                     ModelAPI_AttributeRefAttr::typeId());
1014         std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1015         for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1016           anAllRefAttrInitialized = (*anIt)->isInitialized();
1017         }
1018         if (anAllRefAttrInitialized) {
1019           // Activate dimension value editing on double click
1020           ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1021           QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1022           // Find corresponded widget to activate value editing
1023           foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1024             if (aWgt->attributeID() == "ConstraintValue") {
1025               // the featue should be displayed in order to find the AIS text position,
1026               // the place where the editor will be shown
1027               aFeature->setDisplayed(true);
1028               /// the execute is necessary to perform in the feature compute for flyout position
1029               aFeature->execute();
1030
1031               Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1032               Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1033
1034               PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1035               if (anEditor) {
1036                 int aX = 0, anY = 0;
1037
1038                 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1039                 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1040                 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1041                 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1042                 Handle(AIS_InteractiveObject) anAISIO;
1043                 if (anAIS.get() != NULL) {
1044                   anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1045                 }
1046                 if (anAIS.get() != NULL) {
1047                   Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1048
1049                   if (!anAISIO.IsNull()) {
1050                     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1051                     if (!aDim.IsNull()) {
1052                       gp_Pnt aPosition = aDim->GetTextPosition();
1053
1054                       ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1055                       Handle(V3d_View) aView = aViewer->activeView();
1056                       int aCX, aCY;
1057                       aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1058
1059                       QWidget* aViewPort = aViewer->activeViewPort();
1060                       QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1061                       aX = aGlPoint.x();
1062                       anY = aGlPoint.y();
1063                     }
1064                   }
1065                   anEditor->setCursorPosition(aX, anY);
1066                   anEditor->showPopupEditor(false);
1067                 }
1068               }
1069             }
1070           }
1071         }
1072       }
1073     }
1074     anOperation->commit();
1075   }
1076 }
1077
1078 bool PartSet_SketcherMgr::canUndo() const
1079 {
1080   return isNestedCreateOperation(getCurrentOperation());
1081 }
1082
1083 bool PartSet_SketcherMgr::canRedo() const
1084 {
1085   return isNestedCreateOperation(getCurrentOperation());
1086 }
1087
1088 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1089 {
1090   bool aCanErase = true;
1091   // when the sketch operation is active, results of sketch sub-feature can not be hidden
1092   if (myCurrentSketch.get()) {
1093     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1094     if (aResult.get()) {
1095       // Display sketcher objects
1096       for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1097
1098         FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1099         std::list<ResultPtr> aResults = aFeature->results();
1100         std::list<ResultPtr>::const_iterator anIt;
1101         for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1102           aCanErase = *anIt != aResult;
1103         }
1104       }
1105     }
1106   }
1107   return aCanErase;
1108 }
1109
1110 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1111 {
1112   bool aCanDisplay = true;
1113
1114   bool aHasActiveSketch = activeSketch().get() != NULL;
1115   if (aHasActiveSketch) {
1116     // 1. the sketch feature should not be displayed during the sketch active operation
1117     // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch 
1118     // nested features can be visualized
1119     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1120     if (aFeature.get() != NULL && aFeature == activeSketch()) {
1121       aCanDisplay = false;
1122     }
1123   }
1124   else { // there are no an active sketch
1125     // 2. sketch sub-features should not be visualized if the sketch operation is not active
1126     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1127     if (aFeature.get() != NULL) {
1128       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1129                               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1130       if (aSketchFeature.get()) {
1131         aCanDisplay = false;
1132       }
1133     }
1134   }
1135
1136   // 3. the method should not filter the objects, which are not related to the current operation.
1137   // The object is filtered just if it is a current operation feature or this feature result
1138   bool isObjectFound = false;
1139   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1140                                                                (getCurrentOperation());
1141   if (aFOperation) {
1142     FeaturePtr aFeature = aFOperation->feature();
1143     if (aFeature.get()) {
1144       std::list<ResultPtr> aResults = aFeature->results();
1145       if (theObject == aFeature)
1146         isObjectFound = true;
1147       else {
1148         std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1149         for (; anIt != aLast && !isObjectFound; anIt++) {
1150           isObjectFound = *anIt == theObject;
1151         }
1152       }
1153     }
1154   }
1155   if (isObjectFound) {
1156     // 4. For created nested feature operation do not display the created feature if
1157     // the mouse curstor leaves the OCC window.
1158     // The correction cases, which ignores this condition:
1159     // a. the property panel values modification
1160     // b. the popup menu activated
1161     // c. widget editor control
1162     #ifndef DEBUG_DO_NOT_BY_ENTER
1163     if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1164       ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1165       ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1166       // the active widget editor should not influence here. The presentation should be visible always
1167       // when this widget is active.
1168       if (!anEditorWdg && !myIsPopupMenuActive) {
1169         // during a nested create operation, the feature is redisplayed only if the mouse over view
1170         // of there was a value modified in the property panel after the mouse left the view
1171         aCanDisplay = canDisplayCurrentCreatedFeature();
1172       }
1173     }
1174     #endif
1175   }
1176
1177   // checks the sketcher constraints visibility according to active sketch check box states
1178   if (aCanDisplay) {
1179     bool aProcessed = false;
1180     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1181     if (aFeature.get()) {
1182       bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1183       if (aProcessed)
1184         aCanDisplay = aConstraintDisplayed;
1185     }
1186   }
1187
1188   return aCanDisplay;
1189 }
1190
1191 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1192                                              const PartSet_Tools::ConstraintVisibleState& theState,
1193                                              bool& isProcessed) const
1194 {
1195   bool aSwitchedOn = true;
1196
1197   const QStringList& aConstrIds = constraintsIdList();
1198
1199   std::string aKind = theFeature->getKind();
1200   if (aConstrIds.contains(QString(aKind.c_str()))) {
1201     bool isTypedConstraint = false;
1202
1203     switch (theState) {
1204       case PartSet_Tools::Dimensional: {
1205         bool isDistance = isDistanceKind(aKind);
1206         if (isDistance) {
1207           isProcessed = true;
1208           aSwitchedOn = myIsConstraintsShown[theState];
1209         }
1210       }
1211       break;
1212       case PartSet_Tools::Geometrical: {
1213         bool isGeometrical = !isDistanceKind(aKind);
1214         if (isGeometrical) {
1215           isProcessed = true;
1216           aSwitchedOn = myIsConstraintsShown[theState];
1217         }
1218       }
1219       break;
1220       case PartSet_Tools::Any: {
1221         isProcessed = true;
1222         bool isDistance = isDistanceKind(aKind);
1223         if (isDistance)
1224           aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1225         else
1226           aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1227       }
1228       break;
1229     default:
1230       break;
1231     }
1232   }
1233   return aSwitchedOn;
1234 }
1235
1236 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1237 {
1238   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1239                                                                            (getCurrentOperation());
1240   if (aFOperation && myCurrentSketch.get()) {
1241     // find results of the current operation
1242     // these results should not be proposed to be deleted
1243     FeaturePtr anOperationFeature = aFOperation->feature();
1244     std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1245     std::set<ResultPtr> anOperationResults;
1246     std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1247                                         aRLast = anOperationResultList.end();
1248     for (; aRIt != aRLast; aRIt++)
1249       anOperationResults.insert(*aRIt);
1250
1251     std::set<FeaturePtr> anObjectsToBeDeleted;
1252     QStringList anObjectsToBeDeletedNames;
1253     std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1254     for (; anIt != aLast; anIt++) {
1255       ObjectPtr anObject = *anIt;
1256       bool aCanErase = true;
1257       // when the sketch operation is active, results of sketch sub-feature can not be hidden
1258       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1259       // the result is found between current feature results
1260       if (anOperationResults.find(aResult) != anOperationResults.end())
1261         continue;
1262
1263       if (aResult.get()) {
1264         // Display sketcher objects
1265         for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1266           FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1267           std::list<ResultPtr> aResults = aFeature->results();
1268           std::list<ResultPtr>::const_iterator anIt;
1269           for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1270             aCanErase = *anIt != aResult;
1271           }
1272         }
1273       }
1274       if (!aCanErase) {
1275         FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1276         if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1277           anObjectsToBeDeleted.insert(aFeature);
1278           anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1279         }
1280       }
1281     }
1282     if (!anObjectsToBeDeleted.empty()) {
1283       QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1284       QString aMessage = tr("The following features have incorrect presentation and \
1285 will be hidden: %1. Would you like to delete them?")
1286                          .arg(aFeatureNames);
1287       int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1288                                            aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1289                                            QMessageBox::Cancel);
1290       if (anAnswer == QMessageBox::Ok) {
1291         QObjectPtrList anObjects;
1292         std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1293                                              aLast = anObjectsToBeDeleted.end();
1294         for (; anIt != aLast; anIt++)
1295           anObjects.append(*anIt);
1296         SessionPtr aMgr = ModelAPI_Session::get();
1297         DocumentPtr aDoc = aMgr->activeDocument();
1298         bool aIsOp = aMgr->isOperation();
1299         if (!aIsOp)
1300           aMgr->startOperation();
1301         workshop()->deleteFeatures(anObjects);
1302         //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1303         //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1304         //Events_Loop::loop()->flush(aDeletedEvent);
1305         //Events_Loop::loop()->flush(aRedispEvent);
1306
1307         if (!aIsOp)
1308           aMgr->finishOperation();
1309       }
1310     }
1311   }
1312 }
1313
1314 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1315 {
1316   bool aCanDisplay = myIsMouseOverWindow;
1317   if (!aCanDisplay) {
1318     ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1319     if (anActiveWidget)
1320       aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1321   }
1322   return aCanDisplay;
1323 }
1324
1325 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1326 {
1327   return isNestedCreateOperation(theOperation) ||
1328          myModule->sketchReentranceMgr()->isInternalEditActive();
1329 }
1330
1331 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1332 {
1333   return myIsConstraintsShown;
1334 }
1335
1336 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1337 {
1338   bool isFoundObject = false;
1339
1340   FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1341   if (anObjectFeature.get()) {
1342     int aSize = myCurrentSketch->numberOfSubs();
1343     for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1344       FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1345       isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1346     }
1347   }
1348   return isFoundObject;
1349 }
1350
1351 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1352 {
1353   if (myPlaneFilter.IsNull()) 
1354    myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1355
1356   myPlaneFilter->setPlane(thePln);
1357 }
1358
1359 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1360                                               const FeaturePtr& theSketch,
1361                                               ModuleBase_IWorkshop* theWorkshop,
1362                                               FeatureToSelectionMap& theSelection)
1363 {
1364   if (theFeature.get() == NULL)
1365     return;
1366
1367   std::set<AttributePtr> aSelectedAttributes;
1368   std::set<ResultPtr> aSelectedResults;
1369
1370   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1371   Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1372   if (!aContext.IsNull()) {
1373     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1374     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1375
1376     std::list<ResultPtr> aResults = theFeature->results();
1377     std::list<ResultPtr>::const_iterator aIt;
1378     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1379     {
1380       ResultPtr aResult = *aIt;
1381       AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1382       if (aAISObj.get() == NULL)
1383         continue;
1384       Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1385       for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1386       {
1387         Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1388         if (anOwner->Selectable() != anAISIO)
1389           continue;
1390         getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1391                                aSelectedAttributes, aSelectedResults);
1392       }
1393       for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1394         Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1395         if (anOwner.IsNull())
1396           continue;
1397         if (anOwner->Selectable() != anAISIO)
1398           continue;
1399         getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1400                                aSelectedAttributes, aSelectedResults);
1401       }
1402     }
1403   }
1404   theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1405 }
1406
1407 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1408                                              const FeaturePtr& theSketch,
1409                                              ModuleBase_IWorkshop* theWorkshop,
1410                                              const FeatureToSelectionMap& theSelection,
1411                                              SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1412 {
1413   if (theFeature.get() == NULL)
1414     return;
1415
1416   FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1417   std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1418   std::set<ResultPtr> aSelectedResults = anIt.value().second;
1419
1420   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1421
1422   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1423   XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1424
1425   // 1. found the feature's owners. Check the AIS objects of the constructions
1426   AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1427   if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1428     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1429
1430     SelectMgr_IndexedMapOfOwner aSelectedOwners;
1431     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1432     for  (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1433       Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1434       if (!anOwner.IsNull())
1435         theOwnersToSelect.Add(anOwner);
1436     }
1437   }
1438
1439   // 2. found the feature results's owners
1440   std::list<ResultPtr> aResults = theFeature->results();
1441   std::list<ResultPtr>::const_iterator aIt;
1442   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1443   {
1444     ResultPtr aResult = *aIt;
1445     AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1446     if (aAISObj.get() == NULL)
1447       continue; 
1448     Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1449
1450     SelectMgr_IndexedMapOfOwner aSelectedOwners;  
1451     aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1452     for  ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1453       Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1454       if ( anOwner.IsNull() || !anOwner->HasShape() )
1455         continue;
1456       const TopoDS_Shape& aShape = anOwner->Shape();
1457       TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1458       if (aShapeType == TopAbs_VERTEX) {
1459         AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1460         if (aPntAttr.get() != NULL &&
1461             aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1462           theOwnersToSelect.Add(anOwner);
1463         }
1464       }
1465       else if (aShapeType == TopAbs_EDGE) {
1466         bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1467         if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1468             theOwnersToSelect.FindIndex(anOwner) <= 0)
1469           theOwnersToSelect.Add(anOwner);
1470       }
1471     }
1472   }
1473 }
1474
1475 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1476 {
1477   if (isToConnect) {
1478     connect(theWidget, SIGNAL(beforeValuesChanged()),
1479             this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1480     connect(theWidget, SIGNAL(afterValuesChanged()),
1481             this, SLOT(onAfterValuesChangedInPropertyPanel()));
1482   }
1483   else {
1484     disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1485                 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1486     disconnect(theWidget, SIGNAL(afterValuesChanged()),
1487                 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1488   }
1489 }
1490
1491 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1492 {
1493   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1494                                                                            (getCurrentOperation());
1495   if (aFOperation) {
1496     if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1497         PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1498         thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1499       FeaturePtr aFeature = aFOperation->feature();
1500       visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1501     }
1502   }
1503 }
1504
1505 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1506 {
1507   return myModule->workshop()->currentOperation();
1508 }
1509
1510 //**************************************************************
1511 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1512 {
1513   ModuleBase_ModelWidget* aWidget = 0;
1514   ModuleBase_Operation* anOperation = getCurrentOperation();
1515   if (anOperation) {
1516     ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1517     if (aPanel)
1518       aWidget = aPanel->activeWidget();
1519   }
1520   return aWidget;
1521 }
1522
1523 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1524                                            const bool isEditOperation,
1525                                            const bool isToDisplay,
1526                                            const bool isFlushRedisplay)
1527 {
1528   #ifdef DEBUG_DO_NOT_BY_ENTER
1529   return;
1530   #endif
1531
1532   if (isEditOperation || !theFeature.get())
1533     return;
1534
1535   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1536   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1537
1538   // 1. change visibility of the object itself, here the presentable object is processed,
1539   // e.g. constraints features
1540   //FeaturePtr aFeature = aFOperation->feature();
1541   std::list<ResultPtr> aResults = theFeature->results();
1542   if (isToDisplay)
1543     theFeature->setDisplayed(true);
1544   else
1545     theFeature->setDisplayed(false);
1546
1547   // change visibility of the object results, e.g. non-constraint features
1548   std::list<ResultPtr>::const_iterator aIt;
1549   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1550     if (isToDisplay) {
1551       (*aIt)->setDisplayed(true);
1552     }
1553     else {
1554       (*aIt)->setDisplayed(false);
1555     }
1556   }
1557   if (isFlushRedisplay)
1558     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1559 }
1560
1561 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1562 {
1563   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1564   ModuleBase_ISelection* aSelect = aWorkshop->selection();
1565   QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1566
1567   QList<FeaturePtr> aFeatureList;
1568   if (theHighlightedOnly) {
1569     fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1570   }
1571   else {
1572     fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1573
1574     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1575     fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1576   }
1577
1578   // 1. it is necessary to save current selection in order to restore it after the features moving
1579   myCurrentSelection.clear();
1580   QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1581   for (; anIt != aLast; anIt++) {
1582     getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1583   }
1584   //qDebug(QString("  storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1585 }
1586
1587 void PartSet_SketcherMgr::restoreSelection()
1588 {
1589   //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1590   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1591   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1592   FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1593                                         aSLast = myCurrentSelection.end();
1594   SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1595   for (; aSIt != aSLast; aSIt++) {
1596     anOwnersToSelect.Clear();
1597     getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1598                         anOwnersToSelect);
1599     aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1600   }
1601 }
1602
1603 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1604 {
1605   PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1606   if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1607     return;
1608   if (myCurrentSketch.get() == NULL)
1609     return;
1610
1611   myIsConstraintsShown[aType] = theState;
1612
1613   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1614   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1615
1616   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1617     FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1618     bool aProcessed = false;
1619     bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, aType, aProcessed);
1620     if (aProcessed)
1621       aSubFeature->setDisplayed(aConstraintDisplayed);
1622   }
1623   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1624 }
1625
1626 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1627 {
1628   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1629   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1630   return aConnector->workshop();
1631 }
1632
1633 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1634 {
1635   return workshop()->operationMgr();
1636 }
1637