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_SketcherReetntrantMgr.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_MouseProcessor.h"
11 #include "PartSet_Tools.h"
12 #include "PartSet_WidgetSketchLabel.h"
13 #include "PartSet_WidgetEditor.h"
14 #include "PartSet_ResultSketchPrs.h"
16 #include <XGUI_ModuleConnector.h>
17 #include <XGUI_Displayer.h>
18 #include <XGUI_Workshop.h>
19 #include <XGUI_ContextMenuMgr.h>
20 #include <XGUI_Selection.h>
21 #include <XGUI_SelectionMgr.h>
22 #include <XGUI_ModuleConnector.h>
23 #include <XGUI_PropertyPanel.h>
24 #include <XGUI_ViewerProxy.h>
25 #include <XGUI_OperationMgr.h>
26 #include <XGUI_ErrorMgr.h>
27 #include <XGUI_Tools.h>
29 #include <ModuleBase_IPropertyPanel.h>
30 #include <ModuleBase_ISelection.h>
31 #include <ModuleBase_IViewer.h>
32 #include <ModuleBase_IWorkshop.h>
33 #include <ModuleBase_IViewWindow.h>
34 #include <ModuleBase_ModelWidget.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_OperationFeature.h>
37 #include <ModuleBase_Operation.h>
38 #include <ModuleBase_WidgetEditor.h>
39 #include <ModuleBase_ViewerPrs.h>
40 #include <ModuleBase_Tools.h>
41 #include <ModuleBase_ResultPrs.h>
43 #include <GeomDataAPI_Point2D.h>
45 #include <Events_Loop.h>
47 #include <SketchPlugin_Line.h>
48 #include <SketchPlugin_Sketch.h>
49 #include <SketchPlugin_Point.h>
50 #include <SketchPlugin_Arc.h>
51 #include <SketchPlugin_Circle.h>
52 #include <SketchPlugin_ConstraintLength.h>
53 #include <SketchPlugin_ConstraintDistance.h>
54 #include <SketchPlugin_ConstraintParallel.h>
55 #include <SketchPlugin_ConstraintPerpendicular.h>
56 #include <SketchPlugin_ConstraintRadius.h>
57 #include <SketchPlugin_ConstraintRigid.h>
58 #include <SketchPlugin_ConstraintHorizontal.h>
59 #include <SketchPlugin_ConstraintVertical.h>
60 #include <SketchPlugin_ConstraintEqual.h>
61 #include <SketchPlugin_ConstraintTangent.h>
62 #include <SketchPlugin_ConstraintCoincidence.h>
63 #include <SketchPlugin_ConstraintFillet.h>
64 #include <SketchPlugin_ConstraintMirror.h>
65 #include <SketchPlugin_ConstraintAngle.h>
66 #include <SketchPlugin_ConstraintCollinear.h>
67 #include <SketchPlugin_ConstraintMiddle.h>
68 #include <SketchPlugin_MultiRotation.h>
69 #include <SketchPlugin_MultiTranslation.h>
70 #include <SketchPlugin_IntersectionPoint.h>
72 #include <SketcherPrs_Tools.h>
74 #include <SelectMgr_IndexedMapOfOwner.hxx>
75 #include <StdSelect_BRepOwner.hxx>
77 //#include <AIS_DimensionSelectionMode.hxx>
78 #include <AIS_Shape.hxx>
79 #include <AIS_Dimension.hxx>
81 #include <ModelAPI_Events.h>
82 #include <ModelAPI_Session.h>
83 #include <ModelAPI_AttributeString.h>
85 #include <ModelAPI_Validator.h>
86 #include <ModelAPI_Tools.h>
88 #include <QMouseEvent>
89 #include <QApplication>
91 #include <QMessageBox>
92 #include <QMainWindow>
94 //#define DEBUG_DO_NOT_BY_ENTER
95 //#define DEBUG_SKETCHER_ENTITIES
97 //#define DEBUG_CURSOR
99 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
100 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
101 /// result as is to the list of results.
102 /// \param theOwner a viewer selected owner
103 /// \param theFeature a feature, where the attribute is searched
104 /// \param theSketch a current sketch
105 /// \param theSelectedAttribute an output list of attributes
106 /// \param theSelectedResults an output list of edge results
107 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
108 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
109 const ResultPtr& theResult,
110 std::set<AttributePtr>& aSelectedAttributes,
111 std::set<ResultPtr>& aSelectedResults)
113 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
114 if (aBRepOwner.IsNull())
116 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
117 aBRepOwner->Selectable());
118 if (aBRepOwner->HasShape()) {
119 const TopoDS_Shape& aShape = aBRepOwner->Shape();
120 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
121 if (aShapeType == TopAbs_VERTEX) {
122 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
124 if (aPntAttr.get() != NULL)
125 aSelectedAttributes.insert(aPntAttr);
127 else if (aShapeType == TopAbs_EDGE &&
128 aSelectedResults.find(theResult) == aSelectedResults.end()) {
129 aSelectedResults.insert(theResult);
134 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
135 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
136 myIsMouseOverWindow(false),
137 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
138 myIsPopupMenuActive(false)
140 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
141 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
143 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
145 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
146 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
148 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
149 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
151 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
152 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
154 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
155 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
157 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
158 XGUI_Workshop* aWorkshop = aConnector->workshop();
159 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
161 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
162 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
163 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
166 PartSet_SketcherMgr::~PartSet_SketcherMgr()
168 if (!myPlaneFilter.IsNull())
169 myPlaneFilter.Nullify();
172 void PartSet_SketcherMgr::onEnterViewPort()
174 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
175 // created feature because it should be done in onMouseMove(). Some widgets watch
176 // the mouse move and use the cursor position to update own values. If the presentaion is
177 // redisplayed before this update, the feature presentation jumps from reset value to current.
178 myIsMouseOverWindow = true;
180 #ifdef DEBUG_DO_NOT_BY_ENTER
184 if (canChangeCursor(getCurrentOperation())) {
185 QCursor* aCurrentCursor = QApplication::overrideCursor();
186 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
187 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
189 qDebug("onEnterViewPort() : Qt::CrossCursor");
194 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
197 operationMgr()->onValidateOperation();
199 // we need change displayed state of the current operation feature
200 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
201 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
202 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
203 // presentation becomes valid and redisplay happens
204 //ModuleBase_Operation* aOperation = getCurrentOperation();
205 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
206 (getCurrentOperation());
208 FeaturePtr aFeature = aFOperation->feature();
209 if (aFeature.get() && aFeature->data()->isValid()) {
210 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
215 void PartSet_SketcherMgr::onLeaveViewPort()
217 myIsMouseOverViewProcessed = false;
218 myIsMouseOverWindow = false;
220 #ifdef DEBUG_DO_NOT_BY_ENTER
224 if (canChangeCursor(getCurrentOperation())) {
225 QApplication::restoreOverrideCursor();
227 qDebug("onLeaveViewPort() : None");
231 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
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 // it is important to validate operation here only if sketch entity create operation is active
240 // because at this operation we reacts to the mouse leave/enter view port
241 operationMgr()->onValidateOperation();
243 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
244 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
245 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
246 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
247 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
248 // obtained after reset value
249 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
250 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
252 anActiveWidget->reset();
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 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
258 (getCurrentOperation());
260 FeaturePtr aFeature = aFOperation->feature();
261 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
263 // we should update viewer after the presentation are hidden in the viewer
264 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
265 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
268 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
270 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
271 myModule->sketchReentranceMgr()->isInternalEditActive())
273 // it is necessary to save current selection in order to restore it after the values are modifed
276 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
277 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
278 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
279 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
282 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
284 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
285 myModule->sketchReentranceMgr()->isInternalEditActive()) {
286 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
289 // it is necessary to restore current selection in order to restore it after the values are modified
291 myCurrentSelection.clear();
293 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
294 // viewer happens by deselect/select the modified objects. The flag should be restored after
295 // the selection processing. The update viewer should be also called.
296 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
297 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
298 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
299 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
300 aDisplayer->updateViewer();
305 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
307 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, 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_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
324 (getCurrentOperation());
328 if (aFOperation->isEditOperation()) {
329 // If the current widget is a selector, do nothing, it processes the mouse press
330 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
331 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
336 // Use only for sketch operations
337 if (myCurrentSketch) {
338 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
341 bool isSketcher = isSketchOperation(aFOperation);
342 bool isSketchOpe = isNestedSketchOperation(aFOperation, activeSketch());
344 // Avoid non-sketch operations
345 if ((!isSketchOpe) && (!isSketcher))
348 bool isEditing = aFOperation->isEditOperation();
350 // Ignore creation sketch operation
351 if ((!isSketcher) && (!isEditing))
354 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
355 // Remember highlighted objects for editing
356 ModuleBase_ISelection* aSelect = aWorkshop->selection();
358 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
359 storeSelection(!aHasShift);
361 if (myCurrentSelection.empty()) {
362 if (isSketchOpe && (!isSketcher))
363 // commit previous operation
364 if (!aFOperation->commit())
365 aFOperation->abort();
368 // Init flyout point for radius rotation
369 FeaturePtr aFeature = myCurrentSelection.begin().key();
373 get2dPoint(theWnd, theEvent, myCurrentPoint);
376 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
377 // selection should be restored before edit operation start to process the
378 // selected entities, e.g. selection of point(attribute on a line) should edit the point
381 if (aFeature.get() != NULL) {
382 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
383 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
384 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
385 DataPtr aData = aSPFeature->data();
386 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
387 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
388 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
389 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
392 } else if (isSketchOpe && isEditing) {
393 // If selected another object commit current result
394 aFOperation->commit();
397 get2dPoint(theWnd, theEvent, myCurrentPoint);
400 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
401 // selection should be restored before edit operation start to process the
402 // selected entities, e.g. selection of point(attribute on a line) should edit the point
410 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
412 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
415 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
416 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
417 if (!aViewer->canDragByMouse())
419 ModuleBase_Operation* aOp = getCurrentOperation();
421 if (isNestedSketchOperation(aOp, activeSketch())) {
422 // Only for sketcher operations
425 myCurrentSelection.clear();
431 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
432 myIsDragging = false;
434 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
435 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
437 aProcessor->mouseReleased(theWnd, theEvent);
440 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
442 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
445 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
446 // 1. perform the widget mouse move functionality and display the presentation
447 // the mouse move should be processed in the widget, if it can in order to visualize correct
448 // presentation. These widgets correct the feature attribute according to the mouse position
449 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
450 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
452 aProcessor->mouseMoved(theWnd, theEvent);
453 if (!myIsMouseOverViewProcessed) {
454 myIsMouseOverViewProcessed = true;
456 // the feature is to be erased here, but it is correct to call canDisplayObject because
457 // there can be additional check (e.g. editor widget in distance constraint)
458 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
459 (getCurrentOperation());
461 FeaturePtr aFeature = aFOperation->feature();
462 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
466 //myClickedPoint.clear();
469 // 1. the current selection is saved in the mouse press method in order to restore it after moving
470 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
471 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
472 // deselected). This flag should be restored in the slot, processed the mouse release signal.
474 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
475 if (!aCurrentOperation)
477 if (isSketchOperation(aCurrentOperation))
478 return; // No edit operation activated
480 Handle(V3d_View) aView = theWnd->v3dView();
481 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
483 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
484 double dX = aX - myCurrentPoint.myCurX;
485 double dY = aY - myCurrentPoint.myCurY;
487 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
488 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
489 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
490 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
491 // viewer happens by deselect/select the modified objects. The flag should be restored after
492 // the selection processing. The update viewer should be also called.
493 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
495 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
496 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
497 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
498 aLast = myCurrentSelection.end();
499 // 4. the features and attributes modification(move)
500 bool isModified = false;
501 for (; anIt != aLast; anIt++) {
502 FeaturePtr aFeature = anIt.key();
504 std::set<AttributePtr> anAttributes = anIt.value().first;
505 // Process selection by attribute: the priority to the attribute
506 if (!anAttributes.empty()) {
507 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
508 anAttLast = anAttributes.end();
509 for (; anAttIt != anAttLast; anAttIt++) {
510 AttributePtr anAttr = *anAttIt;
511 if (anAttr.get() == NULL)
513 std::string aAttrId = anAttr->id();
514 DataPtr aData = aFeature->data();
515 if (aData->isValid()) {
516 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
517 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
518 if (aPoint.get() != NULL) {
519 bool isImmutable = aPoint->setImmutable(true);
520 aPoint->move(dX, dY);
522 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
523 aPoint->setImmutable(isImmutable);
528 // Process selection by feature
529 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
530 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
531 if (aSketchFeature) {
532 aSketchFeature->move(dX, dY);
534 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
538 // the modified state of the current operation should be updated if there are features, which
541 aCurrentOperation->onValuesChanged();
543 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
544 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
546 // 5. it is necessary to save current selection in order to restore it after the features moving
548 // 6. restore the update viewer flag and call this update
549 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
550 aDisplayer->updateViewer();
553 myCurrentPoint.setValue(aX, aY);
557 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
559 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
560 (getCurrentOperation());
561 if (aFOperation && aFOperation->isEditOperation()) {
562 std::string aId = aFOperation->id().toStdString();
563 if (isDistanceOperation(aFOperation))
565 // Activate dimension value editing on double click
566 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
567 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
568 // Find corresponded widget to activate value editing
569 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
570 if (aWgt->attributeID() == SketchPlugin_Constraint::VALUE() ||
571 aWgt->attributeID() == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) {
572 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
574 anEditor->showPopupEditor();
582 void PartSet_SketcherMgr::onApplicationStarted()
584 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
585 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
586 XGUI_Workshop* aWorkshop = aConnector->workshop();
587 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
589 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
590 if (aPropertyPanel) {
591 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
592 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
594 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
595 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
596 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
597 aReentranceMgr, SLOT(onWidgetActivated()));
600 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
601 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
602 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
604 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
605 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
606 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
609 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
611 //if (!myClickedPoint.myIsInitialized)
614 //ModuleBase_Operation* aOperation = getCurrentOperation();
615 // the distance constraint feature should not use the clickedd point
616 // this is workaround in order to don't throw down the flyout point value,
617 // set by execute() method of these type of features
618 //if (isDistanceOperation(aOperation))
621 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
623 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
627 void PartSet_SketcherMgr::onBeforeContextMenu()
629 myIsPopupMenuActive = true;
632 void PartSet_SketcherMgr::onAfterContextMenu()
634 myIsPopupMenuActive = false;
637 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
640 Handle(V3d_View) aView = theWnd->v3dView();
641 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
643 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
644 thePoint.setValue(aX, anY);
647 void PartSet_SketcherMgr::launchEditing()
649 if (!myCurrentSelection.empty()) {
650 FeaturePtr aFeature = myCurrentSelection.begin().key();
651 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
652 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
653 if (aSPFeature && (!aSPFeature->isExternal())) {
654 myModule->editFeature(aSPFeature);
659 bool PartSet_SketcherMgr::sketchSolverError()
661 bool anError = false;
662 CompositeFeaturePtr aSketch = activeSketch();
664 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
665 anError = !aAttributeString->value().empty();
670 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
672 std::string anError = "";
673 if (!theFeature.get() || !theFeature->data()->isValid())
674 return anError.c_str();
676 CompositeFeaturePtr aSketch = activeSketch();
677 if (aSketch.get() && aSketch == theFeature) {
678 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
679 anError = aAttributeString->value();
680 ModuleBase_Tools::translate(aSketch->getKind(), anError);
682 return anError.c_str();
685 void PartSet_SketcherMgr::clearClickedFlags()
687 //myClickedPoint.clear();
688 myCurrentPoint.clear();
691 const QStringList& PartSet_SketcherMgr::replicationsIdList()
693 static QStringList aReplicationIds;
694 if (aReplicationIds.size() == 0) {
695 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
696 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
697 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
699 return aReplicationIds;
702 const QStringList& PartSet_SketcherMgr::constraintsIdList()
704 static QStringList aConstraintIds;
705 if (aConstraintIds.size() == 0) {
706 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
707 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
708 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
709 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
710 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
711 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
712 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
713 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
714 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
715 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
716 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
717 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
718 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
719 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
721 return aConstraintIds;
724 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
728 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
729 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
730 theModes.append(SketcherPrs_Tools::Sel_Constraint);
731 theModes.append(TopAbs_VERTEX);
732 theModes.append(TopAbs_EDGE);
735 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
737 Handle(AIS_InteractiveObject) aPrs;
739 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
740 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
741 aPrs = new PartSet_ResultSketchPrs(theResult);
746 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
748 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
751 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation,
752 const CompositeFeaturePtr& theSketch)
754 bool aNestedSketch = false;
756 if (theOperation && theSketch.get()) {
757 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
760 FeaturePtr aFeature = aFOperation->feature();
761 aNestedSketch = theSketch->isSub(aFeature);
764 return aNestedSketch;
767 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
768 const CompositeFeaturePtr& theSketch)
770 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
772 return aFOperation && !aFOperation->isEditOperation() &&
773 isNestedSketchOperation(aFOperation, theSketch);
776 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
777 const CompositeFeaturePtr& theSketch)
779 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
781 return aFOperation && aFOperation->isEditOperation() &&
782 isNestedSketchOperation(aFOperation, theSketch);
785 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
787 return (theId == SketchPlugin_Line::ID()) ||
788 (theId == SketchPlugin_Point::ID()) ||
789 (theId == SketchPlugin_Arc::ID()) ||
790 (theId == SketchPlugin_Circle::ID());
793 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
795 std::string anId = theOperation ? theOperation->id().toStdString() : "";
797 return isDistanceKind(anId);
800 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
802 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
803 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
804 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
805 (theKind == SketchPlugin_ConstraintAngle::ID());
808 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
810 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
811 (getCurrentOperation());
815 myModule->onViewTransformed();
817 // Display all sketcher sub-Objects
818 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
819 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
821 // Hide sketcher result
822 std::list<ResultPtr> aResults = myCurrentSketch->results();
823 std::list<ResultPtr>::const_iterator aIt;
824 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
825 (*aIt)->setDisplayed(false);
827 myCurrentSketch->setDisplayed(false);
829 // Remove invalid sketch entities
830 std::set<FeaturePtr> anInvalidFeatures;
831 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
832 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
833 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
834 if (aFeature.get()) {
835 if (!aFactory->validate(aFeature))
836 anInvalidFeatures.insert(aFeature);
839 if (!anInvalidFeatures.empty()) {
840 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
841 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
843 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
844 aLast = anInvalidFeatures.end();
845 // separate features to references to parameter features and references to others
846 QStringList anInvalidFeatureNames;
847 for (; anIt != aLast; anIt++) {
848 FeaturePtr aFeature = *anIt;
850 anInvalidFeatureNames.append(aFeature->name().c_str());
852 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
853 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
854 std::set<FeaturePtr> aFeatureRefsToDelete;
855 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
856 aFeatureRefsToDelete, aPrefixInfo)) {
857 if (!aFeatureRefsToDelete.empty())
858 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
859 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
860 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
861 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
862 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
866 // Display sketcher objects
868 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
869 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
870 #ifdef DEBUG_SKETCHER_ENTITIES
871 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
873 std::list<ResultPtr> aResults = aFeature->results();
874 std::list<ResultPtr>::const_iterator aIt;
875 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
876 (*aIt)->setDisplayed(true);
878 aFeature->setDisplayed(true);
880 #ifdef DEBUG_SKETCHER_ENTITIES
881 QString anInfoStr = anInfo.join(";\t");
882 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
885 if(myCirclePointFilter.IsNull()) {
886 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
889 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
891 if (myPlaneFilter.IsNull())
892 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
894 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
895 bool aHasPlane = false;
896 std::shared_ptr<GeomAPI_Pln> aPln;
897 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
898 myPlaneFilter->setPlane(aPln);
900 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
901 // all displayed objects should be activated in current selection modes according to switched
904 aConnector->activateModuleSelectionModes();
907 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
909 myIsMouseOverWindow = false;
910 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
911 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
912 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
914 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
916 DataPtr aData = myCurrentSketch->data();
917 if (!aData->isValid()) {
918 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
919 // The sketch was aborted
920 myCurrentSketch = CompositeFeaturePtr();
921 // TODO: move this outside of if-else
922 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
923 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
925 // Erase all sketcher objects
926 QObjectPtrList aObjects = aDisplayer->displayedObjects();
927 foreach (ObjectPtr aObj, aObjects) {
928 DataPtr aObjData = aObj->data();
929 if (!aObjData->isValid())
930 aObj->setDisplayed(false);
934 // Hide all sketcher sub-Objects
935 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
936 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
937 std::list<ResultPtr> aResults = aFeature->results();
938 std::list<ResultPtr>::const_iterator aIt;
939 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
940 (*aIt)->setDisplayed(false);
942 aFeature->setDisplayed(false);
944 // Display sketcher result
945 std::list<ResultPtr> aResults = myCurrentSketch->results();
946 std::list<ResultPtr>::const_iterator aIt;
947 Events_Loop* aLoop = Events_Loop::loop();
948 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
950 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
952 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
953 if (!aFOperation->isDisplayedOnStart(*aIt)) {
954 (*aIt)->setDisplayed(true);
955 // this display event is needed because sketch already may have "displayed" state,
956 // but not displayed while it is still active (issue 613, abort of existing sketch)
957 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
960 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
961 myCurrentSketch->setDisplayed(true);
963 myCurrentSketch = CompositeFeaturePtr();
965 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
966 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
968 Events_Loop::loop()->flush(aDispEvent);
970 // restore the module selection modes, which were changed on startSketch
971 aConnector->activateModuleSelectionModes();
974 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
976 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
977 QCursor* aCurrentCursor = QApplication::overrideCursor();
978 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
979 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
981 qDebug("startNestedSketch() : Qt::CrossCursor");
987 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
989 myIsMouseOverViewProcessed = true;
990 operationMgr()->onValidateOperation();
991 if (canChangeCursor(theOperation)) {
992 QApplication::restoreOverrideCursor();
994 qDebug("stopNestedSketch() : None");
997 /// improvement to deselect automatically all eventual selected objects, when
998 // returning to the neutral point of the Sketcher
999 // if the operation is restarted, the previous selection is used to initialize started operation
1000 if (!myModule->sketchReentranceMgr()->isInternalEditStarted())
1001 workshop()->selector()->clearSelection();
1004 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1006 if (isNestedCreateOperation(theOperation, activeSketch())) {
1007 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1010 FeaturePtr aFeature = aFOperation->feature();
1011 // it is necessary to check the the feature data validity because
1012 // some kind of features are removed by an operation commit(the macro state of a feature)
1013 if (aFeature.get() && aFeature->data()->isValid()) {
1014 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1020 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1023 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1025 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1028 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1030 bool isOperationStopped = false;
1031 ModuleBase_Operation* anOperation = getCurrentOperation();
1032 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation, activeSketch())) {
1033 // Set final definitions if they are necessary
1034 //propertyPanelDefined(aOperation);
1035 /// Commit sketcher operations automatically
1036 /// distance operation are able to show popup editor to modify the distance value
1037 /// after entering the value, the operation should be committed/aborted(by Esc key)
1038 bool aCanCommitOperation = true;
1039 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1041 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1042 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1043 aCanCommitOperation);
1044 if (!aValueAccepted)
1045 return isOperationStopped;
1048 if (aCanCommitOperation)
1049 isOperationStopped = anOperation->commit();
1051 anOperation->abort();
1052 isOperationStopped = true;
1055 return isOperationStopped;
1058 bool PartSet_SketcherMgr::canUndo() const
1060 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1063 bool PartSet_SketcherMgr::canRedo() const
1065 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1068 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1070 bool aCanErase = true;
1071 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1072 if (myCurrentSketch.get()) {
1073 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1074 if (aResult.get()) {
1075 // Display sketcher objects
1076 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1078 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1079 std::list<ResultPtr> aResults = aFeature->results();
1080 std::list<ResultPtr>::const_iterator anIt;
1081 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1082 aCanErase = *anIt != aResult;
1090 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1092 bool aCanDisplay = true;
1094 bool aHasActiveSketch = activeSketch().get() != NULL;
1095 if (aHasActiveSketch) {
1096 // 1. the sketch feature should not be displayed during the sketch active operation
1097 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1098 // nested features can be visualized
1099 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1100 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1101 aCanDisplay = false;
1103 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1104 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1105 /// some sketch entities should be never shown, e.g. projection feature
1106 if (aSketchFeature.get())
1107 aCanDisplay = aSketchFeature->canBeDisplayed();
1109 else { // there are no an active sketch
1110 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1111 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1112 if (aFeature.get() != NULL) {
1113 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1114 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1115 if (aSketchFeature.get()) {
1116 aCanDisplay = false;
1121 // 3. the method should not filter the objects, which are not related to the current operation.
1122 // The object is filtered just if it is a current operation feature or this feature result
1124 bool isObjectFound = false;
1125 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1126 (getCurrentOperation());
1128 FeaturePtr aFeature = aFOperation->feature();
1129 if (aFeature.get()) {
1130 std::list<ResultPtr> aResults = aFeature->results();
1131 if (theObject == aFeature)
1132 isObjectFound = true;
1134 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1135 for (; anIt != aLast && !isObjectFound; anIt++) {
1136 isObjectFound = *anIt == theObject;
1141 if (isObjectFound) {
1142 // 4. For created nested feature operation do not display the created feature if
1143 // the mouse curstor leaves the OCC window.
1144 // The correction cases, which ignores this condition:
1145 // a. the property panel values modification
1146 // b. the popup menu activated
1147 // c. widget editor control
1148 #ifndef DEBUG_DO_NOT_BY_ENTER
1149 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1150 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1151 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1152 // the active widget editor should not influence here. The presentation should be visible always
1153 // when this widget is active.
1154 if (!anEditorWdg && !myIsPopupMenuActive) {
1155 // during a nested create operation, the feature is redisplayed only if the mouse over view
1156 // of there was a value modified in the property panel after the mouse left the view
1157 aCanDisplay = canDisplayCurrentCreatedFeature();
1164 // checks the sketcher constraints visibility according to active sketch check box states
1166 bool aProcessed = false;
1167 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1168 if (aFeature.get()) {
1169 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1171 aCanDisplay = aConstraintDisplayed;
1178 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1179 const PartSet_Tools::ConstraintVisibleState& theState,
1180 bool& isProcessed) const
1182 bool aSwitchedOn = true;
1184 const QStringList& aConstrIds = constraintsIdList();
1186 std::string aKind = theFeature->getKind();
1187 if (aConstrIds.contains(QString(aKind.c_str()))) {
1188 bool isTypedConstraint = false;
1191 case PartSet_Tools::Dimensional: {
1192 bool isDistance = isDistanceKind(aKind);
1195 aSwitchedOn = myIsConstraintsShown[theState];
1199 case PartSet_Tools::Geometrical: {
1200 bool isGeometrical = !isDistanceKind(aKind);
1201 if (isGeometrical) {
1203 aSwitchedOn = myIsConstraintsShown[theState];
1207 case PartSet_Tools::Any: {
1209 bool isDistance = isDistanceKind(aKind);
1211 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1213 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1223 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1225 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1226 (getCurrentOperation());
1227 if (aFOperation && myCurrentSketch.get()) {
1228 // find results of the current operation
1229 // these results should not be proposed to be deleted
1230 FeaturePtr anOperationFeature = aFOperation->feature();
1231 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1232 std::set<ResultPtr> anOperationResults;
1233 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1234 aRLast = anOperationResultList.end();
1235 for (; aRIt != aRLast; aRIt++)
1236 anOperationResults.insert(*aRIt);
1238 std::set<FeaturePtr> anObjectsToBeDeleted;
1239 QStringList anObjectsToBeDeletedNames;
1240 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1241 for (; anIt != aLast; anIt++) {
1242 ObjectPtr anObject = *anIt;
1243 bool aCanErase = true;
1244 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1245 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1246 // the result is found between current feature results
1247 if (anOperationResults.find(aResult) != anOperationResults.end())
1250 if (aResult.get()) {
1251 // Display sketcher objects
1252 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1253 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1254 std::list<ResultPtr> aResults = aFeature->results();
1255 std::list<ResultPtr>::const_iterator anIt;
1256 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1257 aCanErase = *anIt != aResult;
1262 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1263 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1264 anObjectsToBeDeleted.insert(aFeature);
1265 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1269 if (!anObjectsToBeDeleted.empty()) {
1270 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1271 QString aMessage = tr("The following features have incorrect presentation and \
1272 will be hidden: %1. Would you like to delete them?")
1273 .arg(aFeatureNames);
1274 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1275 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1276 QMessageBox::Cancel);
1277 if (anAnswer == QMessageBox::Ok) {
1278 QObjectPtrList anObjects;
1279 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1280 aLast = anObjectsToBeDeleted.end();
1281 for (; anIt != aLast; anIt++)
1282 anObjects.append(*anIt);
1283 SessionPtr aMgr = ModelAPI_Session::get();
1284 DocumentPtr aDoc = aMgr->activeDocument();
1285 bool aIsOp = aMgr->isOperation();
1287 aMgr->startOperation();
1288 workshop()->deleteFeatures(anObjects);
1289 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1290 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1291 //Events_Loop::loop()->flush(aDeletedEvent);
1292 //Events_Loop::loop()->flush(aRedispEvent);
1295 aMgr->finishOperation();
1301 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1303 bool aCanDisplay = myIsMouseOverWindow;
1305 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1307 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1312 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1314 return isNestedCreateOperation(theOperation, activeSketch()) ||
1315 myModule->sketchReentranceMgr()->isInternalEditActive();
1318 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1320 return myIsConstraintsShown;
1323 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1325 bool isFoundObject = false;
1327 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1328 if (anObjectFeature.get()) {
1329 int aSize = myCurrentSketch->numberOfSubs();
1330 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1331 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1332 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1335 return isFoundObject;
1338 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1340 if (myPlaneFilter.IsNull())
1341 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1343 myPlaneFilter->setPlane(thePln);
1346 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1347 ModuleBase_IWorkshop* theWorkshop,
1348 bool& theCanCommitOperation)
1350 bool isValueAccepted = false;
1351 theCanCommitOperation = false;
1353 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1355 FeaturePtr aFeature = aFOperation->feature();
1356 // editor is shown only if all attribute references are filled by preseletion
1357 bool anAllRefAttrInitialized = true;
1359 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1360 ModelAPI_AttributeRefAttr::typeId());
1361 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1362 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1363 anAllRefAttrInitialized = (*anIt)->isInitialized();
1365 if (anAllRefAttrInitialized) {
1366 // Activate dimension value editing on double click
1367 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1368 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1369 // Find corresponded widget to activate value editing
1370 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1371 if (aWgt->attributeID() == "ConstraintValue") {
1372 // the featue should be displayed in order to find the AIS text position,
1373 // the place where the editor will be shown
1374 aFeature->setDisplayed(true);
1375 /// the execute is necessary to perform in the feature compute for flyout position
1376 aFeature->execute();
1378 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1379 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1381 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1383 int aX = 0, anY = 0;
1385 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1386 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1387 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1388 Handle(AIS_InteractiveObject) anAISIO;
1389 if (anAIS.get() != NULL) {
1390 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1392 if (anAIS.get() != NULL) {
1393 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1395 if (!anAISIO.IsNull()) {
1396 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1397 if (!aDim.IsNull()) {
1398 gp_Pnt aPosition = aDim->GetTextPosition();
1400 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1401 Handle(V3d_View) aView = aViewer->activeView();
1403 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1405 QWidget* aViewPort = aViewer->activeViewPort();
1406 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1411 anEditor->setCursorPosition(aX, anY);
1412 isValueAccepted = anEditor->showPopupEditor(false);
1413 theCanCommitOperation = true;
1419 return isValueAccepted;
1422 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1423 const FeaturePtr& theSketch,
1424 ModuleBase_IWorkshop* theWorkshop,
1425 const FeatureToSelectionMap& theSelection,
1426 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1428 if (theFeature.get() == NULL)
1431 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1432 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1433 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1435 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1437 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1438 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1440 // 1. found the feature's owners. Check the AIS objects of the constructions
1441 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1442 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1443 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1445 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1446 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1447 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1448 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1449 if (!anOwner.IsNull())
1450 theOwnersToSelect.Add(anOwner);
1454 // 2. found the feature results's owners
1455 std::list<ResultPtr> aResults = theFeature->results();
1456 std::list<ResultPtr>::const_iterator aIt;
1457 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1459 ResultPtr aResult = *aIt;
1460 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1461 if (aAISObj.get() == NULL)
1463 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1465 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1466 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1467 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1468 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1469 if ( anOwner.IsNull() || !anOwner->HasShape() )
1471 const TopoDS_Shape& aShape = anOwner->Shape();
1472 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1473 if (aShapeType == TopAbs_VERTEX) {
1474 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1475 if (aPntAttr.get() != NULL &&
1476 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1477 theOwnersToSelect.Add(anOwner);
1480 else if (aShapeType == TopAbs_EDGE) {
1481 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1482 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1483 theOwnersToSelect.FindIndex(anOwner) <= 0)
1484 theOwnersToSelect.Add(anOwner);
1490 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1493 connect(theWidget, SIGNAL(beforeValuesChanged()),
1494 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1495 connect(theWidget, SIGNAL(afterValuesChanged()),
1496 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1499 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1500 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1501 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1502 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1506 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1508 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1509 (getCurrentOperation());
1511 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1512 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation, activeSketch()) &&
1513 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1514 FeaturePtr aFeature = aFOperation->feature();
1515 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1520 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1522 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1523 (getCurrentOperation());
1524 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1525 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation, activeSketch())))
1526 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1528 // update entities selection priorities
1529 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1530 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1531 // update priority for feature
1532 updateSelectionPriority(aFeature, aFeature);
1533 // update priority for results of the feature
1534 std::list<ResultPtr> aResults = aFeature->results();
1535 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1536 for (; anIt != aLastIt; anIt++)
1537 updateSelectionPriority(*anIt, aFeature);
1541 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1543 return myModule->workshop()->currentOperation();
1546 //**************************************************************
1547 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1549 ModuleBase_ModelWidget* aWidget = 0;
1550 ModuleBase_Operation* anOperation = getCurrentOperation();
1552 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1554 aWidget = aPanel->activeWidget();
1559 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1560 const bool isEditOperation,
1561 const bool isToDisplay,
1562 const bool isFlushRedisplay)
1564 #ifdef DEBUG_DO_NOT_BY_ENTER
1568 if (isEditOperation || !theFeature.get())
1571 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1572 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1574 // 1. change visibility of the object itself, here the presentable object is processed,
1575 // e.g. constraints features
1576 //FeaturePtr aFeature = aFOperation->feature();
1577 std::list<ResultPtr> aResults = theFeature->results();
1579 theFeature->setDisplayed(true);
1581 theFeature->setDisplayed(false);
1583 // change visibility of the object results, e.g. non-constraint features
1584 std::list<ResultPtr>::const_iterator aIt;
1585 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1587 (*aIt)->setDisplayed(true);
1590 (*aIt)->setDisplayed(false);
1593 if (isFlushRedisplay)
1594 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1597 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1599 if (!myCurrentSketch.get())
1602 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1603 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1604 QList<ModuleBase_ViewerPrsPtr> aStoredPrs = aSelect->getHighlighted();
1606 QList<FeaturePtr> aFeatureList;
1607 if (!theHighlightedOnly) {
1608 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1609 ModuleBase_ISelection::AllControls);
1610 aStoredPrs.append(aSelected);
1613 // 1. it is necessary to save current selection in order to restore it after the features moving
1614 myCurrentSelection.clear();
1616 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(), aLast = aStoredPrs.end();
1618 CompositeFeaturePtr aSketch = activeSketch();
1619 for (; anIt != aLast; anIt++) {
1620 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1621 ObjectPtr anObject = aPrs->object();
1622 if (!anObject.get())
1625 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1626 FeaturePtr aFeature;
1628 aFeature = ModelAPI_Feature::feature(aResult);
1630 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1633 std::set<AttributePtr> aSelectedAttributes;
1634 std::set<ResultPtr> aSelectedResults;
1635 if (myCurrentSelection.find(aFeature) != myCurrentSelection.end()) {
1636 std::pair<std::set<AttributePtr>, std::set<ResultPtr> > aPair = myCurrentSelection.find(aFeature).value();
1637 aSelectedAttributes = aPair.first;
1638 aSelectedResults = aPair.second;
1641 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1642 if (aResult.get()) {
1643 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1644 aSelectedAttributes, aSelectedResults);
1647 std::list<ResultPtr> aResults = aFeature->results();
1648 std::list<ResultPtr>::const_iterator aIt;
1649 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1650 ResultPtr aResult = *aIt;
1651 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1652 aSelectedAttributes, aSelectedResults);
1655 myCurrentSelection[aFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1657 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1660 void PartSet_SketcherMgr::restoreSelection()
1662 if (!myCurrentSketch.get())
1665 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1666 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1667 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1668 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1669 aSLast = myCurrentSelection.end();
1670 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1671 for (; aSIt != aSLast; aSIt++) {
1672 anOwnersToSelect.Clear();
1673 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1675 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1679 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1681 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1683 updateBySketchParameters(aType, theState);
1686 void PartSet_SketcherMgr::updateBySketchParameters(
1687 const PartSet_Tools::ConstraintVisibleState& theType,
1690 if (myCurrentSketch.get() == NULL)
1693 bool aPrevState = myIsConstraintsShown[theType];
1694 myIsConstraintsShown[theType] = theState;
1697 case PartSet_Tools::Geometrical:
1698 case PartSet_Tools::Dimensional: {
1699 if (aPrevState != theState) {
1700 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1701 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1702 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1703 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1704 bool aProcessed = false;
1705 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1707 aSubFeature->setDisplayed(aConstraintDisplayed);
1709 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1713 case PartSet_Tools::Expressions: {
1714 if (aPrevState != theState) {
1715 /// call all sketch features redisplay, the expression state will be corrected in customize
1716 /// of distance presentation
1717 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1718 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1725 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1726 FeaturePtr theFeature)
1728 if (!theObject.get() || !theFeature.get())
1731 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
1732 Handle(AIS_InteractiveObject) anAISIO;
1733 if (anAIS.get() != NULL) {
1734 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1737 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
1738 int anAdditionalPriority = 0;
1740 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1741 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1742 if (aSPFeature.get() != NULL) {
1744 // 2. Simple segments
1745 // 3. External objects (violet color)
1746 // 4. Auxiliary segments (dotted)
1747 // StdSelect_BRepSelectionTool::Load uses priority calculating:
1748 // Standard_Integer aPriority = (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
1749 // Priority of Vertex is 8, edge(segment) is 7.
1750 // It might be not corrected as provides the condition above.
1751 bool isExternal = aSPFeature->isExternal();
1752 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
1754 if (!isExternal && !isAuxiliary)
1755 anAdditionalPriority = 30;
1758 anAdditionalPriority = 20;
1759 // auxiliary feature
1761 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
1762 // edges/vertices of local selection on not-sketch objects
1764 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1765 if (!aResult.IsNull()) {
1766 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
1772 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1774 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1775 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1776 return aConnector->workshop();
1779 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1781 return workshop()->operationMgr();