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