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_WidgetPoint2d.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_Tools.h"
13 #include "PartSet_WidgetSketchLabel.h"
14 #include "PartSet_WidgetEditor.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>
27 #include <ModuleBase_IPropertyPanel.h>
28 #include <ModuleBase_ISelection.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IWorkshop.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_ModelWidget.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationFeature.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_WidgetEditor.h>
38 #include <GeomDataAPI_Point2D.h>
40 #include <Events_Loop.h>
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Sketch.h>
44 #include <SketchPlugin_Point.h>
45 #include <SketchPlugin_Arc.h>
46 #include <SketchPlugin_Circle.h>
47 #include <SketchPlugin_ConstraintLength.h>
48 #include <SketchPlugin_ConstraintDistance.h>
49 #include <SketchPlugin_ConstraintParallel.h>
50 #include <SketchPlugin_ConstraintPerpendicular.h>
51 #include <SketchPlugin_ConstraintRadius.h>
52 #include <SketchPlugin_ConstraintRigid.h>
53 #include <SketchPlugin_ConstraintHorizontal.h>
54 #include <SketchPlugin_ConstraintVertical.h>
55 #include <SketchPlugin_ConstraintEqual.h>
56 #include <SketchPlugin_ConstraintTangent.h>
57 #include <SketchPlugin_ConstraintCoincidence.h>
58 #include <SketchPlugin_ConstraintFillet.h>
59 #include <SketchPlugin_ConstraintMirror.h>
60 #include <SketchPlugin_ConstraintAngle.h>
61 #include <SketchPlugin_MultiRotation.h>
62 #include <SketchPlugin_MultiTranslation.h>
64 #include <SketcherPrs_Tools.h>
66 #include <SelectMgr_IndexedMapOfOwner.hxx>
67 #include <StdSelect_BRepOwner.hxx>
69 //#include <AIS_DimensionSelectionMode.hxx>
70 #include <AIS_Shape.hxx>
71 #include <AIS_Dimension.hxx>
73 #include <ModelAPI_Events.h>
74 #include <ModelAPI_Session.h>
75 #include <ModelAPI_AttributeString.h>
77 #include <QMouseEvent>
78 #include <QApplication>
81 //#define DEBUG_DO_NOT_BY_ENTER
83 //#define DEBUG_CURSOR
85 /// Returns list of unique objects by sum of objects from List1 and List2
86 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
87 const QList<ModuleBase_ViewerPrs>& theList2)
89 QList<ModuleBase_ViewerPrs> aRes;
90 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
91 if (!aRes.contains(aPrs))
94 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
95 if (!aRes.contains(aPrs))
101 // Fills the list of features the list of selected presentations.
102 // \param theList a list of selected presentations
103 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
104 // and find the corresponded attribute
105 // \param theFeatureList an output list of features
106 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
107 const FeaturePtr theSketch,
108 QList<FeaturePtr>& theFeatureList)
110 QList<ModuleBase_ViewerPrs> aRes;
112 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
113 aLast = theList.end();
114 for (; anIt != aLast; anIt++)
116 ModuleBase_ViewerPrs aPrs = *anIt;
117 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
118 if (aFeature.get() && !theFeatureList.contains(aFeature))
119 theFeatureList.append(aFeature);
123 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
124 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
125 /// result as is to the list of results.
126 /// \param theOwner a viewer selected owner
127 /// \param theFeature a feature, where the attribute is searched
128 /// \param theSketch a current sketch
129 /// \param theSelectedAttribute an output list of attributes
130 /// \param theSelectedResults an output list of edge results
131 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
132 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
133 const ResultPtr& theResult,
134 std::set<AttributePtr>& aSelectedAttributes,
135 std::set<ResultPtr>& aSelectedResults)
137 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
138 if (aBRepOwner.IsNull())
140 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
141 aBRepOwner->Selectable());
142 if (aBRepOwner->HasShape()) {
143 const TopoDS_Shape& aShape = aBRepOwner->Shape();
144 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
145 if (aShapeType == TopAbs_VERTEX) {
146 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
148 if (aPntAttr.get() != NULL)
149 aSelectedAttributes.insert(aPntAttr);
151 else if (aShapeType == TopAbs_EDGE &&
152 aSelectedResults.find(theResult) == aSelectedResults.end()) {
153 aSelectedResults.insert(theResult);
158 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
159 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
160 myIsMouseOverWindow(false),
161 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
162 myIsPopupMenuActive(false)
164 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
165 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
167 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
169 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
170 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
172 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
173 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
175 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
176 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
178 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
179 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
181 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
182 XGUI_Workshop* aWorkshop = aConnector->workshop();
183 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
185 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
186 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
189 PartSet_SketcherMgr::~PartSet_SketcherMgr()
191 if (!myPlaneFilter.IsNull())
192 myPlaneFilter.Nullify();
195 void PartSet_SketcherMgr::onEnterViewPort()
197 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
198 // created feature because it should be done in onMouseMove(). Some widgets watch
199 // the mouse move and use the cursor position to update own values. If the presentaion is
200 // redisplayed before this update, the feature presentation jumps from reset value to current.
201 myIsMouseOverWindow = true;
203 #ifdef DEBUG_DO_NOT_BY_ENTER
207 if (canChangeCursor(getCurrentOperation())) {
208 QCursor* aCurrentCursor = QApplication::overrideCursor();
209 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
210 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
212 qDebug("onEnterViewPort() : Qt::CrossCursor");
217 if (!isNestedCreateOperation(getCurrentOperation()))
220 operationMgr()->onValidateOperation();
222 // we need change displayed state of the current operation feature
223 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
224 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
225 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
226 // presentation becomes valid and redisplay happens
227 //ModuleBase_Operation* aOperation = getCurrentOperation();
228 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
229 (getCurrentOperation());
231 FeaturePtr aFeature = aFOperation->feature();
232 if (aFeature.get() && aFeature->data()->isValid()) {
233 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
238 void PartSet_SketcherMgr::onLeaveViewPort()
240 myIsMouseOverViewProcessed = false;
241 myIsMouseOverWindow = false;
242 // it is important to validate operation here only if sketch entity create operation is active
243 // because at this operation we reacts to the mouse leave/enter view port
244 //operationMgr()->onValidateOperation();
246 #ifdef DEBUG_DO_NOT_BY_ENTER
250 if (canChangeCursor(getCurrentOperation())) {
251 QApplication::restoreOverrideCursor();
253 qDebug("onLeaveViewPort() : None");
257 if (!isNestedCreateOperation(getCurrentOperation()))
260 // the method should be performed if the popup menu is called,
261 // the reset of the current widget should not happen
262 if (myIsPopupMenuActive)
265 operationMgr()->onValidateOperation();
267 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
268 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
269 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
270 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
271 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
272 // obtained after reset value
273 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
274 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
276 anActiveWidget->reset();
278 // hides the presentation of the current operation feature
279 // the feature is to be erased here, but it is correct to call canDisplayObject because
280 // there can be additional check (e.g. editor widget in distance constraint)
281 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
282 (getCurrentOperation());
284 FeaturePtr aFeature = aFOperation->feature();
285 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
287 // we should update viewer after the presentation are hidden in the viewer
288 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
289 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
292 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
294 if (!isNestedEditOperation(getCurrentOperation()) ||
295 myModule->sketchReentranceMgr()->isInternalEditActive())
297 // it is necessary to save current selection in order to restore it after the values are modifed
300 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
301 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
302 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
303 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
306 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
308 if (!isNestedEditOperation(getCurrentOperation()) ||
309 myModule->sketchReentranceMgr()->isInternalEditActive())
311 // it is necessary to restore current selection in order to restore it after the values are modified
313 myCurrentSelection.clear();
315 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
316 // viewer happens by deselect/select the modified objects. The flag should be restored after
317 // the selection processing. The update viewer should be also called.
318 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
319 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
320 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
321 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
322 aDisplayer->updateViewer();
325 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
327 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
330 //get2dPoint(theWnd, theEvent, myClickedPoint);
332 if (!(theEvent->buttons() & Qt::LeftButton))
335 // Clear dragging mode
336 myIsDragging = false;
338 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
339 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
340 if (!aViewer->canDragByMouse())
343 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
344 (getCurrentOperation());
348 if (aFOperation->isEditOperation()) {
349 // If the current widget is a selector, do nothing, it processes the mouse press
350 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
351 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
356 // Use only for sketch operations
357 if (myCurrentSketch) {
358 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
361 bool isSketcher = isSketchOperation(aFOperation);
362 bool isSketchOpe = isNestedSketchOperation(aFOperation);
364 // Avoid non-sketch operations
365 if ((!isSketchOpe) && (!isSketcher))
368 bool isEditing = aFOperation->isEditOperation();
370 // Ignore creation sketch operation
371 if ((!isSketcher) && (!isEditing))
374 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
375 if (!aContext.IsNull()) {
376 // MoveTo in order to highlight current object
377 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
379 // Remember highlighted objects for editing
380 ModuleBase_ISelection* aSelect = aWorkshop->selection();
382 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
383 storeSelection(!aHasShift);
385 if (myCurrentSelection.empty()) {
386 if (isSketchOpe && (!isSketcher))
387 // commit previous operation
388 if (!aFOperation->commit())
389 aFOperation->abort();
392 // Init flyout point for radius rotation
393 FeaturePtr aFeature = myCurrentSelection.begin().key();
397 get2dPoint(theWnd, theEvent, myCurrentPoint);
399 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
400 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
402 if (aFeature.get() != NULL) {
403 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
404 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
405 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
406 DataPtr aData = aSPFeature->data();
407 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
408 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
409 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
410 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
413 } else if (isSketchOpe && isEditing) {
414 // If selected another object commit current result
415 aFOperation->commit();
418 get2dPoint(theWnd, theEvent, myCurrentPoint);
420 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
421 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
423 // this is temporary commented in order to avoid the following wrong case:
424 // Distance constraint is under edition, double click on the digit -> nothing happens
425 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
426 // but as the prev edit is commited an new one is not started, editor is not shown.
427 // This is necessary in order to finalize previous operation
428 //QApplication::processEvents();
434 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
436 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
439 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
440 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
441 if (!aViewer->canDragByMouse())
443 ModuleBase_Operation* aOp = getCurrentOperation();
445 if (isNestedSketchOperation(aOp)) {
446 //get2dPoint(theWnd, theEvent, myClickedPoint);
448 // Only for sketcher operations
452 myCurrentSelection.clear();
453 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
454 if (!aContext.IsNull()) {
455 // Reselect edited object
456 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
457 if (theEvent->modifiers() & Qt::ShiftModifier)
458 aContext->ShiftSelect();
466 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
467 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
468 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
469 myIsDragging = false;
472 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
474 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
477 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
478 myIsMouseOverViewProcessed = true;
479 // 1. perform the widget mouse move functionality and display the presentation
480 // the mouse move should be processed in the widget, if it can in order to visualize correct
481 // presentation. These widgets correct the feature attribute according to the mouse position
482 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
483 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
485 aPoint2DWdg->onMouseMove(theWnd, theEvent);
487 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
490 aDistanceWdg->onMouseMove(theWnd, theEvent);
492 // the feature is to be erased here, but it is correct to call canDisplayObject because
493 // there can be additional check (e.g. editor widget in distance constraint)
494 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
495 (getCurrentOperation());
497 FeaturePtr aFeature = aFOperation->feature();
498 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
502 //myClickedPoint.clear();
505 // 1. the current selection is saved in the mouse press method in order to restore it after moving
506 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
507 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
508 // deselected). This flag should be restored in the slot, processed the mouse release signal.
510 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
511 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
512 //aViewer->enableSelection(false);
514 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
515 if (!aCurrentOperation)
517 if (isSketchOperation(aCurrentOperation))
518 return; // No edit operation activated
520 Handle(V3d_View) aView = theWnd->v3dView();
521 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
523 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
524 double dX = aX - myCurrentPoint.myCurX;
525 double dY = aY - myCurrentPoint.myCurY;
527 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
528 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
529 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
530 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
531 // viewer happens by deselect/select the modified objects. The flag should be restored after
532 // the selection processing. The update viewer should be also called.
533 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
535 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
536 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
537 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
538 aLast = myCurrentSelection.end();
539 // 4. the features and attributes modification(move)
540 bool isModified = false;
541 for (; anIt != aLast; anIt++) {
542 FeaturePtr aFeature = anIt.key();
544 std::set<AttributePtr> anAttributes = anIt.value().first;
545 // Process selection by attribute: the priority to the attribute
546 if (!anAttributes.empty()) {
547 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
548 anAttLast = anAttributes.end();
549 for (; anAttIt != anAttLast; anAttIt++) {
550 AttributePtr anAttr = *anAttIt;
551 if (anAttr.get() == NULL)
553 std::string aAttrId = anAttr->id();
554 DataPtr aData = aFeature->data();
555 if (aData->isValid()) {
556 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
557 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
558 if (aPoint.get() != NULL) {
559 bool isImmutable = aPoint->setImmutable(true);
560 aPoint->move(dX, dY);
562 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
563 aPoint->setImmutable(isImmutable);
568 // Process selection by feature
569 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
570 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
571 if (aSketchFeature) {
572 aSketchFeature->move(dX, dY);
574 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
578 // the modified state of the current operation should be updated if there are features, which
581 aCurrentOperation->onValuesChanged();
583 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
584 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
586 // 5. it is necessary to save current selection in order to restore it after the features moving
588 // 6. restore the update viewer flag and call this update
589 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
590 aDisplayer->updateViewer();
593 myCurrentPoint.setValue(aX, aY);
597 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
599 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
600 (getCurrentOperation());
601 if (aFOperation && aFOperation->isEditOperation()) {
602 std::string aId = aFOperation->id().toStdString();
603 if (isDistanceOperation(aFOperation))
605 // Activate dimension value editing on double click
606 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
607 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
608 // Find corresponded widget to activate value editing
609 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
610 if (aWgt->attributeID() == "ConstraintValue") {
611 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
613 anEditor->showPopupEditor();
621 void PartSet_SketcherMgr::onApplicationStarted()
623 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
624 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
625 XGUI_Workshop* aWorkshop = aConnector->workshop();
626 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
628 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
629 if (aPropertyPanel) {
630 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
631 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
633 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
634 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
635 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
636 aReentranceMgr, SLOT(onWidgetActivated()));
639 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
640 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
641 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
643 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
644 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
645 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
648 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
650 //if (!myClickedPoint.myIsInitialized)
653 //ModuleBase_Operation* aOperation = getCurrentOperation();
654 // the distance constraint feature should not use the clickedd point
655 // this is workaround in order to don't throw down the flyout point value,
656 // set by execute() method of these type of features
657 //if (isDistanceOperation(aOperation))
660 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
662 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
666 void PartSet_SketcherMgr::onBeforeContextMenu()
668 myIsPopupMenuActive = true;
671 void PartSet_SketcherMgr::onAfterContextMenu()
673 myIsPopupMenuActive = false;
676 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
679 Handle(V3d_View) aView = theWnd->v3dView();
680 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
682 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
683 thePoint.setValue(aX, anY);
686 void PartSet_SketcherMgr::launchEditing()
688 if (!myCurrentSelection.empty()) {
689 FeaturePtr aFeature = myCurrentSelection.begin().key();
690 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
691 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
693 myModule->editFeature(aSPFeature);
698 bool PartSet_SketcherMgr::sketchSolverError()
700 bool anError = false;
701 CompositeFeaturePtr aSketch = activeSketch();
703 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
704 anError = !aAttributeString->value().empty();
709 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
711 QString anError = "";
712 if (!theFeature.get() || !theFeature->data()->isValid())
715 CompositeFeaturePtr aSketch = activeSketch();
716 if (aSketch.get() && aSketch == theFeature) {
717 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
718 anError = aAttributeString->value().c_str();
723 void PartSet_SketcherMgr::clearClickedFlags()
725 //myClickedPoint.clear();
726 myCurrentPoint.clear();
729 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
731 static QStringList aIds;
732 if (aIds.size() == 0) {
733 aIds << SketchPlugin_Line::ID().c_str();
734 aIds << SketchPlugin_Point::ID().c_str();
735 aIds << SketchPlugin_Arc::ID().c_str();
736 aIds << SketchPlugin_Circle::ID().c_str();
737 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
738 aIds.append(constraintsIdList());
743 const QStringList& PartSet_SketcherMgr::constraintsIdList()
745 static QStringList aIds;
746 if (aIds.size() == 0) {
747 aIds << SketchPlugin_ConstraintLength::ID().c_str();
748 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
749 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
750 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
751 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
752 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
753 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
754 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
755 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
756 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
757 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
758 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
759 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
760 aIds << SketchPlugin_MultiRotation::ID().c_str();
761 aIds << SketchPlugin_MultiTranslation::ID().c_str();
766 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
770 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
771 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
772 theModes.append(SketcherPrs_Tools::Sel_Constraint);
773 theModes.append(TopAbs_VERTEX);
774 theModes.append(TopAbs_EDGE);
777 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
779 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
782 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
784 return theOperation &&
785 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
788 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
790 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
792 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
795 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
797 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
799 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
802 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
804 return (theId == SketchPlugin_Line::ID()) ||
805 (theId == SketchPlugin_Point::ID()) ||
806 (theId == SketchPlugin_Arc::ID()) ||
807 (theId == SketchPlugin_Circle::ID());
810 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
812 std::string anId = theOperation ? theOperation->id().toStdString() : "";
814 return isDistanceKind(anId);
817 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
819 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
820 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
821 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
822 (theKind == SketchPlugin_ConstraintAngle::ID());
825 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
827 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
828 (getCurrentOperation());
832 myModule->onViewTransformed();
834 // Display all sketcher sub-Objects
835 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
836 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
837 aConnector->workshop()->displayer()->activateTrihedron(true);
839 // Hide sketcher result
840 std::list<ResultPtr> aResults = myCurrentSketch->results();
841 std::list<ResultPtr>::const_iterator aIt;
842 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
843 (*aIt)->setDisplayed(false);
845 myCurrentSketch->setDisplayed(false);
847 // Display sketcher objects
848 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
849 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
850 std::list<ResultPtr> aResults = aFeature->results();
851 std::list<ResultPtr>::const_iterator aIt;
852 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
853 (*aIt)->setDisplayed(true);
855 aFeature->setDisplayed(true);
858 if (myPlaneFilter.IsNull())
859 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
861 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
863 bool aHasPlane = false;
864 std::shared_ptr<GeomAPI_Pln> aPln;
865 if (aFOperation->isEditOperation()) {
866 // If it is editing of sketch then it means that plane is already defined
867 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
871 myPlaneFilter->setPlane(aPln);
873 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
874 // all sketch objects should be activated in the sketch selection modes by edit operation start
875 // in case of creation operation, there is an active widget, which activates own selection mode
876 if (aFOperation->isEditOperation() && aHasPlane)
877 aConnector->activateModuleSelectionModes();
880 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
882 myIsMouseOverWindow = false;
883 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
884 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
886 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
888 DataPtr aData = myCurrentSketch->data();
889 if (!aData->isValid()) {
890 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
891 // The sketch was aborted
892 myCurrentSketch = CompositeFeaturePtr();
893 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
895 // Erase all sketcher objects
896 QStringList aSketchIds = sketchOperationIdList();
897 QObjectPtrList aObjects = aDisplayer->displayedObjects();
898 foreach (ObjectPtr aObj, aObjects) {
899 DataPtr aObjData = aObj->data();
900 if (!aObjData->isValid())
901 aObj->setDisplayed(false);
905 // Hide all sketcher sub-Objects
906 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
907 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
908 std::list<ResultPtr> aResults = aFeature->results();
909 std::list<ResultPtr>::const_iterator aIt;
910 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
911 (*aIt)->setDisplayed(false);
913 aFeature->setDisplayed(false);
915 // Display sketcher result
916 std::list<ResultPtr> aResults = myCurrentSketch->results();
917 std::list<ResultPtr>::const_iterator aIt;
918 Events_Loop* aLoop = Events_Loop::loop();
919 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
921 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
923 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
924 if (!aFOperation->isDisplayedOnStart(*aIt)) {
925 (*aIt)->setDisplayed(true);
926 // this display event is needed because sketch already may have "displayed" state,
927 // but not displayed while it is still active (issue 613, abort of existing sketch)
928 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
931 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
932 myCurrentSketch->setDisplayed(true);
934 myCurrentSketch = CompositeFeaturePtr();
935 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
937 Events_Loop::loop()->flush(aDispEvent);
939 // restore the module selection modes, which were changed on startSketch
940 aConnector->activateModuleSelectionModes();
941 aConnector->workshop()->displayer()->activateTrihedron(false);
944 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
946 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
947 QCursor* aCurrentCursor = QApplication::overrideCursor();
948 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
949 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
951 qDebug("startNestedSketch() : Qt::CrossCursor");
957 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
959 myIsMouseOverViewProcessed = true;
960 operationMgr()->onValidateOperation();
961 if (canChangeCursor(theOperation)) {
962 QApplication::restoreOverrideCursor();
964 qDebug("stopNestedSketch() : None");
969 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
971 if (isNestedCreateOperation(theOperation)) {
972 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
975 FeaturePtr aFeature = aFOperation->feature();
976 // it is necessary to check the the feature data validity because
977 // some kind of features are removed by an operation commit(the macro state of a feature)
978 if (aFeature.get() && aFeature->data()->isValid()) {
979 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
985 void PartSet_SketcherMgr::operationActivatedByPreselection()
987 ModuleBase_Operation* anOperation = getCurrentOperation();
988 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
989 // Set final definitions if they are necessary
990 //propertyPanelDefined(aOperation);
991 /// Commit sketcher operations automatically
992 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
995 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
996 FeaturePtr aFeature = aFOperation->feature();
997 // editor is shown only if all attribute references are filled by preseletion
998 bool anAllRefAttrInitialized = true;
1000 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1001 ModelAPI_AttributeRefAttr::typeId());
1002 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1003 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1004 anAllRefAttrInitialized = (*anIt)->isInitialized();
1006 if (anAllRefAttrInitialized) {
1007 // Activate dimension value editing on double click
1008 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1009 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1010 // Find corresponded widget to activate value editing
1011 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1012 if (aWgt->attributeID() == "ConstraintValue") {
1013 // the featue should be displayed in order to find the AIS text position,
1014 // the place where the editor will be shown
1015 aFeature->setDisplayed(true);
1016 /// the execute is necessary to perform in the feature compute for flyout position
1017 aFeature->execute();
1019 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1020 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1022 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1024 int aX = 0, anY = 0;
1026 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1027 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1028 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1029 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1030 Handle(AIS_InteractiveObject) anAISIO;
1031 if (anAIS.get() != NULL) {
1032 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1034 if (anAIS.get() != NULL) {
1035 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1037 if (!anAISIO.IsNull()) {
1038 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1039 if (!aDim.IsNull()) {
1040 gp_Pnt aPosition = aDim->GetTextPosition();
1042 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1043 Handle(V3d_View) aView = aViewer->activeView();
1045 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1047 QWidget* aViewPort = aViewer->activeViewPort();
1048 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1053 anEditor->setCursorPosition(aX, anY);
1054 anEditor->showPopupEditor(false);
1062 anOperation->commit();
1066 bool PartSet_SketcherMgr::canUndo() const
1068 return isNestedCreateOperation(getCurrentOperation());
1071 bool PartSet_SketcherMgr::canRedo() const
1073 return isNestedCreateOperation(getCurrentOperation());
1076 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1078 bool aCanErase = true;
1079 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1080 if (myCurrentSketch.get()) {
1081 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1082 if (aResult.get()) {
1083 // Display sketcher objects
1084 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1086 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1087 std::list<ResultPtr> aResults = aFeature->results();
1088 std::list<ResultPtr>::const_iterator anIt;
1089 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1090 aCanErase = *anIt != aResult;
1098 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1100 bool aCanDisplay = true;
1102 bool aHasActiveSketch = activeSketch().get() != NULL;
1103 if (aHasActiveSketch) {
1104 // 1. the sketch feature should not be displayed during the sketch active operation
1105 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1106 // nested features can be visualized
1107 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1108 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1109 aCanDisplay = false;
1112 else { // there are no an active sketch
1113 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1114 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1115 if (aFeature.get() != NULL) {
1116 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1117 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1118 if (aSketchFeature.get()) {
1119 aCanDisplay = false;
1124 // 3. the method should not filter the objects, which are not related to the current operation.
1125 // The object is filtered just if it is a current operation feature or this feature result
1126 bool isObjectFound = false;
1127 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1128 (getCurrentOperation());
1130 FeaturePtr aFeature = aFOperation->feature();
1131 if (aFeature.get()) {
1132 std::list<ResultPtr> aResults = aFeature->results();
1133 if (theObject == aFeature)
1134 isObjectFound = true;
1136 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1137 for (; anIt != aLast && !isObjectFound; anIt++) {
1138 isObjectFound = *anIt == theObject;
1146 // 4. For created nested feature operation do not display the created feature if
1147 // the mouse curstor leaves the OCC window.
1148 // The correction cases, which ignores this condition:
1149 // a. the property panel values modification
1150 // b. the popup menu activated
1151 // c. widget editor control
1152 #ifndef DEBUG_DO_NOT_BY_ENTER
1153 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1154 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1155 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1156 // the active widget editor should not influence here. The presentation should be visible always
1157 // when this widget is active.
1158 if (!anEditorWdg && !myIsPopupMenuActive) {
1159 // during a nested create operation, the feature is redisplayed only if the mouse over view
1160 // of there was a value modified in the property panel after the mouse left the view
1161 aCanDisplay = canDisplayCurrentCreatedFeature();
1168 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1170 bool aCanDisplay = myIsMouseOverWindow;
1172 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1174 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1179 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1181 return isNestedCreateOperation(theOperation) ||
1182 myModule->sketchReentranceMgr()->isInternalEditActive();
1185 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1187 return myIsConstraintsShown;
1190 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1192 bool isFoundObject = false;
1194 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1195 if (anObjectFeature.get()) {
1196 int aSize = myCurrentSketch->numberOfSubs();
1197 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1198 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1199 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1202 return isFoundObject;
1205 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1207 if (myPlaneFilter.IsNull())
1208 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1210 myPlaneFilter->setPlane(thePln);
1213 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1214 const FeaturePtr& theSketch,
1215 ModuleBase_IWorkshop* theWorkshop,
1216 FeatureToSelectionMap& theSelection)
1218 if (theFeature.get() == NULL)
1221 std::set<AttributePtr> aSelectedAttributes;
1222 std::set<ResultPtr> aSelectedResults;
1224 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1225 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1226 if (!aContext.IsNull()) {
1227 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1228 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1230 std::list<ResultPtr> aResults = theFeature->results();
1231 std::list<ResultPtr>::const_iterator aIt;
1232 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1234 ResultPtr aResult = *aIt;
1235 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1236 if (aAISObj.get() == NULL)
1238 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1239 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1241 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1242 if (anOwner->Selectable() != anAISIO)
1244 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1245 aSelectedAttributes, aSelectedResults);
1247 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1248 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1249 if (anOwner.IsNull())
1251 if (anOwner->Selectable() != anAISIO)
1253 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1254 aSelectedAttributes, aSelectedResults);
1258 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1261 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1262 const FeaturePtr& theSketch,
1263 ModuleBase_IWorkshop* theWorkshop,
1264 const FeatureToSelectionMap& theSelection,
1265 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1267 if (theFeature.get() == NULL)
1270 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1271 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1272 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1274 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1276 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1277 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1279 // 1. found the feature's owners. Check the AIS objects of the constructions
1280 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1281 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1282 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1284 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1285 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1286 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1287 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1288 if (!anOwner.IsNull())
1289 theOwnersToSelect.Add(anOwner);
1293 // 2. found the feature results's owners
1294 std::list<ResultPtr> aResults = theFeature->results();
1295 std::list<ResultPtr>::const_iterator aIt;
1296 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1298 ResultPtr aResult = *aIt;
1299 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1300 if (aAISObj.get() == NULL)
1302 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1304 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1305 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1306 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1307 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1308 if ( anOwner.IsNull() || !anOwner->HasShape() )
1310 const TopoDS_Shape& aShape = anOwner->Shape();
1311 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1312 if (aShapeType == TopAbs_VERTEX) {
1313 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1314 if (aPntAttr.get() != NULL &&
1315 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1316 theOwnersToSelect.Add(anOwner);
1319 else if (aShapeType == TopAbs_EDGE) {
1320 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1321 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1322 theOwnersToSelect.FindIndex(anOwner) <= 0)
1323 theOwnersToSelect.Add(anOwner);
1329 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1332 connect(theWidget, SIGNAL(beforeValuesChanged()),
1333 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1334 connect(theWidget, SIGNAL(afterValuesChanged()),
1335 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1338 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1339 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1340 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1341 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1345 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1347 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1348 (getCurrentOperation());
1350 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1351 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1352 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1353 FeaturePtr aFeature = aFOperation->feature();
1354 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1359 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1361 return myModule->workshop()->currentOperation();
1364 //**************************************************************
1365 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1367 ModuleBase_ModelWidget* aWidget = 0;
1368 ModuleBase_Operation* anOperation = getCurrentOperation();
1370 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1372 aWidget = aPanel->activeWidget();
1377 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1378 const bool isEditOperation,
1379 const bool isToDisplay,
1380 const bool isFlushRedisplay)
1382 #ifdef DEBUG_DO_NOT_BY_ENTER
1386 if (isEditOperation || !theFeature.get())
1389 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1390 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1392 // 1. change visibility of the object itself, here the presentable object is processed,
1393 // e.g. constraints features
1394 //FeaturePtr aFeature = aFOperation->feature();
1395 std::list<ResultPtr> aResults = theFeature->results();
1397 theFeature->setDisplayed(true);
1399 theFeature->setDisplayed(false);
1401 // change visibility of the object results, e.g. non-constraint features
1402 std::list<ResultPtr>::const_iterator aIt;
1403 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1405 (*aIt)->setDisplayed(true);
1408 (*aIt)->setDisplayed(false);
1411 if (isFlushRedisplay)
1412 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1415 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1417 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1418 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1419 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1421 QList<FeaturePtr> aFeatureList;
1422 if (theHighlightedOnly) {
1423 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1426 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1428 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1429 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1432 // 1. it is necessary to save current selection in order to restore it after the features moving
1433 myCurrentSelection.clear();
1434 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1435 for (; anIt != aLast; anIt++) {
1436 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1438 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1441 void PartSet_SketcherMgr::restoreSelection()
1443 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1444 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1445 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1446 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1447 aSLast = myCurrentSelection.end();
1448 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1449 for (; aSIt != aSLast; aSIt++) {
1450 anOwnersToSelect.Clear();
1451 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1453 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1457 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theState, int theType)
1459 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1460 if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1462 if (myCurrentSketch.get() == NULL)
1465 myIsConstraintsShown[aType] = theState;
1467 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1468 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1470 const QStringList& aConstrIds = constraintsIdList();
1471 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1472 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1473 std::string aKind = aSubFeature->getKind();
1474 if (aConstrIds.contains(QString(aKind.c_str()))) {
1475 bool isTypedConstraint = false;
1476 if (aType == PartSet_Tools::Dimensional) {
1477 isTypedConstraint = isDistanceKind(aKind);
1480 isTypedConstraint = !isDistanceKind(aKind);
1482 if (isTypedConstraint) {
1484 aSubFeature->setDisplayed(true);
1486 aSubFeature->setDisplayed(false);
1490 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1493 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1495 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1496 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1497 XGUI_Workshop* aWorkshop = aConnector->workshop();
1499 return aWorkshop->operationMgr();