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