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
96 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
98 //#define DEBUG_CURSOR
100 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
101 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
102 /// result as is to the list of results.
103 /// \param theOwner a viewer selected owner
104 /// \param theFeature a feature, where the attribute is searched
105 /// \param theSketch a current sketch
106 /// \param theSelectedAttribute an output list of attributes
107 /// \param theSelectedResults an output list of edge results
108 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
109 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
110 const ResultPtr& theResult,
111 std::set<AttributePtr>& aSelectedAttributes,
112 std::set<ResultPtr>& aSelectedResults)
114 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
115 if (aBRepOwner.IsNull())
117 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
118 aBRepOwner->Selectable());
119 if (aBRepOwner->HasShape()) {
120 const TopoDS_Shape& aShape = aBRepOwner->Shape();
121 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
122 if (aShapeType == TopAbs_VERTEX) {
123 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
125 if (aPntAttr.get() != NULL)
126 aSelectedAttributes.insert(aPntAttr);
128 else if (aShapeType == TopAbs_EDGE &&
129 aSelectedResults.find(theResult) == aSelectedResults.end()) {
130 aSelectedResults.insert(theResult);
135 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
136 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
137 myIsMouseOverWindow(false),
138 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
139 myIsPopupMenuActive(false)
141 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
142 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
144 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
146 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
147 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
149 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
150 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
152 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
153 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
155 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
156 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
158 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
159 XGUI_Workshop* aWorkshop = aConnector->workshop();
160 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
162 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
163 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
164 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
167 PartSet_SketcherMgr::~PartSet_SketcherMgr()
169 if (!myPlaneFilter.IsNull())
170 myPlaneFilter.Nullify();
173 void PartSet_SketcherMgr::onEnterViewPort()
175 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
176 // created feature because it should be done in onMouseMove(). Some widgets watch
177 // the mouse move and use the cursor position to update own values. If the presentaion is
178 // redisplayed before this update, the feature presentation jumps from reset value to current.
179 myIsMouseOverWindow = true;
181 #ifdef DEBUG_DO_NOT_BY_ENTER
185 if (canChangeCursor(getCurrentOperation())) {
186 QCursor* aCurrentCursor = QApplication::overrideCursor();
187 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
188 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
190 qDebug("onEnterViewPort() : Qt::CrossCursor");
195 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
198 operationMgr()->onValidateOperation();
200 // we need change displayed state of the current operation feature
201 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
202 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
203 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
204 // presentation becomes valid and redisplay happens
205 //ModuleBase_Operation* aOperation = getCurrentOperation();
206 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
207 (getCurrentOperation());
209 FeaturePtr aFeature = aFOperation->feature();
210 if (aFeature.get() && aFeature->data()->isValid()) {
211 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
216 void PartSet_SketcherMgr::onLeaveViewPort()
218 myIsMouseOverViewProcessed = false;
219 myIsMouseOverWindow = false;
221 #ifdef DEBUG_DO_NOT_BY_ENTER
225 if (canChangeCursor(getCurrentOperation())) {
226 QApplication::restoreOverrideCursor();
228 qDebug("onLeaveViewPort() : None");
232 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
235 // the method should be performed if the popup menu is called,
236 // the reset of the current widget should not happen
237 if (myIsPopupMenuActive)
240 // it is important to validate operation here only if sketch entity create operation is active
241 // because at this operation we reacts to the mouse leave/enter view port
242 operationMgr()->onValidateOperation();
244 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
245 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
246 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
247 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
248 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
249 // obtained after reset value
250 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
251 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
253 anActiveWidget->reset();
255 // hides the presentation of the current operation feature
256 // the feature is to be erased here, but it is correct to call canDisplayObject because
257 // there can be additional check (e.g. editor widget in distance constraint)
258 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
259 (getCurrentOperation());
261 FeaturePtr aFeature = aFOperation->feature();
262 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
264 // we should update viewer after the presentation are hidden in the viewer
265 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
266 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
269 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
271 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
272 myModule->sketchReentranceMgr()->isInternalEditActive())
274 // it is necessary to save current selection in order to restore it after the values are modifed
277 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
278 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
279 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
280 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
283 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
285 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
286 myModule->sketchReentranceMgr()->isInternalEditActive()) {
287 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
290 // it is necessary to restore current selection in order to restore it after the values are modified
292 myCurrentSelection.clear();
294 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
295 // viewer happens by deselect/select the modified objects. The flag should be restored after
296 // the selection processing. The update viewer should be also called.
297 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
298 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
299 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
300 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
301 aDisplayer->updateViewer();
306 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
308 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
311 //get2dPoint(theWnd, theEvent, myClickedPoint);
313 if (!(theEvent->buttons() & Qt::LeftButton))
316 // Clear dragging mode
317 myIsDragging = false;
319 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
320 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
321 if (!aViewer->canDragByMouse())
324 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
325 (getCurrentOperation());
329 if (aFOperation->isEditOperation()) {
330 // If the current widget is a selector, do nothing, it processes the mouse press
331 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
332 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
337 // Use only for sketch operations
338 if (myCurrentSketch) {
339 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
342 bool isSketcher = isSketchOperation(aFOperation);
343 bool isSketchOpe = isNestedSketchOperation(aFOperation);
345 // Avoid non-sketch operations
346 if ((!isSketchOpe) && (!isSketcher))
349 bool isEditing = aFOperation->isEditOperation();
351 // Ignore creation sketch operation
352 if ((!isSketcher) && (!isEditing))
355 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
356 // Remember highlighted objects for editing
357 ModuleBase_ISelection* aSelect = aWorkshop->selection();
359 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
360 storeSelection(!aHasShift);
362 if (myCurrentSelection.empty()) {
363 if (isSketchOpe && (!isSketcher))
364 // commit previous operation
365 if (!aFOperation->commit())
366 aFOperation->abort();
369 // Init flyout point for radius rotation
370 FeaturePtr aFeature = myCurrentSelection.begin().key();
374 get2dPoint(theWnd, theEvent, myCurrentPoint);
377 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
378 // selection should be restored before edit operation start to process the
379 // selected entities, e.g. selection of point(attribute on a line) should edit the point
382 if (aFeature.get() != NULL) {
383 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
384 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
385 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
386 DataPtr aData = aSPFeature->data();
387 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
388 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
389 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
390 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
393 } else if (isSketchOpe && isEditing) {
394 // If selected another object commit current result
395 aFOperation->commit();
398 get2dPoint(theWnd, theEvent, myCurrentPoint);
401 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
402 // selection should be restored before edit operation start to process the
403 // selected entities, e.g. selection of point(attribute on a line) should edit the point
411 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
413 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
416 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
417 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
418 if (!aViewer->canDragByMouse())
420 ModuleBase_Operation* aOp = getCurrentOperation();
422 if (isNestedSketchOperation(aOp)) {
423 // Only for sketcher operations
426 myCurrentSelection.clear();
432 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
433 myIsDragging = false;
435 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
436 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
438 aProcessor->mouseReleased(theWnd, theEvent);
441 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
443 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
444 CompositeFeaturePtr aSketch = activeSketch();
446 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
448 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
449 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
450 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
452 QString anInfoStr = anInfo.join("\n");
453 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
457 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
460 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
461 // 1. perform the widget mouse move functionality and display the presentation
462 // the mouse move should be processed in the widget, if it can in order to visualize correct
463 // presentation. These widgets correct the feature attribute according to the mouse position
464 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
465 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
467 aProcessor->mouseMoved(theWnd, theEvent);
468 if (!myIsMouseOverViewProcessed) {
469 myIsMouseOverViewProcessed = true;
471 // the feature is to be erased here, but it is correct to call canDisplayObject because
472 // there can be additional check (e.g. editor widget in distance constraint)
473 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
474 (getCurrentOperation());
476 FeaturePtr aFeature = aFOperation->feature();
477 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
481 //myClickedPoint.clear();
484 // 1. the current selection is saved in the mouse press method in order to restore it after moving
485 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
486 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
487 // deselected). This flag should be restored in the slot, processed the mouse release signal.
489 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
490 if (!aCurrentOperation)
492 if (isSketchOperation(aCurrentOperation))
493 return; // No edit operation activated
495 Handle(V3d_View) aView = theWnd->v3dView();
496 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
498 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
499 double dX = aX - myCurrentPoint.myCurX;
500 double dY = aY - myCurrentPoint.myCurY;
502 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
503 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
504 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
505 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
506 // viewer happens by deselect/select the modified objects. The flag should be restored after
507 // the selection processing. The update viewer should be also called.
508 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
510 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
511 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
512 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
513 aLast = myCurrentSelection.end();
514 // 4. the features and attributes modification(move)
515 bool isModified = false;
516 for (; anIt != aLast; anIt++) {
517 FeaturePtr aFeature = anIt.key();
519 std::set<AttributePtr> anAttributes = anIt.value().first;
520 // Process selection by attribute: the priority to the attribute
521 if (!anAttributes.empty()) {
522 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
523 anAttLast = anAttributes.end();
524 for (; anAttIt != anAttLast; anAttIt++) {
525 AttributePtr anAttr = *anAttIt;
526 if (anAttr.get() == NULL)
528 std::string aAttrId = anAttr->id();
529 DataPtr aData = aFeature->data();
530 if (aData->isValid()) {
531 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
532 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
533 if (aPoint.get() != NULL) {
534 bool isImmutable = aPoint->setImmutable(true);
535 aPoint->move(dX, dY);
537 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
538 aPoint->setImmutable(isImmutable);
543 // Process selection by feature
544 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
545 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
546 if (aSketchFeature) {
547 aSketchFeature->move(dX, dY);
549 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
553 // the modified state of the current operation should be updated if there are features, which
556 aCurrentOperation->onValuesChanged();
558 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
559 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
561 // 5. it is necessary to save current selection in order to restore it after the features moving
563 // 6. restore the update viewer flag and call this update
564 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
565 aDisplayer->updateViewer();
568 myCurrentPoint.setValue(aX, aY);
572 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
574 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
575 (getCurrentOperation());
576 if (aFOperation && aFOperation->isEditOperation()) {
577 std::string aId = aFOperation->id().toStdString();
578 if (isDistanceOperation(aFOperation))
580 // Activate dimension value editing on double click
581 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
582 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
583 // Find corresponded widget to activate value editing
584 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
585 if (aWgt->attributeID() == SketchPlugin_Constraint::VALUE() ||
586 aWgt->attributeID() == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) {
587 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
589 anEditor->showPopupEditor();
597 void PartSet_SketcherMgr::onApplicationStarted()
599 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
600 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
601 XGUI_Workshop* aWorkshop = aConnector->workshop();
602 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
604 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
605 if (aPropertyPanel) {
606 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
607 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
609 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
610 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
611 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
612 aReentranceMgr, SLOT(onWidgetActivated()));
615 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
616 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
617 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
619 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
620 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
621 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
624 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
626 //if (!myClickedPoint.myIsInitialized)
629 //ModuleBase_Operation* aOperation = getCurrentOperation();
630 // the distance constraint feature should not use the clickedd point
631 // this is workaround in order to don't throw down the flyout point value,
632 // set by execute() method of these type of features
633 //if (isDistanceOperation(aOperation))
636 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
638 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
642 void PartSet_SketcherMgr::onBeforeContextMenu()
644 myIsPopupMenuActive = true;
647 void PartSet_SketcherMgr::onAfterContextMenu()
649 myIsPopupMenuActive = false;
652 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
655 Handle(V3d_View) aView = theWnd->v3dView();
656 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
658 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
659 thePoint.setValue(aX, anY);
662 void PartSet_SketcherMgr::launchEditing()
664 if (!myCurrentSelection.empty()) {
665 FeaturePtr aFeature = myCurrentSelection.begin().key();
666 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
667 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
668 if (aSPFeature && (!aSPFeature->isExternal())) {
669 myModule->editFeature(aSPFeature);
674 bool PartSet_SketcherMgr::sketchSolverError()
676 bool anError = false;
677 CompositeFeaturePtr aSketch = activeSketch();
679 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
680 anError = !aAttributeString->value().empty();
685 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
687 std::string anError = "";
688 if (!theFeature.get() || !theFeature->data()->isValid())
689 return anError.c_str();
691 CompositeFeaturePtr aSketch = activeSketch();
692 if (aSketch.get() && aSketch == theFeature) {
693 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
694 anError = aAttributeString->value();
695 ModuleBase_Tools::translate(aSketch->getKind(), anError);
697 return anError.c_str();
700 void PartSet_SketcherMgr::clearClickedFlags()
702 //myClickedPoint.clear();
703 myCurrentPoint.clear();
706 const QStringList& PartSet_SketcherMgr::replicationsIdList()
708 static QStringList aReplicationIds;
709 if (aReplicationIds.size() == 0) {
710 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
711 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
712 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
714 return aReplicationIds;
717 const QStringList& PartSet_SketcherMgr::constraintsIdList()
719 static QStringList aConstraintIds;
720 if (aConstraintIds.size() == 0) {
721 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
722 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
723 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
724 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
725 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
726 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
727 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
728 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
729 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
730 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
731 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
732 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
733 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
734 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
736 return aConstraintIds;
739 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
743 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
744 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
745 theModes.append(SketcherPrs_Tools::Sel_Constraint);
746 theModes.append(TopAbs_VERTEX);
747 theModes.append(TopAbs_EDGE);
750 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
752 Handle(AIS_InteractiveObject) aPrs;
754 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
755 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
756 aPrs = new PartSet_ResultSketchPrs(theResult);
761 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
763 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
766 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
768 bool aNestedSketch = false;
770 FeaturePtr anActiveSketch = activeSketch();
771 if (anActiveSketch.get() && theOperation) {
772 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
773 anActiveSketch->getKind().c_str());
774 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
776 if (aSketchOperation && aFOperation) {
777 FeaturePtr aFeature = aFOperation->feature();
778 if (aFeature.get()) {
779 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
780 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
784 return aNestedSketch;
787 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
788 const CompositeFeaturePtr& theSketch) const
790 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
792 return aFOperation && !aFOperation->isEditOperation() &&
793 isNestedSketchOperation(aFOperation);
796 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
797 const CompositeFeaturePtr& theSketch) const
799 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
801 return aFOperation && aFOperation->isEditOperation() &&
802 isNestedSketchOperation(aFOperation);
805 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
807 return (theId == SketchPlugin_Line::ID()) ||
808 (theId == SketchPlugin_Point::ID()) ||
809 (theId == SketchPlugin_Arc::ID()) ||
810 (theId == SketchPlugin_Circle::ID());
813 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
815 std::string anId = theOperation ? theOperation->id().toStdString() : "";
817 return isDistanceKind(anId);
820 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
822 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
823 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
824 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
825 (theKind == SketchPlugin_ConstraintAngle::ID());
828 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
830 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
831 (getCurrentOperation());
835 myModule->onViewTransformed();
837 // Display all sketcher sub-Objects
838 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
839 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
841 // Hide sketcher result
842 std::list<ResultPtr> aResults = myCurrentSketch->results();
843 std::list<ResultPtr>::const_iterator aIt;
844 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
845 (*aIt)->setDisplayed(false);
847 myCurrentSketch->setDisplayed(false);
849 // Remove invalid sketch entities
850 std::set<FeaturePtr> anInvalidFeatures;
851 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
852 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
853 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
854 if (aFeature.get()) {
855 if (!aFactory->validate(aFeature))
856 anInvalidFeatures.insert(aFeature);
859 if (!anInvalidFeatures.empty()) {
860 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
861 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
863 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
864 aLast = anInvalidFeatures.end();
865 // separate features to references to parameter features and references to others
866 QStringList anInvalidFeatureNames;
867 for (; anIt != aLast; anIt++) {
868 FeaturePtr aFeature = *anIt;
870 anInvalidFeatureNames.append(aFeature->name().c_str());
872 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
873 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
874 std::set<FeaturePtr> aFeatureRefsToDelete;
875 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
876 aFeatureRefsToDelete, aPrefixInfo)) {
877 if (!aFeatureRefsToDelete.empty())
878 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
879 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
880 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
881 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
882 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
886 // Display sketcher objects
888 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
889 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
890 #ifdef DEBUG_SKETCHER_ENTITIES
891 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
893 std::list<ResultPtr> aResults = aFeature->results();
894 std::list<ResultPtr>::const_iterator aIt;
895 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
896 (*aIt)->setDisplayed(true);
898 aFeature->setDisplayed(true);
900 #ifdef DEBUG_SKETCHER_ENTITIES
901 QString anInfoStr = anInfo.join(";\t");
902 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
905 if(myCirclePointFilter.IsNull()) {
906 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
909 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
911 if (myPlaneFilter.IsNull())
912 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
914 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
915 bool aHasPlane = false;
916 std::shared_ptr<GeomAPI_Pln> aPln;
917 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
918 myPlaneFilter->setPlane(aPln);
920 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
921 // all displayed objects should be activated in current selection modes according to switched
924 aConnector->activateModuleSelectionModes();
927 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
929 myIsMouseOverWindow = false;
930 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
931 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
932 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
934 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
936 DataPtr aData = myCurrentSketch->data();
937 if (!aData->isValid()) {
938 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
939 // The sketch was aborted
940 myCurrentSketch = CompositeFeaturePtr();
941 // TODO: move this outside of if-else
942 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
943 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
945 // Erase all sketcher objects
946 QObjectPtrList aObjects = aDisplayer->displayedObjects();
947 foreach (ObjectPtr aObj, aObjects) {
948 DataPtr aObjData = aObj->data();
949 if (!aObjData->isValid())
950 aObj->setDisplayed(false);
954 // Hide all sketcher sub-Objects
955 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
956 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
957 std::list<ResultPtr> aResults = aFeature->results();
958 std::list<ResultPtr>::const_iterator aIt;
959 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
960 (*aIt)->setDisplayed(false);
962 aFeature->setDisplayed(false);
964 // Display sketcher result
965 std::list<ResultPtr> aResults = myCurrentSketch->results();
966 std::list<ResultPtr>::const_iterator aIt;
967 Events_Loop* aLoop = Events_Loop::loop();
968 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
970 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
972 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
973 if (!aFOperation->isDisplayedOnStart(*aIt)) {
974 (*aIt)->setDisplayed(true);
975 // this display event is needed because sketch already may have "displayed" state,
976 // but not displayed while it is still active (issue 613, abort of existing sketch)
977 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
980 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
981 myCurrentSketch->setDisplayed(true);
983 myCurrentSketch = CompositeFeaturePtr();
985 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
986 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
988 Events_Loop::loop()->flush(aDispEvent);
990 // restore the module selection modes, which were changed on startSketch
991 aConnector->activateModuleSelectionModes();
994 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
996 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
997 QCursor* aCurrentCursor = QApplication::overrideCursor();
998 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
999 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1001 qDebug("startNestedSketch() : Qt::CrossCursor");
1007 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1009 myIsMouseOverViewProcessed = true;
1010 operationMgr()->onValidateOperation();
1011 // when sketch nested operation is stopped the cursor should be restored unconditionally
1012 //if (canChangeCursor(theOperation)) {
1013 QApplication::restoreOverrideCursor();
1015 qDebug("stopNestedSketch() : None");
1018 /// improvement to deselect automatically all eventual selected objects, when
1019 // returning to the neutral point of the Sketcher
1020 // if the operation is restarted, the previous selection is used to initialize started operation
1021 if (!myModule->sketchReentranceMgr()->isInternalEditStarted())
1022 workshop()->selector()->clearSelection();
1025 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1027 if (isNestedCreateOperation(theOperation, activeSketch())) {
1028 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1031 FeaturePtr aFeature = aFOperation->feature();
1032 // it is necessary to check the the feature data validity because
1033 // some kind of features are removed by an operation commit(the macro state of a feature)
1034 if (aFeature.get() && aFeature->data()->isValid()) {
1035 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1041 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1044 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1046 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1049 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1051 bool isOperationStopped = false;
1052 ModuleBase_Operation* anOperation = getCurrentOperation();
1053 if(anOperation && isNestedSketchOperation(anOperation)) {
1054 // Set final definitions if they are necessary
1055 //propertyPanelDefined(aOperation);
1056 /// Commit sketcher operations automatically
1057 /// distance operation are able to show popup editor to modify the distance value
1058 /// after entering the value, the operation should be committed/aborted(by Esc key)
1059 bool aCanCommitOperation = true;
1060 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1062 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1063 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1064 aCanCommitOperation);
1065 if (!aValueAccepted)
1066 return isOperationStopped;
1069 if (aCanCommitOperation)
1070 isOperationStopped = anOperation->commit();
1072 anOperation->abort();
1073 isOperationStopped = true;
1076 return isOperationStopped;
1079 bool PartSet_SketcherMgr::canUndo() const
1081 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1084 bool PartSet_SketcherMgr::canRedo() const
1086 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1089 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1091 bool aCanErase = true;
1092 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1093 if (myCurrentSketch.get()) {
1094 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1095 if (aResult.get()) {
1096 // Display sketcher objects
1097 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1099 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1100 std::list<ResultPtr> aResults = aFeature->results();
1101 std::list<ResultPtr>::const_iterator anIt;
1102 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1103 aCanErase = *anIt != aResult;
1111 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1113 bool aCanDisplay = true;
1115 bool aHasActiveSketch = activeSketch().get() != NULL;
1116 if (aHasActiveSketch) {
1117 // 1. the sketch feature should not be displayed during the sketch active operation
1118 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1119 // nested features can be visualized
1120 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1121 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1122 aCanDisplay = false;
1124 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1125 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1126 /// some sketch entities should be never shown, e.g. projection feature
1127 if (aSketchFeature.get())
1128 aCanDisplay = aSketchFeature->canBeDisplayed();
1130 else { // there are no an active sketch
1131 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1132 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1133 if (aFeature.get() != NULL) {
1134 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1135 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1136 if (aSketchFeature.get()) {
1137 aCanDisplay = false;
1142 // 3. the method should not filter the objects, which are not related to the current operation.
1143 // The object is filtered just if it is a current operation feature or this feature result
1145 bool isObjectFound = false;
1146 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1147 (getCurrentOperation());
1149 FeaturePtr aFeature = aFOperation->feature();
1150 if (aFeature.get()) {
1151 std::list<ResultPtr> aResults = aFeature->results();
1152 if (theObject == aFeature)
1153 isObjectFound = true;
1155 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1156 for (; anIt != aLast && !isObjectFound; anIt++) {
1157 isObjectFound = *anIt == theObject;
1162 if (isObjectFound) {
1163 // 4. For created nested feature operation do not display the created feature if
1164 // the mouse curstor leaves the OCC window.
1165 // The correction cases, which ignores this condition:
1166 // a. the property panel values modification
1167 // b. the popup menu activated
1168 // c. widget editor control
1169 #ifndef DEBUG_DO_NOT_BY_ENTER
1170 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1171 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1172 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1173 // the active widget editor should not influence here. The presentation should be visible always
1174 // when this widget is active.
1175 if (!anEditorWdg && !myIsPopupMenuActive) {
1176 // during a nested create operation, the feature is redisplayed only if the mouse over view
1177 // of there was a value modified in the property panel after the mouse left the view
1178 aCanDisplay = canDisplayCurrentCreatedFeature();
1185 // checks the sketcher constraints visibility according to active sketch check box states
1187 bool aProcessed = false;
1188 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1189 if (aFeature.get()) {
1190 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1192 aCanDisplay = aConstraintDisplayed;
1199 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1200 const PartSet_Tools::ConstraintVisibleState& theState,
1201 bool& isProcessed) const
1203 bool aSwitchedOn = true;
1205 const QStringList& aConstrIds = constraintsIdList();
1207 std::string aKind = theFeature->getKind();
1208 if (aConstrIds.contains(QString(aKind.c_str()))) {
1209 bool isTypedConstraint = false;
1212 case PartSet_Tools::Dimensional: {
1213 bool isDistance = isDistanceKind(aKind);
1216 aSwitchedOn = myIsConstraintsShown[theState];
1220 case PartSet_Tools::Geometrical: {
1221 bool isGeometrical = !isDistanceKind(aKind);
1222 if (isGeometrical) {
1224 aSwitchedOn = myIsConstraintsShown[theState];
1228 case PartSet_Tools::Any: {
1230 bool isDistance = isDistanceKind(aKind);
1232 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1234 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1244 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1246 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1247 (getCurrentOperation());
1248 if (aFOperation && myCurrentSketch.get()) {
1249 // find results of the current operation
1250 // these results should not be proposed to be deleted
1251 FeaturePtr anOperationFeature = aFOperation->feature();
1252 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1253 std::set<ResultPtr> anOperationResults;
1254 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1255 aRLast = anOperationResultList.end();
1256 for (; aRIt != aRLast; aRIt++)
1257 anOperationResults.insert(*aRIt);
1259 std::set<FeaturePtr> anObjectsToBeDeleted;
1260 QStringList anObjectsToBeDeletedNames;
1261 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1262 for (; anIt != aLast; anIt++) {
1263 ObjectPtr anObject = *anIt;
1264 bool aCanErase = true;
1265 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1266 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1267 // the result is found between current feature results
1268 if (anOperationResults.find(aResult) != anOperationResults.end())
1271 if (aResult.get()) {
1272 // Display sketcher objects
1273 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1274 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1275 std::list<ResultPtr> aResults = aFeature->results();
1276 std::list<ResultPtr>::const_iterator anIt;
1277 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1278 aCanErase = *anIt != aResult;
1283 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1284 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1285 anObjectsToBeDeleted.insert(aFeature);
1286 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1290 if (!anObjectsToBeDeleted.empty()) {
1291 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1292 QString aMessage = tr("The following features have incorrect presentation and \
1293 will be hidden: %1. Would you like to delete them?")
1294 .arg(aFeatureNames);
1295 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1296 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1297 QMessageBox::Cancel);
1298 if (anAnswer == QMessageBox::Ok) {
1299 QObjectPtrList anObjects;
1300 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1301 aLast = anObjectsToBeDeleted.end();
1302 for (; anIt != aLast; anIt++)
1303 anObjects.append(*anIt);
1304 SessionPtr aMgr = ModelAPI_Session::get();
1305 DocumentPtr aDoc = aMgr->activeDocument();
1306 bool aIsOp = aMgr->isOperation();
1308 aMgr->startOperation();
1309 workshop()->deleteFeatures(anObjects);
1310 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1311 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1312 //Events_Loop::loop()->flush(aDeletedEvent);
1313 //Events_Loop::loop()->flush(aRedispEvent);
1316 aMgr->finishOperation();
1322 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1324 bool aCanDisplay = myIsMouseOverWindow;
1326 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1328 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1333 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1335 return isNestedCreateOperation(theOperation, activeSketch()) ||
1336 myModule->sketchReentranceMgr()->isInternalEditActive();
1339 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1341 return myIsConstraintsShown;
1344 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1346 bool isFoundObject = false;
1348 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1349 if (anObjectFeature.get()) {
1350 int aSize = myCurrentSketch->numberOfSubs();
1351 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1352 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1353 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1356 return isFoundObject;
1359 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1361 if (myPlaneFilter.IsNull())
1362 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1364 myPlaneFilter->setPlane(thePln);
1367 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1368 ModuleBase_IWorkshop* theWorkshop,
1369 bool& theCanCommitOperation)
1371 bool isValueAccepted = false;
1372 theCanCommitOperation = false;
1374 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1376 FeaturePtr aFeature = aFOperation->feature();
1377 // editor is shown only if all attribute references are filled by preseletion
1378 bool anAllRefAttrInitialized = true;
1380 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1381 ModelAPI_AttributeRefAttr::typeId());
1382 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1383 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1384 anAllRefAttrInitialized = (*anIt)->isInitialized();
1386 if (anAllRefAttrInitialized) {
1387 // Activate dimension value editing on double click
1388 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1389 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1390 // Find corresponded widget to activate value editing
1391 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1392 if (aWgt->attributeID() == "ConstraintValue") {
1393 // the featue should be displayed in order to find the AIS text position,
1394 // the place where the editor will be shown
1395 aFeature->setDisplayed(true);
1396 /// the execute is necessary to perform in the feature compute for flyout position
1397 aFeature->execute();
1399 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1400 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1402 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1404 int aX = 0, anY = 0;
1406 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1407 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1408 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1409 Handle(AIS_InteractiveObject) anAISIO;
1410 if (anAIS.get() != NULL) {
1411 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1413 if (anAIS.get() != NULL) {
1414 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1416 if (!anAISIO.IsNull()) {
1417 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1418 if (!aDim.IsNull()) {
1419 gp_Pnt aPosition = aDim->GetTextPosition();
1421 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1422 Handle(V3d_View) aView = aViewer->activeView();
1424 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1426 QWidget* aViewPort = aViewer->activeViewPort();
1427 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1432 anEditor->setCursorPosition(aX, anY);
1433 isValueAccepted = anEditor->showPopupEditor(false);
1434 theCanCommitOperation = true;
1440 return isValueAccepted;
1443 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1444 const FeaturePtr& theSketch,
1445 ModuleBase_IWorkshop* theWorkshop,
1446 const FeatureToSelectionMap& theSelection,
1447 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1449 if (theFeature.get() == NULL)
1452 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1453 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1454 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1456 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1458 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1459 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1461 // 1. found the feature's owners. Check the AIS objects of the constructions
1462 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1463 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1464 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1466 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1467 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1468 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1469 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1470 if (!anOwner.IsNull())
1471 theOwnersToSelect.Add(anOwner);
1475 // 2. found the feature results's owners
1476 std::list<ResultPtr> aResults = theFeature->results();
1477 std::list<ResultPtr>::const_iterator aIt;
1478 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1480 ResultPtr aResult = *aIt;
1481 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1482 if (aAISObj.get() == NULL)
1484 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1486 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1487 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1488 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1489 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1490 if ( anOwner.IsNull() || !anOwner->HasShape() )
1492 const TopoDS_Shape& aShape = anOwner->Shape();
1493 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1494 if (aShapeType == TopAbs_VERTEX) {
1495 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1496 if (aPntAttr.get() != NULL &&
1497 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1498 theOwnersToSelect.Add(anOwner);
1501 else if (aShapeType == TopAbs_EDGE) {
1502 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1503 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1504 theOwnersToSelect.FindIndex(anOwner) <= 0)
1505 theOwnersToSelect.Add(anOwner);
1511 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1514 connect(theWidget, SIGNAL(beforeValuesChanged()),
1515 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1516 connect(theWidget, SIGNAL(afterValuesChanged()),
1517 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1520 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1521 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1522 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1523 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1527 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1529 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1530 (getCurrentOperation());
1532 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1533 isNestedSketchOperation(aFOperation) &&
1534 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1535 FeaturePtr aFeature = aFOperation->feature();
1536 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1541 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1543 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1544 (getCurrentOperation());
1545 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1546 isNestedSketchOperation(aFOperation)))
1547 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1549 // update entities selection priorities
1550 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1551 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1552 // update priority for feature
1553 updateSelectionPriority(aFeature, aFeature);
1554 // update priority for results of the feature
1555 std::list<ResultPtr> aResults = aFeature->results();
1556 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1557 for (; anIt != aLastIt; anIt++)
1558 updateSelectionPriority(*anIt, aFeature);
1562 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1564 return myModule->workshop()->currentOperation();
1567 //**************************************************************
1568 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1570 ModuleBase_ModelWidget* aWidget = 0;
1571 ModuleBase_Operation* anOperation = getCurrentOperation();
1573 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1575 aWidget = aPanel->activeWidget();
1580 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1581 const bool isEditOperation,
1582 const bool isToDisplay,
1583 const bool isFlushRedisplay)
1585 #ifdef DEBUG_DO_NOT_BY_ENTER
1589 if (isEditOperation || !theFeature.get())
1592 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1593 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1595 // 1. change visibility of the object itself, here the presentable object is processed,
1596 // e.g. constraints features
1597 //FeaturePtr aFeature = aFOperation->feature();
1598 std::list<ResultPtr> aResults = theFeature->results();
1600 theFeature->setDisplayed(true);
1602 theFeature->setDisplayed(false);
1604 // change visibility of the object results, e.g. non-constraint features
1605 std::list<ResultPtr>::const_iterator aIt;
1606 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1608 (*aIt)->setDisplayed(true);
1611 (*aIt)->setDisplayed(false);
1614 if (isFlushRedisplay)
1615 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1618 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1620 if (!myCurrentSketch.get())
1623 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1624 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1625 QList<ModuleBase_ViewerPrsPtr> aStoredPrs = aSelect->getHighlighted();
1627 QList<FeaturePtr> aFeatureList;
1628 if (!theHighlightedOnly) {
1629 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1630 ModuleBase_ISelection::AllControls);
1631 aStoredPrs.append(aSelected);
1634 // 1. it is necessary to save current selection in order to restore it after the features moving
1635 myCurrentSelection.clear();
1637 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(), aLast = aStoredPrs.end();
1639 CompositeFeaturePtr aSketch = activeSketch();
1640 for (; anIt != aLast; anIt++) {
1641 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1642 ObjectPtr anObject = aPrs->object();
1643 if (!anObject.get())
1646 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1647 FeaturePtr aFeature;
1649 aFeature = ModelAPI_Feature::feature(aResult);
1651 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1654 std::set<AttributePtr> aSelectedAttributes;
1655 std::set<ResultPtr> aSelectedResults;
1656 if (myCurrentSelection.find(aFeature) != myCurrentSelection.end()) {
1657 std::pair<std::set<AttributePtr>, std::set<ResultPtr> > aPair = myCurrentSelection.find(aFeature).value();
1658 aSelectedAttributes = aPair.first;
1659 aSelectedResults = aPair.second;
1662 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1663 if (aResult.get()) {
1664 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1665 aSelectedAttributes, aSelectedResults);
1668 std::list<ResultPtr> aResults = aFeature->results();
1669 std::list<ResultPtr>::const_iterator aIt;
1670 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1671 ResultPtr aResult = *aIt;
1672 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1673 aSelectedAttributes, aSelectedResults);
1676 myCurrentSelection[aFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1678 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1681 void PartSet_SketcherMgr::restoreSelection()
1683 if (!myCurrentSketch.get())
1686 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1687 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1688 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1689 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1690 aSLast = myCurrentSelection.end();
1691 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1692 for (; aSIt != aSLast; aSIt++) {
1693 anOwnersToSelect.Clear();
1694 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1696 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1700 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1702 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1704 updateBySketchParameters(aType, theState);
1707 void PartSet_SketcherMgr::updateBySketchParameters(
1708 const PartSet_Tools::ConstraintVisibleState& theType,
1711 if (myCurrentSketch.get() == NULL)
1714 bool aPrevState = myIsConstraintsShown[theType];
1715 myIsConstraintsShown[theType] = theState;
1718 case PartSet_Tools::Geometrical:
1719 case PartSet_Tools::Dimensional: {
1720 if (aPrevState != theState) {
1721 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1722 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1723 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1724 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1725 bool aProcessed = false;
1726 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1728 aSubFeature->setDisplayed(aConstraintDisplayed);
1730 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1734 case PartSet_Tools::Expressions: {
1735 if (aPrevState != theState) {
1736 /// call all sketch features redisplay, the expression state will be corrected in customize
1737 /// of distance presentation
1738 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1739 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1746 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1747 FeaturePtr theFeature)
1749 if (!theObject.get() || !theFeature.get())
1752 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
1753 Handle(AIS_InteractiveObject) anAISIO;
1754 if (anAIS.get() != NULL) {
1755 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1758 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
1759 int anAdditionalPriority = 0;
1761 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1762 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1763 if (aSPFeature.get() != NULL) {
1765 // 2. Simple segments
1766 // 3. External objects (violet color)
1767 // 4. Auxiliary segments (dotted)
1768 // StdSelect_BRepSelectionTool::Load uses priority calculating:
1769 // Standard_Integer aPriority = (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
1770 // Priority of Vertex is 8, edge(segment) is 7.
1771 // It might be not corrected as provides the condition above.
1772 bool isExternal = aSPFeature->isExternal();
1773 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
1775 if (!isExternal && !isAuxiliary)
1776 anAdditionalPriority = 30;
1779 anAdditionalPriority = 20;
1780 // auxiliary feature
1782 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
1783 // edges/vertices of local selection on not-sketch objects
1785 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1786 if (!aResult.IsNull()) {
1787 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
1793 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1795 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1796 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1797 return aConnector->workshop();
1800 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1802 return workshop()->operationMgr();