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_MultiRotation.h>
59 #include <SketchPlugin_MultiTranslation.h>
61 #include <SketcherPrs_Tools.h>
63 #include <SelectMgr_IndexedMapOfOwner.hxx>
64 #include <StdSelect_BRepOwner.hxx>
66 //#include <AIS_DimensionSelectionMode.hxx>
67 #include <AIS_Shape.hxx>
69 #include <ModelAPI_Events.h>
70 #include <ModelAPI_Session.h>
72 #include <QMouseEvent>
73 #include <QApplication>
75 //#define DEBUG_DO_NOT_BY_ENTER
76 //#define DEBUG_MOUSE_OVER_WINDOW_FLAGS
78 /// Returns list of unique objects by sum of objects from List1 and List2
79 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
80 const QList<ModuleBase_ViewerPrs>& theList2)
82 QList<ModuleBase_ViewerPrs> aRes;
83 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
84 if (!aRes.contains(aPrs))
87 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
88 if (!aRes.contains(aPrs))
94 // Fills the list of features the list of selected presentations.
95 // \param theList a list of selected presentations
96 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
97 // and find the corresponded attribute
98 // \param theFeatureList an output list of features
99 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
100 const FeaturePtr theSketch,
101 QList<FeaturePtr>& theFeatureList)
103 QList<ModuleBase_ViewerPrs> aRes;
105 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
106 aLast = theList.end();
107 for (; anIt != aLast; anIt++)
109 ModuleBase_ViewerPrs aPrs = *anIt;
110 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
111 if (aFeature.get() && !theFeatureList.contains(aFeature))
112 theFeatureList.append(aFeature);
116 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
117 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
118 /// result as is to the list of results.
119 /// \param theOwner a viewer selected owner
120 /// \param theFeature a feature, where the attribute is searched
121 /// \param theSketch a current sketch
122 /// \param theSelectedAttribute an output list of attributes
123 /// \param theSelectedResults an output list of edge results
124 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
125 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
126 const ResultPtr& theResult,
127 std::set<AttributePtr>& aSelectedAttributes,
128 std::set<ResultPtr>& aSelectedResults)
130 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
131 if (aBRepOwner.IsNull())
133 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
134 aBRepOwner->Selectable());
135 if (aBRepOwner->HasShape()) {
136 const TopoDS_Shape& aShape = aBRepOwner->Shape();
137 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
138 if (aShapeType == TopAbs_VERTEX) {
139 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
141 if (aPntAttr.get() != NULL)
142 aSelectedAttributes.insert(aPntAttr);
144 else if (aShapeType == TopAbs_EDGE &&
145 aSelectedResults.find(theResult) == aSelectedResults.end()) {
146 aSelectedResults.insert(theResult);
151 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
152 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
153 myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false),
154 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
155 myIsPopupMenuActive(false), myIsConstraintsShown(true)
157 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
158 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
160 myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
162 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
163 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
165 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
166 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
168 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
169 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
171 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
172 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
174 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
175 XGUI_Workshop* aWorkshop = aConnector->workshop();
176 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
179 PartSet_SketcherMgr::~PartSet_SketcherMgr()
181 if (!myPlaneFilter.IsNull())
182 myPlaneFilter.Nullify();
185 void PartSet_SketcherMgr::onEnterViewPort()
187 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
188 // created feature because it should be done in onMouseMove(). Some widgets watch
189 // the mouse move and use the cursor position to update own values. If the presentaion is
190 // redisplayed before this update, the feature presentation jumps from reset value to current.
191 myIsMouseOverWindow = true;
192 myIsPropertyPanelValueChanged = false;
193 operationMgr()->onValidateOperation();
194 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
195 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
198 #ifdef DEBUG_DO_NOT_BY_ENTER
202 if (!isNestedCreateOperation(getCurrentOperation()))
204 // we need change displayed state of the current operation feature
205 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
206 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
207 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
208 // presentation becomes valid and redisplay happens
209 ModuleBase_Operation* aOperation = getCurrentOperation();
211 FeaturePtr aFeature = aOperation->feature();
212 if (aFeature.get() && aFeature->data()->isValid()) {
213 visualizeFeature(aOperation, canDisplayObject(aFeature), false);
218 void PartSet_SketcherMgr::onLeaveViewPort()
220 myIsMouseOverViewProcessed = false;
221 myIsMouseOverWindow = false;
222 myIsPropertyPanelValueChanged = false;
223 operationMgr()->onValidateOperation();
224 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
225 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
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();
252 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
254 // hides the presentation of the current operation feature
255 //myIsPropertyPanelValueChanged = false;
256 // the feature is to be erased here, but it is correct to call canDisplayObject because
257 // there can be additional check (e.g. editor widget in distance constraint)
258 FeaturePtr aFeature = getCurrentOperation()->feature();
259 visualizeFeature(aOperation, canDisplayObject(aFeature));
262 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
264 if (isNestedCreateOperation(getCurrentOperation()))
266 // it is necessary to save current selection in order to restore it after the values are modifed
269 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
270 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
271 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
272 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
275 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
277 if (isNestedCreateOperation(getCurrentOperation()))
279 // it is necessary to restore current selection in order to restore it after the values are modified
281 myCurrentSelection.clear();
283 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
284 // viewer happens by deselect/select the modified objects. The flag should be restored after
285 // the selection processing. The update viewer should be also called.
286 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
287 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
288 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
289 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
290 aDisplayer->updateViewer();
293 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
295 if (!isNestedCreateOperation(getCurrentOperation()))
298 // visualize the current operation feature
299 myIsPropertyPanelValueChanged = true;
300 operationMgr()->onValidateOperation();
301 ModuleBase_Operation* aOperation = getCurrentOperation();
302 // the feature is to be erased here, but it is correct to call canDisplayObject because
303 // there can be additional check (e.g. editor widget in distance constraint)
304 FeaturePtr aFeature = getCurrentOperation()->feature();
305 visualizeFeature(aOperation, canDisplayObject(aFeature));
308 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
310 get2dPoint(theWnd, theEvent, myClickedPoint);
312 if (!(theEvent->buttons() & Qt::LeftButton))
315 // Clear dragging mode
316 myIsDragging = false;
318 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
319 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
320 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
321 if (!aViewer->canDragByMouse())
324 ModuleBase_Operation* aOperation = getCurrentOperation();
325 if (aOperation && aOperation->isEditOperation()) {
326 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
327 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
328 // If the current widget is a selector, do nothing, it processes the mouse press
329 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
334 // Use only for sketch operations
335 if (aOperation && myCurrentSketch) {
336 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
339 bool isSketcher = isSketchOperation(aOperation);
340 bool isSketchOpe = isNestedSketchOperation(aOperation);
342 // Avoid non-sketch operations
343 if ((!isSketchOpe) && (!isSketcher))
346 bool isEditing = aOperation->isEditOperation();
348 // Ignore creation sketch operation
349 if ((!isSketcher) && (!isEditing))
352 // MoveTo in order to highlight current object
353 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
355 // Remember highlighted objects for editing
356 ModuleBase_ISelection* aSelect = aWorkshop->selection();
358 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
359 storeSelection(!aHasShift);
361 if (myCurrentSelection.empty()) {
362 if (isSketchOpe && (!isSketcher))
363 // commit previous operation
364 if (!aOperation->commit())
368 // Init flyout point for radius rotation
369 FeaturePtr aFeature = myCurrentSelection.begin().key();
373 get2dPoint(theWnd, theEvent, myCurrentPoint);
376 if (aFeature.get() != NULL) {
377 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
378 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
379 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
380 DataPtr aData = aSPFeature->data();
381 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
382 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
383 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
384 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
387 } else if (isSketchOpe && isEditing) {
388 // If selected another object commit current result
389 aOperation->commit();
392 get2dPoint(theWnd, theEvent, myCurrentPoint);
395 // This is necessary in order to finalize previous operation
396 QApplication::processEvents();
402 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
404 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
405 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
406 if (!aViewer->canDragByMouse())
408 ModuleBase_Operation* aOp = getCurrentOperation();
410 if (isNestedSketchOperation(aOp)) {
411 get2dPoint(theWnd, theEvent, myClickedPoint);
413 // Only for sketcher operations
417 myCurrentSelection.clear();
418 // Reselect edited object
419 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
420 if (theEvent->modifiers() & Qt::ShiftModifier)
421 aViewer->AISContext()->ShiftSelect();
423 aViewer->AISContext()->Select();
429 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
430 myIsDragging = false;
433 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
435 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
436 myIsMouseOverViewProcessed = true;
437 // 1. perform the widget mouse move functionality and display the presentation
438 ModuleBase_Operation* aOperation = getCurrentOperation();
439 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
440 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
441 // the mouse move should be processed in the widget, if it can in order to visualize correct
442 // presentation. These widgets correct the feature attribute according to the mouse position
443 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
445 aPoint2DWdg->onMouseMove(theWnd, theEvent);
447 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
450 aDistanceWdg->onMouseMove(theWnd, theEvent);
452 // the feature is to be erased here, but it is correct to call canDisplayObject because
453 // there can be additional check (e.g. editor widget in distance constraint)
454 FeaturePtr aFeature = getCurrentOperation()->feature();
455 visualizeFeature(aOperation, canDisplayObject(aFeature));
458 myClickedPoint.clear();
461 // 1. the current selection is saved in the mouse press method in order to restore it after moving
462 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
463 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
464 // deselected). This flag should be restored in the slot, processed the mouse release signal.
465 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
466 aViewer->enableSelection(false);
468 ModuleBase_Operation* aOperation = getCurrentOperation();
471 if (isSketchOperation(aOperation))
472 return; // No edit operation activated
474 Handle(V3d_View) aView = theWnd->v3dView();
475 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
477 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
478 double dX = aX - myCurrentPoint.myCurX;
479 double dY = aY - myCurrentPoint.myCurY;
481 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
482 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
483 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
484 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
485 // viewer happens by deselect/select the modified objects. The flag should be restored after
486 // the selection processing. The update viewer should be also called.
487 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
489 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
490 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
491 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
492 aLast = myCurrentSelection.end();
493 // 4. the features and attributes modification(move)
494 for (; anIt != aLast; anIt++) {
495 FeaturePtr aFeature = anIt.key();
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);
514 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
515 aPoint->setImmutable(isImmutable);
520 // Process selection by feature
521 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
522 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
523 if (aSketchFeature) {
524 aSketchFeature->move(dX, dY);
525 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
529 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
530 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
532 // 5. it is necessary to save current selection in order to restore it after the features moving
534 // 6. restore the update viewer flag and call this update
535 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
536 aDisplayer->updateViewer();
539 myCurrentPoint.setValue(aX, aY);
543 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
545 ModuleBase_Operation* aOperation = getCurrentOperation();
546 if (aOperation && aOperation->isEditOperation()) {
547 std::string aId = aOperation->id().toStdString();
548 if (isDistanceOperation(aOperation))
550 // Activate dimension value editing on double click
551 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
552 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
553 // Find corresponded widget to activate value editing
554 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
555 if (aWgt->attributeID() == "ConstraintValue") {
564 void PartSet_SketcherMgr::onApplicationStarted()
566 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
567 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
568 XGUI_Workshop* aWorkshop = aConnector->workshop();
569 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
570 if (aPropertyPanel) {
571 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
572 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
575 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
576 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
577 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
579 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
580 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
581 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
584 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
586 if (!myClickedPoint.myIsInitialized)
589 ModuleBase_Operation* aOperation = getCurrentOperation();
590 // the distance constraint feature should not use the clickedd point
591 // this is workaround in order to don't throw down the flyout point value,
592 // set by execute() method of these type of features
593 if (isDistanceOperation(aOperation))
596 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
598 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
602 void PartSet_SketcherMgr::onBeforeContextMenu()
604 myIsPopupMenuActive = true;
607 void PartSet_SketcherMgr::onAfterContextMenu()
609 myIsPopupMenuActive = false;
612 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
615 Handle(V3d_View) aView = theWnd->v3dView();
616 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
618 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
619 thePoint.setValue(aX, anY);
622 void PartSet_SketcherMgr::launchEditing()
624 if (!myCurrentSelection.empty()) {
625 FeaturePtr aFeature = myCurrentSelection.begin().key();
626 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
627 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
629 myModule->editFeature(aSPFeature);
635 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
637 static QStringList aIds;
638 if (aIds.size() == 0) {
639 aIds << SketchPlugin_Line::ID().c_str();
640 aIds << SketchPlugin_Point::ID().c_str();
641 aIds << SketchPlugin_Arc::ID().c_str();
642 aIds << SketchPlugin_Circle::ID().c_str();
643 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
644 aIds.append(constraintsIdList());
649 const QStringList& PartSet_SketcherMgr::constraintsIdList()
651 static QStringList aIds;
652 if (aIds.size() == 0) {
653 aIds << SketchPlugin_ConstraintLength::ID().c_str();
654 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
655 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
656 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
657 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
658 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
659 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
660 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
661 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
662 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
663 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
664 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
665 aIds << SketchPlugin_MultiRotation::ID().c_str();
666 aIds << SketchPlugin_MultiTranslation::ID().c_str();
671 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
675 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
676 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
677 theModes.append(SketcherPrs_Tools::Sel_Constraint);
678 theModes.append(TopAbs_VERTEX);
679 theModes.append(TopAbs_EDGE);
682 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
684 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
687 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
689 return theOperation &&
690 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
693 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
695 return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
698 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
700 return (theId == SketchPlugin_Line::ID()) ||
701 (theId == SketchPlugin_Point::ID()) ||
702 (theId == SketchPlugin_Arc::ID()) ||
703 (theId == SketchPlugin_Circle::ID());
706 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
708 std::string aId = theOperation ? theOperation->id().toStdString() : "";
710 return (aId == SketchPlugin_ConstraintLength::ID()) ||
711 (aId == SketchPlugin_ConstraintDistance::ID()) ||
712 (aId == SketchPlugin_ConstraintRadius::ID());
715 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
717 myModule->onViewTransformed();
719 // Display all sketcher sub-Objects
720 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
721 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
723 // Hide sketcher result
724 std::list<ResultPtr> aResults = myCurrentSketch->results();
725 std::list<ResultPtr>::const_iterator aIt;
726 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
727 (*aIt)->setDisplayed(false);
729 myCurrentSketch->setDisplayed(false);
731 // Display sketcher objects
732 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
733 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
734 std::list<ResultPtr> aResults = aFeature->results();
735 std::list<ResultPtr>::const_iterator aIt;
736 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
737 (*aIt)->setDisplayed(true);
739 aFeature->setDisplayed(true);
742 if (myPlaneFilter.IsNull())
743 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
745 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
747 bool aHasPlane = false;
748 if (theOperation->isEditOperation()) {
749 // If it is editing of sketch then it means that plane is already defined
750 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
752 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
756 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
757 // all sketch objects should be activated in the sketch selection modes by edit operation start
758 // in case of creation operation, there is an active widget, which activates own selection mode
759 if (theOperation->isEditOperation() && aHasPlane)
760 aConnector->activateModuleSelectionModes();
763 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
765 myIsMouseOverWindow = false;
766 myIsConstraintsShown = true;
767 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
768 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
770 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
772 DataPtr aData = myCurrentSketch->data();
773 if (!aData->isValid()) {
774 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
775 // The sketch was aborted
776 myCurrentSketch = CompositeFeaturePtr();
777 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
779 // Erase all sketcher objects
780 QStringList aSketchIds = sketchOperationIdList();
781 QObjectPtrList aObjects = aDisplayer->displayedObjects();
782 foreach (ObjectPtr aObj, aObjects) {
783 DataPtr aObjData = aObj->data();
784 if (!aObjData->isValid())
785 aObj->setDisplayed(false);
789 // Hide all sketcher sub-Objects
790 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
791 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
792 std::list<ResultPtr> aResults = aFeature->results();
793 std::list<ResultPtr>::const_iterator aIt;
794 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
795 (*aIt)->setDisplayed(false);
797 aFeature->setDisplayed(false);
799 // Display sketcher result
800 std::list<ResultPtr> aResults = myCurrentSketch->results();
801 std::list<ResultPtr>::const_iterator aIt;
802 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
803 (*aIt)->setDisplayed(true);
805 myCurrentSketch->setDisplayed(true);
807 myCurrentSketch = CompositeFeaturePtr();
808 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
810 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
812 // restore the module selection modes, which were changed on startSketch
813 aConnector->activateModuleSelectionModes();
816 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
818 if (constraintsIdList().contains(theOperation->id())) {
819 // Show constraints if a constraint was created
820 onShowConstraintsToggle(true);
822 connectToPropertyPanel(true);
825 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
827 connectToPropertyPanel(false);
828 myIsPropertyPanelValueChanged = false;
829 myIsMouseOverViewProcessed = true;
830 operationMgr()->onValidateOperation();
833 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
835 if (isNestedCreateOperation(theOperation)) {
836 FeaturePtr aFeature = theOperation->feature();
837 // it is necessary to check the the feature data validity because
838 // some kind of features are removed by an operation commit(the macro state of a feature)
839 if (aFeature.get() && aFeature->data()->isValid()) {
840 visualizeFeature(theOperation, true);
845 bool PartSet_SketcherMgr::canUndo() const
847 return isNestedCreateOperation(getCurrentOperation());
850 bool PartSet_SketcherMgr::canRedo() const
852 return isNestedCreateOperation(getCurrentOperation());
855 bool PartSet_SketcherMgr::canCommitOperation() const
857 bool aCanCommit = true;
859 if (isNestedCreateOperation(getCurrentOperation()) && !canDisplayCurrentCreatedFeature())
865 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
867 bool aCanDisplay = true;
869 bool aHasActiveSketch = activeSketch().get() != NULL;
870 if (aHasActiveSketch) {
871 // 1. the sketch feature should not be displayed during the sketch active operation
872 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
873 // nested features can be visualized
874 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
875 if (aFeature.get() != NULL && aFeature == activeSketch()) {
879 else { // there are no an active sketch
880 // 2. sketch sub-features should not be visualized if the sketch operation is not active
881 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
882 if (aFeature.get() != NULL) {
883 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
884 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
885 if (aSketchFeature.get()) {
891 // 3. the method should not filter the objects, which are not related to the current operation.
892 // The object is filtered just if it is a current operation feature or this feature result
893 bool isObjectFound = false;
894 ModuleBase_Operation* anOperation = getCurrentOperation();
896 FeaturePtr aFeature = anOperation->feature();
897 if (aFeature.get()) {
898 std::list<ResultPtr> aResults = aFeature->results();
899 if (theObject == aFeature)
900 isObjectFound = true;
902 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
903 for (; anIt != aLast; anIt++) {
904 isObjectFound = *anIt == theObject;
912 // 4. For created nested feature operation do not display the created feature if
913 // the mouse curstor leaves the OCC window.
914 // The correction cases, which ignores this condition:
915 // a. the property panel values modification
916 // b. the popup menu activated
917 // c. widget editor control
918 #ifndef DEBUG_DO_NOT_BY_ENTER
919 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
920 ModuleBase_Operation* aOperation = getCurrentOperation();
921 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
922 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
923 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
924 // the active widget editor should not influence here. The presentation should be visible always
925 // when this widget is active.
926 if (!anEditorWdg && !myIsPopupMenuActive) {
927 // during a nested create operation, the feature is redisplayed only if the mouse over view
928 // of there was a value modified in the property panel after the mouse left the view
929 aCanDisplay = canDisplayCurrentCreatedFeature();
936 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
938 return myIsPropertyPanelValueChanged || myIsMouseOverWindow;
939 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
940 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
944 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
946 bool isFoundObject = false;
948 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
949 if (anObjectFeature.get()) {
950 int aSize = myCurrentSketch->numberOfSubs();
951 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
952 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
953 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
956 return isFoundObject;
959 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
961 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
964 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
965 const FeaturePtr& theSketch,
966 ModuleBase_IWorkshop* theWorkshop,
967 FeatureToSelectionMap& theSelection)
969 if (theFeature.get() == NULL)
972 std::set<AttributePtr> aSelectedAttributes;
973 std::set<ResultPtr> aSelectedResults;
975 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
976 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
977 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
978 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
980 std::list<ResultPtr> aResults = theFeature->results();
981 std::list<ResultPtr>::const_iterator aIt;
982 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
984 ResultPtr aResult = *aIt;
985 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
986 if (aAISObj.get() == NULL)
988 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
989 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
991 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
992 if (anOwner->Selectable() != anAISIO)
994 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
995 aSelectedAttributes, aSelectedResults);
997 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
998 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
999 if (anOwner->Selectable() != anAISIO)
1001 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1002 aSelectedAttributes, aSelectedResults);
1005 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1008 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1009 const FeaturePtr& theSketch,
1010 ModuleBase_IWorkshop* theWorkshop,
1011 const FeatureToSelectionMap& theSelection,
1012 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1014 if (theFeature.get() == NULL)
1017 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1018 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1019 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1021 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1022 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1023 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1024 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1026 // 1. found the feature's owners. Check the AIS objects of the constructions
1027 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1028 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1029 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1031 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1032 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1033 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1034 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1035 if (!anOwner.IsNull())
1036 anOwnersToSelect.Add(anOwner);
1040 // 2. found the feature results's owners
1041 std::list<ResultPtr> aResults = theFeature->results();
1042 std::list<ResultPtr>::const_iterator aIt;
1043 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1045 ResultPtr aResult = *aIt;
1046 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1047 if (aAISObj.get() == NULL)
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(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1055 if ( anOwner.IsNull() || !anOwner->HasShape() )
1057 const TopoDS_Shape& aShape = anOwner->Shape();
1058 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1059 if (aShapeType == TopAbs_VERTEX) {
1060 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1061 if (aPntAttr.get() != NULL &&
1062 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1063 anOwnersToSelect.Add(anOwner);
1066 else if (aShapeType == TopAbs_EDGE) {
1067 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1068 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1069 anOwnersToSelect.FindIndex(anOwner) <= 0)
1070 anOwnersToSelect.Add(anOwner);
1076 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1078 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1079 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1080 XGUI_Workshop* aWorkshop = aConnector->workshop();
1081 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1082 if (aPropertyPanel) {
1083 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1084 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1086 connect(aWidget, SIGNAL(beforeValuesChanged()),
1087 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1088 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1089 connect(aWidget, SIGNAL(afterValuesChanged()),
1090 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1093 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1094 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1095 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1096 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1097 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1103 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1105 return myModule->workshop()->currentOperation();
1108 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1109 const bool isToDisplay,
1110 const bool isFlushRedisplay)
1112 #ifdef DEBUG_DO_NOT_BY_ENTER
1116 if (!theOperation || theOperation->isEditOperation())
1119 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1120 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1122 // 1. change visibility of the object itself, here the presentable object is processed,
1123 // e.g. constraints features
1124 FeaturePtr aFeature = theOperation->feature();
1125 std::list<ResultPtr> aResults = aFeature->results();
1127 aFeature->setDisplayed(true);
1129 aFeature->setDisplayed(false);
1131 // change visibility of the object results, e.g. non-constraint features
1132 std::list<ResultPtr>::const_iterator aIt;
1133 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1135 (*aIt)->setDisplayed(true);
1138 (*aIt)->setDisplayed(false);
1141 if (isFlushRedisplay)
1142 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1145 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1147 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1148 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1149 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1151 QList<FeaturePtr> aFeatureList;
1152 if (theHighlightedOnly) {
1153 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1156 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1158 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1159 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1162 // 1. it is necessary to save current selection in order to restore it after the features moving
1163 myCurrentSelection.clear();
1164 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1165 for (; anIt != aLast; anIt++) {
1166 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1168 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1171 void PartSet_SketcherMgr::restoreSelection()
1173 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1174 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1175 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1176 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1177 aSLast = myCurrentSelection.end();
1178 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1179 for (; aSIt != aSLast; aSIt++) {
1180 anOwnersToSelect.Clear();
1181 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1183 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1187 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1189 if (myIsConstraintsShown == theOn)
1191 if (myCurrentSketch.get() == NULL)
1194 myIsConstraintsShown = theOn;
1196 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1197 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1199 const QStringList& aConstrIds = constraintsIdList();
1200 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1201 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1202 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1203 if (myIsConstraintsShown)
1204 aSubFeature->setDisplayed(true);
1206 aSubFeature->setDisplayed(false);
1209 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1212 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1214 return QString("myIsPropertyPanelValueChanged = %1, myIsMouseOverWindow = %2")
1215 .arg(myIsPropertyPanelValueChanged).arg(myIsMouseOverWindow);
1218 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1220 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1221 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1222 XGUI_Workshop* aWorkshop = aConnector->workshop();
1224 return aWorkshop->operationMgr();