1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_SketcherReetntrantMgr.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_WidgetPoint2d.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_Tools.h"
13 #include "PartSet_WidgetSketchLabel.h"
14 #include "PartSet_WidgetEditor.h"
16 #include <XGUI_ModuleConnector.h>
17 #include <XGUI_Displayer.h>
18 #include <XGUI_Workshop.h>
19 #include <XGUI_ContextMenuMgr.h>
20 #include <XGUI_Selection.h>
21 #include <XGUI_SelectionMgr.h>
22 #include <XGUI_ModuleConnector.h>
23 #include <XGUI_PropertyPanel.h>
24 #include <XGUI_ViewerProxy.h>
25 #include <XGUI_OperationMgr.h>
27 #include <ModuleBase_IPropertyPanel.h>
28 #include <ModuleBase_ISelection.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IWorkshop.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_ModelWidget.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationFeature.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_WidgetEditor.h>
38 #include <GeomDataAPI_Point2D.h>
40 #include <Events_Loop.h>
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Sketch.h>
44 #include <SketchPlugin_Point.h>
45 #include <SketchPlugin_Arc.h>
46 #include <SketchPlugin_Circle.h>
47 #include <SketchPlugin_ConstraintLength.h>
48 #include <SketchPlugin_ConstraintDistance.h>
49 #include <SketchPlugin_ConstraintParallel.h>
50 #include <SketchPlugin_ConstraintPerpendicular.h>
51 #include <SketchPlugin_ConstraintRadius.h>
52 #include <SketchPlugin_ConstraintRigid.h>
53 #include <SketchPlugin_ConstraintHorizontal.h>
54 #include <SketchPlugin_ConstraintVertical.h>
55 #include <SketchPlugin_ConstraintEqual.h>
56 #include <SketchPlugin_ConstraintTangent.h>
57 #include <SketchPlugin_ConstraintCoincidence.h>
58 #include <SketchPlugin_ConstraintFillet.h>
59 #include <SketchPlugin_ConstraintMirror.h>
60 #include <SketchPlugin_ConstraintAngle.h>
61 #include <SketchPlugin_ConstraintCollinear.h>
62 #include <SketchPlugin_ConstraintMiddle.h>
63 #include <SketchPlugin_MultiRotation.h>
64 #include <SketchPlugin_MultiTranslation.h>
66 #include <SketcherPrs_Tools.h>
68 #include <SelectMgr_IndexedMapOfOwner.hxx>
69 #include <StdSelect_BRepOwner.hxx>
71 //#include <AIS_DimensionSelectionMode.hxx>
72 #include <AIS_Shape.hxx>
73 #include <AIS_Dimension.hxx>
75 #include <ModelAPI_Events.h>
76 #include <ModelAPI_Session.h>
77 #include <ModelAPI_AttributeString.h>
79 #include <QMouseEvent>
80 #include <QApplication>
82 #include <QMessageBox>
84 //#define DEBUG_DO_NOT_BY_ENTER
86 //#define DEBUG_CURSOR
88 //#define DEBUG_INTERSECTION_POINT
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())
316 // it is necessary to restore current selection in order to restore it after the values are modified
318 myCurrentSelection.clear();
320 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
321 // viewer happens by deselect/select the modified objects. The flag should be restored after
322 // the selection processing. The update viewer should be also called.
323 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
324 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
325 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
326 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
327 aDisplayer->updateViewer();
330 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
332 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
335 //get2dPoint(theWnd, theEvent, myClickedPoint);
337 if (!(theEvent->buttons() & Qt::LeftButton))
340 // Clear dragging mode
341 myIsDragging = false;
343 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
344 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
345 if (!aViewer->canDragByMouse())
348 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
349 (getCurrentOperation());
353 if (aFOperation->isEditOperation()) {
354 // If the current widget is a selector, do nothing, it processes the mouse press
355 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
356 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
361 // Use only for sketch operations
362 if (myCurrentSketch) {
363 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
366 bool isSketcher = isSketchOperation(aFOperation);
367 bool isSketchOpe = isNestedSketchOperation(aFOperation);
369 // Avoid non-sketch operations
370 if ((!isSketchOpe) && (!isSketcher))
373 bool isEditing = aFOperation->isEditOperation();
375 // Ignore creation sketch operation
376 if ((!isSketcher) && (!isEditing))
379 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
380 if (!aContext.IsNull()) {
381 // MoveTo in order to highlight current object
382 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
384 // Remember highlighted objects for editing
385 ModuleBase_ISelection* aSelect = aWorkshop->selection();
387 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
388 storeSelection(!aHasShift);
390 if (myCurrentSelection.empty()) {
391 if (isSketchOpe && (!isSketcher))
392 // commit previous operation
393 if (!aFOperation->commit())
394 aFOperation->abort();
397 // Init flyout point for radius rotation
398 FeaturePtr aFeature = myCurrentSelection.begin().key();
402 get2dPoint(theWnd, theEvent, myCurrentPoint);
405 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
407 if (aFeature.get() != NULL) {
408 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
409 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
410 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
411 DataPtr aData = aSPFeature->data();
412 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
413 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
414 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
415 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
418 } else if (isSketchOpe && isEditing) {
419 // If selected another object commit current result
420 aFOperation->commit();
423 get2dPoint(theWnd, theEvent, myCurrentPoint);
426 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
428 // this is temporary commented in order to avoid the following wrong case:
429 // Distance constraint is under edition, double click on the digit -> nothing happens
430 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
431 // but as the prev edit is commited an new one is not started, editor is not shown.
432 // This is necessary in order to finalize previous operation
433 //QApplication::processEvents();
439 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
441 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
444 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
445 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
446 if (!aViewer->canDragByMouse())
448 ModuleBase_Operation* aOp = getCurrentOperation();
450 if (isNestedSketchOperation(aOp)) {
451 //get2dPoint(theWnd, theEvent, myClickedPoint);
453 // Only for sketcher operations
457 myCurrentSelection.clear();
458 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
459 if (!aContext.IsNull()) {
460 // Reselect edited object
461 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
462 if (theEvent->modifiers() & Qt::ShiftModifier)
463 aContext->ShiftSelect();
472 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
473 myIsDragging = false;
476 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
478 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
481 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
482 myIsMouseOverViewProcessed = true;
483 // 1. perform the widget mouse move functionality and display the presentation
484 // the mouse move should be processed in the widget, if it can in order to visualize correct
485 // presentation. These widgets correct the feature attribute according to the mouse position
486 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
487 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
489 aPoint2DWdg->onMouseMove(theWnd, theEvent);
491 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
494 aDistanceWdg->onMouseMove(theWnd, theEvent);
496 // the feature is to be erased here, but it is correct to call canDisplayObject because
497 // there can be additional check (e.g. editor widget in distance constraint)
498 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
499 (getCurrentOperation());
501 FeaturePtr aFeature = aFOperation->feature();
502 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
506 //myClickedPoint.clear();
509 // 1. the current selection is saved in the mouse press method in order to restore it after moving
510 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
511 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
512 // deselected). This flag should be restored in the slot, processed the mouse release signal.
514 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
515 if (!aCurrentOperation)
517 if (isSketchOperation(aCurrentOperation))
518 return; // No edit operation activated
520 Handle(V3d_View) aView = theWnd->v3dView();
521 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
523 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
524 double dX = aX - myCurrentPoint.myCurX;
525 double dY = aY - myCurrentPoint.myCurY;
527 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
528 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
529 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
530 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
531 // viewer happens by deselect/select the modified objects. The flag should be restored after
532 // the selection processing. The update viewer should be also called.
533 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
535 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
536 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
537 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
538 aLast = myCurrentSelection.end();
539 // 4. the features and attributes modification(move)
540 bool isModified = false;
541 for (; anIt != aLast; anIt++) {
542 FeaturePtr aFeature = anIt.key();
544 std::set<AttributePtr> anAttributes = anIt.value().first;
545 // Process selection by attribute: the priority to the attribute
546 if (!anAttributes.empty()) {
547 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
548 anAttLast = anAttributes.end();
549 for (; anAttIt != anAttLast; anAttIt++) {
550 AttributePtr anAttr = *anAttIt;
551 if (anAttr.get() == NULL)
553 std::string aAttrId = anAttr->id();
554 DataPtr aData = aFeature->data();
555 if (aData->isValid()) {
556 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
557 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
558 if (aPoint.get() != NULL) {
559 bool isImmutable = aPoint->setImmutable(true);
560 aPoint->move(dX, dY);
562 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
563 aPoint->setImmutable(isImmutable);
568 // Process selection by feature
569 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
570 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
571 if (aSketchFeature) {
572 aSketchFeature->move(dX, dY);
574 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
578 // the modified state of the current operation should be updated if there are features, which
581 aCurrentOperation->onValuesChanged();
583 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
584 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
586 // 5. it is necessary to save current selection in order to restore it after the features moving
588 // 6. restore the update viewer flag and call this update
589 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
590 aDisplayer->updateViewer();
593 myCurrentPoint.setValue(aX, aY);
597 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
599 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
600 (getCurrentOperation());
601 if (aFOperation && aFOperation->isEditOperation()) {
602 std::string aId = aFOperation->id().toStdString();
603 if (isDistanceOperation(aFOperation))
605 // Activate dimension value editing on double click
606 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
607 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
608 // Find corresponded widget to activate value editing
609 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
610 if (aWgt->attributeID() == "ConstraintValue") {
611 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
613 anEditor->showPopupEditor();
621 void PartSet_SketcherMgr::onApplicationStarted()
623 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
624 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
625 XGUI_Workshop* aWorkshop = aConnector->workshop();
626 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
628 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
629 if (aPropertyPanel) {
630 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
631 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
633 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
634 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
635 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
636 aReentranceMgr, SLOT(onWidgetActivated()));
639 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
640 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
641 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
643 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
644 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
645 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
648 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
650 //if (!myClickedPoint.myIsInitialized)
653 //ModuleBase_Operation* aOperation = getCurrentOperation();
654 // the distance constraint feature should not use the clickedd point
655 // this is workaround in order to don't throw down the flyout point value,
656 // set by execute() method of these type of features
657 //if (isDistanceOperation(aOperation))
660 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
662 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
666 void PartSet_SketcherMgr::onBeforeContextMenu()
668 myIsPopupMenuActive = true;
671 void PartSet_SketcherMgr::onAfterContextMenu()
673 myIsPopupMenuActive = false;
676 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
679 Handle(V3d_View) aView = theWnd->v3dView();
680 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
682 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
683 thePoint.setValue(aX, anY);
686 void PartSet_SketcherMgr::launchEditing()
688 if (!myCurrentSelection.empty()) {
689 FeaturePtr aFeature = myCurrentSelection.begin().key();
690 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
691 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
693 myModule->editFeature(aSPFeature);
698 bool PartSet_SketcherMgr::sketchSolverError()
700 bool anError = false;
701 CompositeFeaturePtr aSketch = activeSketch();
703 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
704 anError = !aAttributeString->value().empty();
709 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
711 QString anError = "";
712 if (!theFeature.get() || !theFeature->data()->isValid())
715 CompositeFeaturePtr aSketch = activeSketch();
716 if (aSketch.get() && aSketch == theFeature) {
717 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
718 anError = aAttributeString->value().c_str();
723 void PartSet_SketcherMgr::clearClickedFlags()
725 //myClickedPoint.clear();
726 myCurrentPoint.clear();
729 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
731 static QStringList aIds;
732 if (aIds.size() == 0) {
733 aIds << SketchPlugin_Line::ID().c_str();
734 aIds << SketchPlugin_Point::ID().c_str();
735 aIds << SketchPlugin_Arc::ID().c_str();
736 aIds << SketchPlugin_Circle::ID().c_str();
737 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
738 aIds << SketchPlugin_Circle::ID().c_str();
740 // SketchRectangle is a python feature, so its ID is passed just as a string
741 aIds << "SketchRectangle";
742 aIds.append(constraintsIdList());
747 const QStringList& PartSet_SketcherMgr::constraintsIdList()
749 static QStringList aIds;
750 if (aIds.size() == 0) {
751 aIds << SketchPlugin_ConstraintLength::ID().c_str();
752 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
753 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
754 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
755 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
756 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
757 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
758 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
759 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
760 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
761 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
762 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
763 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
764 aIds << SketchPlugin_MultiRotation::ID().c_str();
765 aIds << SketchPlugin_MultiTranslation::ID().c_str();
766 aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
767 aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
772 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
776 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
777 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
778 theModes.append(SketcherPrs_Tools::Sel_Constraint);
779 theModes.append(TopAbs_VERTEX);
780 theModes.append(TopAbs_EDGE);
783 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
785 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
788 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
790 return theOperation &&
791 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
794 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
796 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
798 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
801 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
803 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
805 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
808 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
810 return (theId == SketchPlugin_Line::ID()) ||
811 (theId == SketchPlugin_Point::ID()) ||
812 (theId == SketchPlugin_Arc::ID()) ||
813 (theId == SketchPlugin_Circle::ID());
816 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
818 std::string anId = theOperation ? theOperation->id().toStdString() : "";
820 return isDistanceKind(anId);
823 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
825 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
826 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
827 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
828 (theKind == SketchPlugin_ConstraintAngle::ID());
831 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
833 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
834 (getCurrentOperation());
838 myModule->onViewTransformed();
840 // Display all sketcher sub-Objects
841 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
842 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
843 aConnector->workshop()->displayer()->activateTrihedron(true);
845 // Hide sketcher result
846 std::list<ResultPtr> aResults = myCurrentSketch->results();
847 std::list<ResultPtr>::const_iterator aIt;
848 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
849 (*aIt)->setDisplayed(false);
851 myCurrentSketch->setDisplayed(false);
853 // Display sketcher objects
854 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
855 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
856 std::list<ResultPtr> aResults = aFeature->results();
857 std::list<ResultPtr>::const_iterator aIt;
858 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
859 (*aIt)->setDisplayed(true);
861 aFeature->setDisplayed(true);
864 if (myPlaneFilter.IsNull())
865 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
867 #ifndef DEBUG_INTERSECTION_POINT
868 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
870 bool aHasPlane = false;
871 std::shared_ptr<GeomAPI_Pln> aPln;
872 if (aFOperation->isEditOperation()) {
873 // If it is editing of sketch then it means that plane is already defined
874 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
878 myPlaneFilter->setPlane(aPln);
880 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
881 // all sketch objects should be activated in the sketch selection modes by edit operation start
882 // in case of creation operation, there is an active widget, which activates own selection mode
883 if (aFOperation->isEditOperation() && aHasPlane)
884 aConnector->activateModuleSelectionModes();
887 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
889 myIsMouseOverWindow = false;
890 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
891 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
893 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
895 DataPtr aData = myCurrentSketch->data();
896 if (!aData->isValid()) {
897 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
898 // The sketch was aborted
899 myCurrentSketch = CompositeFeaturePtr();
900 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
902 // Erase all sketcher objects
903 QStringList aSketchIds = sketchOperationIdList();
904 QObjectPtrList aObjects = aDisplayer->displayedObjects();
905 foreach (ObjectPtr aObj, aObjects) {
906 DataPtr aObjData = aObj->data();
907 if (!aObjData->isValid())
908 aObj->setDisplayed(false);
912 // Hide all sketcher sub-Objects
913 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
914 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
915 std::list<ResultPtr> aResults = aFeature->results();
916 std::list<ResultPtr>::const_iterator aIt;
917 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
918 (*aIt)->setDisplayed(false);
920 aFeature->setDisplayed(false);
922 // Display sketcher result
923 std::list<ResultPtr> aResults = myCurrentSketch->results();
924 std::list<ResultPtr>::const_iterator aIt;
925 Events_Loop* aLoop = Events_Loop::loop();
926 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
928 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
930 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
931 if (!aFOperation->isDisplayedOnStart(*aIt)) {
932 (*aIt)->setDisplayed(true);
933 // this display event is needed because sketch already may have "displayed" state,
934 // but not displayed while it is still active (issue 613, abort of existing sketch)
935 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
938 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
939 myCurrentSketch->setDisplayed(true);
941 myCurrentSketch = CompositeFeaturePtr();
942 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
944 Events_Loop::loop()->flush(aDispEvent);
946 // restore the module selection modes, which were changed on startSketch
947 aConnector->activateModuleSelectionModes();
948 aConnector->workshop()->displayer()->activateTrihedron(false);
951 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
953 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
954 QCursor* aCurrentCursor = QApplication::overrideCursor();
955 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
956 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
958 qDebug("startNestedSketch() : Qt::CrossCursor");
964 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
966 myIsMouseOverViewProcessed = true;
967 operationMgr()->onValidateOperation();
968 if (canChangeCursor(theOperation)) {
969 QApplication::restoreOverrideCursor();
971 qDebug("stopNestedSketch() : None");
976 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
978 if (isNestedCreateOperation(theOperation)) {
979 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
982 FeaturePtr aFeature = aFOperation->feature();
983 // it is necessary to check the the feature data validity because
984 // some kind of features are removed by an operation commit(the macro state of a feature)
985 if (aFeature.get() && aFeature->data()->isValid()) {
986 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
992 void PartSet_SketcherMgr::operationActivatedByPreselection()
994 ModuleBase_Operation* anOperation = getCurrentOperation();
995 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
996 // Set final definitions if they are necessary
997 //propertyPanelDefined(aOperation);
998 /// Commit sketcher operations automatically
999 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1002 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1003 FeaturePtr aFeature = aFOperation->feature();
1004 // editor is shown only if all attribute references are filled by preseletion
1005 bool anAllRefAttrInitialized = true;
1007 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1008 ModelAPI_AttributeRefAttr::typeId());
1009 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1010 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1011 anAllRefAttrInitialized = (*anIt)->isInitialized();
1013 if (anAllRefAttrInitialized) {
1014 // Activate dimension value editing on double click
1015 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1016 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1017 // Find corresponded widget to activate value editing
1018 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1019 if (aWgt->attributeID() == "ConstraintValue") {
1020 // the featue should be displayed in order to find the AIS text position,
1021 // the place where the editor will be shown
1022 aFeature->setDisplayed(true);
1023 /// the execute is necessary to perform in the feature compute for flyout position
1024 aFeature->execute();
1026 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1027 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1029 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1031 int aX = 0, anY = 0;
1033 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1034 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1035 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1036 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1037 Handle(AIS_InteractiveObject) anAISIO;
1038 if (anAIS.get() != NULL) {
1039 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1041 if (anAIS.get() != NULL) {
1042 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1044 if (!anAISIO.IsNull()) {
1045 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1046 if (!aDim.IsNull()) {
1047 gp_Pnt aPosition = aDim->GetTextPosition();
1049 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1050 Handle(V3d_View) aView = aViewer->activeView();
1052 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1054 QWidget* aViewPort = aViewer->activeViewPort();
1055 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1060 anEditor->setCursorPosition(aX, anY);
1061 anEditor->showPopupEditor(false);
1069 anOperation->commit();
1073 bool PartSet_SketcherMgr::canUndo() const
1075 return isNestedCreateOperation(getCurrentOperation());
1078 bool PartSet_SketcherMgr::canRedo() const
1080 return isNestedCreateOperation(getCurrentOperation());
1083 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1085 bool aCanErase = true;
1086 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1087 if (myCurrentSketch.get()) {
1088 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1089 if (aResult.get()) {
1090 // Display sketcher objects
1091 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1093 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1094 std::list<ResultPtr> aResults = aFeature->results();
1095 std::list<ResultPtr>::const_iterator anIt;
1096 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1097 aCanErase = *anIt != aResult;
1105 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1107 bool aCanDisplay = true;
1109 bool aHasActiveSketch = activeSketch().get() != NULL;
1110 if (aHasActiveSketch) {
1111 // 1. the sketch feature should not be displayed during the sketch active operation
1112 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1113 // nested features can be visualized
1114 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1115 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1116 aCanDisplay = false;
1119 else { // there are no an active sketch
1120 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1121 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1122 if (aFeature.get() != NULL) {
1123 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1124 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1125 if (aSketchFeature.get()) {
1126 aCanDisplay = false;
1131 // 3. the method should not filter the objects, which are not related to the current operation.
1132 // The object is filtered just if it is a current operation feature or this feature result
1133 bool isObjectFound = false;
1134 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1135 (getCurrentOperation());
1137 FeaturePtr aFeature = aFOperation->feature();
1138 if (aFeature.get()) {
1139 std::list<ResultPtr> aResults = aFeature->results();
1140 if (theObject == aFeature)
1141 isObjectFound = true;
1143 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1144 for (; anIt != aLast && !isObjectFound; anIt++) {
1145 isObjectFound = *anIt == theObject;
1153 // 4. For created nested feature operation do not display the created feature if
1154 // the mouse curstor leaves the OCC window.
1155 // The correction cases, which ignores this condition:
1156 // a. the property panel values modification
1157 // b. the popup menu activated
1158 // c. widget editor control
1159 #ifndef DEBUG_DO_NOT_BY_ENTER
1160 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1161 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1162 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1163 // the active widget editor should not influence here. The presentation should be visible always
1164 // when this widget is active.
1165 if (!anEditorWdg && !myIsPopupMenuActive) {
1166 // during a nested create operation, the feature is redisplayed only if the mouse over view
1167 // of there was a value modified in the property panel after the mouse left the view
1168 aCanDisplay = canDisplayCurrentCreatedFeature();
1175 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1177 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1178 (getCurrentOperation());
1179 if (aFOperation && myCurrentSketch.get()) {
1180 // find results of the current operation
1181 // these results should not be proposed to be deleted
1182 FeaturePtr anOperationFeature = aFOperation->feature();
1183 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1184 std::set<ResultPtr> anOperationResults;
1185 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1186 aRLast = anOperationResultList.end();
1187 for (; aRIt != aRLast; aRIt++)
1188 anOperationResults.insert(*aRIt);
1190 std::set<FeaturePtr> anObjectsToBeDeleted;
1191 QStringList anObjectsToBeDeletedNames;
1192 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1193 for (; anIt != aLast; anIt++) {
1194 ObjectPtr anObject = *anIt;
1195 bool aCanErase = true;
1196 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1197 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1198 // the result is found between current feature results
1199 if (anOperationResults.find(aResult) != anOperationResults.end())
1202 if (aResult.get()) {
1203 // Display sketcher objects
1204 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1205 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1206 std::list<ResultPtr> aResults = aFeature->results();
1207 std::list<ResultPtr>::const_iterator anIt;
1208 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1209 aCanErase = *anIt != aResult;
1214 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1215 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1216 anObjectsToBeDeleted.insert(aFeature);
1217 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1221 if (!anObjectsToBeDeleted.empty()) {
1222 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1223 QString aMessage = tr("The following features have incorrect presentation and \
1224 will be hidden: %1. Would you like to delete them?")
1225 .arg(aFeatureNames);
1226 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1227 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1228 QMessageBox::Cancel);
1229 if (anAnswer == QMessageBox::Ok) {
1230 QObjectPtrList anObjects;
1231 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1232 aLast = anObjectsToBeDeleted.end();
1233 for (; anIt != aLast; anIt++)
1234 anObjects.append(*anIt);
1235 SessionPtr aMgr = ModelAPI_Session::get();
1236 DocumentPtr aDoc = aMgr->activeDocument();
1237 bool aIsOp = aMgr->isOperation();
1239 aMgr->startOperation();
1240 workshop()->deleteFeatures(anObjects);
1241 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1242 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1243 //Events_Loop::loop()->flush(aDeletedEvent);
1244 //Events_Loop::loop()->flush(aRedispEvent);
1247 aMgr->finishOperation();
1253 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1255 bool aCanDisplay = myIsMouseOverWindow;
1257 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1259 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1264 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1266 return isNestedCreateOperation(theOperation) ||
1267 myModule->sketchReentranceMgr()->isInternalEditActive();
1270 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1272 return myIsConstraintsShown;
1275 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1277 bool isFoundObject = false;
1279 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1280 if (anObjectFeature.get()) {
1281 int aSize = myCurrentSketch->numberOfSubs();
1282 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1283 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1284 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1287 return isFoundObject;
1290 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1292 if (myPlaneFilter.IsNull())
1293 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1295 myPlaneFilter->setPlane(thePln);
1298 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1299 const FeaturePtr& theSketch,
1300 ModuleBase_IWorkshop* theWorkshop,
1301 FeatureToSelectionMap& theSelection)
1303 if (theFeature.get() == NULL)
1306 std::set<AttributePtr> aSelectedAttributes;
1307 std::set<ResultPtr> aSelectedResults;
1309 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1310 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1311 if (!aContext.IsNull()) {
1312 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1313 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1315 std::list<ResultPtr> aResults = theFeature->results();
1316 std::list<ResultPtr>::const_iterator aIt;
1317 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1319 ResultPtr aResult = *aIt;
1320 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1321 if (aAISObj.get() == NULL)
1323 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1324 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1326 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1327 if (anOwner->Selectable() != anAISIO)
1329 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1330 aSelectedAttributes, aSelectedResults);
1332 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1333 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1334 if (anOwner.IsNull())
1336 if (anOwner->Selectable() != anAISIO)
1338 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1339 aSelectedAttributes, aSelectedResults);
1343 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1346 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1347 const FeaturePtr& theSketch,
1348 ModuleBase_IWorkshop* theWorkshop,
1349 const FeatureToSelectionMap& theSelection,
1350 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1352 if (theFeature.get() == NULL)
1355 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1356 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1357 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1359 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1361 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1362 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1364 // 1. found the feature's owners. Check the AIS objects of the constructions
1365 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1366 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1367 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1369 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1370 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1371 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1372 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1373 if (!anOwner.IsNull())
1374 theOwnersToSelect.Add(anOwner);
1378 // 2. found the feature results's owners
1379 std::list<ResultPtr> aResults = theFeature->results();
1380 std::list<ResultPtr>::const_iterator aIt;
1381 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1383 ResultPtr aResult = *aIt;
1384 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1385 if (aAISObj.get() == NULL)
1387 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1389 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1390 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1391 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1392 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1393 if ( anOwner.IsNull() || !anOwner->HasShape() )
1395 const TopoDS_Shape& aShape = anOwner->Shape();
1396 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1397 if (aShapeType == TopAbs_VERTEX) {
1398 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1399 if (aPntAttr.get() != NULL &&
1400 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1401 theOwnersToSelect.Add(anOwner);
1404 else if (aShapeType == TopAbs_EDGE) {
1405 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1406 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1407 theOwnersToSelect.FindIndex(anOwner) <= 0)
1408 theOwnersToSelect.Add(anOwner);
1414 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1417 connect(theWidget, SIGNAL(beforeValuesChanged()),
1418 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1419 connect(theWidget, SIGNAL(afterValuesChanged()),
1420 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1423 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1424 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1425 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1426 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1430 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1432 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1433 (getCurrentOperation());
1435 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1436 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1437 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1438 FeaturePtr aFeature = aFOperation->feature();
1439 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1444 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1446 return myModule->workshop()->currentOperation();
1449 //**************************************************************
1450 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1452 ModuleBase_ModelWidget* aWidget = 0;
1453 ModuleBase_Operation* anOperation = getCurrentOperation();
1455 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1457 aWidget = aPanel->activeWidget();
1462 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1463 const bool isEditOperation,
1464 const bool isToDisplay,
1465 const bool isFlushRedisplay)
1467 #ifdef DEBUG_DO_NOT_BY_ENTER
1471 if (isEditOperation || !theFeature.get())
1474 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1475 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1477 // 1. change visibility of the object itself, here the presentable object is processed,
1478 // e.g. constraints features
1479 //FeaturePtr aFeature = aFOperation->feature();
1480 std::list<ResultPtr> aResults = theFeature->results();
1482 theFeature->setDisplayed(true);
1484 theFeature->setDisplayed(false);
1486 // change visibility of the object results, e.g. non-constraint features
1487 std::list<ResultPtr>::const_iterator aIt;
1488 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1490 (*aIt)->setDisplayed(true);
1493 (*aIt)->setDisplayed(false);
1496 if (isFlushRedisplay)
1497 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1500 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1502 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1503 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1504 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1506 QList<FeaturePtr> aFeatureList;
1507 if (theHighlightedOnly) {
1508 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1511 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1513 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1514 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1517 // 1. it is necessary to save current selection in order to restore it after the features moving
1518 myCurrentSelection.clear();
1519 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1520 for (; anIt != aLast; anIt++) {
1521 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1523 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1526 void PartSet_SketcherMgr::restoreSelection()
1528 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1529 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1530 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1531 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1532 aSLast = myCurrentSelection.end();
1533 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1534 for (; aSIt != aSLast; aSIt++) {
1535 anOwnersToSelect.Clear();
1536 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1538 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1542 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theState, int theType)
1544 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1545 if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1547 if (myCurrentSketch.get() == NULL)
1550 myIsConstraintsShown[aType] = theState;
1552 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1553 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1555 const QStringList& aConstrIds = constraintsIdList();
1556 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1557 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1558 std::string aKind = aSubFeature->getKind();
1559 if (aConstrIds.contains(QString(aKind.c_str()))) {
1560 bool isTypedConstraint = false;
1561 if (aType == PartSet_Tools::Dimensional) {
1562 isTypedConstraint = isDistanceKind(aKind);
1565 isTypedConstraint = !isDistanceKind(aKind);
1567 if (isTypedConstraint) {
1569 aSubFeature->setDisplayed(true);
1571 aSubFeature->setDisplayed(false);
1575 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1578 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1580 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1581 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1582 return aConnector->workshop();
1585 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1587 return workshop()->operationMgr();