1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
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"
14 #include <ModuleBase_WidgetEditor.h>
15 #include <ModuleBase_ModelWidget.h>
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>
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>
36 #include <GeomDataAPI_Point2D.h>
38 #include <Events_Loop.h>
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_ConstraintAngle.h>
59 #include <SketchPlugin_MultiRotation.h>
60 #include <SketchPlugin_MultiTranslation.h>
62 #include <SketcherPrs_Tools.h>
64 #include <SelectMgr_IndexedMapOfOwner.hxx>
65 #include <StdSelect_BRepOwner.hxx>
67 //#include <AIS_DimensionSelectionMode.hxx>
68 #include <AIS_Shape.hxx>
70 #include <ModelAPI_Events.h>
71 #include <ModelAPI_Session.h>
73 #include <QMouseEvent>
74 #include <QApplication>
76 //#define DEBUG_DO_NOT_BY_ENTER
77 //#define DEBUG_MOUSE_OVER_WINDOW_FLAGS
79 /// Returns list of unique objects by sum of objects from List1 and List2
80 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
81 const QList<ModuleBase_ViewerPrs>& theList2)
83 QList<ModuleBase_ViewerPrs> aRes;
84 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
85 if (!aRes.contains(aPrs))
88 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
89 if (!aRes.contains(aPrs))
95 // Fills the list of features the list of selected presentations.
96 // \param theList a list of selected presentations
97 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
98 // and find the corresponded attribute
99 // \param theFeatureList an output list of features
100 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
101 const FeaturePtr theSketch,
102 QList<FeaturePtr>& theFeatureList)
104 QList<ModuleBase_ViewerPrs> aRes;
106 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
107 aLast = theList.end();
108 for (; anIt != aLast; anIt++)
110 ModuleBase_ViewerPrs aPrs = *anIt;
111 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
112 if (aFeature.get() && !theFeatureList.contains(aFeature))
113 theFeatureList.append(aFeature);
117 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
118 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
119 /// result as is to the list of results.
120 /// \param theOwner a viewer selected owner
121 /// \param theFeature a feature, where the attribute is searched
122 /// \param theSketch a current sketch
123 /// \param theSelectedAttribute an output list of attributes
124 /// \param theSelectedResults an output list of edge results
125 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
126 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
127 const ResultPtr& theResult,
128 std::set<AttributePtr>& aSelectedAttributes,
129 std::set<ResultPtr>& aSelectedResults)
131 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
132 if (aBRepOwner.IsNull())
134 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
135 aBRepOwner->Selectable());
136 if (aBRepOwner->HasShape()) {
137 const TopoDS_Shape& aShape = aBRepOwner->Shape();
138 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
139 if (aShapeType == TopAbs_VERTEX) {
140 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
142 if (aPntAttr.get() != NULL)
143 aSelectedAttributes.insert(aPntAttr);
145 else if (aShapeType == TopAbs_EDGE &&
146 aSelectedResults.find(theResult) == aSelectedResults.end()) {
147 aSelectedResults.insert(theResult);
152 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
153 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
154 myIsResetCurrentValue(false), myIsMouseOverWindow(false),
155 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
156 myIsPopupMenuActive(false), myIsConstraintsShown(true)
158 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
159 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
161 myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
163 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
164 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
166 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
167 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
169 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
170 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
172 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
173 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
175 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
176 XGUI_Workshop* aWorkshop = aConnector->workshop();
177 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
180 PartSet_SketcherMgr::~PartSet_SketcherMgr()
182 if (!myPlaneFilter.IsNull())
183 myPlaneFilter.Nullify();
186 void PartSet_SketcherMgr::onEnterViewPort()
188 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
189 // created feature because it should be done in onMouseMove(). Some widgets watch
190 // the mouse move and use the cursor position to update own values. If the presentaion is
191 // redisplayed before this update, the feature presentation jumps from reset value to current.
192 myIsMouseOverWindow = true;
193 myIsResetCurrentValue = false;
194 operationMgr()->onValidateOperation();
195 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
196 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
199 #ifdef DEBUG_DO_NOT_BY_ENTER
203 if (!isNestedCreateOperation(getCurrentOperation()))
205 // we need change displayed state of the current operation feature
206 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
207 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
208 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
209 // presentation becomes valid and redisplay happens
210 ModuleBase_Operation* aOperation = getCurrentOperation();
212 FeaturePtr aFeature = aOperation->feature();
213 if (aFeature.get() && aFeature->data()->isValid()) {
214 visualizeFeature(aOperation, canDisplayObject(aFeature), false);
219 void PartSet_SketcherMgr::onLeaveViewPort()
221 myIsMouseOverViewProcessed = false;
222 myIsMouseOverWindow = false;
223 operationMgr()->onValidateOperation();
224 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
225 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
228 #ifdef DEBUG_DO_NOT_BY_ENTER
232 if (!isNestedCreateOperation(getCurrentOperation()))
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)
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 && aActiveWgt->reset()) {
250 myIsResetCurrentValue = true;
252 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
254 // hides the presentation of the current operation feature
255 // the feature is to be erased here, but it is correct to call canDisplayObject because
256 // there can be additional check (e.g. editor widget in distance constraint)
257 FeaturePtr aFeature = getCurrentOperation()->feature();
258 visualizeFeature(aOperation, canDisplayObject(aFeature));
261 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
263 if (isNestedCreateOperation(getCurrentOperation()))
265 // it is necessary to save current selection in order to restore it after the values are modifed
268 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
269 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
270 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
271 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
274 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
276 if (isNestedCreateOperation(getCurrentOperation()))
278 // it is necessary to restore current selection in order to restore it after the values are modified
280 myCurrentSelection.clear();
282 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
283 // viewer happens by deselect/select the modified objects. The flag should be restored after
284 // the selection processing. The update viewer should be also called.
285 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
286 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
287 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
288 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
289 aDisplayer->updateViewer();
292 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
294 if (!isNestedCreateOperation(getCurrentOperation()))
297 // visualize the current operation feature
298 myIsResetCurrentValue = false;
299 operationMgr()->onValidateOperation();
300 ModuleBase_Operation* aOperation = getCurrentOperation();
301 // the feature is to be erased here, but it is correct to call canDisplayObject because
302 // there can be additional check (e.g. editor widget in distance constraint)
303 FeaturePtr aFeature = getCurrentOperation()->feature();
304 visualizeFeature(aOperation, canDisplayObject(aFeature));
307 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
309 get2dPoint(theWnd, theEvent, myClickedPoint);
311 if (!(theEvent->buttons() & Qt::LeftButton))
314 // Clear dragging mode
315 myIsDragging = false;
317 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
318 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
319 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
320 if (!aViewer->canDragByMouse())
323 ModuleBase_Operation* aOperation = getCurrentOperation();
324 if (aOperation && aOperation->isEditOperation()) {
325 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
326 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
327 // If the current widget is a selector, do nothing, it processes the mouse press
328 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
333 // Use only for sketch operations
334 if (aOperation && myCurrentSketch) {
335 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
338 bool isSketcher = isSketchOperation(aOperation);
339 bool isSketchOpe = isNestedSketchOperation(aOperation);
341 // Avoid non-sketch operations
342 if ((!isSketchOpe) && (!isSketcher))
345 bool isEditing = aOperation->isEditOperation();
347 // Ignore creation sketch operation
348 if ((!isSketcher) && (!isEditing))
351 // MoveTo in order to highlight current object
352 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
354 // Remember highlighted objects for editing
355 ModuleBase_ISelection* aSelect = aWorkshop->selection();
357 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
358 storeSelection(!aHasShift);
360 if (myCurrentSelection.empty()) {
361 if (isSketchOpe && (!isSketcher))
362 // commit previous operation
363 if (!aOperation->commit())
367 // Init flyout point for radius rotation
368 FeaturePtr aFeature = myCurrentSelection.begin().key();
372 get2dPoint(theWnd, theEvent, myCurrentPoint);
375 if (aFeature.get() != NULL) {
376 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
377 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
378 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
379 DataPtr aData = aSPFeature->data();
380 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
381 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
382 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
383 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
386 } else if (isSketchOpe && isEditing) {
387 // If selected another object commit current result
388 aOperation->commit();
391 get2dPoint(theWnd, theEvent, myCurrentPoint);
394 // This is necessary in order to finalize previous operation
395 QApplication::processEvents();
401 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
403 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
404 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
405 if (!aViewer->canDragByMouse())
407 ModuleBase_Operation* aOp = getCurrentOperation();
409 if (isNestedSketchOperation(aOp)) {
410 get2dPoint(theWnd, theEvent, myClickedPoint);
412 // Only for sketcher operations
416 myCurrentSelection.clear();
417 // Reselect edited object
418 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
419 if (theEvent->modifiers() & Qt::ShiftModifier)
420 aViewer->AISContext()->ShiftSelect();
422 aViewer->AISContext()->Select();
428 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
429 myIsDragging = false;
432 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
434 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
435 myIsMouseOverViewProcessed = true;
436 // 1. perform the widget mouse move functionality and display the presentation
437 ModuleBase_Operation* aOperation = getCurrentOperation();
438 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
439 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
440 // the mouse move should be processed in the widget, if it can in order to visualize correct
441 // presentation. These widgets correct the feature attribute according to the mouse position
442 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
444 aPoint2DWdg->onMouseMove(theWnd, theEvent);
446 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
449 aDistanceWdg->onMouseMove(theWnd, theEvent);
451 // the feature is to be erased here, but it is correct to call canDisplayObject because
452 // there can be additional check (e.g. editor widget in distance constraint)
453 FeaturePtr aFeature = getCurrentOperation()->feature();
454 visualizeFeature(aOperation, canDisplayObject(aFeature));
457 myClickedPoint.clear();
460 // 1. the current selection is saved in the mouse press method in order to restore it after moving
461 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
462 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
463 // deselected). This flag should be restored in the slot, processed the mouse release signal.
464 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
465 aViewer->enableSelection(false);
467 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
468 if (!aCurrentOperation)
470 if (isSketchOperation(aCurrentOperation))
471 return; // No edit operation activated
473 Handle(V3d_View) aView = theWnd->v3dView();
474 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
476 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
477 double dX = aX - myCurrentPoint.myCurX;
478 double dY = aY - myCurrentPoint.myCurY;
480 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
481 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
482 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
483 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
484 // viewer happens by deselect/select the modified objects. The flag should be restored after
485 // the selection processing. The update viewer should be also called.
486 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
488 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
489 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
490 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
491 aLast = myCurrentSelection.end();
492 // 4. the features and attributes modification(move)
493 bool isModified = false;
494 for (; anIt != aLast; anIt++) {
495 FeaturePtr aFeature = anIt.key();
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)
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);
515 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
516 aPoint->setImmutable(isImmutable);
521 // Process selection by feature
522 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
523 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
524 if (aSketchFeature) {
525 aSketchFeature->move(dX, dY);
527 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
531 // the modified state of the current operation should be updated if there are features, which
534 aCurrentOperation->onValuesChanged();
536 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
537 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
539 // 5. it is necessary to save current selection in order to restore it after the features moving
541 // 6. restore the update viewer flag and call this update
542 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
543 aDisplayer->updateViewer();
546 myCurrentPoint.setValue(aX, aY);
550 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
552 ModuleBase_Operation* aOperation = getCurrentOperation();
553 if (aOperation && aOperation->isEditOperation()) {
554 std::string aId = aOperation->id().toStdString();
555 if (isDistanceOperation(aOperation))
557 // Activate dimension value editing on double click
558 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
559 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
560 // Find corresponded widget to activate value editing
561 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
562 if (aWgt->attributeID() == "ConstraintValue") {
571 void PartSet_SketcherMgr::onApplicationStarted()
573 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
574 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
575 XGUI_Workshop* aWorkshop = aConnector->workshop();
576 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
577 if (aPropertyPanel) {
578 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
579 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
582 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
583 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
584 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
586 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
587 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
588 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
591 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
593 if (!myClickedPoint.myIsInitialized)
596 ModuleBase_Operation* aOperation = getCurrentOperation();
597 // the distance constraint feature should not use the clickedd point
598 // this is workaround in order to don't throw down the flyout point value,
599 // set by execute() method of these type of features
600 if (isDistanceOperation(aOperation))
603 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
605 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
609 void PartSet_SketcherMgr::onBeforeContextMenu()
611 myIsPopupMenuActive = true;
614 void PartSet_SketcherMgr::onAfterContextMenu()
616 myIsPopupMenuActive = false;
619 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
622 Handle(V3d_View) aView = theWnd->v3dView();
623 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
625 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
626 thePoint.setValue(aX, anY);
629 void PartSet_SketcherMgr::launchEditing()
631 if (!myCurrentSelection.empty()) {
632 FeaturePtr aFeature = myCurrentSelection.begin().key();
633 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
634 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
636 myModule->editFeature(aSPFeature);
642 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
644 static QStringList aIds;
645 if (aIds.size() == 0) {
646 aIds << SketchPlugin_Line::ID().c_str();
647 aIds << SketchPlugin_Point::ID().c_str();
648 aIds << SketchPlugin_Arc::ID().c_str();
649 aIds << SketchPlugin_Circle::ID().c_str();
650 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
651 aIds.append(constraintsIdList());
656 const QStringList& PartSet_SketcherMgr::constraintsIdList()
658 static QStringList aIds;
659 if (aIds.size() == 0) {
660 aIds << SketchPlugin_ConstraintLength::ID().c_str();
661 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
662 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
663 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
664 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
665 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
666 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
667 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
668 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
669 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
670 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
671 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
672 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
673 aIds << SketchPlugin_MultiRotation::ID().c_str();
674 aIds << SketchPlugin_MultiTranslation::ID().c_str();
679 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
683 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
684 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
685 theModes.append(SketcherPrs_Tools::Sel_Constraint);
686 theModes.append(TopAbs_VERTEX);
687 theModes.append(TopAbs_EDGE);
690 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
692 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
695 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
697 return theOperation &&
698 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
701 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
703 return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
706 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
708 return (theId == SketchPlugin_Line::ID()) ||
709 (theId == SketchPlugin_Point::ID()) ||
710 (theId == SketchPlugin_Arc::ID()) ||
711 (theId == SketchPlugin_Circle::ID());
714 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
716 std::string aId = theOperation ? theOperation->id().toStdString() : "";
718 return (aId == SketchPlugin_ConstraintLength::ID()) ||
719 (aId == SketchPlugin_ConstraintDistance::ID()) ||
720 (aId == SketchPlugin_ConstraintRadius::ID()) ||
721 (aId == SketchPlugin_ConstraintAngle::ID());
724 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
726 myModule->onViewTransformed();
728 // Display all sketcher sub-Objects
729 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
730 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
732 // Hide sketcher result
733 std::list<ResultPtr> aResults = myCurrentSketch->results();
734 std::list<ResultPtr>::const_iterator aIt;
735 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
736 (*aIt)->setDisplayed(false);
738 myCurrentSketch->setDisplayed(false);
740 // Display sketcher objects
741 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
742 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
743 std::list<ResultPtr> aResults = aFeature->results();
744 std::list<ResultPtr>::const_iterator aIt;
745 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
746 (*aIt)->setDisplayed(true);
748 aFeature->setDisplayed(true);
751 if (myPlaneFilter.IsNull())
752 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
754 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
756 bool aHasPlane = false;
757 std::shared_ptr<GeomAPI_Pln> aPln;
758 if (theOperation->isEditOperation()) {
759 // If it is editing of sketch then it means that plane is already defined
760 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
764 myPlaneFilter->setPlane(aPln);
766 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
767 // all sketch objects should be activated in the sketch selection modes by edit operation start
768 // in case of creation operation, there is an active widget, which activates own selection mode
769 if (theOperation->isEditOperation() && aHasPlane)
770 aConnector->activateModuleSelectionModes();
773 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
775 myIsMouseOverWindow = false;
776 myIsConstraintsShown = true;
777 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
778 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
780 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
782 DataPtr aData = myCurrentSketch->data();
783 if (!aData->isValid()) {
784 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
785 // The sketch was aborted
786 myCurrentSketch = CompositeFeaturePtr();
787 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
789 // Erase all sketcher objects
790 QStringList aSketchIds = sketchOperationIdList();
791 QObjectPtrList aObjects = aDisplayer->displayedObjects();
792 foreach (ObjectPtr aObj, aObjects) {
793 DataPtr aObjData = aObj->data();
794 if (!aObjData->isValid())
795 aObj->setDisplayed(false);
799 // Hide all sketcher sub-Objects
800 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
801 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
802 std::list<ResultPtr> aResults = aFeature->results();
803 std::list<ResultPtr>::const_iterator aIt;
804 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
805 (*aIt)->setDisplayed(false);
807 aFeature->setDisplayed(false);
809 // Display sketcher result
810 std::list<ResultPtr> aResults = myCurrentSketch->results();
811 std::list<ResultPtr>::const_iterator aIt;
812 Events_Loop* aLoop = Events_Loop::loop();
813 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
814 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
815 (*aIt)->setDisplayed(true);
816 // this display event is needed because sketch already may have "displayed" state,
817 // but not displayed while it is still active (issue 613, abort of existing sketch)
818 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
820 myCurrentSketch->setDisplayed(true);
822 myCurrentSketch = CompositeFeaturePtr();
823 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
825 Events_Loop::loop()->flush(aDispEvent);
827 // restore the module selection modes, which were changed on startSketch
828 aConnector->activateModuleSelectionModes();
831 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
833 if (constraintsIdList().contains(theOperation->id())) {
834 // Show constraints if a constraint was created
835 onShowConstraintsToggle(true);
837 connectToPropertyPanel(true);
840 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
842 connectToPropertyPanel(false);
843 myIsResetCurrentValue = false;
844 myIsMouseOverViewProcessed = true;
845 operationMgr()->onValidateOperation();
848 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
850 if (isNestedCreateOperation(theOperation)) {
851 FeaturePtr aFeature = theOperation->feature();
852 // it is necessary to check the the feature data validity because
853 // some kind of features are removed by an operation commit(the macro state of a feature)
854 if (aFeature.get() && aFeature->data()->isValid()) {
855 visualizeFeature(theOperation, true);
860 bool PartSet_SketcherMgr::canUndo() const
862 return isNestedCreateOperation(getCurrentOperation());
865 bool PartSet_SketcherMgr::canRedo() const
867 return isNestedCreateOperation(getCurrentOperation());
870 bool PartSet_SketcherMgr::canCommitOperation() const
872 bool aCanCommit = true;
874 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
880 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
882 bool aCanDisplay = true;
884 bool aHasActiveSketch = activeSketch().get() != NULL;
885 if (aHasActiveSketch) {
886 // 1. the sketch feature should not be displayed during the sketch active operation
887 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
888 // nested features can be visualized
889 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
890 if (aFeature.get() != NULL && aFeature == activeSketch()) {
894 else { // there are no an active sketch
895 // 2. sketch sub-features should not be visualized if the sketch operation is not active
896 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
897 if (aFeature.get() != NULL) {
898 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
899 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
900 if (aSketchFeature.get()) {
906 // 3. the method should not filter the objects, which are not related to the current operation.
907 // The object is filtered just if it is a current operation feature or this feature result
908 bool isObjectFound = false;
909 ModuleBase_Operation* anOperation = getCurrentOperation();
911 FeaturePtr aFeature = anOperation->feature();
912 if (aFeature.get()) {
913 std::list<ResultPtr> aResults = aFeature->results();
914 if (theObject == aFeature)
915 isObjectFound = true;
917 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
918 for (; anIt != aLast; anIt++) {
919 isObjectFound = *anIt == theObject;
927 // 4. For created nested feature operation do not display the created feature if
928 // the mouse curstor leaves the OCC window.
929 // The correction cases, which ignores this condition:
930 // a. the property panel values modification
931 // b. the popup menu activated
932 // c. widget editor control
933 #ifndef DEBUG_DO_NOT_BY_ENTER
934 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
935 ModuleBase_Operation* aOperation = getCurrentOperation();
936 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
937 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
938 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
939 // the active widget editor should not influence here. The presentation should be visible always
940 // when this widget is active.
941 if (!anEditorWdg && !myIsPopupMenuActive) {
942 // during a nested create operation, the feature is redisplayed only if the mouse over view
943 // of there was a value modified in the property panel after the mouse left the view
944 aCanDisplay = canDisplayCurrentCreatedFeature();
951 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
953 return myIsMouseOverWindow || !myIsResetCurrentValue;
954 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
955 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
959 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
961 bool isFoundObject = false;
963 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
964 if (anObjectFeature.get()) {
965 int aSize = myCurrentSketch->numberOfSubs();
966 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
967 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
968 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
971 return isFoundObject;
974 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
976 if (myPlaneFilter.IsNull())
977 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
979 myPlaneFilter->setPlane(thePln);
982 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
983 const FeaturePtr& theSketch,
984 ModuleBase_IWorkshop* theWorkshop,
985 FeatureToSelectionMap& theSelection)
987 if (theFeature.get() == NULL)
990 std::set<AttributePtr> aSelectedAttributes;
991 std::set<ResultPtr> aSelectedResults;
993 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
994 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
995 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
996 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
998 std::list<ResultPtr> aResults = theFeature->results();
999 std::list<ResultPtr>::const_iterator aIt;
1000 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1002 ResultPtr aResult = *aIt;
1003 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1004 if (aAISObj.get() == NULL)
1006 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1007 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1009 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1010 if (anOwner->Selectable() != anAISIO)
1012 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1013 aSelectedAttributes, aSelectedResults);
1015 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1016 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1017 if (anOwner.IsNull())
1019 if (anOwner->Selectable() != anAISIO)
1021 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1022 aSelectedAttributes, aSelectedResults);
1025 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1028 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1029 const FeaturePtr& theSketch,
1030 ModuleBase_IWorkshop* theWorkshop,
1031 const FeatureToSelectionMap& theSelection,
1032 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1034 if (theFeature.get() == NULL)
1037 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1038 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1039 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1041 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1042 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1043 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1044 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1046 // 1. found the feature's owners. Check the AIS objects of the constructions
1047 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1048 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1049 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
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(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1055 if (!anOwner.IsNull())
1056 anOwnersToSelect.Add(anOwner);
1060 // 2. found the feature results's owners
1061 std::list<ResultPtr> aResults = theFeature->results();
1062 std::list<ResultPtr>::const_iterator aIt;
1063 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1065 ResultPtr aResult = *aIt;
1066 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1067 if (aAISObj.get() == NULL)
1069 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1071 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1072 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1073 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1074 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1075 if ( anOwner.IsNull() || !anOwner->HasShape() )
1077 const TopoDS_Shape& aShape = anOwner->Shape();
1078 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1079 if (aShapeType == TopAbs_VERTEX) {
1080 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1081 if (aPntAttr.get() != NULL &&
1082 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1083 anOwnersToSelect.Add(anOwner);
1086 else if (aShapeType == TopAbs_EDGE) {
1087 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1088 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1089 anOwnersToSelect.FindIndex(anOwner) <= 0)
1090 anOwnersToSelect.Add(anOwner);
1096 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1098 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1099 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1100 XGUI_Workshop* aWorkshop = aConnector->workshop();
1101 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1102 if (aPropertyPanel) {
1103 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1104 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1106 connect(aWidget, SIGNAL(beforeValuesChanged()),
1107 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1108 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1109 connect(aWidget, SIGNAL(afterValuesChanged()),
1110 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1113 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1114 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1115 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1116 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1117 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1123 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1125 return myModule->workshop()->currentOperation();
1128 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1129 const bool isToDisplay,
1130 const bool isFlushRedisplay)
1132 #ifdef DEBUG_DO_NOT_BY_ENTER
1136 if (!theOperation || theOperation->isEditOperation())
1139 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1140 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1142 // 1. change visibility of the object itself, here the presentable object is processed,
1143 // e.g. constraints features
1144 FeaturePtr aFeature = theOperation->feature();
1145 std::list<ResultPtr> aResults = aFeature->results();
1147 aFeature->setDisplayed(true);
1149 aFeature->setDisplayed(false);
1151 // change visibility of the object results, e.g. non-constraint features
1152 std::list<ResultPtr>::const_iterator aIt;
1153 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1155 (*aIt)->setDisplayed(true);
1158 (*aIt)->setDisplayed(false);
1161 if (isFlushRedisplay)
1162 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1165 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1167 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1168 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1169 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1171 QList<FeaturePtr> aFeatureList;
1172 if (theHighlightedOnly) {
1173 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1176 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1178 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1179 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1182 // 1. it is necessary to save current selection in order to restore it after the features moving
1183 myCurrentSelection.clear();
1184 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1185 for (; anIt != aLast; anIt++) {
1186 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1188 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1191 void PartSet_SketcherMgr::restoreSelection()
1193 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1194 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1195 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1196 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1197 aSLast = myCurrentSelection.end();
1198 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1199 for (; aSIt != aSLast; aSIt++) {
1200 anOwnersToSelect.Clear();
1201 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1203 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1207 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1209 if (myIsConstraintsShown == theOn)
1211 if (myCurrentSketch.get() == NULL)
1214 myIsConstraintsShown = theOn;
1216 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1217 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1219 const QStringList& aConstrIds = constraintsIdList();
1220 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1221 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1222 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1223 if (myIsConstraintsShown)
1224 aSubFeature->setDisplayed(true);
1226 aSubFeature->setDisplayed(false);
1229 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1232 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1234 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1235 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1238 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1240 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1241 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1242 XGUI_Workshop* aWorkshop = aConnector->workshop();
1244 return aWorkshop->operationMgr();