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 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* aOperation = getCurrentOperation();
470 if (isSketchOperation(aOperation))
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 for (; anIt != aLast; anIt++) {
494 FeaturePtr aFeature = anIt.key();
496 std::set<AttributePtr> anAttributes = anIt.value().first;
497 // Process selection by attribute: the priority to the attribute
498 if (!anAttributes.empty()) {
499 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
500 anAttLast = anAttributes.end();
501 for (; anAttIt != anAttLast; anAttIt++) {
502 AttributePtr anAttr = *anAttIt;
503 if (anAttr.get() == NULL)
505 std::string aAttrId = anAttr->id();
506 DataPtr aData = aFeature->data();
507 if (aData->isValid()) {
508 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
509 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
510 if (aPoint.get() != NULL) {
511 bool isImmutable = aPoint->setImmutable(true);
512 aPoint->move(dX, dY);
513 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
514 aPoint->setImmutable(isImmutable);
519 // Process selection by feature
520 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
521 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
522 if (aSketchFeature) {
523 aSketchFeature->move(dX, dY);
524 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
528 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
529 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
531 // 5. it is necessary to save current selection in order to restore it after the features moving
533 // 6. restore the update viewer flag and call this update
534 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
535 aDisplayer->updateViewer();
538 myCurrentPoint.setValue(aX, aY);
542 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
544 ModuleBase_Operation* aOperation = getCurrentOperation();
545 if (aOperation && aOperation->isEditOperation()) {
546 std::string aId = aOperation->id().toStdString();
547 if (isDistanceOperation(aOperation))
549 // Activate dimension value editing on double click
550 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
551 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
552 // Find corresponded widget to activate value editing
553 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
554 if (aWgt->attributeID() == "ConstraintValue") {
563 void PartSet_SketcherMgr::onApplicationStarted()
565 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
566 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
567 XGUI_Workshop* aWorkshop = aConnector->workshop();
568 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
569 if (aPropertyPanel) {
570 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
571 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
574 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
575 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
576 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
578 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
579 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
580 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
583 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
585 if (!myClickedPoint.myIsInitialized)
588 ModuleBase_Operation* aOperation = getCurrentOperation();
589 // the distance constraint feature should not use the clickedd point
590 // this is workaround in order to don't throw down the flyout point value,
591 // set by execute() method of these type of features
592 if (isDistanceOperation(aOperation))
595 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
597 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
601 void PartSet_SketcherMgr::onBeforeContextMenu()
603 myIsPopupMenuActive = true;
606 void PartSet_SketcherMgr::onAfterContextMenu()
608 myIsPopupMenuActive = false;
611 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
614 Handle(V3d_View) aView = theWnd->v3dView();
615 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
617 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
618 thePoint.setValue(aX, anY);
621 void PartSet_SketcherMgr::launchEditing()
623 if (!myCurrentSelection.empty()) {
624 FeaturePtr aFeature = myCurrentSelection.begin().key();
625 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
626 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
628 myModule->editFeature(aSPFeature);
634 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
636 static QStringList aIds;
637 if (aIds.size() == 0) {
638 aIds << SketchPlugin_Line::ID().c_str();
639 aIds << SketchPlugin_Point::ID().c_str();
640 aIds << SketchPlugin_Arc::ID().c_str();
641 aIds << SketchPlugin_Circle::ID().c_str();
642 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
643 aIds.append(constraintsIdList());
648 const QStringList& PartSet_SketcherMgr::constraintsIdList()
650 static QStringList aIds;
651 if (aIds.size() == 0) {
652 aIds << SketchPlugin_ConstraintLength::ID().c_str();
653 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
654 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
655 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
656 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
657 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
658 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
659 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
660 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
661 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
662 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
663 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
664 aIds << SketchPlugin_MultiRotation::ID().c_str();
665 aIds << SketchPlugin_MultiTranslation::ID().c_str();
670 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
674 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
675 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
676 theModes.append(SketcherPrs_Tools::Sel_Constraint);
677 theModes.append(TopAbs_VERTEX);
678 theModes.append(TopAbs_EDGE);
681 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
683 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
686 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
688 return theOperation &&
689 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
692 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
694 return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
697 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
699 return (theId == SketchPlugin_Line::ID()) ||
700 (theId == SketchPlugin_Point::ID()) ||
701 (theId == SketchPlugin_Arc::ID()) ||
702 (theId == SketchPlugin_Circle::ID());
705 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
707 std::string aId = theOperation ? theOperation->id().toStdString() : "";
709 return (aId == SketchPlugin_ConstraintLength::ID()) ||
710 (aId == SketchPlugin_ConstraintDistance::ID()) ||
711 (aId == SketchPlugin_ConstraintRadius::ID());
714 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
716 myModule->onViewTransformed();
718 // Display all sketcher sub-Objects
719 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
720 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
722 // Hide sketcher result
723 std::list<ResultPtr> aResults = myCurrentSketch->results();
724 std::list<ResultPtr>::const_iterator aIt;
725 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
726 (*aIt)->setDisplayed(false);
728 myCurrentSketch->setDisplayed(false);
730 // Display sketcher objects
731 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
732 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
733 std::list<ResultPtr> aResults = aFeature->results();
734 std::list<ResultPtr>::const_iterator aIt;
735 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
736 (*aIt)->setDisplayed(true);
738 aFeature->setDisplayed(true);
741 if (myPlaneFilter.IsNull())
742 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
744 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
746 bool aHasPlane = false;
747 if (theOperation->isEditOperation()) {
748 // If it is editing of sketch then it means that plane is already defined
749 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
751 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
755 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
756 // all sketch objects should be activated in the sketch selection modes by edit operation start
757 // in case of creation operation, there is an active widget, which activates own selection mode
758 if (theOperation->isEditOperation() && aHasPlane)
759 aConnector->activateModuleSelectionModes();
762 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
764 myIsMouseOverWindow = false;
765 myIsConstraintsShown = true;
766 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
767 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
769 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
771 DataPtr aData = myCurrentSketch->data();
772 if (!aData->isValid()) {
773 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
774 // The sketch was aborted
775 myCurrentSketch = CompositeFeaturePtr();
776 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
778 // Erase all sketcher objects
779 QStringList aSketchIds = sketchOperationIdList();
780 QObjectPtrList aObjects = aDisplayer->displayedObjects();
781 foreach (ObjectPtr aObj, aObjects) {
782 DataPtr aObjData = aObj->data();
783 if (!aObjData->isValid())
784 aObj->setDisplayed(false);
788 // Hide all sketcher sub-Objects
789 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
790 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
791 std::list<ResultPtr> aResults = aFeature->results();
792 std::list<ResultPtr>::const_iterator aIt;
793 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
794 (*aIt)->setDisplayed(false);
796 aFeature->setDisplayed(false);
798 // Display sketcher result
799 std::list<ResultPtr> aResults = myCurrentSketch->results();
800 std::list<ResultPtr>::const_iterator aIt;
801 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
802 (*aIt)->setDisplayed(true);
804 myCurrentSketch->setDisplayed(true);
806 myCurrentSketch = CompositeFeaturePtr();
807 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
809 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
811 // restore the module selection modes, which were changed on startSketch
812 aConnector->activateModuleSelectionModes();
815 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
817 if (constraintsIdList().contains(theOperation->id())) {
818 // Show constraints if a constraint was created
819 onShowConstraintsToggle(true);
821 connectToPropertyPanel(true);
824 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
826 connectToPropertyPanel(false);
827 myIsPropertyPanelValueChanged = false;
828 myIsMouseOverViewProcessed = true;
829 operationMgr()->onValidateOperation();
832 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
834 if (isNestedCreateOperation(theOperation)) {
835 FeaturePtr aFeature = theOperation->feature();
836 // it is necessary to check the the feature data validity because
837 // some kind of features are removed by an operation commit(the macro state of a feature)
838 if (aFeature.get() && aFeature->data()->isValid()) {
839 visualizeFeature(theOperation, true);
844 bool PartSet_SketcherMgr::canUndo() const
846 return isNestedCreateOperation(getCurrentOperation());
849 bool PartSet_SketcherMgr::canRedo() const
851 return isNestedCreateOperation(getCurrentOperation());
854 bool PartSet_SketcherMgr::canCommitOperation() const
856 bool aCanCommit = true;
858 if (isNestedCreateOperation(getCurrentOperation()) && !canDisplayCurrentCreatedFeature())
864 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
866 bool aCanDisplay = true;
868 bool aHasActiveSketch = activeSketch().get() != NULL;
869 if (aHasActiveSketch) {
870 // 1. the sketch feature should not be displayed during the sketch active operation
871 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
872 // nested features can be visualized
873 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
874 if (aFeature.get() != NULL && aFeature == activeSketch()) {
878 else { // there are no an active sketch
879 // 2. sketch sub-features should not be visualized if the sketch operation is not active
880 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
881 if (aFeature.get() != NULL) {
882 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
883 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
884 if (aSketchFeature.get()) {
890 // 3. the method should not filter the objects, which are not related to the current operation.
891 // The object is filtered just if it is a current operation feature or this feature result
892 bool isObjectFound = false;
893 ModuleBase_Operation* anOperation = getCurrentOperation();
895 FeaturePtr aFeature = anOperation->feature();
896 if (aFeature.get()) {
897 std::list<ResultPtr> aResults = aFeature->results();
898 if (theObject == aFeature)
899 isObjectFound = true;
901 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
902 for (; anIt != aLast; anIt++) {
903 isObjectFound = *anIt == theObject;
911 // 4. For created nested feature operation do not display the created feature if
912 // the mouse curstor leaves the OCC window.
913 // The correction cases, which ignores this condition:
914 // a. the property panel values modification
915 // b. the popup menu activated
916 // c. widget editor control
917 #ifndef DEBUG_DO_NOT_BY_ENTER
918 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
919 ModuleBase_Operation* aOperation = getCurrentOperation();
920 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
921 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
922 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
923 // the active widget editor should not influence here. The presentation should be visible always
924 // when this widget is active.
925 if (!anEditorWdg && !myIsPopupMenuActive) {
926 // during a nested create operation, the feature is redisplayed only if the mouse over view
927 // of there was a value modified in the property panel after the mouse left the view
928 aCanDisplay = canDisplayCurrentCreatedFeature();
935 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
937 return myIsPropertyPanelValueChanged || myIsMouseOverWindow;
938 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
939 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
943 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
945 bool isFoundObject = false;
947 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
948 if (anObjectFeature.get()) {
949 int aSize = myCurrentSketch->numberOfSubs();
950 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
951 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
952 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
955 return isFoundObject;
958 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
960 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
963 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
964 const FeaturePtr& theSketch,
965 ModuleBase_IWorkshop* theWorkshop,
966 FeatureToSelectionMap& theSelection)
968 if (theFeature.get() == NULL)
971 std::set<AttributePtr> aSelectedAttributes;
972 std::set<ResultPtr> aSelectedResults;
974 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
975 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
976 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
977 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
979 std::list<ResultPtr> aResults = theFeature->results();
980 std::list<ResultPtr>::const_iterator aIt;
981 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
983 ResultPtr aResult = *aIt;
984 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
985 if (aAISObj.get() == NULL)
987 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
988 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
990 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
991 if (anOwner->Selectable() != anAISIO)
993 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
994 aSelectedAttributes, aSelectedResults);
996 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
997 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
998 if (anOwner->Selectable() != anAISIO)
1000 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1001 aSelectedAttributes, aSelectedResults);
1004 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1007 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1008 const FeaturePtr& theSketch,
1009 ModuleBase_IWorkshop* theWorkshop,
1010 const FeatureToSelectionMap& theSelection,
1011 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1013 if (theFeature.get() == NULL)
1016 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1017 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1018 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1020 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1021 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1022 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1023 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1025 // 1. found the feature's owners. Check the AIS objects of the constructions
1026 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1027 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1028 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1030 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1031 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1032 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1033 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1034 if (!anOwner.IsNull())
1035 anOwnersToSelect.Add(anOwner);
1039 // 2. found the feature results's owners
1040 std::list<ResultPtr> aResults = theFeature->results();
1041 std::list<ResultPtr>::const_iterator aIt;
1042 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1044 ResultPtr aResult = *aIt;
1045 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1046 if (aAISObj.get() == NULL)
1048 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1050 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1051 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1052 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1053 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1054 if ( anOwner.IsNull() || !anOwner->HasShape() )
1056 const TopoDS_Shape& aShape = anOwner->Shape();
1057 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1058 if (aShapeType == TopAbs_VERTEX) {
1059 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1060 if (aPntAttr.get() != NULL &&
1061 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1062 anOwnersToSelect.Add(anOwner);
1065 else if (aShapeType == TopAbs_EDGE) {
1066 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1067 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1068 anOwnersToSelect.FindIndex(anOwner) <= 0)
1069 anOwnersToSelect.Add(anOwner);
1075 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1077 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1078 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1079 XGUI_Workshop* aWorkshop = aConnector->workshop();
1080 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1081 if (aPropertyPanel) {
1082 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1083 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1085 connect(aWidget, SIGNAL(beforeValuesChanged()),
1086 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1087 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1088 connect(aWidget, SIGNAL(afterValuesChanged()),
1089 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1092 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1093 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1094 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1095 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1096 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1102 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1104 return myModule->workshop()->currentOperation();
1107 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1108 const bool isToDisplay,
1109 const bool isFlushRedisplay)
1111 #ifdef DEBUG_DO_NOT_BY_ENTER
1115 if (!theOperation || theOperation->isEditOperation())
1118 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1119 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1121 // 1. change visibility of the object itself, here the presentable object is processed,
1122 // e.g. constraints features
1123 FeaturePtr aFeature = theOperation->feature();
1124 std::list<ResultPtr> aResults = aFeature->results();
1126 aFeature->setDisplayed(true);
1128 aFeature->setDisplayed(false);
1130 // change visibility of the object results, e.g. non-constraint features
1131 std::list<ResultPtr>::const_iterator aIt;
1132 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1134 (*aIt)->setDisplayed(true);
1137 (*aIt)->setDisplayed(false);
1140 if (isFlushRedisplay)
1141 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1144 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1146 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1147 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1148 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1150 QList<FeaturePtr> aFeatureList;
1151 if (theHighlightedOnly) {
1152 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1155 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1157 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1158 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1161 // 1. it is necessary to save current selection in order to restore it after the features moving
1162 myCurrentSelection.clear();
1163 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1164 for (; anIt != aLast; anIt++) {
1165 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1167 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1170 void PartSet_SketcherMgr::restoreSelection()
1172 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1173 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1174 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1175 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1176 aSLast = myCurrentSelection.end();
1177 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1178 for (; aSIt != aSLast; aSIt++) {
1179 anOwnersToSelect.Clear();
1180 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1182 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1186 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1188 if (myIsConstraintsShown == theOn)
1190 if (myCurrentSketch.get() == NULL)
1193 myIsConstraintsShown = theOn;
1195 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1196 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1198 const QStringList& aConstrIds = constraintsIdList();
1199 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1200 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1201 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1202 if (myIsConstraintsShown)
1203 aSubFeature->setDisplayed(true);
1205 aSubFeature->setDisplayed(false);
1208 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1211 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1213 return QString("myIsPropertyPanelValueChanged = %1, myIsMouseOverWindow = %2")
1214 .arg(myIsPropertyPanelValueChanged).arg(myIsMouseOverWindow);
1217 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1219 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1220 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1221 XGUI_Workshop* aWorkshop = aConnector->workshop();
1223 return aWorkshop->operationMgr();