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 myIsResetCurrentValue(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 myIsResetCurrentValue = 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 operationMgr()->onValidateOperation();
223 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
224 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
227 #ifdef DEBUG_DO_NOT_BY_ENTER
231 if (!isNestedCreateOperation(getCurrentOperation()))
233 // the method should be performed if the popup menu is called,
234 // the reset of the current widget should not happen
235 if (myIsPopupMenuActive)
238 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
239 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
240 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
241 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
242 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
243 // obtained after reset value
244 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
245 ModuleBase_Operation* aOperation = getCurrentOperation();
246 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
247 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
248 if (aActiveWgt && aActiveWgt->reset()) {
249 myIsResetCurrentValue = true;
251 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
253 // hides the presentation of the current operation feature
254 // the feature is to be erased here, but it is correct to call canDisplayObject because
255 // there can be additional check (e.g. editor widget in distance constraint)
256 FeaturePtr aFeature = getCurrentOperation()->feature();
257 visualizeFeature(aOperation, canDisplayObject(aFeature));
260 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
262 if (isNestedCreateOperation(getCurrentOperation()))
264 // it is necessary to save current selection in order to restore it after the values are modifed
267 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
268 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
269 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
270 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
273 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
275 if (isNestedCreateOperation(getCurrentOperation()))
277 // it is necessary to restore current selection in order to restore it after the values are modified
279 myCurrentSelection.clear();
281 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
282 // viewer happens by deselect/select the modified objects. The flag should be restored after
283 // the selection processing. The update viewer should be also called.
284 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
285 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
286 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
287 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
288 aDisplayer->updateViewer();
291 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
293 if (!isNestedCreateOperation(getCurrentOperation()))
296 // visualize the current operation feature
297 myIsResetCurrentValue = false;
298 operationMgr()->onValidateOperation();
299 ModuleBase_Operation* aOperation = getCurrentOperation();
300 // the feature is to be erased here, but it is correct to call canDisplayObject because
301 // there can be additional check (e.g. editor widget in distance constraint)
302 FeaturePtr aFeature = getCurrentOperation()->feature();
303 visualizeFeature(aOperation, canDisplayObject(aFeature));
306 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
308 get2dPoint(theWnd, theEvent, myClickedPoint);
310 if (!(theEvent->buttons() & Qt::LeftButton))
313 // Clear dragging mode
314 myIsDragging = false;
316 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
317 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
318 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
319 if (!aViewer->canDragByMouse())
322 ModuleBase_Operation* aOperation = getCurrentOperation();
323 if (aOperation && aOperation->isEditOperation()) {
324 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
325 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
326 // If the current widget is a selector, do nothing, it processes the mouse press
327 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
332 // Use only for sketch operations
333 if (aOperation && myCurrentSketch) {
334 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
337 bool isSketcher = isSketchOperation(aOperation);
338 bool isSketchOpe = isNestedSketchOperation(aOperation);
340 // Avoid non-sketch operations
341 if ((!isSketchOpe) && (!isSketcher))
344 bool isEditing = aOperation->isEditOperation();
346 // Ignore creation sketch operation
347 if ((!isSketcher) && (!isEditing))
350 // MoveTo in order to highlight current object
351 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
353 // Remember highlighted objects for editing
354 ModuleBase_ISelection* aSelect = aWorkshop->selection();
356 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
357 storeSelection(!aHasShift);
359 if (myCurrentSelection.empty()) {
360 if (isSketchOpe && (!isSketcher))
361 // commit previous operation
362 if (!aOperation->commit())
366 // Init flyout point for radius rotation
367 FeaturePtr aFeature = myCurrentSelection.begin().key();
371 get2dPoint(theWnd, theEvent, myCurrentPoint);
374 if (aFeature.get() != NULL) {
375 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
376 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
377 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
378 DataPtr aData = aSPFeature->data();
379 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
380 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
381 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
382 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
385 } else if (isSketchOpe && isEditing) {
386 // If selected another object commit current result
387 aOperation->commit();
390 get2dPoint(theWnd, theEvent, myCurrentPoint);
393 // This is necessary in order to finalize previous operation
394 QApplication::processEvents();
400 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
402 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
403 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
404 if (!aViewer->canDragByMouse())
406 ModuleBase_Operation* aOp = getCurrentOperation();
408 if (isNestedSketchOperation(aOp)) {
409 get2dPoint(theWnd, theEvent, myClickedPoint);
411 // Only for sketcher operations
415 myCurrentSelection.clear();
416 // Reselect edited object
417 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
418 if (theEvent->modifiers() & Qt::ShiftModifier)
419 aViewer->AISContext()->ShiftSelect();
421 aViewer->AISContext()->Select();
427 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
428 myIsDragging = false;
431 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
433 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
434 myIsMouseOverViewProcessed = true;
435 // 1. perform the widget mouse move functionality and display the presentation
436 ModuleBase_Operation* aOperation = getCurrentOperation();
437 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
438 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
439 // the mouse move should be processed in the widget, if it can in order to visualize correct
440 // presentation. These widgets correct the feature attribute according to the mouse position
441 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
443 aPoint2DWdg->onMouseMove(theWnd, theEvent);
445 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
448 aDistanceWdg->onMouseMove(theWnd, theEvent);
450 // the feature is to be erased here, but it is correct to call canDisplayObject because
451 // there can be additional check (e.g. editor widget in distance constraint)
452 FeaturePtr aFeature = getCurrentOperation()->feature();
453 visualizeFeature(aOperation, canDisplayObject(aFeature));
456 myClickedPoint.clear();
459 // 1. the current selection is saved in the mouse press method in order to restore it after moving
460 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
461 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
462 // deselected). This flag should be restored in the slot, processed the mouse release signal.
463 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
464 aViewer->enableSelection(false);
466 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
467 if (!aCurrentOperation)
469 if (isSketchOperation(aCurrentOperation))
470 return; // No edit operation activated
472 Handle(V3d_View) aView = theWnd->v3dView();
473 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
475 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
476 double dX = aX - myCurrentPoint.myCurX;
477 double dY = aY - myCurrentPoint.myCurY;
479 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
480 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
481 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
482 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
483 // viewer happens by deselect/select the modified objects. The flag should be restored after
484 // the selection processing. The update viewer should be also called.
485 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
487 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
488 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
489 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
490 aLast = myCurrentSelection.end();
491 // 4. the features and attributes modification(move)
492 bool isModified = false;
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);
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);
526 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
530 // the modified state of the current operation should be updated if there are features, which
533 aCurrentOperation->onValuesChanged();
534 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
535 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
537 // 5. it is necessary to save current selection in order to restore it after the features moving
539 // 6. restore the update viewer flag and call this update
540 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
541 aDisplayer->updateViewer();
544 myCurrentPoint.setValue(aX, aY);
548 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
550 ModuleBase_Operation* aOperation = getCurrentOperation();
551 if (aOperation && aOperation->isEditOperation()) {
552 std::string aId = aOperation->id().toStdString();
553 if (isDistanceOperation(aOperation))
555 // Activate dimension value editing on double click
556 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
557 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
558 // Find corresponded widget to activate value editing
559 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
560 if (aWgt->attributeID() == "ConstraintValue") {
569 void PartSet_SketcherMgr::onApplicationStarted()
571 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
572 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
573 XGUI_Workshop* aWorkshop = aConnector->workshop();
574 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
575 if (aPropertyPanel) {
576 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
577 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
580 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
581 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
582 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
584 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
585 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
586 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
589 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
591 if (!myClickedPoint.myIsInitialized)
594 ModuleBase_Operation* aOperation = getCurrentOperation();
595 // the distance constraint feature should not use the clickedd point
596 // this is workaround in order to don't throw down the flyout point value,
597 // set by execute() method of these type of features
598 if (isDistanceOperation(aOperation))
601 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
603 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
607 void PartSet_SketcherMgr::onBeforeContextMenu()
609 myIsPopupMenuActive = true;
612 void PartSet_SketcherMgr::onAfterContextMenu()
614 myIsPopupMenuActive = false;
617 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
620 Handle(V3d_View) aView = theWnd->v3dView();
621 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
623 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
624 thePoint.setValue(aX, anY);
627 void PartSet_SketcherMgr::launchEditing()
629 if (!myCurrentSelection.empty()) {
630 FeaturePtr aFeature = myCurrentSelection.begin().key();
631 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
632 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
634 myModule->editFeature(aSPFeature);
640 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
642 static QStringList aIds;
643 if (aIds.size() == 0) {
644 aIds << SketchPlugin_Line::ID().c_str();
645 aIds << SketchPlugin_Point::ID().c_str();
646 aIds << SketchPlugin_Arc::ID().c_str();
647 aIds << SketchPlugin_Circle::ID().c_str();
648 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
649 aIds.append(constraintsIdList());
654 const QStringList& PartSet_SketcherMgr::constraintsIdList()
656 static QStringList aIds;
657 if (aIds.size() == 0) {
658 aIds << SketchPlugin_ConstraintLength::ID().c_str();
659 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
660 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
661 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
662 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
663 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
664 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
665 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
666 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
667 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
668 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
669 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
670 aIds << SketchPlugin_MultiRotation::ID().c_str();
671 aIds << SketchPlugin_MultiTranslation::ID().c_str();
676 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
680 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
681 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
682 theModes.append(SketcherPrs_Tools::Sel_Constraint);
683 theModes.append(TopAbs_VERTEX);
684 theModes.append(TopAbs_EDGE);
687 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
689 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
692 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
694 return theOperation &&
695 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
698 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
700 return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
703 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
705 return (theId == SketchPlugin_Line::ID()) ||
706 (theId == SketchPlugin_Point::ID()) ||
707 (theId == SketchPlugin_Arc::ID()) ||
708 (theId == SketchPlugin_Circle::ID());
711 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
713 std::string aId = theOperation ? theOperation->id().toStdString() : "";
715 return (aId == SketchPlugin_ConstraintLength::ID()) ||
716 (aId == SketchPlugin_ConstraintDistance::ID()) ||
717 (aId == SketchPlugin_ConstraintRadius::ID());
720 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
722 myModule->onViewTransformed();
724 // Display all sketcher sub-Objects
725 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
726 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
728 // Hide sketcher result
729 std::list<ResultPtr> aResults = myCurrentSketch->results();
730 std::list<ResultPtr>::const_iterator aIt;
731 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
732 (*aIt)->setDisplayed(false);
734 myCurrentSketch->setDisplayed(false);
736 // Display sketcher objects
737 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
738 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
739 std::list<ResultPtr> aResults = aFeature->results();
740 std::list<ResultPtr>::const_iterator aIt;
741 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
742 (*aIt)->setDisplayed(true);
744 aFeature->setDisplayed(true);
747 if (myPlaneFilter.IsNull())
748 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
750 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
752 bool aHasPlane = false;
753 std::shared_ptr<GeomAPI_Pln> aPln;
754 if (theOperation->isEditOperation()) {
755 // If it is editing of sketch then it means that plane is already defined
756 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
760 myPlaneFilter->setPlane(aPln);
762 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
763 // all sketch objects should be activated in the sketch selection modes by edit operation start
764 // in case of creation operation, there is an active widget, which activates own selection mode
765 if (theOperation->isEditOperation() && aHasPlane)
766 aConnector->activateModuleSelectionModes();
769 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
771 myIsMouseOverWindow = false;
772 myIsConstraintsShown = true;
773 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
774 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
776 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
778 DataPtr aData = myCurrentSketch->data();
779 if (!aData->isValid()) {
780 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
781 // The sketch was aborted
782 myCurrentSketch = CompositeFeaturePtr();
783 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
785 // Erase all sketcher objects
786 QStringList aSketchIds = sketchOperationIdList();
787 QObjectPtrList aObjects = aDisplayer->displayedObjects();
788 foreach (ObjectPtr aObj, aObjects) {
789 DataPtr aObjData = aObj->data();
790 if (!aObjData->isValid())
791 aObj->setDisplayed(false);
795 // Hide all sketcher sub-Objects
796 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
797 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
798 std::list<ResultPtr> aResults = aFeature->results();
799 std::list<ResultPtr>::const_iterator aIt;
800 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
801 (*aIt)->setDisplayed(false);
803 aFeature->setDisplayed(false);
805 // Display sketcher result
806 std::list<ResultPtr> aResults = myCurrentSketch->results();
807 std::list<ResultPtr>::const_iterator aIt;
808 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
809 (*aIt)->setDisplayed(true);
811 myCurrentSketch->setDisplayed(true);
813 myCurrentSketch = CompositeFeaturePtr();
814 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
816 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
818 // restore the module selection modes, which were changed on startSketch
819 aConnector->activateModuleSelectionModes();
822 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
824 if (constraintsIdList().contains(theOperation->id())) {
825 // Show constraints if a constraint was created
826 onShowConstraintsToggle(true);
828 connectToPropertyPanel(true);
831 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
833 connectToPropertyPanel(false);
834 myIsResetCurrentValue = false;
835 myIsMouseOverViewProcessed = true;
836 operationMgr()->onValidateOperation();
839 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
841 if (isNestedCreateOperation(theOperation)) {
842 FeaturePtr aFeature = theOperation->feature();
843 // it is necessary to check the the feature data validity because
844 // some kind of features are removed by an operation commit(the macro state of a feature)
845 if (aFeature.get() && aFeature->data()->isValid()) {
846 visualizeFeature(theOperation, true);
851 bool PartSet_SketcherMgr::canUndo() const
853 return isNestedCreateOperation(getCurrentOperation());
856 bool PartSet_SketcherMgr::canRedo() const
858 return isNestedCreateOperation(getCurrentOperation());
861 bool PartSet_SketcherMgr::canCommitOperation() const
863 bool aCanCommit = true;
865 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
871 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
873 bool aCanDisplay = true;
875 bool aHasActiveSketch = activeSketch().get() != NULL;
876 if (aHasActiveSketch) {
877 // 1. the sketch feature should not be displayed during the sketch active operation
878 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
879 // nested features can be visualized
880 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
881 if (aFeature.get() != NULL && aFeature == activeSketch()) {
885 else { // there are no an active sketch
886 // 2. sketch sub-features should not be visualized if the sketch operation is not active
887 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
888 if (aFeature.get() != NULL) {
889 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
890 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
891 if (aSketchFeature.get()) {
897 // 3. the method should not filter the objects, which are not related to the current operation.
898 // The object is filtered just if it is a current operation feature or this feature result
899 bool isObjectFound = false;
900 ModuleBase_Operation* anOperation = getCurrentOperation();
902 FeaturePtr aFeature = anOperation->feature();
903 if (aFeature.get()) {
904 std::list<ResultPtr> aResults = aFeature->results();
905 if (theObject == aFeature)
906 isObjectFound = true;
908 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
909 for (; anIt != aLast; anIt++) {
910 isObjectFound = *anIt == theObject;
918 // 4. For created nested feature operation do not display the created feature if
919 // the mouse curstor leaves the OCC window.
920 // The correction cases, which ignores this condition:
921 // a. the property panel values modification
922 // b. the popup menu activated
923 // c. widget editor control
924 #ifndef DEBUG_DO_NOT_BY_ENTER
925 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
926 ModuleBase_Operation* aOperation = getCurrentOperation();
927 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
928 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
929 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
930 // the active widget editor should not influence here. The presentation should be visible always
931 // when this widget is active.
932 if (!anEditorWdg && !myIsPopupMenuActive) {
933 // during a nested create operation, the feature is redisplayed only if the mouse over view
934 // of there was a value modified in the property panel after the mouse left the view
935 aCanDisplay = canDisplayCurrentCreatedFeature();
942 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
944 return myIsMouseOverWindow || !myIsResetCurrentValue;
945 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
946 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
950 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
952 bool isFoundObject = false;
954 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
955 if (anObjectFeature.get()) {
956 int aSize = myCurrentSketch->numberOfSubs();
957 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
958 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
959 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
962 return isFoundObject;
965 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
967 myPlaneFilter->setPlane(thePln);
970 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
971 const FeaturePtr& theSketch,
972 ModuleBase_IWorkshop* theWorkshop,
973 FeatureToSelectionMap& theSelection)
975 if (theFeature.get() == NULL)
978 std::set<AttributePtr> aSelectedAttributes;
979 std::set<ResultPtr> aSelectedResults;
981 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
982 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
983 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
984 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
986 std::list<ResultPtr> aResults = theFeature->results();
987 std::list<ResultPtr>::const_iterator aIt;
988 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
990 ResultPtr aResult = *aIt;
991 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
992 if (aAISObj.get() == NULL)
994 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
995 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
997 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
998 if (anOwner->Selectable() != anAISIO)
1000 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1001 aSelectedAttributes, aSelectedResults);
1003 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1004 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1005 if (anOwner.IsNull())
1007 if (anOwner->Selectable() != anAISIO)
1009 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1010 aSelectedAttributes, aSelectedResults);
1013 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1016 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1017 const FeaturePtr& theSketch,
1018 ModuleBase_IWorkshop* theWorkshop,
1019 const FeatureToSelectionMap& theSelection,
1020 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1022 if (theFeature.get() == NULL)
1025 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1026 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1027 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1029 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1030 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1031 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1032 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1034 // 1. found the feature's owners. Check the AIS objects of the constructions
1035 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1036 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1037 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1039 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1040 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1041 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1042 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1043 if (!anOwner.IsNull())
1044 anOwnersToSelect.Add(anOwner);
1048 // 2. found the feature results's owners
1049 std::list<ResultPtr> aResults = theFeature->results();
1050 std::list<ResultPtr>::const_iterator aIt;
1051 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1053 ResultPtr aResult = *aIt;
1054 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1055 if (aAISObj.get() == NULL)
1057 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1059 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1060 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1061 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1062 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1063 if ( anOwner.IsNull() || !anOwner->HasShape() )
1065 const TopoDS_Shape& aShape = anOwner->Shape();
1066 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1067 if (aShapeType == TopAbs_VERTEX) {
1068 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1069 if (aPntAttr.get() != NULL &&
1070 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1071 anOwnersToSelect.Add(anOwner);
1074 else if (aShapeType == TopAbs_EDGE) {
1075 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1076 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1077 anOwnersToSelect.FindIndex(anOwner) <= 0)
1078 anOwnersToSelect.Add(anOwner);
1084 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1086 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1087 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1088 XGUI_Workshop* aWorkshop = aConnector->workshop();
1089 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1090 if (aPropertyPanel) {
1091 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1092 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1094 connect(aWidget, SIGNAL(beforeValuesChanged()),
1095 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1096 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1097 connect(aWidget, SIGNAL(afterValuesChanged()),
1098 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1101 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1102 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1103 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1104 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1105 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1111 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1113 return myModule->workshop()->currentOperation();
1116 void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
1117 const bool isToDisplay,
1118 const bool isFlushRedisplay)
1120 #ifdef DEBUG_DO_NOT_BY_ENTER
1124 if (!theOperation || theOperation->isEditOperation())
1127 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1128 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1130 // 1. change visibility of the object itself, here the presentable object is processed,
1131 // e.g. constraints features
1132 FeaturePtr aFeature = theOperation->feature();
1133 std::list<ResultPtr> aResults = aFeature->results();
1135 aFeature->setDisplayed(true);
1137 aFeature->setDisplayed(false);
1139 // change visibility of the object results, e.g. non-constraint features
1140 std::list<ResultPtr>::const_iterator aIt;
1141 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1143 (*aIt)->setDisplayed(true);
1146 (*aIt)->setDisplayed(false);
1149 if (isFlushRedisplay)
1150 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1153 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1155 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1156 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1157 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1159 QList<FeaturePtr> aFeatureList;
1160 if (theHighlightedOnly) {
1161 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1164 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1166 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1167 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1170 // 1. it is necessary to save current selection in order to restore it after the features moving
1171 myCurrentSelection.clear();
1172 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1173 for (; anIt != aLast; anIt++) {
1174 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1176 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1179 void PartSet_SketcherMgr::restoreSelection()
1181 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1182 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1183 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1184 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1185 aSLast = myCurrentSelection.end();
1186 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1187 for (; aSIt != aSLast; aSIt++) {
1188 anOwnersToSelect.Clear();
1189 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1191 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1195 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1197 if (myIsConstraintsShown == theOn)
1199 if (myCurrentSketch.get() == NULL)
1202 myIsConstraintsShown = theOn;
1204 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1205 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1207 const QStringList& aConstrIds = constraintsIdList();
1208 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1209 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1210 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1211 if (myIsConstraintsShown)
1212 aSubFeature->setDisplayed(true);
1214 aSubFeature->setDisplayed(false);
1217 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1220 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1222 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1223 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1226 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1228 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1229 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1230 XGUI_Workshop* aWorkshop = aConnector->workshop();
1232 return aWorkshop->operationMgr();