1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_SketcherReetntrantMgr.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_WidgetPoint2d.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_Tools.h"
13 #include "PartSet_WidgetSketchLabel.h"
14 #include "PartSet_WidgetEditor.h"
15 #include "PartSet_ResultSketchPrs.h"
17 #include <XGUI_ModuleConnector.h>
18 #include <XGUI_Displayer.h>
19 #include <XGUI_Workshop.h>
20 #include <XGUI_ContextMenuMgr.h>
21 #include <XGUI_Selection.h>
22 #include <XGUI_SelectionMgr.h>
23 #include <XGUI_ModuleConnector.h>
24 #include <XGUI_PropertyPanel.h>
25 #include <XGUI_ViewerProxy.h>
26 #include <XGUI_OperationMgr.h>
27 #include <XGUI_Tools.h>
29 #include <ModuleBase_IPropertyPanel.h>
30 #include <ModuleBase_ISelection.h>
31 #include <ModuleBase_IViewer.h>
32 #include <ModuleBase_IWorkshop.h>
33 #include <ModuleBase_IViewWindow.h>
34 #include <ModuleBase_ModelWidget.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_OperationFeature.h>
37 #include <ModuleBase_Operation.h>
38 #include <ModuleBase_WidgetEditor.h>
39 #include <ModuleBase_ViewerPrs.h>
41 #include <GeomDataAPI_Point2D.h>
43 #include <Events_Loop.h>
45 #include <SketchPlugin_Line.h>
46 #include <SketchPlugin_Sketch.h>
47 #include <SketchPlugin_Point.h>
48 #include <SketchPlugin_Arc.h>
49 #include <SketchPlugin_Circle.h>
50 #include <SketchPlugin_ConstraintLength.h>
51 #include <SketchPlugin_ConstraintDistance.h>
52 #include <SketchPlugin_ConstraintParallel.h>
53 #include <SketchPlugin_ConstraintPerpendicular.h>
54 #include <SketchPlugin_ConstraintRadius.h>
55 #include <SketchPlugin_ConstraintRigid.h>
56 #include <SketchPlugin_ConstraintHorizontal.h>
57 #include <SketchPlugin_ConstraintVertical.h>
58 #include <SketchPlugin_ConstraintEqual.h>
59 #include <SketchPlugin_ConstraintTangent.h>
60 #include <SketchPlugin_ConstraintCoincidence.h>
61 #include <SketchPlugin_ConstraintFillet.h>
62 #include <SketchPlugin_ConstraintMirror.h>
63 #include <SketchPlugin_ConstraintAngle.h>
64 #include <SketchPlugin_ConstraintCollinear.h>
65 #include <SketchPlugin_ConstraintMiddle.h>
66 #include <SketchPlugin_MultiRotation.h>
67 #include <SketchPlugin_MultiTranslation.h>
68 #include <SketchPlugin_IntersectionPoint.h>
70 #include <SketcherPrs_Tools.h>
72 #include <SelectMgr_IndexedMapOfOwner.hxx>
73 #include <StdSelect_BRepOwner.hxx>
75 //#include <AIS_DimensionSelectionMode.hxx>
76 #include <AIS_Shape.hxx>
77 #include <AIS_Dimension.hxx>
79 #include <ModelAPI_Events.h>
80 #include <ModelAPI_Session.h>
81 #include <ModelAPI_AttributeString.h>
83 #include <QMouseEvent>
84 #include <QApplication>
86 #include <QMessageBox>
88 //#define DEBUG_DO_NOT_BY_ENTER
90 //#define DEBUG_CURSOR
92 /// Returns list of unique objects by sum of objects from List1 and List2
93 /*QList<ModuleBase_ViewerPrsPtr> getSumList(const QList<ModuleBase_ViewerPrsPtr>& theList1,
94 const QList<ModuleBase_ViewerPrsPtr>& theList2)
96 QList<ModuleBase_ViewerPrsPtr> aRes;
97 foreach (ModuleBase_ViewerPrsPtr aPrs, theList1) {
98 if (!aRes.contains(aPrs))
101 foreach (ModuleBase_ViewerPrsPtr aPrs, theList2) {
102 if (!aRes.contains(aPrs))
108 // Fills the list of features the list of selected presentations.
109 // \param theList a list of selected presentations
110 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
111 // and find the corresponded attribute
112 // \param theFeatureList an output list of features
113 void fillFeatureList(const QList<ModuleBase_ViewerPrsPtr>& theList,
114 const FeaturePtr theSketch,
115 QList<FeaturePtr>& theFeatureList)
117 QList<ModuleBase_ViewerPrsPtr> aRes;
119 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theList.begin(),
120 aLast = theList.end();
121 for (; anIt != aLast; anIt++)
123 ModuleBase_ViewerPrsPtr aPrs = *anIt;
124 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs->object());
125 if (aFeature.get() && !theFeatureList.contains(aFeature))
126 theFeatureList.append(aFeature);
130 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
131 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
132 /// result as is to the list of results.
133 /// \param theOwner a viewer selected owner
134 /// \param theFeature a feature, where the attribute is searched
135 /// \param theSketch a current sketch
136 /// \param theSelectedAttribute an output list of attributes
137 /// \param theSelectedResults an output list of edge results
138 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
139 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
140 const ResultPtr& theResult,
141 std::set<AttributePtr>& aSelectedAttributes,
142 std::set<ResultPtr>& aSelectedResults)
144 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
145 if (aBRepOwner.IsNull())
147 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
148 aBRepOwner->Selectable());
149 if (aBRepOwner->HasShape()) {
150 const TopoDS_Shape& aShape = aBRepOwner->Shape();
151 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
152 if (aShapeType == TopAbs_VERTEX) {
153 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
155 if (aPntAttr.get() != NULL)
156 aSelectedAttributes.insert(aPntAttr);
158 else if (aShapeType == TopAbs_EDGE &&
159 aSelectedResults.find(theResult) == aSelectedResults.end()) {
160 aSelectedResults.insert(theResult);
165 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
166 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
167 myIsMouseOverWindow(false),
168 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
169 myIsPopupMenuActive(false)
171 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
172 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
174 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
176 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
177 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
179 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
180 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
182 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
183 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
185 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
186 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
188 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
189 XGUI_Workshop* aWorkshop = aConnector->workshop();
190 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
192 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
193 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
194 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
197 PartSet_SketcherMgr::~PartSet_SketcherMgr()
199 if (!myPlaneFilter.IsNull())
200 myPlaneFilter.Nullify();
203 void PartSet_SketcherMgr::onEnterViewPort()
205 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
206 // created feature because it should be done in onMouseMove(). Some widgets watch
207 // the mouse move and use the cursor position to update own values. If the presentaion is
208 // redisplayed before this update, the feature presentation jumps from reset value to current.
209 myIsMouseOverWindow = true;
211 #ifdef DEBUG_DO_NOT_BY_ENTER
215 if (canChangeCursor(getCurrentOperation())) {
216 QCursor* aCurrentCursor = QApplication::overrideCursor();
217 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
218 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
220 qDebug("onEnterViewPort() : Qt::CrossCursor");
225 if (!isNestedCreateOperation(getCurrentOperation()))
228 operationMgr()->onValidateOperation();
230 // we need change displayed state of the current operation feature
231 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
232 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
233 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
234 // presentation becomes valid and redisplay happens
235 //ModuleBase_Operation* aOperation = getCurrentOperation();
236 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
237 (getCurrentOperation());
239 FeaturePtr aFeature = aFOperation->feature();
240 if (aFeature.get() && aFeature->data()->isValid()) {
241 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
246 void PartSet_SketcherMgr::onLeaveViewPort()
248 myIsMouseOverViewProcessed = false;
249 myIsMouseOverWindow = false;
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 // it is important to validate operation here only if sketch entity create operation is active
271 // because at this operation we reacts to the mouse leave/enter view port
272 operationMgr()->onValidateOperation();
274 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
275 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
276 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
277 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
278 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
279 // obtained after reset value
280 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
281 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
283 anActiveWidget->reset();
285 // hides the presentation of the current operation feature
286 // the feature is to be erased here, but it is correct to call canDisplayObject because
287 // there can be additional check (e.g. editor widget in distance constraint)
288 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
289 (getCurrentOperation());
291 FeaturePtr aFeature = aFOperation->feature();
292 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
294 // we should update viewer after the presentation are hidden in the viewer
295 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
296 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
299 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
301 if (!isNestedEditOperation(getCurrentOperation()) ||
302 myModule->sketchReentranceMgr()->isInternalEditActive())
304 // it is necessary to save current selection in order to restore it after the values are modifed
307 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
308 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
309 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
310 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
313 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
315 if (!isNestedEditOperation(getCurrentOperation()) ||
316 myModule->sketchReentranceMgr()->isInternalEditActive()) {
317 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
320 // it is necessary to restore current selection in order to restore it after the values are modified
322 myCurrentSelection.clear();
324 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
325 // viewer happens by deselect/select the modified objects. The flag should be restored after
326 // the selection processing. The update viewer should be also called.
327 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
328 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
329 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
330 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
331 aDisplayer->updateViewer();
336 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
338 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
341 //get2dPoint(theWnd, theEvent, myClickedPoint);
343 if (!(theEvent->buttons() & Qt::LeftButton))
346 // Clear dragging mode
347 myIsDragging = false;
349 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
350 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
351 if (!aViewer->canDragByMouse())
354 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
355 (getCurrentOperation());
359 if (aFOperation->isEditOperation()) {
360 // If the current widget is a selector, do nothing, it processes the mouse press
361 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
362 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
367 // Use only for sketch operations
368 if (myCurrentSketch) {
369 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
372 bool isSketcher = isSketchOperation(aFOperation);
373 bool isSketchOpe = isNestedSketchOperation(aFOperation);
375 // Avoid non-sketch operations
376 if ((!isSketchOpe) && (!isSketcher))
379 bool isEditing = aFOperation->isEditOperation();
381 // Ignore creation sketch operation
382 if ((!isSketcher) && (!isEditing))
385 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
386 if (!aContext.IsNull()) {
387 // MoveTo in order to highlight current object
388 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
390 // Remember highlighted objects for editing
391 ModuleBase_ISelection* aSelect = aWorkshop->selection();
393 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
394 storeSelection(!aHasShift);
396 if (myCurrentSelection.empty()) {
397 if (isSketchOpe && (!isSketcher))
398 // commit previous operation
399 if (!aFOperation->commit())
400 aFOperation->abort();
403 // Init flyout point for radius rotation
404 FeaturePtr aFeature = myCurrentSelection.begin().key();
408 get2dPoint(theWnd, theEvent, myCurrentPoint);
411 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
413 if (aFeature.get() != NULL) {
414 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
415 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
416 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
417 DataPtr aData = aSPFeature->data();
418 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
419 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
420 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
421 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
424 } else if (isSketchOpe && isEditing) {
425 // If selected another object commit current result
426 aFOperation->commit();
429 get2dPoint(theWnd, theEvent, myCurrentPoint);
432 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
434 // this is temporary commented in order to avoid the following wrong case:
435 // Distance constraint is under edition, double click on the digit -> nothing happens
436 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
437 // but as the prev edit is commited an new one is not started, editor is not shown.
438 // This is necessary in order to finalize previous operation
439 //QApplication::processEvents();
445 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
447 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
450 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
451 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
452 if (!aViewer->canDragByMouse())
454 ModuleBase_Operation* aOp = getCurrentOperation();
456 if (isNestedSketchOperation(aOp)) {
457 //get2dPoint(theWnd, theEvent, myClickedPoint);
459 // Only for sketcher operations
463 myCurrentSelection.clear();
464 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
465 if (!aContext.IsNull()) {
466 // Reselect edited object
467 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
468 if (theEvent->modifiers() & Qt::ShiftModifier)
469 aContext->ShiftSelect();
478 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
479 myIsDragging = false;
482 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
484 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
487 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
488 myIsMouseOverViewProcessed = true;
489 // 1. perform the widget mouse move functionality and display the presentation
490 // the mouse move should be processed in the widget, if it can in order to visualize correct
491 // presentation. These widgets correct the feature attribute according to the mouse position
492 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
493 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
495 aPoint2DWdg->onMouseMove(theWnd, theEvent);
497 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
500 aDistanceWdg->onMouseMove(theWnd, theEvent);
502 // the feature is to be erased here, but it is correct to call canDisplayObject because
503 // there can be additional check (e.g. editor widget in distance constraint)
504 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
505 (getCurrentOperation());
507 FeaturePtr aFeature = aFOperation->feature();
508 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
512 //myClickedPoint.clear();
515 // 1. the current selection is saved in the mouse press method in order to restore it after moving
516 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
517 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
518 // deselected). This flag should be restored in the slot, processed the mouse release signal.
520 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
521 if (!aCurrentOperation)
523 if (isSketchOperation(aCurrentOperation))
524 return; // No edit operation activated
526 Handle(V3d_View) aView = theWnd->v3dView();
527 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
529 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
530 double dX = aX - myCurrentPoint.myCurX;
531 double dY = aY - myCurrentPoint.myCurY;
533 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
534 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
535 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
536 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
537 // viewer happens by deselect/select the modified objects. The flag should be restored after
538 // the selection processing. The update viewer should be also called.
539 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
541 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
542 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
543 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
544 aLast = myCurrentSelection.end();
545 // 4. the features and attributes modification(move)
546 bool isModified = false;
547 for (; anIt != aLast; anIt++) {
548 FeaturePtr aFeature = anIt.key();
550 std::set<AttributePtr> anAttributes = anIt.value().first;
551 // Process selection by attribute: the priority to the attribute
552 if (!anAttributes.empty()) {
553 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
554 anAttLast = anAttributes.end();
555 for (; anAttIt != anAttLast; anAttIt++) {
556 AttributePtr anAttr = *anAttIt;
557 if (anAttr.get() == NULL)
559 std::string aAttrId = anAttr->id();
560 DataPtr aData = aFeature->data();
561 if (aData->isValid()) {
562 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
563 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
564 if (aPoint.get() != NULL) {
565 bool isImmutable = aPoint->setImmutable(true);
566 aPoint->move(dX, dY);
568 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
569 aPoint->setImmutable(isImmutable);
574 // Process selection by feature
575 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
576 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
577 if (aSketchFeature) {
578 aSketchFeature->move(dX, dY);
580 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
584 // the modified state of the current operation should be updated if there are features, which
587 aCurrentOperation->onValuesChanged();
589 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
590 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
592 // 5. it is necessary to save current selection in order to restore it after the features moving
594 // 6. restore the update viewer flag and call this update
595 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
596 aDisplayer->updateViewer();
599 myCurrentPoint.setValue(aX, aY);
603 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
605 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
606 (getCurrentOperation());
607 if (aFOperation && aFOperation->isEditOperation()) {
608 std::string aId = aFOperation->id().toStdString();
609 if (isDistanceOperation(aFOperation))
611 // Activate dimension value editing on double click
612 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
613 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
614 // Find corresponded widget to activate value editing
615 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
616 if (aWgt->attributeID() == SketchPlugin_Constraint::VALUE() ||
617 aWgt->attributeID() == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) {
618 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
620 anEditor->showPopupEditor();
628 void PartSet_SketcherMgr::onApplicationStarted()
630 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
631 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
632 XGUI_Workshop* aWorkshop = aConnector->workshop();
633 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
635 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
636 if (aPropertyPanel) {
637 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
638 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
640 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
641 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
642 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
643 aReentranceMgr, SLOT(onWidgetActivated()));
646 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
647 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
648 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
650 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
651 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
652 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
655 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
657 //if (!myClickedPoint.myIsInitialized)
660 //ModuleBase_Operation* aOperation = getCurrentOperation();
661 // the distance constraint feature should not use the clickedd point
662 // this is workaround in order to don't throw down the flyout point value,
663 // set by execute() method of these type of features
664 //if (isDistanceOperation(aOperation))
667 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
669 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
673 void PartSet_SketcherMgr::onBeforeContextMenu()
675 myIsPopupMenuActive = true;
678 void PartSet_SketcherMgr::onAfterContextMenu()
680 myIsPopupMenuActive = false;
683 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
686 Handle(V3d_View) aView = theWnd->v3dView();
687 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
689 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
690 thePoint.setValue(aX, anY);
693 void PartSet_SketcherMgr::launchEditing()
695 if (!myCurrentSelection.empty()) {
696 FeaturePtr aFeature = myCurrentSelection.begin().key();
697 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
698 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
700 myModule->editFeature(aSPFeature);
705 bool PartSet_SketcherMgr::sketchSolverError()
707 bool anError = false;
708 CompositeFeaturePtr aSketch = activeSketch();
710 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
711 anError = !aAttributeString->value().empty();
716 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
718 QString anError = "";
719 if (!theFeature.get() || !theFeature->data()->isValid())
722 CompositeFeaturePtr aSketch = activeSketch();
723 if (aSketch.get() && aSketch == theFeature) {
724 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
725 anError = aAttributeString->value().c_str();
730 void PartSet_SketcherMgr::clearClickedFlags()
732 //myClickedPoint.clear();
733 myCurrentPoint.clear();
736 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
738 static QStringList aIds;
739 if (aIds.size() == 0) {
740 aIds << SketchPlugin_Line::ID().c_str();
741 aIds << SketchPlugin_Point::ID().c_str();
742 aIds << SketchPlugin_Arc::ID().c_str();
743 aIds << SketchPlugin_Circle::ID().c_str();
744 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
745 aIds << SketchPlugin_IntersectionPoint::ID().c_str();
747 // SketchRectangle is a python feature, so its ID is passed just as a string
748 aIds << "SketchRectangle";
749 aIds.append(constraintsIdList());
754 const QStringList& PartSet_SketcherMgr::constraintsIdList()
756 static QStringList aIds;
757 if (aIds.size() == 0) {
758 aIds << SketchPlugin_ConstraintLength::ID().c_str();
759 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
760 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
761 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
762 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
763 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
764 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
765 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
766 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
767 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
768 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
769 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
770 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
771 aIds << SketchPlugin_MultiRotation::ID().c_str();
772 aIds << SketchPlugin_MultiTranslation::ID().c_str();
773 aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
774 aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
779 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
783 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
784 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
785 theModes.append(SketcherPrs_Tools::Sel_Constraint);
786 theModes.append(TopAbs_VERTEX);
787 theModes.append(TopAbs_EDGE);
790 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
792 Handle(AIS_InteractiveObject) aPrs;
794 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
795 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
796 aPrs = new PartSet_ResultSketchPrs(theResult);
801 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
803 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
806 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
808 return theOperation &&
809 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
812 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
814 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
816 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
819 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
821 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
823 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
826 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
828 return (theId == SketchPlugin_Line::ID()) ||
829 (theId == SketchPlugin_Point::ID()) ||
830 (theId == SketchPlugin_Arc::ID()) ||
831 (theId == SketchPlugin_Circle::ID());
834 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
836 std::string anId = theOperation ? theOperation->id().toStdString() : "";
838 return isDistanceKind(anId);
841 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
843 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
844 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
845 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
846 (theKind == SketchPlugin_ConstraintAngle::ID());
849 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
851 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
852 (getCurrentOperation());
856 myModule->onViewTransformed();
858 // Display all sketcher sub-Objects
859 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
860 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
861 aConnector->workshop()->displayer()->activateTrihedron(true);
863 // Hide sketcher result
864 std::list<ResultPtr> aResults = myCurrentSketch->results();
865 std::list<ResultPtr>::const_iterator aIt;
866 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
867 (*aIt)->setDisplayed(false);
869 myCurrentSketch->setDisplayed(false);
871 // Display sketcher objects
872 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
873 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
874 std::list<ResultPtr> aResults = aFeature->results();
875 std::list<ResultPtr>::const_iterator aIt;
876 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
877 (*aIt)->setDisplayed(true);
879 aFeature->setDisplayed(true);
882 if(myCirclePointFilter.IsNull()) {
883 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
886 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
888 if (myPlaneFilter.IsNull())
889 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
891 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
892 bool aHasPlane = false;
893 std::shared_ptr<GeomAPI_Pln> aPln;
894 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
895 myPlaneFilter->setPlane(aPln);
897 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
898 // all displayed objects should be activated in current selection modes according to switched
901 aConnector->activateModuleSelectionModes();
904 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
906 myIsMouseOverWindow = false;
907 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
908 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
909 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
911 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
913 DataPtr aData = myCurrentSketch->data();
914 if (!aData->isValid()) {
915 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
916 // The sketch was aborted
917 myCurrentSketch = CompositeFeaturePtr();
918 // TODO: move this outside of if-else
919 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
920 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
922 // Erase all sketcher objects
923 QStringList aSketchIds = sketchOperationIdList();
924 QObjectPtrList aObjects = aDisplayer->displayedObjects();
925 foreach (ObjectPtr aObj, aObjects) {
926 DataPtr aObjData = aObj->data();
927 if (!aObjData->isValid())
928 aObj->setDisplayed(false);
932 // Hide all sketcher sub-Objects
933 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
934 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
935 std::list<ResultPtr> aResults = aFeature->results();
936 std::list<ResultPtr>::const_iterator aIt;
937 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
938 (*aIt)->setDisplayed(false);
940 aFeature->setDisplayed(false);
942 // Display sketcher result
943 std::list<ResultPtr> aResults = myCurrentSketch->results();
944 std::list<ResultPtr>::const_iterator aIt;
945 Events_Loop* aLoop = Events_Loop::loop();
946 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
948 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
950 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
951 if (!aFOperation->isDisplayedOnStart(*aIt)) {
952 (*aIt)->setDisplayed(true);
953 // this display event is needed because sketch already may have "displayed" state,
954 // but not displayed while it is still active (issue 613, abort of existing sketch)
955 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
958 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
959 myCurrentSketch->setDisplayed(true);
961 myCurrentSketch = CompositeFeaturePtr();
963 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
964 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
966 Events_Loop::loop()->flush(aDispEvent);
968 // restore the module selection modes, which were changed on startSketch
969 aConnector->activateModuleSelectionModes();
970 aConnector->workshop()->displayer()->activateTrihedron(false);
973 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
975 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
976 QCursor* aCurrentCursor = QApplication::overrideCursor();
977 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
978 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
980 qDebug("startNestedSketch() : Qt::CrossCursor");
986 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
988 myIsMouseOverViewProcessed = true;
989 operationMgr()->onValidateOperation();
990 if (canChangeCursor(theOperation)) {
991 QApplication::restoreOverrideCursor();
993 qDebug("stopNestedSketch() : None");
998 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1000 if (isNestedCreateOperation(theOperation)) {
1001 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1004 FeaturePtr aFeature = aFOperation->feature();
1005 // it is necessary to check the the feature data validity because
1006 // some kind of features are removed by an operation commit(the macro state of a feature)
1007 if (aFeature.get() && aFeature->data()->isValid()) {
1008 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1014 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1017 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1019 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1022 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1024 bool isOperationStopped = false;
1025 ModuleBase_Operation* anOperation = getCurrentOperation();
1026 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1027 // Set final definitions if they are necessary
1028 //propertyPanelDefined(aOperation);
1029 /// Commit sketcher operations automatically
1030 /// distance operation are able to show popup editor to modify the distance value
1031 /// after entering the value, the operation should be committed/aborted(by Esc key)
1032 bool aCanCommitOperation = true;
1033 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1035 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation))
1036 aCanCommitOperation = setDistanceValueByPreselection(anOperation, myModule->workshop());
1038 if (aCanCommitOperation)
1039 isOperationStopped = anOperation->commit();
1041 anOperation->abort();
1042 isOperationStopped = true;
1045 return isOperationStopped;
1048 bool PartSet_SketcherMgr::canUndo() const
1050 return isNestedCreateOperation(getCurrentOperation());
1053 bool PartSet_SketcherMgr::canRedo() const
1055 return isNestedCreateOperation(getCurrentOperation());
1058 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1060 bool aCanErase = true;
1061 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1062 if (myCurrentSketch.get()) {
1063 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1064 if (aResult.get()) {
1065 // Display sketcher objects
1066 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1068 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1069 std::list<ResultPtr> aResults = aFeature->results();
1070 std::list<ResultPtr>::const_iterator anIt;
1071 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1072 aCanErase = *anIt != aResult;
1080 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1082 bool aCanDisplay = true;
1084 bool aHasActiveSketch = activeSketch().get() != NULL;
1085 if (aHasActiveSketch) {
1086 // 1. the sketch feature should not be displayed during the sketch active operation
1087 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1088 // nested features can be visualized
1089 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1090 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1091 aCanDisplay = false;
1094 else { // there are no an active sketch
1095 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1096 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1097 if (aFeature.get() != NULL) {
1098 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1099 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1100 if (aSketchFeature.get()) {
1101 aCanDisplay = false;
1106 // 3. the method should not filter the objects, which are not related to the current operation.
1107 // The object is filtered just if it is a current operation feature or this feature result
1108 bool isObjectFound = false;
1109 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1110 (getCurrentOperation());
1112 FeaturePtr aFeature = aFOperation->feature();
1113 if (aFeature.get()) {
1114 std::list<ResultPtr> aResults = aFeature->results();
1115 if (theObject == aFeature)
1116 isObjectFound = true;
1118 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1119 for (; anIt != aLast && !isObjectFound; anIt++) {
1120 isObjectFound = *anIt == theObject;
1125 if (isObjectFound) {
1126 // 4. For created nested feature operation do not display the created feature if
1127 // the mouse curstor leaves the OCC window.
1128 // The correction cases, which ignores this condition:
1129 // a. the property panel values modification
1130 // b. the popup menu activated
1131 // c. widget editor control
1132 #ifndef DEBUG_DO_NOT_BY_ENTER
1133 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1134 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1135 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1136 // the active widget editor should not influence here. The presentation should be visible always
1137 // when this widget is active.
1138 if (!anEditorWdg && !myIsPopupMenuActive) {
1139 // during a nested create operation, the feature is redisplayed only if the mouse over view
1140 // of there was a value modified in the property panel after the mouse left the view
1141 aCanDisplay = canDisplayCurrentCreatedFeature();
1147 // checks the sketcher constraints visibility according to active sketch check box states
1149 bool aProcessed = false;
1150 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1151 if (aFeature.get()) {
1152 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1154 aCanDisplay = aConstraintDisplayed;
1161 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1162 const PartSet_Tools::ConstraintVisibleState& theState,
1163 bool& isProcessed) const
1165 bool aSwitchedOn = true;
1167 const QStringList& aConstrIds = constraintsIdList();
1169 std::string aKind = theFeature->getKind();
1170 if (aConstrIds.contains(QString(aKind.c_str()))) {
1171 bool isTypedConstraint = false;
1174 case PartSet_Tools::Dimensional: {
1175 bool isDistance = isDistanceKind(aKind);
1178 aSwitchedOn = myIsConstraintsShown[theState];
1182 case PartSet_Tools::Geometrical: {
1183 bool isGeometrical = !isDistanceKind(aKind);
1184 if (isGeometrical) {
1186 aSwitchedOn = myIsConstraintsShown[theState];
1190 case PartSet_Tools::Any: {
1192 bool isDistance = isDistanceKind(aKind);
1194 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1196 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1206 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1208 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1209 (getCurrentOperation());
1210 if (aFOperation && myCurrentSketch.get()) {
1211 // find results of the current operation
1212 // these results should not be proposed to be deleted
1213 FeaturePtr anOperationFeature = aFOperation->feature();
1214 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1215 std::set<ResultPtr> anOperationResults;
1216 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1217 aRLast = anOperationResultList.end();
1218 for (; aRIt != aRLast; aRIt++)
1219 anOperationResults.insert(*aRIt);
1221 std::set<FeaturePtr> anObjectsToBeDeleted;
1222 QStringList anObjectsToBeDeletedNames;
1223 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1224 for (; anIt != aLast; anIt++) {
1225 ObjectPtr anObject = *anIt;
1226 bool aCanErase = true;
1227 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1228 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1229 // the result is found between current feature results
1230 if (anOperationResults.find(aResult) != anOperationResults.end())
1233 if (aResult.get()) {
1234 // Display sketcher objects
1235 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1236 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1237 std::list<ResultPtr> aResults = aFeature->results();
1238 std::list<ResultPtr>::const_iterator anIt;
1239 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1240 aCanErase = *anIt != aResult;
1245 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1246 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1247 anObjectsToBeDeleted.insert(aFeature);
1248 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1252 if (!anObjectsToBeDeleted.empty()) {
1253 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1254 QString aMessage = tr("The following features have incorrect presentation and \
1255 will be hidden: %1. Would you like to delete them?")
1256 .arg(aFeatureNames);
1257 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1258 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1259 QMessageBox::Cancel);
1260 if (anAnswer == QMessageBox::Ok) {
1261 QObjectPtrList anObjects;
1262 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1263 aLast = anObjectsToBeDeleted.end();
1264 for (; anIt != aLast; anIt++)
1265 anObjects.append(*anIt);
1266 SessionPtr aMgr = ModelAPI_Session::get();
1267 DocumentPtr aDoc = aMgr->activeDocument();
1268 bool aIsOp = aMgr->isOperation();
1270 aMgr->startOperation();
1271 workshop()->deleteFeatures(anObjects);
1272 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1273 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1274 //Events_Loop::loop()->flush(aDeletedEvent);
1275 //Events_Loop::loop()->flush(aRedispEvent);
1278 aMgr->finishOperation();
1284 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1286 bool aCanDisplay = myIsMouseOverWindow;
1288 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1290 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1295 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1297 return isNestedCreateOperation(theOperation) ||
1298 myModule->sketchReentranceMgr()->isInternalEditActive();
1301 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1303 return myIsConstraintsShown;
1306 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1308 bool isFoundObject = false;
1310 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1311 if (anObjectFeature.get()) {
1312 int aSize = myCurrentSketch->numberOfSubs();
1313 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1314 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1315 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1318 return isFoundObject;
1321 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1323 if (myPlaneFilter.IsNull())
1324 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1326 myPlaneFilter->setPlane(thePln);
1329 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1330 ModuleBase_IWorkshop* theWorkshop)
1332 bool isValueAccepted = false;
1334 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1336 FeaturePtr aFeature = aFOperation->feature();
1337 // editor is shown only if all attribute references are filled by preseletion
1338 bool anAllRefAttrInitialized = true;
1340 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1341 ModelAPI_AttributeRefAttr::typeId());
1342 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1343 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1344 anAllRefAttrInitialized = (*anIt)->isInitialized();
1346 if (anAllRefAttrInitialized) {
1347 // Activate dimension value editing on double click
1348 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1349 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1350 // Find corresponded widget to activate value editing
1351 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1352 if (aWgt->attributeID() == "ConstraintValue") {
1353 // the featue should be displayed in order to find the AIS text position,
1354 // the place where the editor will be shown
1355 aFeature->setDisplayed(true);
1356 /// the execute is necessary to perform in the feature compute for flyout position
1357 aFeature->execute();
1359 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1360 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1362 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1364 int aX = 0, anY = 0;
1366 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1367 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1368 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1369 Handle(AIS_InteractiveObject) anAISIO;
1370 if (anAIS.get() != NULL) {
1371 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1373 if (anAIS.get() != NULL) {
1374 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1376 if (!anAISIO.IsNull()) {
1377 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1378 if (!aDim.IsNull()) {
1379 gp_Pnt aPosition = aDim->GetTextPosition();
1381 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1382 Handle(V3d_View) aView = aViewer->activeView();
1384 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1386 QWidget* aViewPort = aViewer->activeViewPort();
1387 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1392 anEditor->setCursorPosition(aX, anY);
1393 isValueAccepted = anEditor->showPopupEditor(false);
1399 return isValueAccepted;
1402 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1403 const FeaturePtr& theSketch,
1404 ModuleBase_IWorkshop* theWorkshop,
1405 FeatureToSelectionMap& theSelection)
1407 if (theFeature.get() == NULL)
1410 std::set<AttributePtr> aSelectedAttributes;
1411 std::set<ResultPtr> aSelectedResults;
1413 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1414 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1415 if (!aContext.IsNull()) {
1416 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1417 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1419 std::list<ResultPtr> aResults = theFeature->results();
1420 std::list<ResultPtr>::const_iterator aIt;
1421 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1423 ResultPtr aResult = *aIt;
1424 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1425 if (aAISObj.get() == NULL)
1427 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1428 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1430 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1431 if (anOwner->Selectable() != anAISIO)
1433 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1434 aSelectedAttributes, aSelectedResults);
1436 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1437 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1438 if (anOwner.IsNull())
1440 if (anOwner->Selectable() != anAISIO)
1442 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1443 aSelectedAttributes, aSelectedResults);
1447 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1450 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1451 const FeaturePtr& theSketch,
1452 ModuleBase_IWorkshop* theWorkshop,
1453 const FeatureToSelectionMap& theSelection,
1454 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1456 if (theFeature.get() == NULL)
1459 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1460 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1461 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1463 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1465 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1466 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1468 // 1. found the feature's owners. Check the AIS objects of the constructions
1469 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1470 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1471 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1473 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1474 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1475 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1476 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1477 if (!anOwner.IsNull())
1478 theOwnersToSelect.Add(anOwner);
1482 // 2. found the feature results's owners
1483 std::list<ResultPtr> aResults = theFeature->results();
1484 std::list<ResultPtr>::const_iterator aIt;
1485 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1487 ResultPtr aResult = *aIt;
1488 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1489 if (aAISObj.get() == NULL)
1491 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1493 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1494 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1495 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1496 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1497 if ( anOwner.IsNull() || !anOwner->HasShape() )
1499 const TopoDS_Shape& aShape = anOwner->Shape();
1500 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1501 if (aShapeType == TopAbs_VERTEX) {
1502 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1503 if (aPntAttr.get() != NULL &&
1504 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1505 theOwnersToSelect.Add(anOwner);
1508 else if (aShapeType == TopAbs_EDGE) {
1509 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1510 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1511 theOwnersToSelect.FindIndex(anOwner) <= 0)
1512 theOwnersToSelect.Add(anOwner);
1518 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1521 connect(theWidget, SIGNAL(beforeValuesChanged()),
1522 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1523 connect(theWidget, SIGNAL(afterValuesChanged()),
1524 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1527 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1528 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1529 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1530 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1534 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1536 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1537 (getCurrentOperation());
1539 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1540 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1541 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1542 FeaturePtr aFeature = aFOperation->feature();
1543 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1548 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1550 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1551 (getCurrentOperation());
1552 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1553 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)))
1554 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1557 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1559 return myModule->workshop()->currentOperation();
1562 //**************************************************************
1563 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1565 ModuleBase_ModelWidget* aWidget = 0;
1566 ModuleBase_Operation* anOperation = getCurrentOperation();
1568 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1570 aWidget = aPanel->activeWidget();
1575 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1576 const bool isEditOperation,
1577 const bool isToDisplay,
1578 const bool isFlushRedisplay)
1580 #ifdef DEBUG_DO_NOT_BY_ENTER
1584 if (isEditOperation || !theFeature.get())
1587 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1588 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1590 // 1. change visibility of the object itself, here the presentable object is processed,
1591 // e.g. constraints features
1592 //FeaturePtr aFeature = aFOperation->feature();
1593 std::list<ResultPtr> aResults = theFeature->results();
1595 theFeature->setDisplayed(true);
1597 theFeature->setDisplayed(false);
1599 // change visibility of the object results, e.g. non-constraint features
1600 std::list<ResultPtr>::const_iterator aIt;
1601 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1603 (*aIt)->setDisplayed(true);
1606 (*aIt)->setDisplayed(false);
1609 if (isFlushRedisplay)
1610 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1613 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1615 if (!myCurrentSketch.get())
1618 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1619 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1620 QList<ModuleBase_ViewerPrsPtr> aHighlighted = aSelect->getHighlighted();
1622 QList<FeaturePtr> aFeatureList;
1623 if (theHighlightedOnly) {
1624 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1627 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1629 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1630 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1633 // 1. it is necessary to save current selection in order to restore it after the features moving
1634 myCurrentSelection.clear();
1635 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1636 for (; anIt != aLast; anIt++) {
1637 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1639 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1642 void PartSet_SketcherMgr::restoreSelection()
1644 if (!myCurrentSketch.get())
1647 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1648 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1649 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1650 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1651 aSLast = myCurrentSelection.end();
1652 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1653 for (; aSIt != aSLast; aSIt++) {
1654 anOwnersToSelect.Clear();
1655 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1657 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1661 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1663 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1665 updateBySketchParameters(aType, theState);
1668 void PartSet_SketcherMgr::updateBySketchParameters(
1669 const PartSet_Tools::ConstraintVisibleState& theType,
1672 if (myCurrentSketch.get() == NULL)
1675 bool aPrevState = myIsConstraintsShown[theType];
1676 myIsConstraintsShown[theType] = theState;
1679 case PartSet_Tools::Geometrical:
1680 case PartSet_Tools::Dimensional: {
1681 if (aPrevState != theState) {
1682 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1683 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1684 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1685 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1686 bool aProcessed = false;
1687 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1689 aSubFeature->setDisplayed(aConstraintDisplayed);
1691 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1695 case PartSet_Tools::Expressions: {
1696 if (aPrevState != theState) {
1697 /// call all sketch features redisplay, the expression state will be corrected in customize
1698 /// of distance presentation
1699 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1700 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1707 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1709 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1710 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1711 return aConnector->workshop();
1714 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1716 return workshop()->operationMgr();