1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_SketcherReetntrantMgr.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_WidgetPoint2d.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_Tools.h"
13 #include "PartSet_WidgetSketchLabel.h"
14 #include "PartSet_WidgetEditor.h"
16 #include <XGUI_ModuleConnector.h>
17 #include <XGUI_Displayer.h>
18 #include <XGUI_Workshop.h>
19 #include <XGUI_ContextMenuMgr.h>
20 #include <XGUI_Selection.h>
21 #include <XGUI_SelectionMgr.h>
22 #include <XGUI_ModuleConnector.h>
23 #include <XGUI_PropertyPanel.h>
24 #include <XGUI_ViewerProxy.h>
25 #include <XGUI_OperationMgr.h>
27 #include <ModuleBase_IPropertyPanel.h>
28 #include <ModuleBase_ISelection.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IWorkshop.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_ModelWidget.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationFeature.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_WidgetEditor.h>
38 #include <GeomDataAPI_Point2D.h>
40 #include <Events_Loop.h>
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Sketch.h>
44 #include <SketchPlugin_Point.h>
45 #include <SketchPlugin_Arc.h>
46 #include <SketchPlugin_Circle.h>
47 #include <SketchPlugin_ConstraintLength.h>
48 #include <SketchPlugin_ConstraintDistance.h>
49 #include <SketchPlugin_ConstraintParallel.h>
50 #include <SketchPlugin_ConstraintPerpendicular.h>
51 #include <SketchPlugin_ConstraintRadius.h>
52 #include <SketchPlugin_ConstraintRigid.h>
53 #include <SketchPlugin_ConstraintHorizontal.h>
54 #include <SketchPlugin_ConstraintVertical.h>
55 #include <SketchPlugin_ConstraintEqual.h>
56 #include <SketchPlugin_ConstraintTangent.h>
57 #include <SketchPlugin_ConstraintCoincidence.h>
58 #include <SketchPlugin_ConstraintFillet.h>
59 #include <SketchPlugin_ConstraintMirror.h>
60 #include <SketchPlugin_ConstraintAngle.h>
61 #include <SketchPlugin_ConstraintCollinear.h>
62 #include <SketchPlugin_ConstraintMiddle.h>
63 #include <SketchPlugin_MultiRotation.h>
64 #include <SketchPlugin_MultiTranslation.h>
65 #include <SketchPlugin_IntersectionPoint.h>
67 #include <SketcherPrs_Tools.h>
69 #include <SelectMgr_IndexedMapOfOwner.hxx>
70 #include <StdSelect_BRepOwner.hxx>
72 //#include <AIS_DimensionSelectionMode.hxx>
73 #include <AIS_Shape.hxx>
74 #include <AIS_Dimension.hxx>
76 #include <ModelAPI_Events.h>
77 #include <ModelAPI_Session.h>
78 #include <ModelAPI_AttributeString.h>
80 #include <QMouseEvent>
81 #include <QApplication>
83 #include <QMessageBox>
85 //#define DEBUG_DO_NOT_BY_ENTER
87 //#define DEBUG_CURSOR
89 /// Returns list of unique objects by sum of objects from List1 and List2
90 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
91 const QList<ModuleBase_ViewerPrs>& theList2)
93 QList<ModuleBase_ViewerPrs> aRes;
94 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
95 if (!aRes.contains(aPrs))
98 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
99 if (!aRes.contains(aPrs))
105 // Fills the list of features the list of selected presentations.
106 // \param theList a list of selected presentations
107 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
108 // and find the corresponded attribute
109 // \param theFeatureList an output list of features
110 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
111 const FeaturePtr theSketch,
112 QList<FeaturePtr>& theFeatureList)
114 QList<ModuleBase_ViewerPrs> aRes;
116 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
117 aLast = theList.end();
118 for (; anIt != aLast; anIt++)
120 ModuleBase_ViewerPrs aPrs = *anIt;
121 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
122 if (aFeature.get() && !theFeatureList.contains(aFeature))
123 theFeatureList.append(aFeature);
127 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
128 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
129 /// result as is to the list of results.
130 /// \param theOwner a viewer selected owner
131 /// \param theFeature a feature, where the attribute is searched
132 /// \param theSketch a current sketch
133 /// \param theSelectedAttribute an output list of attributes
134 /// \param theSelectedResults an output list of edge results
135 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
136 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
137 const ResultPtr& theResult,
138 std::set<AttributePtr>& aSelectedAttributes,
139 std::set<ResultPtr>& aSelectedResults)
141 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
142 if (aBRepOwner.IsNull())
144 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
145 aBRepOwner->Selectable());
146 if (aBRepOwner->HasShape()) {
147 const TopoDS_Shape& aShape = aBRepOwner->Shape();
148 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
149 if (aShapeType == TopAbs_VERTEX) {
150 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
152 if (aPntAttr.get() != NULL)
153 aSelectedAttributes.insert(aPntAttr);
155 else if (aShapeType == TopAbs_EDGE &&
156 aSelectedResults.find(theResult) == aSelectedResults.end()) {
157 aSelectedResults.insert(theResult);
162 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
163 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
164 myIsMouseOverWindow(false),
165 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
166 myIsPopupMenuActive(false)
168 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
169 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
171 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
173 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
174 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
176 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
177 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
179 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
180 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
182 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
183 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
185 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
186 XGUI_Workshop* aWorkshop = aConnector->workshop();
187 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
189 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
190 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
193 PartSet_SketcherMgr::~PartSet_SketcherMgr()
195 if (!myPlaneFilter.IsNull())
196 myPlaneFilter.Nullify();
199 void PartSet_SketcherMgr::onEnterViewPort()
201 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
202 // created feature because it should be done in onMouseMove(). Some widgets watch
203 // the mouse move and use the cursor position to update own values. If the presentaion is
204 // redisplayed before this update, the feature presentation jumps from reset value to current.
205 myIsMouseOverWindow = true;
207 #ifdef DEBUG_DO_NOT_BY_ENTER
211 if (canChangeCursor(getCurrentOperation())) {
212 QCursor* aCurrentCursor = QApplication::overrideCursor();
213 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
214 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
216 qDebug("onEnterViewPort() : Qt::CrossCursor");
221 if (!isNestedCreateOperation(getCurrentOperation()))
224 operationMgr()->onValidateOperation();
226 // we need change displayed state of the current operation feature
227 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
228 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
229 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
230 // presentation becomes valid and redisplay happens
231 //ModuleBase_Operation* aOperation = getCurrentOperation();
232 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
233 (getCurrentOperation());
235 FeaturePtr aFeature = aFOperation->feature();
236 if (aFeature.get() && aFeature->data()->isValid()) {
237 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
242 void PartSet_SketcherMgr::onLeaveViewPort()
244 myIsMouseOverViewProcessed = false;
245 myIsMouseOverWindow = false;
246 // it is important to validate operation here only if sketch entity create operation is active
247 // because at this operation we reacts to the mouse leave/enter view port
248 //operationMgr()->onValidateOperation();
250 #ifdef DEBUG_DO_NOT_BY_ENTER
254 if (canChangeCursor(getCurrentOperation())) {
255 QApplication::restoreOverrideCursor();
257 qDebug("onLeaveViewPort() : None");
261 if (!isNestedCreateOperation(getCurrentOperation()))
264 // the method should be performed if the popup menu is called,
265 // the reset of the current widget should not happen
266 if (myIsPopupMenuActive)
269 operationMgr()->onValidateOperation();
271 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
272 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
273 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
274 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
275 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
276 // obtained after reset value
277 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
278 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
280 anActiveWidget->reset();
282 // hides the presentation of the current operation feature
283 // the feature is to be erased here, but it is correct to call canDisplayObject because
284 // there can be additional check (e.g. editor widget in distance constraint)
285 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
286 (getCurrentOperation());
288 FeaturePtr aFeature = aFOperation->feature();
289 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
291 // we should update viewer after the presentation are hidden in the viewer
292 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
293 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
296 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
298 if (!isNestedEditOperation(getCurrentOperation()) ||
299 myModule->sketchReentranceMgr()->isInternalEditActive())
301 // it is necessary to save current selection in order to restore it after the values are modifed
304 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
305 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
306 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
307 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
310 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
312 if (!isNestedEditOperation(getCurrentOperation()) ||
313 myModule->sketchReentranceMgr()->isInternalEditActive()) {
314 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
317 // it is necessary to restore current selection in order to restore it after the values are modified
319 myCurrentSelection.clear();
321 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
322 // viewer happens by deselect/select the modified objects. The flag should be restored after
323 // the selection processing. The update viewer should be also called.
324 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
325 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
326 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
327 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
328 aDisplayer->updateViewer();
333 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
335 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
338 //get2dPoint(theWnd, theEvent, myClickedPoint);
340 if (!(theEvent->buttons() & Qt::LeftButton))
343 // Clear dragging mode
344 myIsDragging = false;
346 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
347 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
348 if (!aViewer->canDragByMouse())
351 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
352 (getCurrentOperation());
356 if (aFOperation->isEditOperation()) {
357 // If the current widget is a selector, do nothing, it processes the mouse press
358 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
359 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
364 // Use only for sketch operations
365 if (myCurrentSketch) {
366 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
369 bool isSketcher = isSketchOperation(aFOperation);
370 bool isSketchOpe = isNestedSketchOperation(aFOperation);
372 // Avoid non-sketch operations
373 if ((!isSketchOpe) && (!isSketcher))
376 bool isEditing = aFOperation->isEditOperation();
378 // Ignore creation sketch operation
379 if ((!isSketcher) && (!isEditing))
382 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
383 if (!aContext.IsNull()) {
384 // MoveTo in order to highlight current object
385 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
387 // Remember highlighted objects for editing
388 ModuleBase_ISelection* aSelect = aWorkshop->selection();
390 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
391 storeSelection(!aHasShift);
393 if (myCurrentSelection.empty()) {
394 if (isSketchOpe && (!isSketcher))
395 // commit previous operation
396 if (!aFOperation->commit())
397 aFOperation->abort();
400 // Init flyout point for radius rotation
401 FeaturePtr aFeature = myCurrentSelection.begin().key();
405 get2dPoint(theWnd, theEvent, myCurrentPoint);
408 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
410 if (aFeature.get() != NULL) {
411 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
412 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
413 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
414 DataPtr aData = aSPFeature->data();
415 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
416 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
417 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
418 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
421 } else if (isSketchOpe && isEditing) {
422 // If selected another object commit current result
423 aFOperation->commit();
426 get2dPoint(theWnd, theEvent, myCurrentPoint);
429 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
431 // this is temporary commented in order to avoid the following wrong case:
432 // Distance constraint is under edition, double click on the digit -> nothing happens
433 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
434 // but as the prev edit is commited an new one is not started, editor is not shown.
435 // This is necessary in order to finalize previous operation
436 //QApplication::processEvents();
442 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
444 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
447 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
448 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
449 if (!aViewer->canDragByMouse())
451 ModuleBase_Operation* aOp = getCurrentOperation();
453 if (isNestedSketchOperation(aOp)) {
454 //get2dPoint(theWnd, theEvent, myClickedPoint);
456 // Only for sketcher operations
460 myCurrentSelection.clear();
461 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
462 if (!aContext.IsNull()) {
463 // Reselect edited object
464 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
465 if (theEvent->modifiers() & Qt::ShiftModifier)
466 aContext->ShiftSelect();
475 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
476 myIsDragging = false;
479 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
481 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
484 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
485 myIsMouseOverViewProcessed = true;
486 // 1. perform the widget mouse move functionality and display the presentation
487 // the mouse move should be processed in the widget, if it can in order to visualize correct
488 // presentation. These widgets correct the feature attribute according to the mouse position
489 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
490 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
492 aPoint2DWdg->onMouseMove(theWnd, theEvent);
494 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
497 aDistanceWdg->onMouseMove(theWnd, theEvent);
499 // the feature is to be erased here, but it is correct to call canDisplayObject because
500 // there can be additional check (e.g. editor widget in distance constraint)
501 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
502 (getCurrentOperation());
504 FeaturePtr aFeature = aFOperation->feature();
505 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
509 //myClickedPoint.clear();
512 // 1. the current selection is saved in the mouse press method in order to restore it after moving
513 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
514 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
515 // deselected). This flag should be restored in the slot, processed the mouse release signal.
517 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
518 if (!aCurrentOperation)
520 if (isSketchOperation(aCurrentOperation))
521 return; // No edit operation activated
523 Handle(V3d_View) aView = theWnd->v3dView();
524 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
526 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
527 double dX = aX - myCurrentPoint.myCurX;
528 double dY = aY - myCurrentPoint.myCurY;
530 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
531 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
532 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
533 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
534 // viewer happens by deselect/select the modified objects. The flag should be restored after
535 // the selection processing. The update viewer should be also called.
536 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
538 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
539 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
540 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
541 aLast = myCurrentSelection.end();
542 // 4. the features and attributes modification(move)
543 bool isModified = false;
544 for (; anIt != aLast; anIt++) {
545 FeaturePtr aFeature = anIt.key();
547 std::set<AttributePtr> anAttributes = anIt.value().first;
548 // Process selection by attribute: the priority to the attribute
549 if (!anAttributes.empty()) {
550 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
551 anAttLast = anAttributes.end();
552 for (; anAttIt != anAttLast; anAttIt++) {
553 AttributePtr anAttr = *anAttIt;
554 if (anAttr.get() == NULL)
556 std::string aAttrId = anAttr->id();
557 DataPtr aData = aFeature->data();
558 if (aData->isValid()) {
559 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
560 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
561 if (aPoint.get() != NULL) {
562 bool isImmutable = aPoint->setImmutable(true);
563 aPoint->move(dX, dY);
565 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
566 aPoint->setImmutable(isImmutable);
571 // Process selection by feature
572 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
573 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
574 if (aSketchFeature) {
575 aSketchFeature->move(dX, dY);
577 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
581 // the modified state of the current operation should be updated if there are features, which
584 aCurrentOperation->onValuesChanged();
586 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
587 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
589 // 5. it is necessary to save current selection in order to restore it after the features moving
591 // 6. restore the update viewer flag and call this update
592 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
593 aDisplayer->updateViewer();
596 myCurrentPoint.setValue(aX, aY);
600 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
602 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
603 (getCurrentOperation());
604 if (aFOperation && aFOperation->isEditOperation()) {
605 std::string aId = aFOperation->id().toStdString();
606 if (isDistanceOperation(aFOperation))
608 // Activate dimension value editing on double click
609 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
610 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
611 // Find corresponded widget to activate value editing
612 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
613 if (aWgt->attributeID() == "ConstraintValue") {
614 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
616 anEditor->showPopupEditor();
624 void PartSet_SketcherMgr::onApplicationStarted()
626 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
627 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
628 XGUI_Workshop* aWorkshop = aConnector->workshop();
629 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
631 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
632 if (aPropertyPanel) {
633 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
634 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
636 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
637 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
638 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
639 aReentranceMgr, SLOT(onWidgetActivated()));
642 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
643 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
644 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
646 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
647 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
648 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
651 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
653 //if (!myClickedPoint.myIsInitialized)
656 //ModuleBase_Operation* aOperation = getCurrentOperation();
657 // the distance constraint feature should not use the clickedd point
658 // this is workaround in order to don't throw down the flyout point value,
659 // set by execute() method of these type of features
660 //if (isDistanceOperation(aOperation))
663 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
665 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
669 void PartSet_SketcherMgr::onBeforeContextMenu()
671 myIsPopupMenuActive = true;
674 void PartSet_SketcherMgr::onAfterContextMenu()
676 myIsPopupMenuActive = false;
679 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
682 Handle(V3d_View) aView = theWnd->v3dView();
683 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
685 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
686 thePoint.setValue(aX, anY);
689 void PartSet_SketcherMgr::launchEditing()
691 if (!myCurrentSelection.empty()) {
692 FeaturePtr aFeature = myCurrentSelection.begin().key();
693 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
694 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
696 myModule->editFeature(aSPFeature);
701 bool PartSet_SketcherMgr::sketchSolverError()
703 bool anError = false;
704 CompositeFeaturePtr aSketch = activeSketch();
706 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
707 anError = !aAttributeString->value().empty();
712 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
714 QString anError = "";
715 if (!theFeature.get() || !theFeature->data()->isValid())
718 CompositeFeaturePtr aSketch = activeSketch();
719 if (aSketch.get() && aSketch == theFeature) {
720 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
721 anError = aAttributeString->value().c_str();
726 void PartSet_SketcherMgr::clearClickedFlags()
728 //myClickedPoint.clear();
729 myCurrentPoint.clear();
732 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
734 static QStringList aIds;
735 if (aIds.size() == 0) {
736 aIds << SketchPlugin_Line::ID().c_str();
737 aIds << SketchPlugin_Point::ID().c_str();
738 aIds << SketchPlugin_Arc::ID().c_str();
739 aIds << SketchPlugin_Circle::ID().c_str();
740 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
741 aIds << SketchPlugin_IntersectionPoint::ID().c_str();
743 // SketchRectangle is a python feature, so its ID is passed just as a string
744 aIds << "SketchRectangle";
745 aIds.append(constraintsIdList());
750 const QStringList& PartSet_SketcherMgr::constraintsIdList()
752 static QStringList aIds;
753 if (aIds.size() == 0) {
754 aIds << SketchPlugin_ConstraintLength::ID().c_str();
755 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
756 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
757 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
758 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
759 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
760 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
761 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
762 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
763 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
764 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
765 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
766 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
767 aIds << SketchPlugin_MultiRotation::ID().c_str();
768 aIds << SketchPlugin_MultiTranslation::ID().c_str();
769 aIds << SketchPlugin_ConstraintCollinear::ID().c_str();
770 aIds << SketchPlugin_ConstraintMiddle::ID().c_str();
775 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
779 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
780 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
781 theModes.append(SketcherPrs_Tools::Sel_Constraint);
782 theModes.append(TopAbs_VERTEX);
783 theModes.append(TopAbs_EDGE);
786 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
788 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
791 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
793 return theOperation &&
794 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
797 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
799 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
801 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
804 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
806 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
808 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
811 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
813 return (theId == SketchPlugin_Line::ID()) ||
814 (theId == SketchPlugin_Point::ID()) ||
815 (theId == SketchPlugin_Arc::ID()) ||
816 (theId == SketchPlugin_Circle::ID());
819 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
821 std::string anId = theOperation ? theOperation->id().toStdString() : "";
823 return isDistanceKind(anId);
826 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
828 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
829 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
830 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
831 (theKind == SketchPlugin_ConstraintAngle::ID());
834 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
836 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
837 (getCurrentOperation());
841 myModule->onViewTransformed();
843 // Display all sketcher sub-Objects
844 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
845 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
846 aConnector->workshop()->displayer()->activateTrihedron(true);
848 // Hide sketcher result
849 std::list<ResultPtr> aResults = myCurrentSketch->results();
850 std::list<ResultPtr>::const_iterator aIt;
851 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
852 (*aIt)->setDisplayed(false);
854 myCurrentSketch->setDisplayed(false);
856 // Display sketcher objects
857 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
858 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
859 std::list<ResultPtr> aResults = aFeature->results();
860 std::list<ResultPtr>::const_iterator aIt;
861 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
862 (*aIt)->setDisplayed(true);
864 aFeature->setDisplayed(true);
867 if(myCirclePointFilter.IsNull()) {
868 myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
871 myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
873 if (myPlaneFilter.IsNull())
874 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
876 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
877 bool aHasPlane = false;
878 std::shared_ptr<GeomAPI_Pln> aPln;
879 if (aFOperation->isEditOperation()) {
880 // If it is editing of sketch then it means that plane is already defined
881 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
885 myPlaneFilter->setPlane(aPln);
887 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
888 // all sketch objects should be activated in the sketch selection modes by edit operation start
889 // in case of creation operation, there is an active widget, which activates own selection mode
890 if (aFOperation->isEditOperation() && aHasPlane)
891 aConnector->activateModuleSelectionModes();
894 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
896 myIsMouseOverWindow = false;
897 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
898 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
900 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
902 DataPtr aData = myCurrentSketch->data();
903 if (!aData->isValid()) {
904 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
905 // The sketch was aborted
906 myCurrentSketch = CompositeFeaturePtr();
907 // TODO: move this outside of if-else
908 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
909 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
911 // Erase all sketcher objects
912 QStringList aSketchIds = sketchOperationIdList();
913 QObjectPtrList aObjects = aDisplayer->displayedObjects();
914 foreach (ObjectPtr aObj, aObjects) {
915 DataPtr aObjData = aObj->data();
916 if (!aObjData->isValid())
917 aObj->setDisplayed(false);
921 // Hide all sketcher sub-Objects
922 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
923 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
924 std::list<ResultPtr> aResults = aFeature->results();
925 std::list<ResultPtr>::const_iterator aIt;
926 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
927 (*aIt)->setDisplayed(false);
929 aFeature->setDisplayed(false);
931 // Display sketcher result
932 std::list<ResultPtr> aResults = myCurrentSketch->results();
933 std::list<ResultPtr>::const_iterator aIt;
934 Events_Loop* aLoop = Events_Loop::loop();
935 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
937 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
939 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
940 if (!aFOperation->isDisplayedOnStart(*aIt)) {
941 (*aIt)->setDisplayed(true);
942 // this display event is needed because sketch already may have "displayed" state,
943 // but not displayed while it is still active (issue 613, abort of existing sketch)
944 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
947 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
948 myCurrentSketch->setDisplayed(true);
950 myCurrentSketch = CompositeFeaturePtr();
952 myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
953 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
955 Events_Loop::loop()->flush(aDispEvent);
957 // restore the module selection modes, which were changed on startSketch
958 aConnector->activateModuleSelectionModes();
959 aConnector->workshop()->displayer()->activateTrihedron(false);
962 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
964 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
965 QCursor* aCurrentCursor = QApplication::overrideCursor();
966 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
967 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
969 qDebug("startNestedSketch() : Qt::CrossCursor");
975 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
977 myIsMouseOverViewProcessed = true;
978 operationMgr()->onValidateOperation();
979 if (canChangeCursor(theOperation)) {
980 QApplication::restoreOverrideCursor();
982 qDebug("stopNestedSketch() : None");
987 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
989 if (isNestedCreateOperation(theOperation)) {
990 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
993 FeaturePtr aFeature = aFOperation->feature();
994 // it is necessary to check the the feature data validity because
995 // some kind of features are removed by an operation commit(the macro state of a feature)
996 if (aFeature.get() && aFeature->data()->isValid()) {
997 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1003 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
1006 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
1008 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1011 void PartSet_SketcherMgr::operationActivatedByPreselection()
1013 ModuleBase_Operation* anOperation = getCurrentOperation();
1014 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1015 // Set final definitions if they are necessary
1016 //propertyPanelDefined(aOperation);
1017 /// Commit sketcher operations automatically
1018 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1021 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1022 FeaturePtr aFeature = aFOperation->feature();
1023 // editor is shown only if all attribute references are filled by preseletion
1024 bool anAllRefAttrInitialized = true;
1026 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1027 ModelAPI_AttributeRefAttr::typeId());
1028 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1029 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1030 anAllRefAttrInitialized = (*anIt)->isInitialized();
1032 if (anAllRefAttrInitialized) {
1033 // Activate dimension value editing on double click
1034 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1035 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1036 // Find corresponded widget to activate value editing
1037 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1038 if (aWgt->attributeID() == "ConstraintValue") {
1039 // the featue should be displayed in order to find the AIS text position,
1040 // the place where the editor will be shown
1041 aFeature->setDisplayed(true);
1042 /// the execute is necessary to perform in the feature compute for flyout position
1043 aFeature->execute();
1045 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1046 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1048 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1050 int aX = 0, anY = 0;
1052 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1053 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1054 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1055 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1056 Handle(AIS_InteractiveObject) anAISIO;
1057 if (anAIS.get() != NULL) {
1058 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1060 if (anAIS.get() != NULL) {
1061 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1063 if (!anAISIO.IsNull()) {
1064 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1065 if (!aDim.IsNull()) {
1066 gp_Pnt aPosition = aDim->GetTextPosition();
1068 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1069 Handle(V3d_View) aView = aViewer->activeView();
1071 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1073 QWidget* aViewPort = aViewer->activeViewPort();
1074 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1079 anEditor->setCursorPosition(aX, anY);
1080 anEditor->showPopupEditor(false);
1088 anOperation->commit();
1092 bool PartSet_SketcherMgr::canUndo() const
1094 return isNestedCreateOperation(getCurrentOperation());
1097 bool PartSet_SketcherMgr::canRedo() const
1099 return isNestedCreateOperation(getCurrentOperation());
1102 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1104 bool aCanErase = true;
1105 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1106 if (myCurrentSketch.get()) {
1107 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1108 if (aResult.get()) {
1109 // Display sketcher objects
1110 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1112 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1113 std::list<ResultPtr> aResults = aFeature->results();
1114 std::list<ResultPtr>::const_iterator anIt;
1115 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1116 aCanErase = *anIt != aResult;
1124 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1126 bool aCanDisplay = true;
1128 bool aHasActiveSketch = activeSketch().get() != NULL;
1129 if (aHasActiveSketch) {
1130 // 1. the sketch feature should not be displayed during the sketch active operation
1131 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1132 // nested features can be visualized
1133 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1134 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1135 aCanDisplay = false;
1138 else { // there are no an active sketch
1139 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1140 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1141 if (aFeature.get() != NULL) {
1142 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1143 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1144 if (aSketchFeature.get()) {
1145 aCanDisplay = false;
1150 // 3. the method should not filter the objects, which are not related to the current operation.
1151 // The object is filtered just if it is a current operation feature or this feature result
1152 bool isObjectFound = false;
1153 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1154 (getCurrentOperation());
1156 FeaturePtr aFeature = aFOperation->feature();
1157 if (aFeature.get()) {
1158 std::list<ResultPtr> aResults = aFeature->results();
1159 if (theObject == aFeature)
1160 isObjectFound = true;
1162 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1163 for (; anIt != aLast && !isObjectFound; anIt++) {
1164 isObjectFound = *anIt == theObject;
1169 if (isObjectFound) {
1170 // 4. For created nested feature operation do not display the created feature if
1171 // the mouse curstor leaves the OCC window.
1172 // The correction cases, which ignores this condition:
1173 // a. the property panel values modification
1174 // b. the popup menu activated
1175 // c. widget editor control
1176 #ifndef DEBUG_DO_NOT_BY_ENTER
1177 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1178 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1179 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1180 // the active widget editor should not influence here. The presentation should be visible always
1181 // when this widget is active.
1182 if (!anEditorWdg && !myIsPopupMenuActive) {
1183 // during a nested create operation, the feature is redisplayed only if the mouse over view
1184 // of there was a value modified in the property panel after the mouse left the view
1185 aCanDisplay = canDisplayCurrentCreatedFeature();
1191 // checks the sketcher constraints visibility according to active sketch check box states
1193 bool aProcessed = false;
1194 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1195 if (aFeature.get()) {
1196 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1198 aCanDisplay = aConstraintDisplayed;
1205 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1206 const PartSet_Tools::ConstraintVisibleState& theState,
1207 bool& isProcessed) const
1209 bool aSwitchedOn = true;
1211 const QStringList& aConstrIds = constraintsIdList();
1213 std::string aKind = theFeature->getKind();
1214 if (aConstrIds.contains(QString(aKind.c_str()))) {
1215 bool isTypedConstraint = false;
1218 case PartSet_Tools::Dimensional: {
1219 bool isDistance = isDistanceKind(aKind);
1222 aSwitchedOn = myIsConstraintsShown[theState];
1226 case PartSet_Tools::Geometrical: {
1227 bool isGeometrical = !isDistanceKind(aKind);
1228 if (isGeometrical) {
1230 aSwitchedOn = myIsConstraintsShown[theState];
1234 case PartSet_Tools::Any: {
1236 bool isDistance = isDistanceKind(aKind);
1238 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1240 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1250 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1252 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1253 (getCurrentOperation());
1254 if (aFOperation && myCurrentSketch.get()) {
1255 // find results of the current operation
1256 // these results should not be proposed to be deleted
1257 FeaturePtr anOperationFeature = aFOperation->feature();
1258 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1259 std::set<ResultPtr> anOperationResults;
1260 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1261 aRLast = anOperationResultList.end();
1262 for (; aRIt != aRLast; aRIt++)
1263 anOperationResults.insert(*aRIt);
1265 std::set<FeaturePtr> anObjectsToBeDeleted;
1266 QStringList anObjectsToBeDeletedNames;
1267 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1268 for (; anIt != aLast; anIt++) {
1269 ObjectPtr anObject = *anIt;
1270 bool aCanErase = true;
1271 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1272 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1273 // the result is found between current feature results
1274 if (anOperationResults.find(aResult) != anOperationResults.end())
1277 if (aResult.get()) {
1278 // Display sketcher objects
1279 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1280 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1281 std::list<ResultPtr> aResults = aFeature->results();
1282 std::list<ResultPtr>::const_iterator anIt;
1283 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1284 aCanErase = *anIt != aResult;
1289 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1290 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1291 anObjectsToBeDeleted.insert(aFeature);
1292 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1296 if (!anObjectsToBeDeleted.empty()) {
1297 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1298 QString aMessage = tr("The following features have incorrect presentation and \
1299 will be hidden: %1. Would you like to delete them?")
1300 .arg(aFeatureNames);
1301 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1302 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1303 QMessageBox::Cancel);
1304 if (anAnswer == QMessageBox::Ok) {
1305 QObjectPtrList anObjects;
1306 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1307 aLast = anObjectsToBeDeleted.end();
1308 for (; anIt != aLast; anIt++)
1309 anObjects.append(*anIt);
1310 SessionPtr aMgr = ModelAPI_Session::get();
1311 DocumentPtr aDoc = aMgr->activeDocument();
1312 bool aIsOp = aMgr->isOperation();
1314 aMgr->startOperation();
1315 workshop()->deleteFeatures(anObjects);
1316 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1317 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1318 //Events_Loop::loop()->flush(aDeletedEvent);
1319 //Events_Loop::loop()->flush(aRedispEvent);
1322 aMgr->finishOperation();
1328 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1330 bool aCanDisplay = myIsMouseOverWindow;
1332 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1334 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1339 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1341 return isNestedCreateOperation(theOperation) ||
1342 myModule->sketchReentranceMgr()->isInternalEditActive();
1345 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1347 return myIsConstraintsShown;
1350 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1352 bool isFoundObject = false;
1354 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1355 if (anObjectFeature.get()) {
1356 int aSize = myCurrentSketch->numberOfSubs();
1357 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1358 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1359 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1362 return isFoundObject;
1365 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1367 if (myPlaneFilter.IsNull())
1368 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1370 myPlaneFilter->setPlane(thePln);
1373 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1374 const FeaturePtr& theSketch,
1375 ModuleBase_IWorkshop* theWorkshop,
1376 FeatureToSelectionMap& theSelection)
1378 if (theFeature.get() == NULL)
1381 std::set<AttributePtr> aSelectedAttributes;
1382 std::set<ResultPtr> aSelectedResults;
1384 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1385 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1386 if (!aContext.IsNull()) {
1387 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1388 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1390 std::list<ResultPtr> aResults = theFeature->results();
1391 std::list<ResultPtr>::const_iterator aIt;
1392 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1394 ResultPtr aResult = *aIt;
1395 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1396 if (aAISObj.get() == NULL)
1398 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1399 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1401 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1402 if (anOwner->Selectable() != anAISIO)
1404 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1405 aSelectedAttributes, aSelectedResults);
1407 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1408 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1409 if (anOwner.IsNull())
1411 if (anOwner->Selectable() != anAISIO)
1413 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1414 aSelectedAttributes, aSelectedResults);
1418 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1421 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1422 const FeaturePtr& theSketch,
1423 ModuleBase_IWorkshop* theWorkshop,
1424 const FeatureToSelectionMap& theSelection,
1425 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1427 if (theFeature.get() == NULL)
1430 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1431 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1432 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1434 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1436 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1437 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1439 // 1. found the feature's owners. Check the AIS objects of the constructions
1440 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1441 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1442 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1444 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1445 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1446 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1447 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1448 if (!anOwner.IsNull())
1449 theOwnersToSelect.Add(anOwner);
1453 // 2. found the feature results's owners
1454 std::list<ResultPtr> aResults = theFeature->results();
1455 std::list<ResultPtr>::const_iterator aIt;
1456 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1458 ResultPtr aResult = *aIt;
1459 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1460 if (aAISObj.get() == NULL)
1462 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1464 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1465 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1466 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1467 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1468 if ( anOwner.IsNull() || !anOwner->HasShape() )
1470 const TopoDS_Shape& aShape = anOwner->Shape();
1471 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1472 if (aShapeType == TopAbs_VERTEX) {
1473 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1474 if (aPntAttr.get() != NULL &&
1475 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1476 theOwnersToSelect.Add(anOwner);
1479 else if (aShapeType == TopAbs_EDGE) {
1480 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1481 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1482 theOwnersToSelect.FindIndex(anOwner) <= 0)
1483 theOwnersToSelect.Add(anOwner);
1489 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1492 connect(theWidget, SIGNAL(beforeValuesChanged()),
1493 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1494 connect(theWidget, SIGNAL(afterValuesChanged()),
1495 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1498 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1499 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1500 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1501 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1505 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1507 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1508 (getCurrentOperation());
1510 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1511 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1512 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1513 FeaturePtr aFeature = aFOperation->feature();
1514 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1519 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1521 return myModule->workshop()->currentOperation();
1524 //**************************************************************
1525 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1527 ModuleBase_ModelWidget* aWidget = 0;
1528 ModuleBase_Operation* anOperation = getCurrentOperation();
1530 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1532 aWidget = aPanel->activeWidget();
1537 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1538 const bool isEditOperation,
1539 const bool isToDisplay,
1540 const bool isFlushRedisplay)
1542 #ifdef DEBUG_DO_NOT_BY_ENTER
1546 if (isEditOperation || !theFeature.get())
1549 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1550 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1552 // 1. change visibility of the object itself, here the presentable object is processed,
1553 // e.g. constraints features
1554 //FeaturePtr aFeature = aFOperation->feature();
1555 std::list<ResultPtr> aResults = theFeature->results();
1557 theFeature->setDisplayed(true);
1559 theFeature->setDisplayed(false);
1561 // change visibility of the object results, e.g. non-constraint features
1562 std::list<ResultPtr>::const_iterator aIt;
1563 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1565 (*aIt)->setDisplayed(true);
1568 (*aIt)->setDisplayed(false);
1571 if (isFlushRedisplay)
1572 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1575 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1577 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1578 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1579 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1581 QList<FeaturePtr> aFeatureList;
1582 if (theHighlightedOnly) {
1583 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1586 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1588 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1589 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1592 // 1. it is necessary to save current selection in order to restore it after the features moving
1593 myCurrentSelection.clear();
1594 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1595 for (; anIt != aLast; anIt++) {
1596 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1598 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1601 void PartSet_SketcherMgr::restoreSelection()
1603 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1604 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1605 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1606 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1607 aSLast = myCurrentSelection.end();
1608 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1609 for (; aSIt != aSLast; aSIt++) {
1610 anOwnersToSelect.Clear();
1611 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1613 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1617 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1619 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1620 if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1622 if (myCurrentSketch.get() == NULL)
1625 myIsConstraintsShown[aType] = theState;
1627 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1628 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1630 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1631 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1632 bool aProcessed = false;
1633 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, aType, aProcessed);
1635 aSubFeature->setDisplayed(aConstraintDisplayed);
1637 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1640 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1642 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1643 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1644 return aConnector->workshop();
1647 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1649 return workshop()->operationMgr();