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;
194 PartSet_SketcherMgr::~PartSet_SketcherMgr()
196 if (!myPlaneFilter.IsNull())
197 myPlaneFilter.Nullify();
200 void PartSet_SketcherMgr::onEnterViewPort()
202 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
203 // created feature because it should be done in onMouseMove(). Some widgets watch
204 // the mouse move and use the cursor position to update own values. If the presentaion is
205 // redisplayed before this update, the feature presentation jumps from reset value to current.
206 myIsMouseOverWindow = true;
208 #ifdef DEBUG_DO_NOT_BY_ENTER
212 if (canChangeCursor(getCurrentOperation())) {
213 QCursor* aCurrentCursor = QApplication::overrideCursor();
214 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
215 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
217 qDebug("onEnterViewPort() : Qt::CrossCursor");
222 if (!isNestedCreateOperation(getCurrentOperation()))
225 operationMgr()->onValidateOperation();
227 // we need change displayed state of the current operation feature
228 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
229 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
230 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
231 // presentation becomes valid and redisplay happens
232 //ModuleBase_Operation* aOperation = getCurrentOperation();
233 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
234 (getCurrentOperation());
236 FeaturePtr aFeature = aFOperation->feature();
237 if (aFeature.get() && aFeature->data()->isValid()) {
238 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
243 void PartSet_SketcherMgr::onLeaveViewPort()
245 myIsMouseOverViewProcessed = false;
246 myIsMouseOverWindow = false;
247 // it is important to validate operation here only if sketch entity create operation is active
248 // because at this operation we reacts to the mouse leave/enter view port
249 //operationMgr()->onValidateOperation();
251 #ifdef DEBUG_DO_NOT_BY_ENTER
255 if (canChangeCursor(getCurrentOperation())) {
256 QApplication::restoreOverrideCursor();
258 qDebug("onLeaveViewPort() : None");
262 if (!isNestedCreateOperation(getCurrentOperation()))
265 // the method should be performed if the popup menu is called,
266 // the reset of the current widget should not happen
267 if (myIsPopupMenuActive)
270 operationMgr()->onValidateOperation();
272 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
273 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
274 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
275 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
276 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
277 // obtained after reset value
278 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
279 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
281 anActiveWidget->reset();
283 // hides the presentation of the current operation feature
284 // the feature is to be erased here, but it is correct to call canDisplayObject because
285 // there can be additional check (e.g. editor widget in distance constraint)
286 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
287 (getCurrentOperation());
289 FeaturePtr aFeature = aFOperation->feature();
290 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
292 // we should update viewer after the presentation are hidden in the viewer
293 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
294 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
297 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
299 if (!isNestedEditOperation(getCurrentOperation()) ||
300 myModule->sketchReentranceMgr()->isInternalEditActive())
302 // it is necessary to save current selection in order to restore it after the values are modifed
305 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
306 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
307 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
308 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
311 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
313 if (!isNestedEditOperation(getCurrentOperation()) ||
314 myModule->sketchReentranceMgr()->isInternalEditActive()) {
315 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
318 // it is necessary to restore current selection in order to restore it after the values are modified
320 myCurrentSelection.clear();
322 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
323 // viewer happens by deselect/select the modified objects. The flag should be restored after
324 // the selection processing. The update viewer should be also called.
325 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
326 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
327 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
328 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
329 aDisplayer->updateViewer();
334 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
336 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
339 //get2dPoint(theWnd, theEvent, myClickedPoint);
341 if (!(theEvent->buttons() & Qt::LeftButton))
344 // Clear dragging mode
345 myIsDragging = false;
347 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
348 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
349 if (!aViewer->canDragByMouse())
352 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
353 (getCurrentOperation());
357 if (aFOperation->isEditOperation()) {
358 // If the current widget is a selector, do nothing, it processes the mouse press
359 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
360 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
365 // Use only for sketch operations
366 if (myCurrentSketch) {
367 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
370 bool isSketcher = isSketchOperation(aFOperation);
371 bool isSketchOpe = isNestedSketchOperation(aFOperation);
373 // Avoid non-sketch operations
374 if ((!isSketchOpe) && (!isSketcher))
377 bool isEditing = aFOperation->isEditOperation();
379 // Ignore creation sketch operation
380 if ((!isSketcher) && (!isEditing))
383 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
384 if (!aContext.IsNull()) {
385 // MoveTo in order to highlight current object
386 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
388 // Remember highlighted objects for editing
389 ModuleBase_ISelection* aSelect = aWorkshop->selection();
391 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
392 storeSelection(!aHasShift);
394 if (myCurrentSelection.empty()) {
395 if (isSketchOpe && (!isSketcher))
396 // commit previous operation
397 if (!aFOperation->commit())
398 aFOperation->abort();
401 // Init flyout point for radius rotation
402 FeaturePtr aFeature = myCurrentSelection.begin().key();
406 get2dPoint(theWnd, theEvent, myCurrentPoint);
409 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
411 if (aFeature.get() != NULL) {
412 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
413 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
414 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
415 DataPtr aData = aSPFeature->data();
416 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
417 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
418 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
419 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
422 } else if (isSketchOpe && isEditing) {
423 // If selected another object commit current result
424 aFOperation->commit();
427 get2dPoint(theWnd, theEvent, myCurrentPoint);
430 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
432 // this is temporary commented in order to avoid the following wrong case:
433 // Distance constraint is under edition, double click on the digit -> nothing happens
434 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
435 // but as the prev edit is commited an new one is not started, editor is not shown.
436 // This is necessary in order to finalize previous operation
437 //QApplication::processEvents();
443 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
445 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
448 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
449 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
450 if (!aViewer->canDragByMouse())
452 ModuleBase_Operation* aOp = getCurrentOperation();
454 if (isNestedSketchOperation(aOp)) {
455 //get2dPoint(theWnd, theEvent, myClickedPoint);
457 // Only for sketcher operations
461 myCurrentSelection.clear();
462 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
463 if (!aContext.IsNull()) {
464 // Reselect edited object
465 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
466 if (theEvent->modifiers() & Qt::ShiftModifier)
467 aContext->ShiftSelect();
476 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
477 myIsDragging = false;
480 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
482 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
485 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
486 myIsMouseOverViewProcessed = true;
487 // 1. perform the widget mouse move functionality and display the presentation
488 // the mouse move should be processed in the widget, if it can in order to visualize correct
489 // presentation. These widgets correct the feature attribute according to the mouse position
490 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
491 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
493 aPoint2DWdg->onMouseMove(theWnd, theEvent);
495 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
498 aDistanceWdg->onMouseMove(theWnd, theEvent);
500 // the feature is to be erased here, but it is correct to call canDisplayObject because
501 // there can be additional check (e.g. editor widget in distance constraint)
502 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
503 (getCurrentOperation());
505 FeaturePtr aFeature = aFOperation->feature();
506 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
510 //myClickedPoint.clear();
513 // 1. the current selection is saved in the mouse press method in order to restore it after moving
514 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
515 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
516 // deselected). This flag should be restored in the slot, processed the mouse release signal.
518 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
519 if (!aCurrentOperation)
521 if (isSketchOperation(aCurrentOperation))
522 return; // No edit operation activated
524 Handle(V3d_View) aView = theWnd->v3dView();
525 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
527 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
528 double dX = aX - myCurrentPoint.myCurX;
529 double dY = aY - myCurrentPoint.myCurY;
531 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
532 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
533 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
534 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
535 // viewer happens by deselect/select the modified objects. The flag should be restored after
536 // the selection processing. The update viewer should be also called.
537 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
539 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
540 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
541 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
542 aLast = myCurrentSelection.end();
543 // 4. the features and attributes modification(move)
544 bool isModified = false;
545 for (; anIt != aLast; anIt++) {
546 FeaturePtr aFeature = anIt.key();
548 std::set<AttributePtr> anAttributes = anIt.value().first;
549 // Process selection by attribute: the priority to the attribute
550 if (!anAttributes.empty()) {
551 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
552 anAttLast = anAttributes.end();
553 for (; anAttIt != anAttLast; anAttIt++) {
554 AttributePtr anAttr = *anAttIt;
555 if (anAttr.get() == NULL)
557 std::string aAttrId = anAttr->id();
558 DataPtr aData = aFeature->data();
559 if (aData->isValid()) {
560 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
561 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
562 if (aPoint.get() != NULL) {
563 bool isImmutable = aPoint->setImmutable(true);
564 aPoint->move(dX, dY);
566 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
567 aPoint->setImmutable(isImmutable);
572 // Process selection by feature
573 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
574 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
575 if (aSketchFeature) {
576 aSketchFeature->move(dX, dY);
578 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
582 // the modified state of the current operation should be updated if there are features, which
585 aCurrentOperation->onValuesChanged();
587 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
588 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
590 // 5. it is necessary to save current selection in order to restore it after the features moving
592 // 6. restore the update viewer flag and call this update
593 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
594 aDisplayer->updateViewer();
597 myCurrentPoint.setValue(aX, aY);
601 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
603 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
604 (getCurrentOperation());
605 if (aFOperation && aFOperation->isEditOperation()) {
606 std::string aId = aFOperation->id().toStdString();
607 if (isDistanceOperation(aFOperation))
609 // Activate dimension value editing on double click
610 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
611 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
612 // Find corresponded widget to activate value editing
613 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
614 if (aWgt->attributeID() == "ConstraintValue") {
615 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
617 anEditor->showPopupEditor();
625 void PartSet_SketcherMgr::onApplicationStarted()
627 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
628 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
629 XGUI_Workshop* aWorkshop = aConnector->workshop();
630 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
632 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
633 if (aPropertyPanel) {
634 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
635 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
637 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
638 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
639 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
640 aReentranceMgr, SLOT(onWidgetActivated()));
643 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
644 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
645 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
647 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
648 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
649 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
652 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
654 //if (!myClickedPoint.myIsInitialized)
657 //ModuleBase_Operation* aOperation = getCurrentOperation();
658 // the distance constraint feature should not use the clickedd point
659 // this is workaround in order to don't throw down the flyout point value,
660 // set by execute() method of these type of features
661 //if (isDistanceOperation(aOperation))
664 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
666 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
670 void PartSet_SketcherMgr::onBeforeContextMenu()
672 myIsPopupMenuActive = true;
675 void PartSet_SketcherMgr::onAfterContextMenu()
677 myIsPopupMenuActive = false;
680 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
683 Handle(V3d_View) aView = theWnd->v3dView();
684 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
686 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
687 thePoint.setValue(aX, anY);
690 void PartSet_SketcherMgr::launchEditing()
692 if (!myCurrentSelection.empty()) {
693 FeaturePtr aFeature = myCurrentSelection.begin().key();
694 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
695 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
697 myModule->editFeature(aSPFeature);
702 bool PartSet_SketcherMgr::sketchSolverError()
704 bool anError = false;
705 CompositeFeaturePtr aSketch = activeSketch();
707 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
708 anError = !aAttributeString->value().empty();
713 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
715 QString anError = "";
716 if (!theFeature.get() || !theFeature->data()->isValid())
719 CompositeFeaturePtr aSketch = activeSketch();
720 if (aSketch.get() && aSketch == theFeature) {
721 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
722 anError = aAttributeString->value().c_str();
727 void PartSet_SketcherMgr::clearClickedFlags()
729 //myClickedPoint.clear();
730 myCurrentPoint.clear();
733 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
735 static QStringList aIds;
736 if (aIds.size() == 0) {
737 aIds << SketchPlugin_Line::ID().c_str();
738 aIds << SketchPlugin_Point::ID().c_str();
739 aIds << SketchPlugin_Arc::ID().c_str();
740 aIds << SketchPlugin_Circle::ID().c_str();
741 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
742 aIds << SketchPlugin_IntersectionPoint::ID().c_str();
744 // SketchRectangle is a python feature, so its ID is passed just as a string
745 aIds << "SketchRectangle";
746 aIds.append(constraintsIdList());
751 const QStringList& PartSet_SketcherMgr::constraintsIdList()
753 static QStringList aIds;
754 if (aIds.size() == 0) {
755 aIds << SketchPlugin_ConstraintLength::ID().c_str();
756 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
757 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
758 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
759 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
760 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
761 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
762 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
763 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
764 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
765 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
766 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
767 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
768 aIds << SketchPlugin_MultiRotation::ID().c_str();
769 aIds << SketchPlugin_MultiTranslation::ID().c_str();
770 aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
771 aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
776 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
780 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
781 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
782 theModes.append(SketcherPrs_Tools::Sel_Constraint);
783 theModes.append(TopAbs_VERTEX);
784 theModes.append(TopAbs_EDGE);
787 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
789 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
792 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
794 return theOperation &&
795 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
798 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
800 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
802 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
805 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
807 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
809 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
812 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
814 return (theId == SketchPlugin_Line::ID()) ||
815 (theId == SketchPlugin_Point::ID()) ||
816 (theId == SketchPlugin_Arc::ID()) ||
817 (theId == SketchPlugin_Circle::ID());
820 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
822 std::string anId = theOperation ? theOperation->id().toStdString() : "";
824 return isDistanceKind(anId);
827 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
829 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
830 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
831 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
832 (theKind == SketchPlugin_ConstraintAngle::ID());
835 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
837 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
838 (getCurrentOperation());
842 myModule->onViewTransformed();
844 // Display all sketcher sub-Objects
845 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
846 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
847 aConnector->workshop()->displayer()->activateTrihedron(true);
849 // Hide sketcher result
850 std::list<ResultPtr> aResults = myCurrentSketch->results();
851 std::list<ResultPtr>::const_iterator aIt;
852 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
853 (*aIt)->setDisplayed(false);
855 myCurrentSketch->setDisplayed(false);
857 // Display sketcher objects
858 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
859 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
860 std::list<ResultPtr> aResults = aFeature->results();
861 std::list<ResultPtr>::const_iterator aIt;
862 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
863 (*aIt)->setDisplayed(true);
865 aFeature->setDisplayed(true);
868 if(myCirclePointFilter.IsNull()) {
869 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
872 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
874 if (myPlaneFilter.IsNull())
875 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
877 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
878 bool aHasPlane = false;
879 std::shared_ptr<GeomAPI_Pln> aPln;
880 if (aFOperation->isEditOperation()) {
881 // If it is editing of sketch then it means that plane is already defined
882 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
886 myPlaneFilter->setPlane(aPln);
888 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
889 // all sketch objects should be activated in the sketch selection modes by edit operation start
890 // in case of creation operation, there is an active widget, which activates own selection mode
891 if (aFOperation->isEditOperation() && aHasPlane)
892 aConnector->activateModuleSelectionModes();
895 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
897 myIsMouseOverWindow = false;
898 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
899 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
901 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
903 DataPtr aData = myCurrentSketch->data();
904 if (!aData->isValid()) {
905 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
906 // The sketch was aborted
907 myCurrentSketch = CompositeFeaturePtr();
908 // TODO: move this outside of if-else
909 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
910 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
912 // Erase all sketcher objects
913 QStringList aSketchIds = sketchOperationIdList();
914 QObjectPtrList aObjects = aDisplayer->displayedObjects();
915 foreach (ObjectPtr aObj, aObjects) {
916 DataPtr aObjData = aObj->data();
917 if (!aObjData->isValid())
918 aObj->setDisplayed(false);
922 // Hide all sketcher sub-Objects
923 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
924 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
925 std::list<ResultPtr> aResults = aFeature->results();
926 std::list<ResultPtr>::const_iterator aIt;
927 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
928 (*aIt)->setDisplayed(false);
930 aFeature->setDisplayed(false);
932 // Display sketcher result
933 std::list<ResultPtr> aResults = myCurrentSketch->results();
934 std::list<ResultPtr>::const_iterator aIt;
935 Events_Loop* aLoop = Events_Loop::loop();
936 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
938 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
940 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
941 if (!aFOperation->isDisplayedOnStart(*aIt)) {
942 (*aIt)->setDisplayed(true);
943 // this display event is needed because sketch already may have "displayed" state,
944 // but not displayed while it is still active (issue 613, abort of existing sketch)
945 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
948 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
949 myCurrentSketch->setDisplayed(true);
951 myCurrentSketch = CompositeFeaturePtr();
953 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
954 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
956 Events_Loop::loop()->flush(aDispEvent);
958 // restore the module selection modes, which were changed on startSketch
959 aConnector->activateModuleSelectionModes();
960 aConnector->workshop()->displayer()->activateTrihedron(false);
963 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
965 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
966 QCursor* aCurrentCursor = QApplication::overrideCursor();
967 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
968 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
970 qDebug("startNestedSketch() : Qt::CrossCursor");
976 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
978 myIsMouseOverViewProcessed = true;
979 operationMgr()->onValidateOperation();
980 if (canChangeCursor(theOperation)) {
981 QApplication::restoreOverrideCursor();
983 qDebug("stopNestedSketch() : None");
988 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
990 if (isNestedCreateOperation(theOperation)) {
991 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
994 FeaturePtr aFeature = aFOperation->feature();
995 // it is necessary to check the the feature data validity because
996 // some kind of features are removed by an operation commit(the macro state of a feature)
997 if (aFeature.get() && aFeature->data()->isValid()) {
998 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1004 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1007 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1009 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1012 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1014 bool isOperationStopped = false;
1015 ModuleBase_Operation* anOperation = getCurrentOperation();
1016 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1017 // Set final definitions if they are necessary
1018 //propertyPanelDefined(aOperation);
1019 /// Commit sketcher operations automatically
1020 /// distance operation are able to show popup editor to modify the distance value
1021 /// after entering the value, the operation should be committed/aborted(by Esc key)
1022 bool aCanCommitOperation = true;
1023 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1025 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation))
1026 aCanCommitOperation = setDistanceValueByPreselection(anOperation, myModule->workshop());
1028 if (aCanCommitOperation)
1029 isOperationStopped = anOperation->commit();
1031 anOperation->abort();
1032 isOperationStopped = true;
1035 return isOperationStopped;
1038 bool PartSet_SketcherMgr::canUndo() const
1040 return isNestedCreateOperation(getCurrentOperation());
1043 bool PartSet_SketcherMgr::canRedo() const
1045 return isNestedCreateOperation(getCurrentOperation());
1048 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1050 bool aCanErase = true;
1051 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1052 if (myCurrentSketch.get()) {
1053 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1054 if (aResult.get()) {
1055 // Display sketcher objects
1056 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1058 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1059 std::list<ResultPtr> aResults = aFeature->results();
1060 std::list<ResultPtr>::const_iterator anIt;
1061 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1062 aCanErase = *anIt != aResult;
1070 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1072 bool aCanDisplay = true;
1074 bool aHasActiveSketch = activeSketch().get() != NULL;
1075 if (aHasActiveSketch) {
1076 // 1. the sketch feature should not be displayed during the sketch active operation
1077 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1078 // nested features can be visualized
1079 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1080 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1081 aCanDisplay = false;
1084 else { // there are no an active sketch
1085 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1086 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1087 if (aFeature.get() != NULL) {
1088 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1089 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1090 if (aSketchFeature.get()) {
1091 aCanDisplay = false;
1096 // 3. the method should not filter the objects, which are not related to the current operation.
1097 // The object is filtered just if it is a current operation feature or this feature result
1098 bool isObjectFound = false;
1099 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1100 (getCurrentOperation());
1102 FeaturePtr aFeature = aFOperation->feature();
1103 if (aFeature.get()) {
1104 std::list<ResultPtr> aResults = aFeature->results();
1105 if (theObject == aFeature)
1106 isObjectFound = true;
1108 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1109 for (; anIt != aLast && !isObjectFound; anIt++) {
1110 isObjectFound = *anIt == theObject;
1115 if (isObjectFound) {
1116 // 4. For created nested feature operation do not display the created feature if
1117 // the mouse curstor leaves the OCC window.
1118 // The correction cases, which ignores this condition:
1119 // a. the property panel values modification
1120 // b. the popup menu activated
1121 // c. widget editor control
1122 #ifndef DEBUG_DO_NOT_BY_ENTER
1123 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1124 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1125 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1126 // the active widget editor should not influence here. The presentation should be visible always
1127 // when this widget is active.
1128 if (!anEditorWdg && !myIsPopupMenuActive) {
1129 // during a nested create operation, the feature is redisplayed only if the mouse over view
1130 // of there was a value modified in the property panel after the mouse left the view
1131 aCanDisplay = canDisplayCurrentCreatedFeature();
1137 // checks the sketcher constraints visibility according to active sketch check box states
1139 bool aProcessed = false;
1140 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1141 if (aFeature.get()) {
1142 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1144 aCanDisplay = aConstraintDisplayed;
1151 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1152 const PartSet_Tools::ConstraintVisibleState& theState,
1153 bool& isProcessed) const
1155 bool aSwitchedOn = true;
1157 const QStringList& aConstrIds = constraintsIdList();
1159 std::string aKind = theFeature->getKind();
1160 if (aConstrIds.contains(QString(aKind.c_str()))) {
1161 bool isTypedConstraint = false;
1164 case PartSet_Tools::Dimensional: {
1165 bool isDistance = isDistanceKind(aKind);
1168 aSwitchedOn = myIsConstraintsShown[theState];
1172 case PartSet_Tools::Geometrical: {
1173 bool isGeometrical = !isDistanceKind(aKind);
1174 if (isGeometrical) {
1176 aSwitchedOn = myIsConstraintsShown[theState];
1180 case PartSet_Tools::Any: {
1182 bool isDistance = isDistanceKind(aKind);
1184 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1186 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1196 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1198 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1199 (getCurrentOperation());
1200 if (aFOperation && myCurrentSketch.get()) {
1201 // find results of the current operation
1202 // these results should not be proposed to be deleted
1203 FeaturePtr anOperationFeature = aFOperation->feature();
1204 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1205 std::set<ResultPtr> anOperationResults;
1206 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1207 aRLast = anOperationResultList.end();
1208 for (; aRIt != aRLast; aRIt++)
1209 anOperationResults.insert(*aRIt);
1211 std::set<FeaturePtr> anObjectsToBeDeleted;
1212 QStringList anObjectsToBeDeletedNames;
1213 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1214 for (; anIt != aLast; anIt++) {
1215 ObjectPtr anObject = *anIt;
1216 bool aCanErase = true;
1217 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1218 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1219 // the result is found between current feature results
1220 if (anOperationResults.find(aResult) != anOperationResults.end())
1223 if (aResult.get()) {
1224 // Display sketcher objects
1225 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1226 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1227 std::list<ResultPtr> aResults = aFeature->results();
1228 std::list<ResultPtr>::const_iterator anIt;
1229 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1230 aCanErase = *anIt != aResult;
1235 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1236 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1237 anObjectsToBeDeleted.insert(aFeature);
1238 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1242 if (!anObjectsToBeDeleted.empty()) {
1243 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1244 QString aMessage = tr("The following features have incorrect presentation and \
1245 will be hidden: %1. Would you like to delete them?")
1246 .arg(aFeatureNames);
1247 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1248 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1249 QMessageBox::Cancel);
1250 if (anAnswer == QMessageBox::Ok) {
1251 QObjectPtrList anObjects;
1252 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1253 aLast = anObjectsToBeDeleted.end();
1254 for (; anIt != aLast; anIt++)
1255 anObjects.append(*anIt);
1256 SessionPtr aMgr = ModelAPI_Session::get();
1257 DocumentPtr aDoc = aMgr->activeDocument();
1258 bool aIsOp = aMgr->isOperation();
1260 aMgr->startOperation();
1261 workshop()->deleteFeatures(anObjects);
1262 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1263 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1264 //Events_Loop::loop()->flush(aDeletedEvent);
1265 //Events_Loop::loop()->flush(aRedispEvent);
1268 aMgr->finishOperation();
1274 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1276 bool aCanDisplay = myIsMouseOverWindow;
1278 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1280 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1285 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1287 return isNestedCreateOperation(theOperation) ||
1288 myModule->sketchReentranceMgr()->isInternalEditActive();
1291 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1293 return myIsConstraintsShown;
1296 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1298 bool isFoundObject = false;
1300 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1301 if (anObjectFeature.get()) {
1302 int aSize = myCurrentSketch->numberOfSubs();
1303 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1304 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1305 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1308 return isFoundObject;
1311 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1313 if (myPlaneFilter.IsNull())
1314 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1316 myPlaneFilter->setPlane(thePln);
1319 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1320 ModuleBase_IWorkshop* theWorkshop)
1322 bool isValueAccepted = false;
1324 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1326 FeaturePtr aFeature = aFOperation->feature();
1327 // editor is shown only if all attribute references are filled by preseletion
1328 bool anAllRefAttrInitialized = true;
1330 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1331 ModelAPI_AttributeRefAttr::typeId());
1332 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1333 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1334 anAllRefAttrInitialized = (*anIt)->isInitialized();
1336 if (anAllRefAttrInitialized) {
1337 // Activate dimension value editing on double click
1338 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1339 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1340 // Find corresponded widget to activate value editing
1341 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1342 if (aWgt->attributeID() == "ConstraintValue") {
1343 // the featue should be displayed in order to find the AIS text position,
1344 // the place where the editor will be shown
1345 aFeature->setDisplayed(true);
1346 /// the execute is necessary to perform in the feature compute for flyout position
1347 aFeature->execute();
1349 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1350 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1352 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1354 int aX = 0, anY = 0;
1356 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1357 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1358 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1359 Handle(AIS_InteractiveObject) anAISIO;
1360 if (anAIS.get() != NULL) {
1361 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1363 if (anAIS.get() != NULL) {
1364 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1366 if (!anAISIO.IsNull()) {
1367 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1368 if (!aDim.IsNull()) {
1369 gp_Pnt aPosition = aDim->GetTextPosition();
1371 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1372 Handle(V3d_View) aView = aViewer->activeView();
1374 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1376 QWidget* aViewPort = aViewer->activeViewPort();
1377 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1382 anEditor->setCursorPosition(aX, anY);
1383 isValueAccepted = anEditor->showPopupEditor(false);
1389 return isValueAccepted;
1392 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1393 const FeaturePtr& theSketch,
1394 ModuleBase_IWorkshop* theWorkshop,
1395 FeatureToSelectionMap& theSelection)
1397 if (theFeature.get() == NULL)
1400 std::set<AttributePtr> aSelectedAttributes;
1401 std::set<ResultPtr> aSelectedResults;
1403 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1404 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1405 if (!aContext.IsNull()) {
1406 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1407 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1409 std::list<ResultPtr> aResults = theFeature->results();
1410 std::list<ResultPtr>::const_iterator aIt;
1411 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1413 ResultPtr aResult = *aIt;
1414 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1415 if (aAISObj.get() == NULL)
1417 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1418 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1420 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1421 if (anOwner->Selectable() != anAISIO)
1423 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1424 aSelectedAttributes, aSelectedResults);
1426 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1427 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1428 if (anOwner.IsNull())
1430 if (anOwner->Selectable() != anAISIO)
1432 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1433 aSelectedAttributes, aSelectedResults);
1437 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1440 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1441 const FeaturePtr& theSketch,
1442 ModuleBase_IWorkshop* theWorkshop,
1443 const FeatureToSelectionMap& theSelection,
1444 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1446 if (theFeature.get() == NULL)
1449 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1450 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1451 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1453 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1455 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1456 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1458 // 1. found the feature's owners. Check the AIS objects of the constructions
1459 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1460 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1461 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1463 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1464 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1465 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1466 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1467 if (!anOwner.IsNull())
1468 theOwnersToSelect.Add(anOwner);
1472 // 2. found the feature results's owners
1473 std::list<ResultPtr> aResults = theFeature->results();
1474 std::list<ResultPtr>::const_iterator aIt;
1475 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1477 ResultPtr aResult = *aIt;
1478 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1479 if (aAISObj.get() == NULL)
1481 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1483 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1484 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1485 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1486 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1487 if ( anOwner.IsNull() || !anOwner->HasShape() )
1489 const TopoDS_Shape& aShape = anOwner->Shape();
1490 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1491 if (aShapeType == TopAbs_VERTEX) {
1492 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1493 if (aPntAttr.get() != NULL &&
1494 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1495 theOwnersToSelect.Add(anOwner);
1498 else if (aShapeType == TopAbs_EDGE) {
1499 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1500 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1501 theOwnersToSelect.FindIndex(anOwner) <= 0)
1502 theOwnersToSelect.Add(anOwner);
1508 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1511 connect(theWidget, SIGNAL(beforeValuesChanged()),
1512 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1513 connect(theWidget, SIGNAL(afterValuesChanged()),
1514 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1517 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1518 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1519 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1520 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1524 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1526 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1527 (getCurrentOperation());
1529 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1530 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1531 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1532 FeaturePtr aFeature = aFOperation->feature();
1533 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1538 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1540 return myModule->workshop()->currentOperation();
1543 //**************************************************************
1544 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1546 ModuleBase_ModelWidget* aWidget = 0;
1547 ModuleBase_Operation* anOperation = getCurrentOperation();
1549 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1551 aWidget = aPanel->activeWidget();
1556 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1557 const bool isEditOperation,
1558 const bool isToDisplay,
1559 const bool isFlushRedisplay)
1561 #ifdef DEBUG_DO_NOT_BY_ENTER
1565 if (isEditOperation || !theFeature.get())
1568 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1569 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1571 // 1. change visibility of the object itself, here the presentable object is processed,
1572 // e.g. constraints features
1573 //FeaturePtr aFeature = aFOperation->feature();
1574 std::list<ResultPtr> aResults = theFeature->results();
1576 theFeature->setDisplayed(true);
1578 theFeature->setDisplayed(false);
1580 // change visibility of the object results, e.g. non-constraint features
1581 std::list<ResultPtr>::const_iterator aIt;
1582 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1584 (*aIt)->setDisplayed(true);
1587 (*aIt)->setDisplayed(false);
1590 if (isFlushRedisplay)
1591 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1594 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1596 if (!myCurrentSketch.get())
1599 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1600 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1601 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1603 QList<FeaturePtr> aFeatureList;
1604 if (theHighlightedOnly) {
1605 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1608 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1610 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1611 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1614 // 1. it is necessary to save current selection in order to restore it after the features moving
1615 myCurrentSelection.clear();
1616 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1617 for (; anIt != aLast; anIt++) {
1618 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1620 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1623 void PartSet_SketcherMgr::restoreSelection()
1625 if (!myCurrentSketch.get())
1628 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1629 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1630 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1631 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1632 aSLast = myCurrentSelection.end();
1633 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1634 for (; aSIt != aSLast; aSIt++) {
1635 anOwnersToSelect.Clear();
1636 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1638 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1642 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1644 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1645 if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1647 if (myCurrentSketch.get() == NULL)
1650 myIsConstraintsShown[aType] = theState;
1652 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1653 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1655 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1656 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1657 bool aProcessed = false;
1658 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, aType, aProcessed);
1660 aSubFeature->setDisplayed(aConstraintDisplayed);
1662 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1665 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1667 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1668 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1669 return aConnector->workshop();
1672 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1674 return workshop()->operationMgr();