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"
15 #include "PartSet_ResultSketchPrs.h"
17 #include <XGUI_ModuleConnector.h>
18 #include <XGUI_Displayer.h>
19 #include <XGUI_Workshop.h>
20 #include <XGUI_ContextMenuMgr.h>
21 #include <XGUI_Selection.h>
22 #include <XGUI_SelectionMgr.h>
23 #include <XGUI_ModuleConnector.h>
24 #include <XGUI_PropertyPanel.h>
25 #include <XGUI_ViewerProxy.h>
26 #include <XGUI_OperationMgr.h>
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>
40 #include <GeomDataAPI_Point2D.h>
42 #include <Events_Loop.h>
44 #include <SketchPlugin_Line.h>
45 #include <SketchPlugin_Sketch.h>
46 #include <SketchPlugin_Point.h>
47 #include <SketchPlugin_Arc.h>
48 #include <SketchPlugin_Circle.h>
49 #include <SketchPlugin_ConstraintLength.h>
50 #include <SketchPlugin_ConstraintDistance.h>
51 #include <SketchPlugin_ConstraintParallel.h>
52 #include <SketchPlugin_ConstraintPerpendicular.h>
53 #include <SketchPlugin_ConstraintRadius.h>
54 #include <SketchPlugin_ConstraintRigid.h>
55 #include <SketchPlugin_ConstraintHorizontal.h>
56 #include <SketchPlugin_ConstraintVertical.h>
57 #include <SketchPlugin_ConstraintEqual.h>
58 #include <SketchPlugin_ConstraintTangent.h>
59 #include <SketchPlugin_ConstraintCoincidence.h>
60 #include <SketchPlugin_ConstraintFillet.h>
61 #include <SketchPlugin_ConstraintMirror.h>
62 #include <SketchPlugin_ConstraintAngle.h>
63 #include <SketchPlugin_ConstraintCollinear.h>
64 #include <SketchPlugin_ConstraintMiddle.h>
65 #include <SketchPlugin_MultiRotation.h>
66 #include <SketchPlugin_MultiTranslation.h>
67 #include <SketchPlugin_IntersectionPoint.h>
69 #include <SketcherPrs_Tools.h>
71 #include <SelectMgr_IndexedMapOfOwner.hxx>
72 #include <StdSelect_BRepOwner.hxx>
74 //#include <AIS_DimensionSelectionMode.hxx>
75 #include <AIS_Shape.hxx>
76 #include <AIS_Dimension.hxx>
78 #include <ModelAPI_Events.h>
79 #include <ModelAPI_Session.h>
80 #include <ModelAPI_AttributeString.h>
82 #include <QMouseEvent>
83 #include <QApplication>
85 #include <QMessageBox>
87 //#define DEBUG_DO_NOT_BY_ENTER
89 //#define DEBUG_CURSOR
91 /// Returns list of unique objects by sum of objects from List1 and List2
92 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
93 const QList<ModuleBase_ViewerPrs>& theList2)
95 QList<ModuleBase_ViewerPrs> aRes;
96 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
97 if (!aRes.contains(aPrs))
100 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
101 if (!aRes.contains(aPrs))
107 // Fills the list of features the list of selected presentations.
108 // \param theList a list of selected presentations
109 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
110 // and find the corresponded attribute
111 // \param theFeatureList an output list of features
112 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
113 const FeaturePtr theSketch,
114 QList<FeaturePtr>& theFeatureList)
116 QList<ModuleBase_ViewerPrs> aRes;
118 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
119 aLast = theList.end();
120 for (; anIt != aLast; anIt++)
122 ModuleBase_ViewerPrs aPrs = *anIt;
123 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
124 if (aFeature.get() && !theFeatureList.contains(aFeature))
125 theFeatureList.append(aFeature);
129 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
130 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
131 /// result as is to the list of results.
132 /// \param theOwner a viewer selected owner
133 /// \param theFeature a feature, where the attribute is searched
134 /// \param theSketch a current sketch
135 /// \param theSelectedAttribute an output list of attributes
136 /// \param theSelectedResults an output list of edge results
137 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
138 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
139 const ResultPtr& theResult,
140 std::set<AttributePtr>& aSelectedAttributes,
141 std::set<ResultPtr>& aSelectedResults)
143 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
144 if (aBRepOwner.IsNull())
146 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
147 aBRepOwner->Selectable());
148 if (aBRepOwner->HasShape()) {
149 const TopoDS_Shape& aShape = aBRepOwner->Shape();
150 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
151 if (aShapeType == TopAbs_VERTEX) {
152 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
154 if (aPntAttr.get() != NULL)
155 aSelectedAttributes.insert(aPntAttr);
157 else if (aShapeType == TopAbs_EDGE &&
158 aSelectedResults.find(theResult) == aSelectedResults.end()) {
159 aSelectedResults.insert(theResult);
164 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
165 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
166 myIsMouseOverWindow(false),
167 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
168 myIsPopupMenuActive(false)
170 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
171 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
173 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
175 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
176 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
178 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
179 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
181 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
182 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
184 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
185 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
187 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
188 XGUI_Workshop* aWorkshop = aConnector->workshop();
189 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
191 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
192 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
193 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
196 PartSet_SketcherMgr::~PartSet_SketcherMgr()
198 if (!myPlaneFilter.IsNull())
199 myPlaneFilter.Nullify();
202 void PartSet_SketcherMgr::onEnterViewPort()
204 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
205 // created feature because it should be done in onMouseMove(). Some widgets watch
206 // the mouse move and use the cursor position to update own values. If the presentaion is
207 // redisplayed before this update, the feature presentation jumps from reset value to current.
208 myIsMouseOverWindow = true;
210 #ifdef DEBUG_DO_NOT_BY_ENTER
214 if (canChangeCursor(getCurrentOperation())) {
215 QCursor* aCurrentCursor = QApplication::overrideCursor();
216 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
217 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
219 qDebug("onEnterViewPort() : Qt::CrossCursor");
224 if (!isNestedCreateOperation(getCurrentOperation()))
227 operationMgr()->onValidateOperation();
229 // we need change displayed state of the current operation feature
230 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
231 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
232 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
233 // presentation becomes valid and redisplay happens
234 //ModuleBase_Operation* aOperation = getCurrentOperation();
235 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
236 (getCurrentOperation());
238 FeaturePtr aFeature = aFOperation->feature();
239 if (aFeature.get() && aFeature->data()->isValid()) {
240 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
245 void PartSet_SketcherMgr::onLeaveViewPort()
247 myIsMouseOverViewProcessed = false;
248 myIsMouseOverWindow = false;
249 // it is important to validate operation here only if sketch entity create operation is active
250 // because at this operation we reacts to the mouse leave/enter view port
251 //operationMgr()->onValidateOperation();
253 #ifdef DEBUG_DO_NOT_BY_ENTER
257 if (canChangeCursor(getCurrentOperation())) {
258 QApplication::restoreOverrideCursor();
260 qDebug("onLeaveViewPort() : None");
264 if (!isNestedCreateOperation(getCurrentOperation()))
267 // the method should be performed if the popup menu is called,
268 // the reset of the current widget should not happen
269 if (myIsPopupMenuActive)
272 operationMgr()->onValidateOperation();
274 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
275 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
276 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
277 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
278 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
279 // obtained after reset value
280 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
281 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
283 anActiveWidget->reset();
285 // hides the presentation of the current operation feature
286 // the feature is to be erased here, but it is correct to call canDisplayObject because
287 // there can be additional check (e.g. editor widget in distance constraint)
288 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
289 (getCurrentOperation());
291 FeaturePtr aFeature = aFOperation->feature();
292 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
294 // we should update viewer after the presentation are hidden in the viewer
295 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
296 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
299 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
301 if (!isNestedEditOperation(getCurrentOperation()) ||
302 myModule->sketchReentranceMgr()->isInternalEditActive())
304 // it is necessary to save current selection in order to restore it after the values are modifed
307 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
308 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
309 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
310 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
313 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
315 if (!isNestedEditOperation(getCurrentOperation()) ||
316 myModule->sketchReentranceMgr()->isInternalEditActive()) {
317 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
320 // it is necessary to restore current selection in order to restore it after the values are modified
322 myCurrentSelection.clear();
324 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
325 // viewer happens by deselect/select the modified objects. The flag should be restored after
326 // the selection processing. The update viewer should be also called.
327 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
328 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
329 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
330 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
331 aDisplayer->updateViewer();
336 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
338 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
341 //get2dPoint(theWnd, theEvent, myClickedPoint);
343 if (!(theEvent->buttons() & Qt::LeftButton))
346 // Clear dragging mode
347 myIsDragging = false;
349 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
350 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
351 if (!aViewer->canDragByMouse())
354 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
355 (getCurrentOperation());
359 if (aFOperation->isEditOperation()) {
360 // If the current widget is a selector, do nothing, it processes the mouse press
361 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
362 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
367 // Use only for sketch operations
368 if (myCurrentSketch) {
369 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
372 bool isSketcher = isSketchOperation(aFOperation);
373 bool isSketchOpe = isNestedSketchOperation(aFOperation);
375 // Avoid non-sketch operations
376 if ((!isSketchOpe) && (!isSketcher))
379 bool isEditing = aFOperation->isEditOperation();
381 // Ignore creation sketch operation
382 if ((!isSketcher) && (!isEditing))
385 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
386 if (!aContext.IsNull()) {
387 // MoveTo in order to highlight current object
388 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
390 // Remember highlighted objects for editing
391 ModuleBase_ISelection* aSelect = aWorkshop->selection();
393 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
394 storeSelection(!aHasShift);
396 if (myCurrentSelection.empty()) {
397 if (isSketchOpe && (!isSketcher))
398 // commit previous operation
399 if (!aFOperation->commit())
400 aFOperation->abort();
403 // Init flyout point for radius rotation
404 FeaturePtr aFeature = myCurrentSelection.begin().key();
408 get2dPoint(theWnd, theEvent, myCurrentPoint);
411 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
413 if (aFeature.get() != NULL) {
414 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
415 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
416 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
417 DataPtr aData = aSPFeature->data();
418 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
419 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
420 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
421 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
424 } else if (isSketchOpe && isEditing) {
425 // If selected another object commit current result
426 aFOperation->commit();
429 get2dPoint(theWnd, theEvent, myCurrentPoint);
432 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
434 // this is temporary commented in order to avoid the following wrong case:
435 // Distance constraint is under edition, double click on the digit -> nothing happens
436 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
437 // but as the prev edit is commited an new one is not started, editor is not shown.
438 // This is necessary in order to finalize previous operation
439 //QApplication::processEvents();
445 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
447 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
450 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
451 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
452 if (!aViewer->canDragByMouse())
454 ModuleBase_Operation* aOp = getCurrentOperation();
456 if (isNestedSketchOperation(aOp)) {
457 //get2dPoint(theWnd, theEvent, myClickedPoint);
459 // Only for sketcher operations
463 myCurrentSelection.clear();
464 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
465 if (!aContext.IsNull()) {
466 // Reselect edited object
467 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
468 if (theEvent->modifiers() & Qt::ShiftModifier)
469 aContext->ShiftSelect();
478 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
479 myIsDragging = false;
482 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
484 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
487 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
488 myIsMouseOverViewProcessed = true;
489 // 1. perform the widget mouse move functionality and display the presentation
490 // the mouse move should be processed in the widget, if it can in order to visualize correct
491 // presentation. These widgets correct the feature attribute according to the mouse position
492 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
493 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
495 aPoint2DWdg->onMouseMove(theWnd, theEvent);
497 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
500 aDistanceWdg->onMouseMove(theWnd, theEvent);
502 // the feature is to be erased here, but it is correct to call canDisplayObject because
503 // there can be additional check (e.g. editor widget in distance constraint)
504 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
505 (getCurrentOperation());
507 FeaturePtr aFeature = aFOperation->feature();
508 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
512 //myClickedPoint.clear();
515 // 1. the current selection is saved in the mouse press method in order to restore it after moving
516 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
517 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
518 // deselected). This flag should be restored in the slot, processed the mouse release signal.
520 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
521 if (!aCurrentOperation)
523 if (isSketchOperation(aCurrentOperation))
524 return; // No edit operation activated
526 Handle(V3d_View) aView = theWnd->v3dView();
527 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
529 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
530 double dX = aX - myCurrentPoint.myCurX;
531 double dY = aY - myCurrentPoint.myCurY;
533 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
534 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
535 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
536 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
537 // viewer happens by deselect/select the modified objects. The flag should be restored after
538 // the selection processing. The update viewer should be also called.
539 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
541 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
542 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
543 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
544 aLast = myCurrentSelection.end();
545 // 4. the features and attributes modification(move)
546 bool isModified = false;
547 for (; anIt != aLast; anIt++) {
548 FeaturePtr aFeature = anIt.key();
550 std::set<AttributePtr> anAttributes = anIt.value().first;
551 // Process selection by attribute: the priority to the attribute
552 if (!anAttributes.empty()) {
553 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
554 anAttLast = anAttributes.end();
555 for (; anAttIt != anAttLast; anAttIt++) {
556 AttributePtr anAttr = *anAttIt;
557 if (anAttr.get() == NULL)
559 std::string aAttrId = anAttr->id();
560 DataPtr aData = aFeature->data();
561 if (aData->isValid()) {
562 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
563 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
564 if (aPoint.get() != NULL) {
565 bool isImmutable = aPoint->setImmutable(true);
566 aPoint->move(dX, dY);
568 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
569 aPoint->setImmutable(isImmutable);
574 // Process selection by feature
575 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
576 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
577 if (aSketchFeature) {
578 aSketchFeature->move(dX, dY);
580 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
584 // the modified state of the current operation should be updated if there are features, which
587 aCurrentOperation->onValuesChanged();
589 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
590 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
592 // 5. it is necessary to save current selection in order to restore it after the features moving
594 // 6. restore the update viewer flag and call this update
595 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
596 aDisplayer->updateViewer();
599 myCurrentPoint.setValue(aX, aY);
603 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
605 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
606 (getCurrentOperation());
607 if (aFOperation && aFOperation->isEditOperation()) {
608 std::string aId = aFOperation->id().toStdString();
609 if (isDistanceOperation(aFOperation))
611 // Activate dimension value editing on double click
612 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
613 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
614 // Find corresponded widget to activate value editing
615 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
616 if (aWgt->attributeID() == "ConstraintValue") {
617 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
619 anEditor->showPopupEditor();
627 void PartSet_SketcherMgr::onApplicationStarted()
629 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
630 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
631 XGUI_Workshop* aWorkshop = aConnector->workshop();
632 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
634 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
635 if (aPropertyPanel) {
636 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
637 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
639 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
640 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
641 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
642 aReentranceMgr, SLOT(onWidgetActivated()));
645 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
646 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
647 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
649 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
650 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
651 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
654 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
656 //if (!myClickedPoint.myIsInitialized)
659 //ModuleBase_Operation* aOperation = getCurrentOperation();
660 // the distance constraint feature should not use the clickedd point
661 // this is workaround in order to don't throw down the flyout point value,
662 // set by execute() method of these type of features
663 //if (isDistanceOperation(aOperation))
666 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
668 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
672 void PartSet_SketcherMgr::onBeforeContextMenu()
674 myIsPopupMenuActive = true;
677 void PartSet_SketcherMgr::onAfterContextMenu()
679 myIsPopupMenuActive = false;
682 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
685 Handle(V3d_View) aView = theWnd->v3dView();
686 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
688 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
689 thePoint.setValue(aX, anY);
692 void PartSet_SketcherMgr::launchEditing()
694 if (!myCurrentSelection.empty()) {
695 FeaturePtr aFeature = myCurrentSelection.begin().key();
696 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
697 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
699 myModule->editFeature(aSPFeature);
704 bool PartSet_SketcherMgr::sketchSolverError()
706 bool anError = false;
707 CompositeFeaturePtr aSketch = activeSketch();
709 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
710 anError = !aAttributeString->value().empty();
715 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
717 QString anError = "";
718 if (!theFeature.get() || !theFeature->data()->isValid())
721 CompositeFeaturePtr aSketch = activeSketch();
722 if (aSketch.get() && aSketch == theFeature) {
723 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
724 anError = aAttributeString->value().c_str();
729 void PartSet_SketcherMgr::clearClickedFlags()
731 //myClickedPoint.clear();
732 myCurrentPoint.clear();
735 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
737 static QStringList aIds;
738 if (aIds.size() == 0) {
739 aIds << SketchPlugin_Line::ID().c_str();
740 aIds << SketchPlugin_Point::ID().c_str();
741 aIds << SketchPlugin_Arc::ID().c_str();
742 aIds << SketchPlugin_Circle::ID().c_str();
743 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
744 aIds << SketchPlugin_IntersectionPoint::ID().c_str();
746 // SketchRectangle is a python feature, so its ID is passed just as a string
747 aIds << "SketchRectangle";
748 aIds.append(constraintsIdList());
753 const QStringList& PartSet_SketcherMgr::constraintsIdList()
755 static QStringList aIds;
756 if (aIds.size() == 0) {
757 aIds << SketchPlugin_ConstraintLength::ID().c_str();
758 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
759 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
760 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
761 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
762 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
763 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
764 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
765 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
766 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
767 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
768 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
769 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
770 aIds << SketchPlugin_MultiRotation::ID().c_str();
771 aIds << SketchPlugin_MultiTranslation::ID().c_str();
772 aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
773 aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
778 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
782 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
783 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
784 theModes.append(SketcherPrs_Tools::Sel_Constraint);
785 theModes.append(TopAbs_VERTEX);
786 theModes.append(TopAbs_EDGE);
789 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
791 Handle(AIS_InteractiveObject) aPrs;
793 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
794 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
795 aPrs = new PartSet_ResultSketchPrs(theResult);
800 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
802 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
805 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
807 return theOperation &&
808 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
811 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
813 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
815 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
818 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
820 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
822 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
825 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
827 return (theId == SketchPlugin_Line::ID()) ||
828 (theId == SketchPlugin_Point::ID()) ||
829 (theId == SketchPlugin_Arc::ID()) ||
830 (theId == SketchPlugin_Circle::ID());
833 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
835 std::string anId = theOperation ? theOperation->id().toStdString() : "";
837 return isDistanceKind(anId);
840 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
842 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
843 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
844 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
845 (theKind == SketchPlugin_ConstraintAngle::ID());
848 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
850 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
851 (getCurrentOperation());
855 myModule->onViewTransformed();
857 // Display all sketcher sub-Objects
858 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
859 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
860 aConnector->workshop()->displayer()->activateTrihedron(true);
862 // Hide sketcher result
863 std::list<ResultPtr> aResults = myCurrentSketch->results();
864 std::list<ResultPtr>::const_iterator aIt;
865 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
866 (*aIt)->setDisplayed(false);
868 myCurrentSketch->setDisplayed(false);
870 // Display sketcher objects
871 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
872 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
873 std::list<ResultPtr> aResults = aFeature->results();
874 std::list<ResultPtr>::const_iterator aIt;
875 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
876 (*aIt)->setDisplayed(true);
878 aFeature->setDisplayed(true);
881 if(myCirclePointFilter.IsNull()) {
882 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
885 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
887 if (myPlaneFilter.IsNull())
888 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
890 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
891 bool aHasPlane = false;
892 std::shared_ptr<GeomAPI_Pln> aPln;
893 if (aFOperation->isEditOperation()) {
894 // If it is editing of sketch then it means that plane is already defined
895 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
899 myPlaneFilter->setPlane(aPln);
901 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
902 // all sketch objects should be activated in the sketch selection modes by edit operation start
903 // in case of creation operation, there is an active widget, which activates own selection mode
904 if (aFOperation->isEditOperation() && aHasPlane)
905 aConnector->activateModuleSelectionModes();
908 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
910 myIsMouseOverWindow = false;
911 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
912 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
913 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
915 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
917 DataPtr aData = myCurrentSketch->data();
918 if (!aData->isValid()) {
919 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
920 // The sketch was aborted
921 myCurrentSketch = CompositeFeaturePtr();
922 // TODO: move this outside of if-else
923 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
924 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
926 // Erase all sketcher objects
927 QStringList aSketchIds = sketchOperationIdList();
928 QObjectPtrList aObjects = aDisplayer->displayedObjects();
929 foreach (ObjectPtr aObj, aObjects) {
930 DataPtr aObjData = aObj->data();
931 if (!aObjData->isValid())
932 aObj->setDisplayed(false);
936 // Hide all sketcher sub-Objects
937 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
938 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
939 std::list<ResultPtr> aResults = aFeature->results();
940 std::list<ResultPtr>::const_iterator aIt;
941 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
942 (*aIt)->setDisplayed(false);
944 aFeature->setDisplayed(false);
946 // Display sketcher result
947 std::list<ResultPtr> aResults = myCurrentSketch->results();
948 std::list<ResultPtr>::const_iterator aIt;
949 Events_Loop* aLoop = Events_Loop::loop();
950 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
952 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
954 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
955 if (!aFOperation->isDisplayedOnStart(*aIt)) {
956 (*aIt)->setDisplayed(true);
957 // this display event is needed because sketch already may have "displayed" state,
958 // but not displayed while it is still active (issue 613, abort of existing sketch)
959 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
962 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
963 myCurrentSketch->setDisplayed(true);
965 myCurrentSketch = CompositeFeaturePtr();
967 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
968 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
970 Events_Loop::loop()->flush(aDispEvent);
972 // restore the module selection modes, which were changed on startSketch
973 aConnector->activateModuleSelectionModes();
974 aConnector->workshop()->displayer()->activateTrihedron(false);
977 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
979 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
980 QCursor* aCurrentCursor = QApplication::overrideCursor();
981 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
982 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
984 qDebug("startNestedSketch() : Qt::CrossCursor");
990 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
992 myIsMouseOverViewProcessed = true;
993 operationMgr()->onValidateOperation();
994 if (canChangeCursor(theOperation)) {
995 QApplication::restoreOverrideCursor();
997 qDebug("stopNestedSketch() : None");
1002 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1004 if (isNestedCreateOperation(theOperation)) {
1005 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1008 FeaturePtr aFeature = aFOperation->feature();
1009 // it is necessary to check the the feature data validity because
1010 // some kind of features are removed by an operation commit(the macro state of a feature)
1011 if (aFeature.get() && aFeature->data()->isValid()) {
1012 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1018 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1021 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1023 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1026 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1028 bool isOperationStopped = false;
1029 ModuleBase_Operation* anOperation = getCurrentOperation();
1030 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1031 // Set final definitions if they are necessary
1032 //propertyPanelDefined(aOperation);
1033 /// Commit sketcher operations automatically
1034 /// distance operation are able to show popup editor to modify the distance value
1035 /// after entering the value, the operation should be committed/aborted(by Esc key)
1036 bool aCanCommitOperation = true;
1037 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1039 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation))
1040 aCanCommitOperation = setDistanceValueByPreselection(anOperation, myModule->workshop());
1042 if (aCanCommitOperation)
1043 isOperationStopped = anOperation->commit();
1045 anOperation->abort();
1046 isOperationStopped = true;
1049 return isOperationStopped;
1052 bool PartSet_SketcherMgr::canUndo() const
1054 return isNestedCreateOperation(getCurrentOperation());
1057 bool PartSet_SketcherMgr::canRedo() const
1059 return isNestedCreateOperation(getCurrentOperation());
1062 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1064 bool aCanErase = true;
1065 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1066 if (myCurrentSketch.get()) {
1067 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1068 if (aResult.get()) {
1069 // Display sketcher objects
1070 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1072 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1073 std::list<ResultPtr> aResults = aFeature->results();
1074 std::list<ResultPtr>::const_iterator anIt;
1075 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1076 aCanErase = *anIt != aResult;
1084 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1086 bool aCanDisplay = true;
1088 bool aHasActiveSketch = activeSketch().get() != NULL;
1089 if (aHasActiveSketch) {
1090 // 1. the sketch feature should not be displayed during the sketch active operation
1091 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1092 // nested features can be visualized
1093 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1094 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1095 aCanDisplay = false;
1098 else { // there are no an active sketch
1099 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1100 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1101 if (aFeature.get() != NULL) {
1102 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1103 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1104 if (aSketchFeature.get()) {
1105 aCanDisplay = false;
1110 // 3. the method should not filter the objects, which are not related to the current operation.
1111 // The object is filtered just if it is a current operation feature or this feature result
1112 bool isObjectFound = false;
1113 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1114 (getCurrentOperation());
1116 FeaturePtr aFeature = aFOperation->feature();
1117 if (aFeature.get()) {
1118 std::list<ResultPtr> aResults = aFeature->results();
1119 if (theObject == aFeature)
1120 isObjectFound = true;
1122 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1123 for (; anIt != aLast && !isObjectFound; anIt++) {
1124 isObjectFound = *anIt == theObject;
1129 if (isObjectFound) {
1130 // 4. For created nested feature operation do not display the created feature if
1131 // the mouse curstor leaves the OCC window.
1132 // The correction cases, which ignores this condition:
1133 // a. the property panel values modification
1134 // b. the popup menu activated
1135 // c. widget editor control
1136 #ifndef DEBUG_DO_NOT_BY_ENTER
1137 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1138 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1139 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1140 // the active widget editor should not influence here. The presentation should be visible always
1141 // when this widget is active.
1142 if (!anEditorWdg && !myIsPopupMenuActive) {
1143 // during a nested create operation, the feature is redisplayed only if the mouse over view
1144 // of there was a value modified in the property panel after the mouse left the view
1145 aCanDisplay = canDisplayCurrentCreatedFeature();
1151 // checks the sketcher constraints visibility according to active sketch check box states
1153 bool aProcessed = false;
1154 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1155 if (aFeature.get()) {
1156 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1158 aCanDisplay = aConstraintDisplayed;
1165 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1166 const PartSet_Tools::ConstraintVisibleState& theState,
1167 bool& isProcessed) const
1169 bool aSwitchedOn = true;
1171 const QStringList& aConstrIds = constraintsIdList();
1173 std::string aKind = theFeature->getKind();
1174 if (aConstrIds.contains(QString(aKind.c_str()))) {
1175 bool isTypedConstraint = false;
1178 case PartSet_Tools::Dimensional: {
1179 bool isDistance = isDistanceKind(aKind);
1182 aSwitchedOn = myIsConstraintsShown[theState];
1186 case PartSet_Tools::Geometrical: {
1187 bool isGeometrical = !isDistanceKind(aKind);
1188 if (isGeometrical) {
1190 aSwitchedOn = myIsConstraintsShown[theState];
1194 case PartSet_Tools::Any: {
1196 bool isDistance = isDistanceKind(aKind);
1198 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1200 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1210 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1212 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1213 (getCurrentOperation());
1214 if (aFOperation && myCurrentSketch.get()) {
1215 // find results of the current operation
1216 // these results should not be proposed to be deleted
1217 FeaturePtr anOperationFeature = aFOperation->feature();
1218 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1219 std::set<ResultPtr> anOperationResults;
1220 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1221 aRLast = anOperationResultList.end();
1222 for (; aRIt != aRLast; aRIt++)
1223 anOperationResults.insert(*aRIt);
1225 std::set<FeaturePtr> anObjectsToBeDeleted;
1226 QStringList anObjectsToBeDeletedNames;
1227 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1228 for (; anIt != aLast; anIt++) {
1229 ObjectPtr anObject = *anIt;
1230 bool aCanErase = true;
1231 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1232 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1233 // the result is found between current feature results
1234 if (anOperationResults.find(aResult) != anOperationResults.end())
1237 if (aResult.get()) {
1238 // Display sketcher objects
1239 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1240 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1241 std::list<ResultPtr> aResults = aFeature->results();
1242 std::list<ResultPtr>::const_iterator anIt;
1243 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1244 aCanErase = *anIt != aResult;
1249 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1250 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1251 anObjectsToBeDeleted.insert(aFeature);
1252 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1256 if (!anObjectsToBeDeleted.empty()) {
1257 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1258 QString aMessage = tr("The following features have incorrect presentation and \
1259 will be hidden: %1. Would you like to delete them?")
1260 .arg(aFeatureNames);
1261 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1262 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1263 QMessageBox::Cancel);
1264 if (anAnswer == QMessageBox::Ok) {
1265 QObjectPtrList anObjects;
1266 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1267 aLast = anObjectsToBeDeleted.end();
1268 for (; anIt != aLast; anIt++)
1269 anObjects.append(*anIt);
1270 SessionPtr aMgr = ModelAPI_Session::get();
1271 DocumentPtr aDoc = aMgr->activeDocument();
1272 bool aIsOp = aMgr->isOperation();
1274 aMgr->startOperation();
1275 workshop()->deleteFeatures(anObjects);
1276 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1277 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1278 //Events_Loop::loop()->flush(aDeletedEvent);
1279 //Events_Loop::loop()->flush(aRedispEvent);
1282 aMgr->finishOperation();
1288 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1290 bool aCanDisplay = myIsMouseOverWindow;
1292 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1294 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1299 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1301 return isNestedCreateOperation(theOperation) ||
1302 myModule->sketchReentranceMgr()->isInternalEditActive();
1305 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1307 return myIsConstraintsShown;
1310 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1312 bool isFoundObject = false;
1314 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1315 if (anObjectFeature.get()) {
1316 int aSize = myCurrentSketch->numberOfSubs();
1317 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1318 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1319 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1322 return isFoundObject;
1325 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1327 if (myPlaneFilter.IsNull())
1328 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1330 myPlaneFilter->setPlane(thePln);
1333 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1334 ModuleBase_IWorkshop* theWorkshop)
1336 bool isValueAccepted = false;
1338 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1340 FeaturePtr aFeature = aFOperation->feature();
1341 // editor is shown only if all attribute references are filled by preseletion
1342 bool anAllRefAttrInitialized = true;
1344 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1345 ModelAPI_AttributeRefAttr::typeId());
1346 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1347 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1348 anAllRefAttrInitialized = (*anIt)->isInitialized();
1350 if (anAllRefAttrInitialized) {
1351 // Activate dimension value editing on double click
1352 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1353 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1354 // Find corresponded widget to activate value editing
1355 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1356 if (aWgt->attributeID() == "ConstraintValue") {
1357 // the featue should be displayed in order to find the AIS text position,
1358 // the place where the editor will be shown
1359 aFeature->setDisplayed(true);
1360 /// the execute is necessary to perform in the feature compute for flyout position
1361 aFeature->execute();
1363 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1364 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1366 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1368 int aX = 0, anY = 0;
1370 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1371 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1372 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1373 Handle(AIS_InteractiveObject) anAISIO;
1374 if (anAIS.get() != NULL) {
1375 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1377 if (anAIS.get() != NULL) {
1378 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1380 if (!anAISIO.IsNull()) {
1381 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1382 if (!aDim.IsNull()) {
1383 gp_Pnt aPosition = aDim->GetTextPosition();
1385 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1386 Handle(V3d_View) aView = aViewer->activeView();
1388 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1390 QWidget* aViewPort = aViewer->activeViewPort();
1391 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1396 anEditor->setCursorPosition(aX, anY);
1397 isValueAccepted = anEditor->showPopupEditor(false);
1403 return isValueAccepted;
1406 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1407 const FeaturePtr& theSketch,
1408 ModuleBase_IWorkshop* theWorkshop,
1409 FeatureToSelectionMap& theSelection)
1411 if (theFeature.get() == NULL)
1414 std::set<AttributePtr> aSelectedAttributes;
1415 std::set<ResultPtr> aSelectedResults;
1417 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1418 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1419 if (!aContext.IsNull()) {
1420 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1421 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1423 std::list<ResultPtr> aResults = theFeature->results();
1424 std::list<ResultPtr>::const_iterator aIt;
1425 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1427 ResultPtr aResult = *aIt;
1428 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1429 if (aAISObj.get() == NULL)
1431 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1432 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1434 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1435 if (anOwner->Selectable() != anAISIO)
1437 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1438 aSelectedAttributes, aSelectedResults);
1440 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1441 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1442 if (anOwner.IsNull())
1444 if (anOwner->Selectable() != anAISIO)
1446 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1447 aSelectedAttributes, aSelectedResults);
1451 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1454 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1455 const FeaturePtr& theSketch,
1456 ModuleBase_IWorkshop* theWorkshop,
1457 const FeatureToSelectionMap& theSelection,
1458 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1460 if (theFeature.get() == NULL)
1463 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1464 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1465 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1467 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1469 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1470 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1472 // 1. found the feature's owners. Check the AIS objects of the constructions
1473 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1474 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1475 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1477 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1478 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1479 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1480 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1481 if (!anOwner.IsNull())
1482 theOwnersToSelect.Add(anOwner);
1486 // 2. found the feature results's owners
1487 std::list<ResultPtr> aResults = theFeature->results();
1488 std::list<ResultPtr>::const_iterator aIt;
1489 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1491 ResultPtr aResult = *aIt;
1492 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1493 if (aAISObj.get() == NULL)
1495 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1497 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1498 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1499 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1500 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1501 if ( anOwner.IsNull() || !anOwner->HasShape() )
1503 const TopoDS_Shape& aShape = anOwner->Shape();
1504 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1505 if (aShapeType == TopAbs_VERTEX) {
1506 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1507 if (aPntAttr.get() != NULL &&
1508 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1509 theOwnersToSelect.Add(anOwner);
1512 else if (aShapeType == TopAbs_EDGE) {
1513 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1514 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1515 theOwnersToSelect.FindIndex(anOwner) <= 0)
1516 theOwnersToSelect.Add(anOwner);
1522 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1525 connect(theWidget, SIGNAL(beforeValuesChanged()),
1526 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1527 connect(theWidget, SIGNAL(afterValuesChanged()),
1528 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1531 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1532 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1533 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1534 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1538 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1540 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1541 (getCurrentOperation());
1543 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1544 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1545 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1546 FeaturePtr aFeature = aFOperation->feature();
1547 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1552 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1554 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1555 (getCurrentOperation());
1556 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1557 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)))
1558 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1561 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1563 return myModule->workshop()->currentOperation();
1566 //**************************************************************
1567 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1569 ModuleBase_ModelWidget* aWidget = 0;
1570 ModuleBase_Operation* anOperation = getCurrentOperation();
1572 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1574 aWidget = aPanel->activeWidget();
1579 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1580 const bool isEditOperation,
1581 const bool isToDisplay,
1582 const bool isFlushRedisplay)
1584 #ifdef DEBUG_DO_NOT_BY_ENTER
1588 if (isEditOperation || !theFeature.get())
1591 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1592 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1594 // 1. change visibility of the object itself, here the presentable object is processed,
1595 // e.g. constraints features
1596 //FeaturePtr aFeature = aFOperation->feature();
1597 std::list<ResultPtr> aResults = theFeature->results();
1599 theFeature->setDisplayed(true);
1601 theFeature->setDisplayed(false);
1603 // change visibility of the object results, e.g. non-constraint features
1604 std::list<ResultPtr>::const_iterator aIt;
1605 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1607 (*aIt)->setDisplayed(true);
1610 (*aIt)->setDisplayed(false);
1613 if (isFlushRedisplay)
1614 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1617 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1619 if (!myCurrentSketch.get())
1622 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1623 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1624 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1626 QList<FeaturePtr> aFeatureList;
1627 if (theHighlightedOnly) {
1628 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1631 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1633 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1634 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1637 // 1. it is necessary to save current selection in order to restore it after the features moving
1638 myCurrentSelection.clear();
1639 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1640 for (; anIt != aLast; anIt++) {
1641 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1643 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1646 void PartSet_SketcherMgr::restoreSelection()
1648 if (!myCurrentSketch.get())
1651 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1652 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1653 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1654 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1655 aSLast = myCurrentSelection.end();
1656 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1657 for (; aSIt != aSLast; aSIt++) {
1658 anOwnersToSelect.Clear();
1659 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1661 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1665 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1667 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1669 updateBySketchParameters(aType, theState);
1672 void PartSet_SketcherMgr::updateBySketchParameters(
1673 const PartSet_Tools::ConstraintVisibleState& theType,
1676 if (myCurrentSketch.get() == NULL)
1679 bool aPrevState = myIsConstraintsShown[theType];
1680 myIsConstraintsShown[theType] = theState;
1683 case PartSet_Tools::Geometrical:
1684 case PartSet_Tools::Dimensional: {
1685 if (aPrevState != theState) {
1686 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1687 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1688 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1689 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1690 bool aProcessed = false;
1691 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1693 aSubFeature->setDisplayed(aConstraintDisplayed);
1695 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1699 case PartSet_Tools::Expressions: {
1700 /// call all sketch features redisplay, the expression state will be corrected in customize
1701 /// of distance presentation
1702 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1703 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1709 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1711 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1712 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1713 return aConnector->workshop();
1716 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1718 return workshop()->operationMgr();