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();
535 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
536 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
537 XGUI_Workshop* aWorkshop = aConnector->workshop();
538 aWorkshop->updateCompositeActionState();
540 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
541 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
543 // 5. it is necessary to save current selection in order to restore it after the features moving
545 // 6. restore the update viewer flag and call this update
546 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
547 aDisplayer->updateViewer();
550 myCurrentPoint.setValue(aX, aY);
554 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
556 ModuleBase_Operation* aOperation = getCurrentOperation();
557 if (aOperation && aOperation->isEditOperation()) {
558 std::string aId = aOperation->id().toStdString();
559 if (isDistanceOperation(aOperation))
561 // Activate dimension value editing on double click
562 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
563 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
564 // Find corresponded widget to activate value editing
565 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
566 if (aWgt->attributeID() == "ConstraintValue") {
575 void PartSet_SketcherMgr::onApplicationStarted()
577 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
578 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
579 XGUI_Workshop* aWorkshop = aConnector->workshop();
580 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
581 if (aPropertyPanel) {
582 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
583 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
586 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
587 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
588 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
590 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
591 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
592 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
595 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
597 if (!myClickedPoint.myIsInitialized)
600 ModuleBase_Operation* aOperation = getCurrentOperation();
601 // the distance constraint feature should not use the clickedd point
602 // this is workaround in order to don't throw down the flyout point value,
603 // set by execute() method of these type of features
604 if (isDistanceOperation(aOperation))
607 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
609 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
613 void PartSet_SketcherMgr::onBeforeContextMenu()
615 myIsPopupMenuActive = true;
618 void PartSet_SketcherMgr::onAfterContextMenu()
620 myIsPopupMenuActive = false;
623 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
626 Handle(V3d_View) aView = theWnd->v3dView();
627 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
629 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
630 thePoint.setValue(aX, anY);
633 void PartSet_SketcherMgr::launchEditing()
635 if (!myCurrentSelection.empty()) {
636 FeaturePtr aFeature = myCurrentSelection.begin().key();
637 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
638 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
640 myModule->editFeature(aSPFeature);
646 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
648 static QStringList aIds;
649 if (aIds.size() == 0) {
650 aIds << SketchPlugin_Line::ID().c_str();
651 aIds << SketchPlugin_Point::ID().c_str();
652 aIds << SketchPlugin_Arc::ID().c_str();
653 aIds << SketchPlugin_Circle::ID().c_str();
654 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
655 aIds.append(constraintsIdList());
660 const QStringList& PartSet_SketcherMgr::constraintsIdList()
662 static QStringList aIds;
663 if (aIds.size() == 0) {
664 aIds << SketchPlugin_ConstraintLength::ID().c_str();
665 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
666 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
667 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
668 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
669 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
670 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
671 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
672 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
673 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
674 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
675 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
676 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
677 aIds << SketchPlugin_MultiRotation::ID().c_str();
678 aIds << SketchPlugin_MultiTranslation::ID().c_str();
683 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
687 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
688 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
689 theModes.append(SketcherPrs_Tools::Sel_Constraint);
690 theModes.append(TopAbs_VERTEX);
691 theModes.append(TopAbs_EDGE);
694 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
696 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
699 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
701 return theOperation &&
702 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
705 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
707 return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
710 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
712 return (theId == SketchPlugin_Line::ID()) ||
713 (theId == SketchPlugin_Point::ID()) ||
714 (theId == SketchPlugin_Arc::ID()) ||
715 (theId == SketchPlugin_Circle::ID());
718 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
720 std::string aId = theOperation ? theOperation->id().toStdString() : "";
722 return (aId == SketchPlugin_ConstraintLength::ID()) ||
723 (aId == SketchPlugin_ConstraintDistance::ID()) ||
724 (aId == SketchPlugin_ConstraintRadius::ID()) ||
725 (aId == SketchPlugin_ConstraintAngle::ID());
728 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
730 myModule->onViewTransformed();
732 // Display all sketcher sub-Objects
733 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
734 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
736 // Hide sketcher result
737 std::list<ResultPtr> aResults = myCurrentSketch->results();
738 std::list<ResultPtr>::const_iterator aIt;
739 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
740 (*aIt)->setDisplayed(false);
742 myCurrentSketch->setDisplayed(false);
744 // Display sketcher objects
745 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
746 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
747 std::list<ResultPtr> aResults = aFeature->results();
748 std::list<ResultPtr>::const_iterator aIt;
749 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
750 (*aIt)->setDisplayed(true);
752 aFeature->setDisplayed(true);
755 if (myPlaneFilter.IsNull())
756 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
758 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
760 bool aHasPlane = false;
761 std::shared_ptr<GeomAPI_Pln> aPln;
762 if (theOperation->isEditOperation()) {
763 // If it is editing of sketch then it means that plane is already defined
764 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
768 myPlaneFilter->setPlane(aPln);
770 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
771 // all sketch objects should be activated in the sketch selection modes by edit operation start
772 // in case of creation operation, there is an active widget, which activates own selection mode
773 if (theOperation->isEditOperation() && aHasPlane)
774 aConnector->activateModuleSelectionModes();
777 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
779 myIsMouseOverWindow = false;
780 myIsConstraintsShown = true;
781 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
782 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
784 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
786 DataPtr aData = myCurrentSketch->data();
787 if (!aData->isValid()) {
788 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
789 // The sketch was aborted
790 myCurrentSketch = CompositeFeaturePtr();
791 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
793 // Erase all sketcher objects
794 QStringList aSketchIds = sketchOperationIdList();
795 QObjectPtrList aObjects = aDisplayer->displayedObjects();
796 foreach (ObjectPtr aObj, aObjects) {
797 DataPtr aObjData = aObj->data();
798 if (!aObjData->isValid())
799 aObj->setDisplayed(false);
803 // Hide all sketcher sub-Objects
804 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
805 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
806 std::list<ResultPtr> aResults = aFeature->results();
807 std::list<ResultPtr>::const_iterator aIt;
808 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
809 (*aIt)->setDisplayed(false);
811 aFeature->setDisplayed(false);
813 // Display sketcher result
814 std::list<ResultPtr> aResults = myCurrentSketch->results();
815 std::list<ResultPtr>::const_iterator aIt;
816 Events_Loop* aLoop = Events_Loop::loop();
817 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
818 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
819 (*aIt)->setDisplayed(true);
820 // this display event is needed because sketch already may have "displayed" state,
821 // but not displayed while it is still active (issue 613, abort of existing sketch)
822 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
824 myCurrentSketch->setDisplayed(true);
826 myCurrentSketch = CompositeFeaturePtr();
827 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
829 Events_Loop::loop()->flush(aDispEvent);
831 // restore the module selection modes, which were changed on startSketch
832 aConnector->activateModuleSelectionModes();
835 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
837 if (constraintsIdList().contains(theOperation->id())) {
838 // Show constraints if a constraint was created
839 onShowConstraintsToggle(true);
841 connectToPropertyPanel(true);
844 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
846 connectToPropertyPanel(false);
847 myIsResetCurrentValue = false;
848 myIsMouseOverViewProcessed = true;
849 operationMgr()->onValidateOperation();
852 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
854 if (isNestedCreateOperation(theOperation)) {
855 FeaturePtr aFeature = theOperation->feature();
856 // it is necessary to check the the feature data validity because
857 // some kind of features are removed by an operation commit(the macro state of a feature)
858 if (aFeature.get() && aFeature->data()->isValid()) {
859 visualizeFeature(theOperation, true);
864 bool PartSet_SketcherMgr::canUndo() const
866 return isNestedCreateOperation(getCurrentOperation());
869 bool PartSet_SketcherMgr::canRedo() const
871 return isNestedCreateOperation(getCurrentOperation());
874 bool PartSet_SketcherMgr::canCommitOperation() const
876 bool aCanCommit = true;
878 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
884 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
886 bool aCanDisplay = true;
888 bool aHasActiveSketch = activeSketch().get() != NULL;
889 if (aHasActiveSketch) {
890 // 1. the sketch feature should not be displayed during the sketch active operation
891 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
892 // nested features can be visualized
893 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
894 if (aFeature.get() != NULL && aFeature == activeSketch()) {
898 else { // there are no an active sketch
899 // 2. sketch sub-features should not be visualized if the sketch operation is not active
900 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
901 if (aFeature.get() != NULL) {
902 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
903 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
904 if (aSketchFeature.get()) {
910 // 3. the method should not filter the objects, which are not related to the current operation.
911 // The object is filtered just if it is a current operation feature or this feature result
912 bool isObjectFound = false;
913 ModuleBase_Operation* anOperation = getCurrentOperation();
915 FeaturePtr aFeature = anOperation->feature();
916 if (aFeature.get()) {
917 std::list<ResultPtr> aResults = aFeature->results();
918 if (theObject == aFeature)
919 isObjectFound = true;
921 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
922 for (; anIt != aLast; anIt++) {
923 isObjectFound = *anIt == theObject;
931 // 4. For created nested feature operation do not display the created feature if
932 // the mouse curstor leaves the OCC window.
933 // The correction cases, which ignores this condition:
934 // a. the property panel values modification
935 // b. the popup menu activated
936 // c. widget editor control
937 #ifndef DEBUG_DO_NOT_BY_ENTER
938 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
939 ModuleBase_Operation* aOperation = getCurrentOperation();
940 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
941 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
942 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
943 // the active widget editor should not influence here. The presentation should be visible always
944 // when this widget is active.
945 if (!anEditorWdg && !myIsPopupMenuActive) {
946 // during a nested create operation, the feature is redisplayed only if the mouse over view
947 // of there was a value modified in the property panel after the mouse left the view
948 aCanDisplay = canDisplayCurrentCreatedFeature();
955 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
957 return myIsMouseOverWindow || !myIsResetCurrentValue;
958 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
959 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
963 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
965 bool isFoundObject = false;
967 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
968 if (anObjectFeature.get()) {
969 int aSize = myCurrentSketch->numberOfSubs();
970 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
971 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
972 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
975 return isFoundObject;
978 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
980 if (myPlaneFilter.IsNull())
981 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
983 myPlaneFilter->setPlane(thePln);
986 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
987 const FeaturePtr& theSketch,
988 ModuleBase_IWorkshop* theWorkshop,
989 FeatureToSelectionMap& theSelection)
991 if (theFeature.get() == NULL)
994 std::set<AttributePtr> aSelectedAttributes;
995 std::set<ResultPtr> aSelectedResults;
997 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
998 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
999 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1000 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1002 std::list<ResultPtr> aResults = theFeature->results();
1003 std::list<ResultPtr>::const_iterator aIt;
1004 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1006 ResultPtr aResult = *aIt;
1007 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1008 if (aAISObj.get() == NULL)
1010 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1011 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1013 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1014 if (anOwner->Selectable() != anAISIO)
1016 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1017 aSelectedAttributes, aSelectedResults);
1019 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1020 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1021 if (anOwner.IsNull())
1023 if (anOwner->Selectable() != anAISIO)
1025 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1026 aSelectedAttributes, aSelectedResults);
1029 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1032 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1033 const FeaturePtr& theSketch,
1034 ModuleBase_IWorkshop* theWorkshop,
1035 const FeatureToSelectionMap& theSelection,
1036 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1038 if (theFeature.get() == NULL)
1041 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1042 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1043 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1045 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1046 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1047 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1048 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1050 // 1. found the feature's owners. Check the AIS objects of the constructions
1051 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1052 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1053 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1055 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1056 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1057 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1058 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1059 if (!anOwner.IsNull())
1060 anOwnersToSelect.Add(anOwner);
1064 // 2. found the feature results's owners
1065 std::list<ResultPtr> aResults = theFeature->results();
1066 std::list<ResultPtr>::const_iterator aIt;
1067 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1069 ResultPtr aResult = *aIt;
1070 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1071 if (aAISObj.get() == NULL)
1073 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1075 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1076 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1077 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1078 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1079 if ( anOwner.IsNull() || !anOwner->HasShape() )
1081 const TopoDS_Shape& aShape = anOwner->Shape();
1082 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1083 if (aShapeType == TopAbs_VERTEX) {
1084 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1085 if (aPntAttr.get() != NULL &&
1086 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1087 anOwnersToSelect.Add(anOwner);
1090 else if (aShapeType == TopAbs_EDGE) {
1091 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1092 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1093 anOwnersToSelect.FindIndex(anOwner) <= 0)
1094 anOwnersToSelect.Add(anOwner);
1100 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1102 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1103 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1104 XGUI_Workshop* aWorkshop = aConnector->workshop();
1105 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1106 if (aPropertyPanel) {
1107 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1108 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1110 connect(aWidget, SIGNAL(beforeValuesChanged()),
1111 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1112 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1113 connect(aWidget, SIGNAL(afterValuesChanged()),
1114 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1117 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1118 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1119 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1120 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1121 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1127 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1129 return myModule->workshop()->currentOperation();
1132 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1133 const bool isToDisplay,
1134 const bool isFlushRedisplay)
1136 #ifdef DEBUG_DO_NOT_BY_ENTER
1140 if (!theOperation || theOperation->isEditOperation())
1143 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1144 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1146 // 1. change visibility of the object itself, here the presentable object is processed,
1147 // e.g. constraints features
1148 FeaturePtr aFeature = theOperation->feature();
1149 std::list<ResultPtr> aResults = aFeature->results();
1151 aFeature->setDisplayed(true);
1153 aFeature->setDisplayed(false);
1155 // change visibility of the object results, e.g. non-constraint features
1156 std::list<ResultPtr>::const_iterator aIt;
1157 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1159 (*aIt)->setDisplayed(true);
1162 (*aIt)->setDisplayed(false);
1165 if (isFlushRedisplay)
1166 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1169 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1171 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1172 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1173 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1175 QList<FeaturePtr> aFeatureList;
1176 if (theHighlightedOnly) {
1177 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1180 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1182 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1183 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1186 // 1. it is necessary to save current selection in order to restore it after the features moving
1187 myCurrentSelection.clear();
1188 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1189 for (; anIt != aLast; anIt++) {
1190 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1192 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1195 void PartSet_SketcherMgr::restoreSelection()
1197 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1198 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1199 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1200 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1201 aSLast = myCurrentSelection.end();
1202 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1203 for (; aSIt != aSLast; aSIt++) {
1204 anOwnersToSelect.Clear();
1205 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1207 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1211 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1213 if (myIsConstraintsShown == theOn)
1215 if (myCurrentSketch.get() == NULL)
1218 myIsConstraintsShown = theOn;
1220 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1221 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1223 const QStringList& aConstrIds = constraintsIdList();
1224 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1225 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1226 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1227 if (myIsConstraintsShown)
1228 aSubFeature->setDisplayed(true);
1230 aSubFeature->setDisplayed(false);
1233 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1236 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1238 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1239 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1242 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1244 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1245 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1246 XGUI_Workshop* aWorkshop = aConnector->workshop();
1248 return aWorkshop->operationMgr();