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_ConstraintCollinear.h>
62 #include <SketchPlugin_ConstraintMiddle.h>
63 #include <SketchPlugin_MultiRotation.h>
64 #include <SketchPlugin_MultiTranslation.h>
65 #include <SketchPlugin_IntersectionPoint.h>
67 #include <SketcherPrs_Tools.h>
69 #include <SelectMgr_IndexedMapOfOwner.hxx>
70 #include <StdSelect_BRepOwner.hxx>
72 //#include <AIS_DimensionSelectionMode.hxx>
73 #include <AIS_Shape.hxx>
74 #include <AIS_Dimension.hxx>
76 #include <ModelAPI_Events.h>
77 #include <ModelAPI_Session.h>
78 #include <ModelAPI_AttributeString.h>
80 #include <QMouseEvent>
81 #include <QApplication>
83 #include <QMessageBox>
85 //#define DEBUG_DO_NOT_BY_ENTER
87 //#define DEBUG_CURSOR
89 /// Returns list of unique objects by sum of objects from List1 and List2
90 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
91 const QList<ModuleBase_ViewerPrs>& theList2)
93 QList<ModuleBase_ViewerPrs> aRes;
94 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
95 if (!aRes.contains(aPrs))
98 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
99 if (!aRes.contains(aPrs))
105 // Fills the list of features the list of selected presentations.
106 // \param theList a list of selected presentations
107 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
108 // and find the corresponded attribute
109 // \param theFeatureList an output list of features
110 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
111 const FeaturePtr theSketch,
112 QList<FeaturePtr>& theFeatureList)
114 QList<ModuleBase_ViewerPrs> aRes;
116 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
117 aLast = theList.end();
118 for (; anIt != aLast; anIt++)
120 ModuleBase_ViewerPrs aPrs = *anIt;
121 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
122 if (aFeature.get() && !theFeatureList.contains(aFeature))
123 theFeatureList.append(aFeature);
127 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
128 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
129 /// result as is to the list of results.
130 /// \param theOwner a viewer selected owner
131 /// \param theFeature a feature, where the attribute is searched
132 /// \param theSketch a current sketch
133 /// \param theSelectedAttribute an output list of attributes
134 /// \param theSelectedResults an output list of edge results
135 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
136 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
137 const ResultPtr& theResult,
138 std::set<AttributePtr>& aSelectedAttributes,
139 std::set<ResultPtr>& aSelectedResults)
141 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
142 if (aBRepOwner.IsNull())
144 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
145 aBRepOwner->Selectable());
146 if (aBRepOwner->HasShape()) {
147 const TopoDS_Shape& aShape = aBRepOwner->Shape();
148 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
149 if (aShapeType == TopAbs_VERTEX) {
150 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
152 if (aPntAttr.get() != NULL)
153 aSelectedAttributes.insert(aPntAttr);
155 else if (aShapeType == TopAbs_EDGE &&
156 aSelectedResults.find(theResult) == aSelectedResults.end()) {
157 aSelectedResults.insert(theResult);
162 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
163 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
164 myIsMouseOverWindow(false),
165 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
166 myIsPopupMenuActive(false)
168 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
169 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
171 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
173 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
174 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
176 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
177 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
179 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
180 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
182 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
183 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
185 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
186 XGUI_Workshop* aWorkshop = aConnector->workshop();
187 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
189 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
190 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
193 PartSet_SketcherMgr::~PartSet_SketcherMgr()
195 if (!myPlaneFilter.IsNull())
196 myPlaneFilter.Nullify();
199 void PartSet_SketcherMgr::onEnterViewPort()
201 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
202 // created feature because it should be done in onMouseMove(). Some widgets watch
203 // the mouse move and use the cursor position to update own values. If the presentaion is
204 // redisplayed before this update, the feature presentation jumps from reset value to current.
205 myIsMouseOverWindow = true;
207 #ifdef DEBUG_DO_NOT_BY_ENTER
211 if (canChangeCursor(getCurrentOperation())) {
212 QCursor* aCurrentCursor = QApplication::overrideCursor();
213 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
214 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
216 qDebug("onEnterViewPort() : Qt::CrossCursor");
221 if (!isNestedCreateOperation(getCurrentOperation()))
224 operationMgr()->onValidateOperation();
226 // we need change displayed state of the current operation feature
227 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
228 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
229 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
230 // presentation becomes valid and redisplay happens
231 //ModuleBase_Operation* aOperation = getCurrentOperation();
232 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
233 (getCurrentOperation());
235 FeaturePtr aFeature = aFOperation->feature();
236 if (aFeature.get() && aFeature->data()->isValid()) {
237 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
242 void PartSet_SketcherMgr::onLeaveViewPort()
244 myIsMouseOverViewProcessed = false;
245 myIsMouseOverWindow = false;
246 // it is important to validate operation here only if sketch entity create operation is active
247 // because at this operation we reacts to the mouse leave/enter view port
248 //operationMgr()->onValidateOperation();
250 #ifdef DEBUG_DO_NOT_BY_ENTER
254 if (canChangeCursor(getCurrentOperation())) {
255 QApplication::restoreOverrideCursor();
257 qDebug("onLeaveViewPort() : None");
261 if (!isNestedCreateOperation(getCurrentOperation()))
264 // the method should be performed if the popup menu is called,
265 // the reset of the current widget should not happen
266 if (myIsPopupMenuActive)
269 operationMgr()->onValidateOperation();
271 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
272 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
273 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
274 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
275 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
276 // obtained after reset value
277 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
278 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
280 anActiveWidget->reset();
282 // hides the presentation of the current operation feature
283 // the feature is to be erased here, but it is correct to call canDisplayObject because
284 // there can be additional check (e.g. editor widget in distance constraint)
285 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
286 (getCurrentOperation());
288 FeaturePtr aFeature = aFOperation->feature();
289 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
291 // we should update viewer after the presentation are hidden in the viewer
292 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
293 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
296 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
298 if (!isNestedEditOperation(getCurrentOperation()) ||
299 myModule->sketchReentranceMgr()->isInternalEditActive())
301 // it is necessary to save current selection in order to restore it after the values are modifed
304 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
305 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
306 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
307 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
310 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
312 if (!isNestedEditOperation(getCurrentOperation()) ||
313 myModule->sketchReentranceMgr()->isInternalEditActive())
315 // it is necessary to restore current selection in order to restore it after the values are modified
317 myCurrentSelection.clear();
319 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
320 // viewer happens by deselect/select the modified objects. The flag should be restored after
321 // the selection processing. The update viewer should be also called.
322 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
323 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
324 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
325 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
326 aDisplayer->updateViewer();
329 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
331 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
334 //get2dPoint(theWnd, theEvent, myClickedPoint);
336 if (!(theEvent->buttons() & Qt::LeftButton))
339 // Clear dragging mode
340 myIsDragging = false;
342 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
343 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
344 if (!aViewer->canDragByMouse())
347 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
348 (getCurrentOperation());
352 if (aFOperation->isEditOperation()) {
353 // If the current widget is a selector, do nothing, it processes the mouse press
354 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
355 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
360 // Use only for sketch operations
361 if (myCurrentSketch) {
362 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
365 bool isSketcher = isSketchOperation(aFOperation);
366 bool isSketchOpe = isNestedSketchOperation(aFOperation);
368 // Avoid non-sketch operations
369 if ((!isSketchOpe) && (!isSketcher))
372 bool isEditing = aFOperation->isEditOperation();
374 // Ignore creation sketch operation
375 if ((!isSketcher) && (!isEditing))
378 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
379 if (!aContext.IsNull()) {
380 // MoveTo in order to highlight current object
381 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
383 // Remember highlighted objects for editing
384 ModuleBase_ISelection* aSelect = aWorkshop->selection();
386 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
387 storeSelection(!aHasShift);
389 if (myCurrentSelection.empty()) {
390 if (isSketchOpe && (!isSketcher))
391 // commit previous operation
392 if (!aFOperation->commit())
393 aFOperation->abort();
396 // Init flyout point for radius rotation
397 FeaturePtr aFeature = myCurrentSelection.begin().key();
401 get2dPoint(theWnd, theEvent, myCurrentPoint);
404 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
406 if (aFeature.get() != NULL) {
407 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
408 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
409 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
410 DataPtr aData = aSPFeature->data();
411 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
412 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
413 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
414 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
417 } else if (isSketchOpe && isEditing) {
418 // If selected another object commit current result
419 aFOperation->commit();
422 get2dPoint(theWnd, theEvent, myCurrentPoint);
425 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
427 // this is temporary commented in order to avoid the following wrong case:
428 // Distance constraint is under edition, double click on the digit -> nothing happens
429 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
430 // but as the prev edit is commited an new one is not started, editor is not shown.
431 // This is necessary in order to finalize previous operation
432 //QApplication::processEvents();
438 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
440 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
443 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
444 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
445 if (!aViewer->canDragByMouse())
447 ModuleBase_Operation* aOp = getCurrentOperation();
449 if (isNestedSketchOperation(aOp)) {
450 //get2dPoint(theWnd, theEvent, myClickedPoint);
452 // Only for sketcher operations
456 myCurrentSelection.clear();
457 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
458 if (!aContext.IsNull()) {
459 // Reselect edited object
460 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
461 if (theEvent->modifiers() & Qt::ShiftModifier)
462 aContext->ShiftSelect();
471 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
472 myIsDragging = false;
475 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
477 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
480 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
481 myIsMouseOverViewProcessed = true;
482 // 1. perform the widget mouse move functionality and display the presentation
483 // the mouse move should be processed in the widget, if it can in order to visualize correct
484 // presentation. These widgets correct the feature attribute according to the mouse position
485 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
486 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
488 aPoint2DWdg->onMouseMove(theWnd, theEvent);
490 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
493 aDistanceWdg->onMouseMove(theWnd, theEvent);
495 // the feature is to be erased here, but it is correct to call canDisplayObject because
496 // there can be additional check (e.g. editor widget in distance constraint)
497 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
498 (getCurrentOperation());
500 FeaturePtr aFeature = aFOperation->feature();
501 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
505 //myClickedPoint.clear();
508 // 1. the current selection is saved in the mouse press method in order to restore it after moving
509 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
510 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
511 // deselected). This flag should be restored in the slot, processed the mouse release signal.
513 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
514 if (!aCurrentOperation)
516 if (isSketchOperation(aCurrentOperation))
517 return; // No edit operation activated
519 Handle(V3d_View) aView = theWnd->v3dView();
520 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
522 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
523 double dX = aX - myCurrentPoint.myCurX;
524 double dY = aY - myCurrentPoint.myCurY;
526 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
527 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
528 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
529 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
530 // viewer happens by deselect/select the modified objects. The flag should be restored after
531 // the selection processing. The update viewer should be also called.
532 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
534 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
535 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
536 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
537 aLast = myCurrentSelection.end();
538 // 4. the features and attributes modification(move)
539 bool isModified = false;
540 for (; anIt != aLast; anIt++) {
541 FeaturePtr aFeature = anIt.key();
543 std::set<AttributePtr> anAttributes = anIt.value().first;
544 // Process selection by attribute: the priority to the attribute
545 if (!anAttributes.empty()) {
546 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
547 anAttLast = anAttributes.end();
548 for (; anAttIt != anAttLast; anAttIt++) {
549 AttributePtr anAttr = *anAttIt;
550 if (anAttr.get() == NULL)
552 std::string aAttrId = anAttr->id();
553 DataPtr aData = aFeature->data();
554 if (aData->isValid()) {
555 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
556 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
557 if (aPoint.get() != NULL) {
558 bool isImmutable = aPoint->setImmutable(true);
559 aPoint->move(dX, dY);
561 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
562 aPoint->setImmutable(isImmutable);
567 // Process selection by feature
568 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
569 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
570 if (aSketchFeature) {
571 aSketchFeature->move(dX, dY);
573 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
577 // the modified state of the current operation should be updated if there are features, which
580 aCurrentOperation->onValuesChanged();
582 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
583 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
585 // 5. it is necessary to save current selection in order to restore it after the features moving
587 // 6. restore the update viewer flag and call this update
588 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
589 aDisplayer->updateViewer();
592 myCurrentPoint.setValue(aX, aY);
596 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
598 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
599 (getCurrentOperation());
600 if (aFOperation && aFOperation->isEditOperation()) {
601 std::string aId = aFOperation->id().toStdString();
602 if (isDistanceOperation(aFOperation))
604 // Activate dimension value editing on double click
605 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
606 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
607 // Find corresponded widget to activate value editing
608 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
609 if (aWgt->attributeID() == "ConstraintValue") {
610 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
612 anEditor->showPopupEditor();
620 void PartSet_SketcherMgr::onApplicationStarted()
622 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
623 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
624 XGUI_Workshop* aWorkshop = aConnector->workshop();
625 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
627 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
628 if (aPropertyPanel) {
629 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
630 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
632 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
633 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
634 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
635 aReentranceMgr, SLOT(onWidgetActivated()));
638 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
639 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
640 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
642 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
643 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
644 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
647 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
649 //if (!myClickedPoint.myIsInitialized)
652 //ModuleBase_Operation* aOperation = getCurrentOperation();
653 // the distance constraint feature should not use the clickedd point
654 // this is workaround in order to don't throw down the flyout point value,
655 // set by execute() method of these type of features
656 //if (isDistanceOperation(aOperation))
659 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
661 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
665 void PartSet_SketcherMgr::onBeforeContextMenu()
667 myIsPopupMenuActive = true;
670 void PartSet_SketcherMgr::onAfterContextMenu()
672 myIsPopupMenuActive = false;
675 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
678 Handle(V3d_View) aView = theWnd->v3dView();
679 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
681 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
682 thePoint.setValue(aX, anY);
685 void PartSet_SketcherMgr::launchEditing()
687 if (!myCurrentSelection.empty()) {
688 FeaturePtr aFeature = myCurrentSelection.begin().key();
689 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
690 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
692 myModule->editFeature(aSPFeature);
697 bool PartSet_SketcherMgr::sketchSolverError()
699 bool anError = false;
700 CompositeFeaturePtr aSketch = activeSketch();
702 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
703 anError = !aAttributeString->value().empty();
708 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
710 QString anError = "";
711 if (!theFeature.get() || !theFeature->data()->isValid())
714 CompositeFeaturePtr aSketch = activeSketch();
715 if (aSketch.get() && aSketch == theFeature) {
716 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
717 anError = aAttributeString->value().c_str();
722 void PartSet_SketcherMgr::clearClickedFlags()
724 //myClickedPoint.clear();
725 myCurrentPoint.clear();
728 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
730 static QStringList aIds;
731 if (aIds.size() == 0) {
732 aIds << SketchPlugin_Line::ID().c_str();
733 aIds << SketchPlugin_Point::ID().c_str();
734 aIds << SketchPlugin_Arc::ID().c_str();
735 aIds << SketchPlugin_Circle::ID().c_str();
736 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
737 aIds << SketchPlugin_IntersectionPoint::ID().c_str();
739 // SketchRectangle is a python feature, so its ID is passed just as a string
740 aIds << "SketchRectangle";
741 aIds.append(constraintsIdList());
746 const QStringList& PartSet_SketcherMgr::constraintsIdList()
748 static QStringList aIds;
749 if (aIds.size() == 0) {
750 aIds << SketchPlugin_ConstraintLength::ID().c_str();
751 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
752 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
753 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
754 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
755 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
756 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
757 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
758 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
759 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
760 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
761 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
762 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
763 aIds << SketchPlugin_MultiRotation::ID().c_str();
764 aIds << SketchPlugin_MultiTranslation::ID().c_str();
765 aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
766 aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
771 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
775 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
776 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
777 theModes.append(SketcherPrs_Tools::Sel_Constraint);
778 theModes.append(TopAbs_VERTEX);
779 theModes.append(TopAbs_EDGE);
782 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
784 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
787 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
789 return theOperation &&
790 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
793 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
795 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
797 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
800 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
802 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
804 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
807 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
809 return (theId == SketchPlugin_Line::ID()) ||
810 (theId == SketchPlugin_Point::ID()) ||
811 (theId == SketchPlugin_Arc::ID()) ||
812 (theId == SketchPlugin_Circle::ID());
815 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
817 std::string anId = theOperation ? theOperation->id().toStdString() : "";
819 return isDistanceKind(anId);
822 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
824 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
825 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
826 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
827 (theKind == SketchPlugin_ConstraintAngle::ID());
830 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
832 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
833 (getCurrentOperation());
837 myModule->onViewTransformed();
839 // Display all sketcher sub-Objects
840 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
841 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
842 aConnector->workshop()->displayer()->activateTrihedron(true);
844 // Hide sketcher result
845 std::list<ResultPtr> aResults = myCurrentSketch->results();
846 std::list<ResultPtr>::const_iterator aIt;
847 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
848 (*aIt)->setDisplayed(false);
850 myCurrentSketch->setDisplayed(false);
852 // Display sketcher objects
853 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
854 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
855 std::list<ResultPtr> aResults = aFeature->results();
856 std::list<ResultPtr>::const_iterator aIt;
857 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
858 (*aIt)->setDisplayed(true);
860 aFeature->setDisplayed(true);
863 if (myPlaneFilter.IsNull())
864 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
866 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
867 bool aHasPlane = false;
868 std::shared_ptr<GeomAPI_Pln> aPln;
869 if (aFOperation->isEditOperation()) {
870 // If it is editing of sketch then it means that plane is already defined
871 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
875 myPlaneFilter->setPlane(aPln);
877 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
878 // all sketch objects should be activated in the sketch selection modes by edit operation start
879 // in case of creation operation, there is an active widget, which activates own selection mode
880 if (aFOperation->isEditOperation() && aHasPlane)
881 aConnector->activateModuleSelectionModes();
884 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
886 myIsMouseOverWindow = false;
887 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
888 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
890 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
892 DataPtr aData = myCurrentSketch->data();
893 if (!aData->isValid()) {
894 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
895 // The sketch was aborted
896 myCurrentSketch = CompositeFeaturePtr();
897 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
899 // Erase all sketcher objects
900 QStringList aSketchIds = sketchOperationIdList();
901 QObjectPtrList aObjects = aDisplayer->displayedObjects();
902 foreach (ObjectPtr aObj, aObjects) {
903 DataPtr aObjData = aObj->data();
904 if (!aObjData->isValid())
905 aObj->setDisplayed(false);
909 // Hide all sketcher sub-Objects
910 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
911 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
912 std::list<ResultPtr> aResults = aFeature->results();
913 std::list<ResultPtr>::const_iterator aIt;
914 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
915 (*aIt)->setDisplayed(false);
917 aFeature->setDisplayed(false);
919 // Display sketcher result
920 std::list<ResultPtr> aResults = myCurrentSketch->results();
921 std::list<ResultPtr>::const_iterator aIt;
922 Events_Loop* aLoop = Events_Loop::loop();
923 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
925 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
927 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
928 if (!aFOperation->isDisplayedOnStart(*aIt)) {
929 (*aIt)->setDisplayed(true);
930 // this display event is needed because sketch already may have "displayed" state,
931 // but not displayed while it is still active (issue 613, abort of existing sketch)
932 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
935 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
936 myCurrentSketch->setDisplayed(true);
938 myCurrentSketch = CompositeFeaturePtr();
939 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
941 Events_Loop::loop()->flush(aDispEvent);
943 // restore the module selection modes, which were changed on startSketch
944 aConnector->activateModuleSelectionModes();
945 aConnector->workshop()->displayer()->activateTrihedron(false);
948 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
950 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
951 QCursor* aCurrentCursor = QApplication::overrideCursor();
952 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
953 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
955 qDebug("startNestedSketch() : Qt::CrossCursor");
961 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
963 myIsMouseOverViewProcessed = true;
964 operationMgr()->onValidateOperation();
965 if (canChangeCursor(theOperation)) {
966 QApplication::restoreOverrideCursor();
968 qDebug("stopNestedSketch() : None");
973 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
975 if (isNestedCreateOperation(theOperation)) {
976 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
979 FeaturePtr aFeature = aFOperation->feature();
980 // it is necessary to check the the feature data validity because
981 // some kind of features are removed by an operation commit(the macro state of a feature)
982 if (aFeature.get() && aFeature->data()->isValid()) {
983 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
989 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
992 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
994 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
997 void PartSet_SketcherMgr::operationActivatedByPreselection()
999 ModuleBase_Operation* anOperation = getCurrentOperation();
1000 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1001 // Set final definitions if they are necessary
1002 //propertyPanelDefined(aOperation);
1003 /// Commit sketcher operations automatically
1004 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1007 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1008 FeaturePtr aFeature = aFOperation->feature();
1009 // editor is shown only if all attribute references are filled by preseletion
1010 bool anAllRefAttrInitialized = true;
1012 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1013 ModelAPI_AttributeRefAttr::typeId());
1014 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1015 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1016 anAllRefAttrInitialized = (*anIt)->isInitialized();
1018 if (anAllRefAttrInitialized) {
1019 // Activate dimension value editing on double click
1020 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1021 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1022 // Find corresponded widget to activate value editing
1023 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1024 if (aWgt->attributeID() == "ConstraintValue") {
1025 // the featue should be displayed in order to find the AIS text position,
1026 // the place where the editor will be shown
1027 aFeature->setDisplayed(true);
1028 /// the execute is necessary to perform in the feature compute for flyout position
1029 aFeature->execute();
1031 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1032 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1034 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1036 int aX = 0, anY = 0;
1038 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1039 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1040 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1041 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1042 Handle(AIS_InteractiveObject) anAISIO;
1043 if (anAIS.get() != NULL) {
1044 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1046 if (anAIS.get() != NULL) {
1047 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1049 if (!anAISIO.IsNull()) {
1050 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1051 if (!aDim.IsNull()) {
1052 gp_Pnt aPosition = aDim->GetTextPosition();
1054 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1055 Handle(V3d_View) aView = aViewer->activeView();
1057 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1059 QWidget* aViewPort = aViewer->activeViewPort();
1060 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1065 anEditor->setCursorPosition(aX, anY);
1066 anEditor->showPopupEditor(false);
1074 anOperation->commit();
1078 bool PartSet_SketcherMgr::canUndo() const
1080 return isNestedCreateOperation(getCurrentOperation());
1083 bool PartSet_SketcherMgr::canRedo() const
1085 return isNestedCreateOperation(getCurrentOperation());
1088 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1090 bool aCanErase = true;
1091 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1092 if (myCurrentSketch.get()) {
1093 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1094 if (aResult.get()) {
1095 // Display sketcher objects
1096 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1098 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1099 std::list<ResultPtr> aResults = aFeature->results();
1100 std::list<ResultPtr>::const_iterator anIt;
1101 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1102 aCanErase = *anIt != aResult;
1110 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1112 bool aCanDisplay = true;
1114 bool aHasActiveSketch = activeSketch().get() != NULL;
1115 if (aHasActiveSketch) {
1116 // 1. the sketch feature should not be displayed during the sketch active operation
1117 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1118 // nested features can be visualized
1119 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1120 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1121 aCanDisplay = false;
1124 else { // there are no an active sketch
1125 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1126 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1127 if (aFeature.get() != NULL) {
1128 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1129 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1130 if (aSketchFeature.get()) {
1131 aCanDisplay = false;
1136 // 3. the method should not filter the objects, which are not related to the current operation.
1137 // The object is filtered just if it is a current operation feature or this feature result
1138 bool isObjectFound = false;
1139 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1140 (getCurrentOperation());
1142 FeaturePtr aFeature = aFOperation->feature();
1143 if (aFeature.get()) {
1144 std::list<ResultPtr> aResults = aFeature->results();
1145 if (theObject == aFeature)
1146 isObjectFound = true;
1148 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1149 for (; anIt != aLast && !isObjectFound; anIt++) {
1150 isObjectFound = *anIt == theObject;
1155 if (isObjectFound) {
1156 // 4. For created nested feature operation do not display the created feature if
1157 // the mouse curstor leaves the OCC window.
1158 // The correction cases, which ignores this condition:
1159 // a. the property panel values modification
1160 // b. the popup menu activated
1161 // c. widget editor control
1162 #ifndef DEBUG_DO_NOT_BY_ENTER
1163 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1164 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1165 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1166 // the active widget editor should not influence here. The presentation should be visible always
1167 // when this widget is active.
1168 if (!anEditorWdg && !myIsPopupMenuActive) {
1169 // during a nested create operation, the feature is redisplayed only if the mouse over view
1170 // of there was a value modified in the property panel after the mouse left the view
1171 aCanDisplay = canDisplayCurrentCreatedFeature();
1177 // checks the sketcher constraints visibility according to active sketch check box states
1179 bool aProcessed = false;
1180 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1181 if (aFeature.get()) {
1182 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1184 aCanDisplay = aConstraintDisplayed;
1191 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1192 const PartSet_Tools::ConstraintVisibleState& theState,
1193 bool& isProcessed) const
1195 bool aSwitchedOn = true;
1197 const QStringList& aConstrIds = constraintsIdList();
1199 std::string aKind = theFeature->getKind();
1200 if (aConstrIds.contains(QString(aKind.c_str()))) {
1201 bool isTypedConstraint = false;
1204 case PartSet_Tools::Dimensional: {
1205 bool isDistance = isDistanceKind(aKind);
1208 aSwitchedOn = myIsConstraintsShown[theState];
1212 case PartSet_Tools::Geometrical: {
1213 bool isGeometrical = !isDistanceKind(aKind);
1214 if (isGeometrical) {
1216 aSwitchedOn = myIsConstraintsShown[theState];
1220 case PartSet_Tools::Any: {
1222 bool isDistance = isDistanceKind(aKind);
1224 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1226 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1236 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1238 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1239 (getCurrentOperation());
1240 if (aFOperation && myCurrentSketch.get()) {
1241 // find results of the current operation
1242 // these results should not be proposed to be deleted
1243 FeaturePtr anOperationFeature = aFOperation->feature();
1244 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1245 std::set<ResultPtr> anOperationResults;
1246 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1247 aRLast = anOperationResultList.end();
1248 for (; aRIt != aRLast; aRIt++)
1249 anOperationResults.insert(*aRIt);
1251 std::set<FeaturePtr> anObjectsToBeDeleted;
1252 QStringList anObjectsToBeDeletedNames;
1253 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1254 for (; anIt != aLast; anIt++) {
1255 ObjectPtr anObject = *anIt;
1256 bool aCanErase = true;
1257 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1258 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1259 // the result is found between current feature results
1260 if (anOperationResults.find(aResult) != anOperationResults.end())
1263 if (aResult.get()) {
1264 // Display sketcher objects
1265 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1266 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1267 std::list<ResultPtr> aResults = aFeature->results();
1268 std::list<ResultPtr>::const_iterator anIt;
1269 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1270 aCanErase = *anIt != aResult;
1275 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1276 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1277 anObjectsToBeDeleted.insert(aFeature);
1278 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1282 if (!anObjectsToBeDeleted.empty()) {
1283 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1284 QString aMessage = tr("The following features have incorrect presentation and \
1285 will be hidden: %1. Would you like to delete them?")
1286 .arg(aFeatureNames);
1287 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1288 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1289 QMessageBox::Cancel);
1290 if (anAnswer == QMessageBox::Ok) {
1291 QObjectPtrList anObjects;
1292 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1293 aLast = anObjectsToBeDeleted.end();
1294 for (; anIt != aLast; anIt++)
1295 anObjects.append(*anIt);
1296 SessionPtr aMgr = ModelAPI_Session::get();
1297 DocumentPtr aDoc = aMgr->activeDocument();
1298 bool aIsOp = aMgr->isOperation();
1300 aMgr->startOperation();
1301 workshop()->deleteFeatures(anObjects);
1302 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1303 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1304 //Events_Loop::loop()->flush(aDeletedEvent);
1305 //Events_Loop::loop()->flush(aRedispEvent);
1308 aMgr->finishOperation();
1314 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1316 bool aCanDisplay = myIsMouseOverWindow;
1318 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1320 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1325 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1327 return isNestedCreateOperation(theOperation) ||
1328 myModule->sketchReentranceMgr()->isInternalEditActive();
1331 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1333 return myIsConstraintsShown;
1336 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1338 bool isFoundObject = false;
1340 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1341 if (anObjectFeature.get()) {
1342 int aSize = myCurrentSketch->numberOfSubs();
1343 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1344 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1345 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1348 return isFoundObject;
1351 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1353 if (myPlaneFilter.IsNull())
1354 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1356 myPlaneFilter->setPlane(thePln);
1359 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1360 const FeaturePtr& theSketch,
1361 ModuleBase_IWorkshop* theWorkshop,
1362 FeatureToSelectionMap& theSelection)
1364 if (theFeature.get() == NULL)
1367 std::set<AttributePtr> aSelectedAttributes;
1368 std::set<ResultPtr> aSelectedResults;
1370 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1371 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1372 if (!aContext.IsNull()) {
1373 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1374 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1376 std::list<ResultPtr> aResults = theFeature->results();
1377 std::list<ResultPtr>::const_iterator aIt;
1378 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1380 ResultPtr aResult = *aIt;
1381 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1382 if (aAISObj.get() == NULL)
1384 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1385 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1387 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1388 if (anOwner->Selectable() != anAISIO)
1390 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1391 aSelectedAttributes, aSelectedResults);
1393 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1394 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1395 if (anOwner.IsNull())
1397 if (anOwner->Selectable() != anAISIO)
1399 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1400 aSelectedAttributes, aSelectedResults);
1404 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1407 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1408 const FeaturePtr& theSketch,
1409 ModuleBase_IWorkshop* theWorkshop,
1410 const FeatureToSelectionMap& theSelection,
1411 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1413 if (theFeature.get() == NULL)
1416 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1417 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1418 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1420 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1422 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1423 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1425 // 1. found the feature's owners. Check the AIS objects of the constructions
1426 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1427 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1428 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1430 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1431 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1432 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1433 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1434 if (!anOwner.IsNull())
1435 theOwnersToSelect.Add(anOwner);
1439 // 2. found the feature results's owners
1440 std::list<ResultPtr> aResults = theFeature->results();
1441 std::list<ResultPtr>::const_iterator aIt;
1442 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1444 ResultPtr aResult = *aIt;
1445 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1446 if (aAISObj.get() == NULL)
1448 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1450 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1451 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1452 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1453 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1454 if ( anOwner.IsNull() || !anOwner->HasShape() )
1456 const TopoDS_Shape& aShape = anOwner->Shape();
1457 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1458 if (aShapeType == TopAbs_VERTEX) {
1459 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1460 if (aPntAttr.get() != NULL &&
1461 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1462 theOwnersToSelect.Add(anOwner);
1465 else if (aShapeType == TopAbs_EDGE) {
1466 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1467 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1468 theOwnersToSelect.FindIndex(anOwner) <= 0)
1469 theOwnersToSelect.Add(anOwner);
1475 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1478 connect(theWidget, SIGNAL(beforeValuesChanged()),
1479 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1480 connect(theWidget, SIGNAL(afterValuesChanged()),
1481 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1484 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1485 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1486 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1487 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1491 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1493 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1494 (getCurrentOperation());
1496 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1497 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1498 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1499 FeaturePtr aFeature = aFOperation->feature();
1500 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1505 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1507 return myModule->workshop()->currentOperation();
1510 //**************************************************************
1511 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1513 ModuleBase_ModelWidget* aWidget = 0;
1514 ModuleBase_Operation* anOperation = getCurrentOperation();
1516 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1518 aWidget = aPanel->activeWidget();
1523 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1524 const bool isEditOperation,
1525 const bool isToDisplay,
1526 const bool isFlushRedisplay)
1528 #ifdef DEBUG_DO_NOT_BY_ENTER
1532 if (isEditOperation || !theFeature.get())
1535 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1536 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1538 // 1. change visibility of the object itself, here the presentable object is processed,
1539 // e.g. constraints features
1540 //FeaturePtr aFeature = aFOperation->feature();
1541 std::list<ResultPtr> aResults = theFeature->results();
1543 theFeature->setDisplayed(true);
1545 theFeature->setDisplayed(false);
1547 // change visibility of the object results, e.g. non-constraint features
1548 std::list<ResultPtr>::const_iterator aIt;
1549 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1551 (*aIt)->setDisplayed(true);
1554 (*aIt)->setDisplayed(false);
1557 if (isFlushRedisplay)
1558 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1561 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1563 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1564 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1565 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1567 QList<FeaturePtr> aFeatureList;
1568 if (theHighlightedOnly) {
1569 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1572 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1574 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1575 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1578 // 1. it is necessary to save current selection in order to restore it after the features moving
1579 myCurrentSelection.clear();
1580 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1581 for (; anIt != aLast; anIt++) {
1582 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1584 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1587 void PartSet_SketcherMgr::restoreSelection()
1589 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1590 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1591 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1592 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1593 aSLast = myCurrentSelection.end();
1594 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1595 for (; aSIt != aSLast; aSIt++) {
1596 anOwnersToSelect.Clear();
1597 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1599 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1603 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1605 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1606 if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1608 if (myCurrentSketch.get() == NULL)
1611 myIsConstraintsShown[aType] = theState;
1613 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1614 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1616 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1617 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1618 bool aProcessed = false;
1619 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, aType, aProcessed);
1621 aSubFeature->setDisplayed(aConstraintDisplayed);
1623 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1626 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1628 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1629 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1630 return aConnector->workshop();
1633 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1635 return workshop()->operationMgr();