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>
26 #include <XGUI_Tools.h>
28 #include <ModuleBase_IPropertyPanel.h>
29 #include <ModuleBase_ISelection.h>
30 #include <ModuleBase_IViewer.h>
31 #include <ModuleBase_IWorkshop.h>
32 #include <ModuleBase_IViewWindow.h>
33 #include <ModuleBase_ModelWidget.h>
34 #include <ModuleBase_Operation.h>
35 #include <ModuleBase_OperationFeature.h>
36 #include <ModuleBase_Operation.h>
37 #include <ModuleBase_WidgetEditor.h>
39 #include <GeomDataAPI_Point2D.h>
41 #include <Events_Loop.h>
43 #include <SketchPlugin_Line.h>
44 #include <SketchPlugin_Sketch.h>
45 #include <SketchPlugin_Point.h>
46 #include <SketchPlugin_Arc.h>
47 #include <SketchPlugin_Circle.h>
48 #include <SketchPlugin_ConstraintLength.h>
49 #include <SketchPlugin_ConstraintDistance.h>
50 #include <SketchPlugin_ConstraintParallel.h>
51 #include <SketchPlugin_ConstraintPerpendicular.h>
52 #include <SketchPlugin_ConstraintRadius.h>
53 #include <SketchPlugin_ConstraintRigid.h>
54 #include <SketchPlugin_ConstraintHorizontal.h>
55 #include <SketchPlugin_ConstraintVertical.h>
56 #include <SketchPlugin_ConstraintEqual.h>
57 #include <SketchPlugin_ConstraintTangent.h>
58 #include <SketchPlugin_ConstraintCoincidence.h>
59 #include <SketchPlugin_ConstraintFillet.h>
60 #include <SketchPlugin_ConstraintMirror.h>
61 #include <SketchPlugin_ConstraintAngle.h>
62 #include <SketchPlugin_ConstraintCollinear.h>
63 #include <SketchPlugin_ConstraintMiddle.h>
64 #include <SketchPlugin_MultiRotation.h>
65 #include <SketchPlugin_MultiTranslation.h>
66 #include <SketchPlugin_IntersectionPoint.h>
68 #include <SketcherPrs_Tools.h>
70 #include <SelectMgr_IndexedMapOfOwner.hxx>
71 #include <StdSelect_BRepOwner.hxx>
73 //#include <AIS_DimensionSelectionMode.hxx>
74 #include <AIS_Shape.hxx>
75 #include <AIS_Dimension.hxx>
77 #include <ModelAPI_Events.h>
78 #include <ModelAPI_Session.h>
79 #include <ModelAPI_AttributeString.h>
81 #include <QMouseEvent>
82 #include <QApplication>
84 #include <QMessageBox>
86 //#define DEBUG_DO_NOT_BY_ENTER
88 //#define DEBUG_CURSOR
90 /// Returns list of unique objects by sum of objects from List1 and List2
91 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
92 const QList<ModuleBase_ViewerPrs>& theList2)
94 QList<ModuleBase_ViewerPrs> aRes;
95 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
96 if (!aRes.contains(aPrs))
99 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
100 if (!aRes.contains(aPrs))
106 // Fills the list of features the list of selected presentations.
107 // \param theList a list of selected presentations
108 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
109 // and find the corresponded attribute
110 // \param theFeatureList an output list of features
111 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
112 const FeaturePtr theSketch,
113 QList<FeaturePtr>& theFeatureList)
115 QList<ModuleBase_ViewerPrs> aRes;
117 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
118 aLast = theList.end();
119 for (; anIt != aLast; anIt++)
121 ModuleBase_ViewerPrs aPrs = *anIt;
122 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
123 if (aFeature.get() && !theFeatureList.contains(aFeature))
124 theFeatureList.append(aFeature);
128 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
129 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
130 /// result as is to the list of results.
131 /// \param theOwner a viewer selected owner
132 /// \param theFeature a feature, where the attribute is searched
133 /// \param theSketch a current sketch
134 /// \param theSelectedAttribute an output list of attributes
135 /// \param theSelectedResults an output list of edge results
136 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
137 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
138 const ResultPtr& theResult,
139 std::set<AttributePtr>& aSelectedAttributes,
140 std::set<ResultPtr>& aSelectedResults)
142 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
143 if (aBRepOwner.IsNull())
145 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
146 aBRepOwner->Selectable());
147 if (aBRepOwner->HasShape()) {
148 const TopoDS_Shape& aShape = aBRepOwner->Shape();
149 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
150 if (aShapeType == TopAbs_VERTEX) {
151 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
153 if (aPntAttr.get() != NULL)
154 aSelectedAttributes.insert(aPntAttr);
156 else if (aShapeType == TopAbs_EDGE &&
157 aSelectedResults.find(theResult) == aSelectedResults.end()) {
158 aSelectedResults.insert(theResult);
163 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
164 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
165 myIsMouseOverWindow(false),
166 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
167 myIsPopupMenuActive(false)
169 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
170 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
172 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
174 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
175 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
177 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
178 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
180 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
181 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
183 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
184 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
186 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
187 XGUI_Workshop* aWorkshop = aConnector->workshop();
188 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
190 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
191 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
192 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
195 PartSet_SketcherMgr::~PartSet_SketcherMgr()
197 if (!myPlaneFilter.IsNull())
198 myPlaneFilter.Nullify();
201 void PartSet_SketcherMgr::onEnterViewPort()
203 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
204 // created feature because it should be done in onMouseMove(). Some widgets watch
205 // the mouse move and use the cursor position to update own values. If the presentaion is
206 // redisplayed before this update, the feature presentation jumps from reset value to current.
207 myIsMouseOverWindow = true;
209 #ifdef DEBUG_DO_NOT_BY_ENTER
213 if (canChangeCursor(getCurrentOperation())) {
214 QCursor* aCurrentCursor = QApplication::overrideCursor();
215 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
216 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
218 qDebug("onEnterViewPort() : Qt::CrossCursor");
223 if (!isNestedCreateOperation(getCurrentOperation()))
226 operationMgr()->onValidateOperation();
228 // we need change displayed state of the current operation feature
229 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
230 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
231 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
232 // presentation becomes valid and redisplay happens
233 //ModuleBase_Operation* aOperation = getCurrentOperation();
234 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
235 (getCurrentOperation());
237 FeaturePtr aFeature = aFOperation->feature();
238 if (aFeature.get() && aFeature->data()->isValid()) {
239 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
244 void PartSet_SketcherMgr::onLeaveViewPort()
246 myIsMouseOverViewProcessed = false;
247 myIsMouseOverWindow = false;
248 // it is important to validate operation here only if sketch entity create operation is active
249 // because at this operation we reacts to the mouse leave/enter view port
250 //operationMgr()->onValidateOperation();
252 #ifdef DEBUG_DO_NOT_BY_ENTER
256 if (canChangeCursor(getCurrentOperation())) {
257 QApplication::restoreOverrideCursor();
259 qDebug("onLeaveViewPort() : None");
263 if (!isNestedCreateOperation(getCurrentOperation()))
266 // the method should be performed if the popup menu is called,
267 // the reset of the current widget should not happen
268 if (myIsPopupMenuActive)
271 operationMgr()->onValidateOperation();
273 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
274 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
275 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
276 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
277 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
278 // obtained after reset value
279 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
280 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
282 anActiveWidget->reset();
284 // hides the presentation of the current operation feature
285 // the feature is to be erased here, but it is correct to call canDisplayObject because
286 // there can be additional check (e.g. editor widget in distance constraint)
287 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
288 (getCurrentOperation());
290 FeaturePtr aFeature = aFOperation->feature();
291 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
293 // we should update viewer after the presentation are hidden in the viewer
294 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
295 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
298 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
300 if (!isNestedEditOperation(getCurrentOperation()) ||
301 myModule->sketchReentranceMgr()->isInternalEditActive())
303 // it is necessary to save current selection in order to restore it after the values are modifed
306 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
307 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
308 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
309 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
312 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
314 if (!isNestedEditOperation(getCurrentOperation()) ||
315 myModule->sketchReentranceMgr()->isInternalEditActive()) {
316 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
319 // it is necessary to restore current selection in order to restore it after the values are modified
321 myCurrentSelection.clear();
323 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
324 // viewer happens by deselect/select the modified objects. The flag should be restored after
325 // the selection processing. The update viewer should be also called.
326 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
327 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
328 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
329 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
330 aDisplayer->updateViewer();
335 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
337 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
340 //get2dPoint(theWnd, theEvent, myClickedPoint);
342 if (!(theEvent->buttons() & Qt::LeftButton))
345 // Clear dragging mode
346 myIsDragging = false;
348 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
349 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
350 if (!aViewer->canDragByMouse())
353 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
354 (getCurrentOperation());
358 if (aFOperation->isEditOperation()) {
359 // If the current widget is a selector, do nothing, it processes the mouse press
360 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
361 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
366 // Use only for sketch operations
367 if (myCurrentSketch) {
368 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
371 bool isSketcher = isSketchOperation(aFOperation);
372 bool isSketchOpe = isNestedSketchOperation(aFOperation);
374 // Avoid non-sketch operations
375 if ((!isSketchOpe) && (!isSketcher))
378 bool isEditing = aFOperation->isEditOperation();
380 // Ignore creation sketch operation
381 if ((!isSketcher) && (!isEditing))
384 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
385 if (!aContext.IsNull()) {
386 // MoveTo in order to highlight current object
387 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
389 // Remember highlighted objects for editing
390 ModuleBase_ISelection* aSelect = aWorkshop->selection();
392 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
393 storeSelection(!aHasShift);
395 if (myCurrentSelection.empty()) {
396 if (isSketchOpe && (!isSketcher))
397 // commit previous operation
398 if (!aFOperation->commit())
399 aFOperation->abort();
402 // Init flyout point for radius rotation
403 FeaturePtr aFeature = myCurrentSelection.begin().key();
407 get2dPoint(theWnd, theEvent, myCurrentPoint);
410 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
412 if (aFeature.get() != NULL) {
413 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
414 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
415 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
416 DataPtr aData = aSPFeature->data();
417 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
418 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
419 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
420 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
423 } else if (isSketchOpe && isEditing) {
424 // If selected another object commit current result
425 aFOperation->commit();
428 get2dPoint(theWnd, theEvent, myCurrentPoint);
431 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
433 // this is temporary commented in order to avoid the following wrong case:
434 // Distance constraint is under edition, double click on the digit -> nothing happens
435 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
436 // but as the prev edit is commited an new one is not started, editor is not shown.
437 // This is necessary in order to finalize previous operation
438 //QApplication::processEvents();
444 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
446 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
449 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
450 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
451 if (!aViewer->canDragByMouse())
453 ModuleBase_Operation* aOp = getCurrentOperation();
455 if (isNestedSketchOperation(aOp)) {
456 //get2dPoint(theWnd, theEvent, myClickedPoint);
458 // Only for sketcher operations
462 myCurrentSelection.clear();
463 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
464 if (!aContext.IsNull()) {
465 // Reselect edited object
466 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
467 if (theEvent->modifiers() & Qt::ShiftModifier)
468 aContext->ShiftSelect();
477 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
478 myIsDragging = false;
481 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
483 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
486 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
487 myIsMouseOverViewProcessed = true;
488 // 1. perform the widget mouse move functionality and display the presentation
489 // the mouse move should be processed in the widget, if it can in order to visualize correct
490 // presentation. These widgets correct the feature attribute according to the mouse position
491 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
492 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
494 aPoint2DWdg->onMouseMove(theWnd, theEvent);
496 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
499 aDistanceWdg->onMouseMove(theWnd, theEvent);
501 // the feature is to be erased here, but it is correct to call canDisplayObject because
502 // there can be additional check (e.g. editor widget in distance constraint)
503 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
504 (getCurrentOperation());
506 FeaturePtr aFeature = aFOperation->feature();
507 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
511 //myClickedPoint.clear();
514 // 1. the current selection is saved in the mouse press method in order to restore it after moving
515 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
516 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
517 // deselected). This flag should be restored in the slot, processed the mouse release signal.
519 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
520 if (!aCurrentOperation)
522 if (isSketchOperation(aCurrentOperation))
523 return; // No edit operation activated
525 Handle(V3d_View) aView = theWnd->v3dView();
526 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
528 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
529 double dX = aX - myCurrentPoint.myCurX;
530 double dY = aY - myCurrentPoint.myCurY;
532 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
533 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
534 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
535 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
536 // viewer happens by deselect/select the modified objects. The flag should be restored after
537 // the selection processing. The update viewer should be also called.
538 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
540 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
541 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
542 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
543 aLast = myCurrentSelection.end();
544 // 4. the features and attributes modification(move)
545 bool isModified = false;
546 for (; anIt != aLast; anIt++) {
547 FeaturePtr aFeature = anIt.key();
549 std::set<AttributePtr> anAttributes = anIt.value().first;
550 // Process selection by attribute: the priority to the attribute
551 if (!anAttributes.empty()) {
552 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
553 anAttLast = anAttributes.end();
554 for (; anAttIt != anAttLast; anAttIt++) {
555 AttributePtr anAttr = *anAttIt;
556 if (anAttr.get() == NULL)
558 std::string aAttrId = anAttr->id();
559 DataPtr aData = aFeature->data();
560 if (aData->isValid()) {
561 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
562 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
563 if (aPoint.get() != NULL) {
564 bool isImmutable = aPoint->setImmutable(true);
565 aPoint->move(dX, dY);
567 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
568 aPoint->setImmutable(isImmutable);
573 // Process selection by feature
574 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
575 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
576 if (aSketchFeature) {
577 aSketchFeature->move(dX, dY);
579 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
583 // the modified state of the current operation should be updated if there are features, which
586 aCurrentOperation->onValuesChanged();
588 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
589 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
591 // 5. it is necessary to save current selection in order to restore it after the features moving
593 // 6. restore the update viewer flag and call this update
594 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
595 aDisplayer->updateViewer();
598 myCurrentPoint.setValue(aX, aY);
602 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
604 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
605 (getCurrentOperation());
606 if (aFOperation && aFOperation->isEditOperation()) {
607 std::string aId = aFOperation->id().toStdString();
608 if (isDistanceOperation(aFOperation))
610 // Activate dimension value editing on double click
611 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
612 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
613 // Find corresponded widget to activate value editing
614 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
615 if (aWgt->attributeID() == "ConstraintValue" ||
616 aWgt->attributeID() == "AngleValue") {
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 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
791 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
794 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
796 return theOperation &&
797 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
800 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
802 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
804 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
807 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
809 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
811 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
814 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
816 return (theId == SketchPlugin_Line::ID()) ||
817 (theId == SketchPlugin_Point::ID()) ||
818 (theId == SketchPlugin_Arc::ID()) ||
819 (theId == SketchPlugin_Circle::ID());
822 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
824 std::string anId = theOperation ? theOperation->id().toStdString() : "";
826 return isDistanceKind(anId);
829 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
831 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
832 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
833 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
834 (theKind == SketchPlugin_ConstraintAngle::ID());
837 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
839 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
840 (getCurrentOperation());
844 myModule->onViewTransformed();
846 // Display all sketcher sub-Objects
847 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
848 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
849 aConnector->workshop()->displayer()->activateTrihedron(true);
851 // Hide sketcher result
852 std::list<ResultPtr> aResults = myCurrentSketch->results();
853 std::list<ResultPtr>::const_iterator aIt;
854 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
855 (*aIt)->setDisplayed(false);
857 myCurrentSketch->setDisplayed(false);
859 // Display sketcher objects
860 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
861 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
862 std::list<ResultPtr> aResults = aFeature->results();
863 std::list<ResultPtr>::const_iterator aIt;
864 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
865 (*aIt)->setDisplayed(true);
867 aFeature->setDisplayed(true);
870 if(myCirclePointFilter.IsNull()) {
871 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
874 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
876 if (myPlaneFilter.IsNull())
877 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
879 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
880 bool aHasPlane = false;
881 std::shared_ptr<GeomAPI_Pln> aPln;
882 if (aFOperation->isEditOperation()) {
883 // If it is editing of sketch then it means that plane is already defined
884 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
888 myPlaneFilter->setPlane(aPln);
890 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
891 // all sketch objects should be activated in the sketch selection modes by edit operation start
892 // in case of creation operation, there is an active widget, which activates own selection mode
893 if (aFOperation->isEditOperation() && aHasPlane)
894 aConnector->activateModuleSelectionModes();
897 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
899 myIsMouseOverWindow = false;
900 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
901 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
902 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
904 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
906 DataPtr aData = myCurrentSketch->data();
907 if (!aData->isValid()) {
908 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
909 // The sketch was aborted
910 myCurrentSketch = CompositeFeaturePtr();
911 // TODO: move this outside of if-else
912 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
913 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
915 // Erase all sketcher objects
916 QStringList aSketchIds = sketchOperationIdList();
917 QObjectPtrList aObjects = aDisplayer->displayedObjects();
918 foreach (ObjectPtr aObj, aObjects) {
919 DataPtr aObjData = aObj->data();
920 if (!aObjData->isValid())
921 aObj->setDisplayed(false);
925 // Hide all sketcher sub-Objects
926 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
927 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
928 std::list<ResultPtr> aResults = aFeature->results();
929 std::list<ResultPtr>::const_iterator aIt;
930 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
931 (*aIt)->setDisplayed(false);
933 aFeature->setDisplayed(false);
935 // Display sketcher result
936 std::list<ResultPtr> aResults = myCurrentSketch->results();
937 std::list<ResultPtr>::const_iterator aIt;
938 Events_Loop* aLoop = Events_Loop::loop();
939 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
941 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
943 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
944 if (!aFOperation->isDisplayedOnStart(*aIt)) {
945 (*aIt)->setDisplayed(true);
946 // this display event is needed because sketch already may have "displayed" state,
947 // but not displayed while it is still active (issue 613, abort of existing sketch)
948 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
951 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
952 myCurrentSketch->setDisplayed(true);
954 myCurrentSketch = CompositeFeaturePtr();
956 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
957 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
959 Events_Loop::loop()->flush(aDispEvent);
961 // restore the module selection modes, which were changed on startSketch
962 aConnector->activateModuleSelectionModes();
963 aConnector->workshop()->displayer()->activateTrihedron(false);
966 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
968 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
969 QCursor* aCurrentCursor = QApplication::overrideCursor();
970 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
971 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
973 qDebug("startNestedSketch() : Qt::CrossCursor");
979 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
981 myIsMouseOverViewProcessed = true;
982 operationMgr()->onValidateOperation();
983 if (canChangeCursor(theOperation)) {
984 QApplication::restoreOverrideCursor();
986 qDebug("stopNestedSketch() : None");
991 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
993 if (isNestedCreateOperation(theOperation)) {
994 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
997 FeaturePtr aFeature = aFOperation->feature();
998 // it is necessary to check the the feature data validity because
999 // some kind of features are removed by an operation commit(the macro state of a feature)
1000 if (aFeature.get() && aFeature->data()->isValid()) {
1001 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1007 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1010 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1012 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1015 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1017 bool isOperationStopped = false;
1018 ModuleBase_Operation* anOperation = getCurrentOperation();
1019 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1020 // Set final definitions if they are necessary
1021 //propertyPanelDefined(aOperation);
1022 /// Commit sketcher operations automatically
1023 /// distance operation are able to show popup editor to modify the distance value
1024 /// after entering the value, the operation should be committed/aborted(by Esc key)
1025 bool aCanCommitOperation = true;
1026 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1028 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation))
1029 aCanCommitOperation = setDistanceValueByPreselection(anOperation, myModule->workshop());
1031 if (aCanCommitOperation)
1032 isOperationStopped = anOperation->commit();
1034 anOperation->abort();
1035 isOperationStopped = true;
1038 return isOperationStopped;
1041 bool PartSet_SketcherMgr::canUndo() const
1043 return isNestedCreateOperation(getCurrentOperation());
1046 bool PartSet_SketcherMgr::canRedo() const
1048 return isNestedCreateOperation(getCurrentOperation());
1051 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1053 bool aCanErase = true;
1054 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1055 if (myCurrentSketch.get()) {
1056 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1057 if (aResult.get()) {
1058 // Display sketcher objects
1059 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1061 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1062 std::list<ResultPtr> aResults = aFeature->results();
1063 std::list<ResultPtr>::const_iterator anIt;
1064 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1065 aCanErase = *anIt != aResult;
1073 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1075 bool aCanDisplay = true;
1077 bool aHasActiveSketch = activeSketch().get() != NULL;
1078 if (aHasActiveSketch) {
1079 // 1. the sketch feature should not be displayed during the sketch active operation
1080 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1081 // nested features can be visualized
1082 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1083 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1084 aCanDisplay = false;
1087 else { // there are no an active sketch
1088 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1089 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1090 if (aFeature.get() != NULL) {
1091 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1092 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1093 if (aSketchFeature.get()) {
1094 aCanDisplay = false;
1099 // 3. the method should not filter the objects, which are not related to the current operation.
1100 // The object is filtered just if it is a current operation feature or this feature result
1101 bool isObjectFound = false;
1102 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1103 (getCurrentOperation());
1105 FeaturePtr aFeature = aFOperation->feature();
1106 if (aFeature.get()) {
1107 std::list<ResultPtr> aResults = aFeature->results();
1108 if (theObject == aFeature)
1109 isObjectFound = true;
1111 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1112 for (; anIt != aLast && !isObjectFound; anIt++) {
1113 isObjectFound = *anIt == theObject;
1118 if (isObjectFound) {
1119 // 4. For created nested feature operation do not display the created feature if
1120 // the mouse curstor leaves the OCC window.
1121 // The correction cases, which ignores this condition:
1122 // a. the property panel values modification
1123 // b. the popup menu activated
1124 // c. widget editor control
1125 #ifndef DEBUG_DO_NOT_BY_ENTER
1126 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1127 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1128 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1129 // the active widget editor should not influence here. The presentation should be visible always
1130 // when this widget is active.
1131 if (!anEditorWdg && !myIsPopupMenuActive) {
1132 // during a nested create operation, the feature is redisplayed only if the mouse over view
1133 // of there was a value modified in the property panel after the mouse left the view
1134 aCanDisplay = canDisplayCurrentCreatedFeature();
1140 // checks the sketcher constraints visibility according to active sketch check box states
1142 bool aProcessed = false;
1143 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1144 if (aFeature.get()) {
1145 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1147 aCanDisplay = aConstraintDisplayed;
1154 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1155 const PartSet_Tools::ConstraintVisibleState& theState,
1156 bool& isProcessed) const
1158 bool aSwitchedOn = true;
1160 const QStringList& aConstrIds = constraintsIdList();
1162 std::string aKind = theFeature->getKind();
1163 if (aConstrIds.contains(QString(aKind.c_str()))) {
1164 bool isTypedConstraint = false;
1167 case PartSet_Tools::Dimensional: {
1168 bool isDistance = isDistanceKind(aKind);
1171 aSwitchedOn = myIsConstraintsShown[theState];
1175 case PartSet_Tools::Geometrical: {
1176 bool isGeometrical = !isDistanceKind(aKind);
1177 if (isGeometrical) {
1179 aSwitchedOn = myIsConstraintsShown[theState];
1183 case PartSet_Tools::Any: {
1185 bool isDistance = isDistanceKind(aKind);
1187 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1189 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1199 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1201 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1202 (getCurrentOperation());
1203 if (aFOperation && myCurrentSketch.get()) {
1204 // find results of the current operation
1205 // these results should not be proposed to be deleted
1206 FeaturePtr anOperationFeature = aFOperation->feature();
1207 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1208 std::set<ResultPtr> anOperationResults;
1209 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1210 aRLast = anOperationResultList.end();
1211 for (; aRIt != aRLast; aRIt++)
1212 anOperationResults.insert(*aRIt);
1214 std::set<FeaturePtr> anObjectsToBeDeleted;
1215 QStringList anObjectsToBeDeletedNames;
1216 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1217 for (; anIt != aLast; anIt++) {
1218 ObjectPtr anObject = *anIt;
1219 bool aCanErase = true;
1220 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1221 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1222 // the result is found between current feature results
1223 if (anOperationResults.find(aResult) != anOperationResults.end())
1226 if (aResult.get()) {
1227 // Display sketcher objects
1228 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1229 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1230 std::list<ResultPtr> aResults = aFeature->results();
1231 std::list<ResultPtr>::const_iterator anIt;
1232 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1233 aCanErase = *anIt != aResult;
1238 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1239 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1240 anObjectsToBeDeleted.insert(aFeature);
1241 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1245 if (!anObjectsToBeDeleted.empty()) {
1246 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1247 QString aMessage = tr("The following features have incorrect presentation and \
1248 will be hidden: %1. Would you like to delete them?")
1249 .arg(aFeatureNames);
1250 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1251 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1252 QMessageBox::Cancel);
1253 if (anAnswer == QMessageBox::Ok) {
1254 QObjectPtrList anObjects;
1255 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1256 aLast = anObjectsToBeDeleted.end();
1257 for (; anIt != aLast; anIt++)
1258 anObjects.append(*anIt);
1259 SessionPtr aMgr = ModelAPI_Session::get();
1260 DocumentPtr aDoc = aMgr->activeDocument();
1261 bool aIsOp = aMgr->isOperation();
1263 aMgr->startOperation();
1264 workshop()->deleteFeatures(anObjects);
1265 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1266 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1267 //Events_Loop::loop()->flush(aDeletedEvent);
1268 //Events_Loop::loop()->flush(aRedispEvent);
1271 aMgr->finishOperation();
1277 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1279 bool aCanDisplay = myIsMouseOverWindow;
1281 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1283 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1288 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1290 return isNestedCreateOperation(theOperation) ||
1291 myModule->sketchReentranceMgr()->isInternalEditActive();
1294 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1296 return myIsConstraintsShown;
1299 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1301 bool isFoundObject = false;
1303 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1304 if (anObjectFeature.get()) {
1305 int aSize = myCurrentSketch->numberOfSubs();
1306 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1307 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1308 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1311 return isFoundObject;
1314 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1316 if (myPlaneFilter.IsNull())
1317 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1319 myPlaneFilter->setPlane(thePln);
1322 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1323 ModuleBase_IWorkshop* theWorkshop)
1325 bool isValueAccepted = false;
1327 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1329 FeaturePtr aFeature = aFOperation->feature();
1330 // editor is shown only if all attribute references are filled by preseletion
1331 bool anAllRefAttrInitialized = true;
1333 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1334 ModelAPI_AttributeRefAttr::typeId());
1335 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1336 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1337 anAllRefAttrInitialized = (*anIt)->isInitialized();
1339 if (anAllRefAttrInitialized) {
1340 // Activate dimension value editing on double click
1341 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1342 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1343 // Find corresponded widget to activate value editing
1344 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1345 if (aWgt->attributeID() == "ConstraintValue") {
1346 // the featue should be displayed in order to find the AIS text position,
1347 // the place where the editor will be shown
1348 aFeature->setDisplayed(true);
1349 /// the execute is necessary to perform in the feature compute for flyout position
1350 aFeature->execute();
1352 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1353 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1355 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1357 int aX = 0, anY = 0;
1359 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1360 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1361 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1362 Handle(AIS_InteractiveObject) anAISIO;
1363 if (anAIS.get() != NULL) {
1364 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1366 if (anAIS.get() != NULL) {
1367 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1369 if (!anAISIO.IsNull()) {
1370 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1371 if (!aDim.IsNull()) {
1372 gp_Pnt aPosition = aDim->GetTextPosition();
1374 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1375 Handle(V3d_View) aView = aViewer->activeView();
1377 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1379 QWidget* aViewPort = aViewer->activeViewPort();
1380 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1385 anEditor->setCursorPosition(aX, anY);
1386 isValueAccepted = anEditor->showPopupEditor(false);
1392 return isValueAccepted;
1395 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1396 const FeaturePtr& theSketch,
1397 ModuleBase_IWorkshop* theWorkshop,
1398 FeatureToSelectionMap& theSelection)
1400 if (theFeature.get() == NULL)
1403 std::set<AttributePtr> aSelectedAttributes;
1404 std::set<ResultPtr> aSelectedResults;
1406 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1407 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1408 if (!aContext.IsNull()) {
1409 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1410 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1412 std::list<ResultPtr> aResults = theFeature->results();
1413 std::list<ResultPtr>::const_iterator aIt;
1414 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1416 ResultPtr aResult = *aIt;
1417 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1418 if (aAISObj.get() == NULL)
1420 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1421 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1423 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1424 if (anOwner->Selectable() != anAISIO)
1426 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1427 aSelectedAttributes, aSelectedResults);
1429 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1430 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1431 if (anOwner.IsNull())
1433 if (anOwner->Selectable() != anAISIO)
1435 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1436 aSelectedAttributes, aSelectedResults);
1440 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1443 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1444 const FeaturePtr& theSketch,
1445 ModuleBase_IWorkshop* theWorkshop,
1446 const FeatureToSelectionMap& theSelection,
1447 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1449 if (theFeature.get() == NULL)
1452 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1453 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1454 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1456 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1458 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1459 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1461 // 1. found the feature's owners. Check the AIS objects of the constructions
1462 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1463 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1464 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1466 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1467 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1468 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1469 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1470 if (!anOwner.IsNull())
1471 theOwnersToSelect.Add(anOwner);
1475 // 2. found the feature results's owners
1476 std::list<ResultPtr> aResults = theFeature->results();
1477 std::list<ResultPtr>::const_iterator aIt;
1478 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1480 ResultPtr aResult = *aIt;
1481 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1482 if (aAISObj.get() == NULL)
1484 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1486 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1487 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1488 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1489 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1490 if ( anOwner.IsNull() || !anOwner->HasShape() )
1492 const TopoDS_Shape& aShape = anOwner->Shape();
1493 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1494 if (aShapeType == TopAbs_VERTEX) {
1495 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1496 if (aPntAttr.get() != NULL &&
1497 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1498 theOwnersToSelect.Add(anOwner);
1501 else if (aShapeType == TopAbs_EDGE) {
1502 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1503 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1504 theOwnersToSelect.FindIndex(anOwner) <= 0)
1505 theOwnersToSelect.Add(anOwner);
1511 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1514 connect(theWidget, SIGNAL(beforeValuesChanged()),
1515 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1516 connect(theWidget, SIGNAL(afterValuesChanged()),
1517 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1520 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1521 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1522 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1523 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1527 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1529 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1530 (getCurrentOperation());
1532 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1533 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1534 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1535 FeaturePtr aFeature = aFOperation->feature();
1536 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1541 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1543 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1544 (getCurrentOperation());
1545 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1546 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)))
1547 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1550 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1552 return myModule->workshop()->currentOperation();
1555 //**************************************************************
1556 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1558 ModuleBase_ModelWidget* aWidget = 0;
1559 ModuleBase_Operation* anOperation = getCurrentOperation();
1561 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1563 aWidget = aPanel->activeWidget();
1568 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1569 const bool isEditOperation,
1570 const bool isToDisplay,
1571 const bool isFlushRedisplay)
1573 #ifdef DEBUG_DO_NOT_BY_ENTER
1577 if (isEditOperation || !theFeature.get())
1580 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1581 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1583 // 1. change visibility of the object itself, here the presentable object is processed,
1584 // e.g. constraints features
1585 //FeaturePtr aFeature = aFOperation->feature();
1586 std::list<ResultPtr> aResults = theFeature->results();
1588 theFeature->setDisplayed(true);
1590 theFeature->setDisplayed(false);
1592 // change visibility of the object results, e.g. non-constraint features
1593 std::list<ResultPtr>::const_iterator aIt;
1594 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1596 (*aIt)->setDisplayed(true);
1599 (*aIt)->setDisplayed(false);
1602 if (isFlushRedisplay)
1603 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1606 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1608 if (!myCurrentSketch.get())
1611 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1612 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1613 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1615 QList<FeaturePtr> aFeatureList;
1616 if (theHighlightedOnly) {
1617 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1620 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1622 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1623 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1626 // 1. it is necessary to save current selection in order to restore it after the features moving
1627 myCurrentSelection.clear();
1628 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1629 for (; anIt != aLast; anIt++) {
1630 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1632 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1635 void PartSet_SketcherMgr::restoreSelection()
1637 if (!myCurrentSketch.get())
1640 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1641 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1642 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1643 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1644 aSLast = myCurrentSelection.end();
1645 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1646 for (; aSIt != aSLast; aSIt++) {
1647 anOwnersToSelect.Clear();
1648 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1650 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1654 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1656 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1658 updateBySketchParameters(aType, theState);
1661 void PartSet_SketcherMgr::updateBySketchParameters(
1662 const PartSet_Tools::ConstraintVisibleState& theType,
1665 if (myCurrentSketch.get() == NULL)
1668 bool aPrevState = myIsConstraintsShown[theType];
1669 myIsConstraintsShown[theType] = theState;
1672 case PartSet_Tools::Geometrical:
1673 case PartSet_Tools::Dimensional: {
1674 if (aPrevState != theState) {
1675 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1676 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1677 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1678 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1679 bool aProcessed = false;
1680 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1682 aSubFeature->setDisplayed(aConstraintDisplayed);
1684 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1688 case PartSet_Tools::Expressions: {
1689 /// call all sketch features redisplay, the expression state will be corrected in customize
1690 /// of distance presentation
1691 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1692 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1698 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1700 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1701 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1702 return aConnector->workshop();
1705 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1707 return workshop()->operationMgr();