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 (myPlaneFilter.IsNull())
868 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
870 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
871 bool aHasPlane = false;
872 std::shared_ptr<GeomAPI_Pln> aPln;
873 if (aFOperation->isEditOperation()) {
874 // If it is editing of sketch then it means that plane is already defined
875 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
879 myPlaneFilter->setPlane(aPln);
881 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
882 // all sketch objects should be activated in the sketch selection modes by edit operation start
883 // in case of creation operation, there is an active widget, which activates own selection mode
884 if (aFOperation->isEditOperation() && aHasPlane)
885 aConnector->activateModuleSelectionModes();
888 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
890 myIsMouseOverWindow = false;
891 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
892 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
894 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
896 DataPtr aData = myCurrentSketch->data();
897 if (!aData->isValid()) {
898 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
899 // The sketch was aborted
900 myCurrentSketch = CompositeFeaturePtr();
901 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
903 // Erase all sketcher objects
904 QStringList aSketchIds = sketchOperationIdList();
905 QObjectPtrList aObjects = aDisplayer->displayedObjects();
906 foreach (ObjectPtr aObj, aObjects) {
907 DataPtr aObjData = aObj->data();
908 if (!aObjData->isValid())
909 aObj->setDisplayed(false);
913 // Hide all sketcher sub-Objects
914 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
915 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
916 std::list<ResultPtr> aResults = aFeature->results();
917 std::list<ResultPtr>::const_iterator aIt;
918 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
919 (*aIt)->setDisplayed(false);
921 aFeature->setDisplayed(false);
923 // Display sketcher result
924 std::list<ResultPtr> aResults = myCurrentSketch->results();
925 std::list<ResultPtr>::const_iterator aIt;
926 Events_Loop* aLoop = Events_Loop::loop();
927 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
929 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
931 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
932 if (!aFOperation->isDisplayedOnStart(*aIt)) {
933 (*aIt)->setDisplayed(true);
934 // this display event is needed because sketch already may have "displayed" state,
935 // but not displayed while it is still active (issue 613, abort of existing sketch)
936 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
939 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
940 myCurrentSketch->setDisplayed(true);
942 myCurrentSketch = CompositeFeaturePtr();
943 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
945 Events_Loop::loop()->flush(aDispEvent);
947 // restore the module selection modes, which were changed on startSketch
948 aConnector->activateModuleSelectionModes();
949 aConnector->workshop()->displayer()->activateTrihedron(false);
952 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
954 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
955 QCursor* aCurrentCursor = QApplication::overrideCursor();
956 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
957 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
959 qDebug("startNestedSketch() : Qt::CrossCursor");
965 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
967 myIsMouseOverViewProcessed = true;
968 operationMgr()->onValidateOperation();
969 if (canChangeCursor(theOperation)) {
970 QApplication::restoreOverrideCursor();
972 qDebug("stopNestedSketch() : None");
977 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
979 if (isNestedCreateOperation(theOperation)) {
980 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
983 FeaturePtr aFeature = aFOperation->feature();
984 // it is necessary to check the the feature data validity because
985 // some kind of features are removed by an operation commit(the macro state of a feature)
986 if (aFeature.get() && aFeature->data()->isValid()) {
987 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
993 void PartSet_SketcherMgr::activatePlaneFilter(const bool& toActivate)
996 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
998 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
1001 void PartSet_SketcherMgr::operationActivatedByPreselection()
1003 ModuleBase_Operation* anOperation = getCurrentOperation();
1004 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1005 // Set final definitions if they are necessary
1006 //propertyPanelDefined(aOperation);
1007 /// Commit sketcher operations automatically
1008 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1011 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1012 FeaturePtr aFeature = aFOperation->feature();
1013 // editor is shown only if all attribute references are filled by preseletion
1014 bool anAllRefAttrInitialized = true;
1016 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1017 ModelAPI_AttributeRefAttr::typeId());
1018 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1019 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1020 anAllRefAttrInitialized = (*anIt)->isInitialized();
1022 if (anAllRefAttrInitialized) {
1023 // Activate dimension value editing on double click
1024 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1025 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1026 // Find corresponded widget to activate value editing
1027 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1028 if (aWgt->attributeID() == "ConstraintValue") {
1029 // the featue should be displayed in order to find the AIS text position,
1030 // the place where the editor will be shown
1031 aFeature->setDisplayed(true);
1032 /// the execute is necessary to perform in the feature compute for flyout position
1033 aFeature->execute();
1035 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1036 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1038 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1040 int aX = 0, anY = 0;
1042 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1043 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1044 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1045 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1046 Handle(AIS_InteractiveObject) anAISIO;
1047 if (anAIS.get() != NULL) {
1048 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1050 if (anAIS.get() != NULL) {
1051 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1053 if (!anAISIO.IsNull()) {
1054 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1055 if (!aDim.IsNull()) {
1056 gp_Pnt aPosition = aDim->GetTextPosition();
1058 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1059 Handle(V3d_View) aView = aViewer->activeView();
1061 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1063 QWidget* aViewPort = aViewer->activeViewPort();
1064 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1069 anEditor->setCursorPosition(aX, anY);
1070 anEditor->showPopupEditor(false);
1078 anOperation->commit();
1082 bool PartSet_SketcherMgr::canUndo() const
1084 return isNestedCreateOperation(getCurrentOperation());
1087 bool PartSet_SketcherMgr::canRedo() const
1089 return isNestedCreateOperation(getCurrentOperation());
1092 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1094 bool aCanErase = true;
1095 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1096 if (myCurrentSketch.get()) {
1097 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1098 if (aResult.get()) {
1099 // Display sketcher objects
1100 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1102 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1103 std::list<ResultPtr> aResults = aFeature->results();
1104 std::list<ResultPtr>::const_iterator anIt;
1105 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1106 aCanErase = *anIt != aResult;
1114 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1116 bool aCanDisplay = true;
1118 bool aHasActiveSketch = activeSketch().get() != NULL;
1119 if (aHasActiveSketch) {
1120 // 1. the sketch feature should not be displayed during the sketch active operation
1121 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1122 // nested features can be visualized
1123 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1124 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1125 aCanDisplay = false;
1128 else { // there are no an active sketch
1129 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1130 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1131 if (aFeature.get() != NULL) {
1132 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1133 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1134 if (aSketchFeature.get()) {
1135 aCanDisplay = false;
1140 // 3. the method should not filter the objects, which are not related to the current operation.
1141 // The object is filtered just if it is a current operation feature or this feature result
1142 bool isObjectFound = false;
1143 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1144 (getCurrentOperation());
1146 FeaturePtr aFeature = aFOperation->feature();
1147 if (aFeature.get()) {
1148 std::list<ResultPtr> aResults = aFeature->results();
1149 if (theObject == aFeature)
1150 isObjectFound = true;
1152 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1153 for (; anIt != aLast && !isObjectFound; anIt++) {
1154 isObjectFound = *anIt == theObject;
1159 if (isObjectFound) {
1160 // 4. For created nested feature operation do not display the created feature if
1161 // the mouse curstor leaves the OCC window.
1162 // The correction cases, which ignores this condition:
1163 // a. the property panel values modification
1164 // b. the popup menu activated
1165 // c. widget editor control
1166 #ifndef DEBUG_DO_NOT_BY_ENTER
1167 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1168 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1169 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1170 // the active widget editor should not influence here. The presentation should be visible always
1171 // when this widget is active.
1172 if (!anEditorWdg && !myIsPopupMenuActive) {
1173 // during a nested create operation, the feature is redisplayed only if the mouse over view
1174 // of there was a value modified in the property panel after the mouse left the view
1175 aCanDisplay = canDisplayCurrentCreatedFeature();
1181 // checks the sketcher constraints visibility according to active sketch check box states
1183 bool aProcessed = false;
1184 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1185 if (aFeature.get()) {
1186 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1188 aCanDisplay = aConstraintDisplayed;
1195 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1196 const PartSet_Tools::ConstraintVisibleState& theState,
1197 bool& isProcessed) const
1199 bool aSwitchedOn = true;
1201 const QStringList& aConstrIds = constraintsIdList();
1203 std::string aKind = theFeature->getKind();
1204 if (aConstrIds.contains(QString(aKind.c_str()))) {
1205 bool isTypedConstraint = false;
1208 case PartSet_Tools::Dimensional: {
1209 bool isDistance = isDistanceKind(aKind);
1212 aSwitchedOn = myIsConstraintsShown[theState];
1216 case PartSet_Tools::Geometrical: {
1217 bool isGeometrical = !isDistanceKind(aKind);
1218 if (isGeometrical) {
1220 aSwitchedOn = myIsConstraintsShown[theState];
1224 case PartSet_Tools::Any: {
1226 bool isDistance = isDistanceKind(aKind);
1228 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1230 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1240 void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1242 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1243 (getCurrentOperation());
1244 if (aFOperation && myCurrentSketch.get()) {
1245 // find results of the current operation
1246 // these results should not be proposed to be deleted
1247 FeaturePtr anOperationFeature = aFOperation->feature();
1248 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1249 std::set<ResultPtr> anOperationResults;
1250 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1251 aRLast = anOperationResultList.end();
1252 for (; aRIt != aRLast; aRIt++)
1253 anOperationResults.insert(*aRIt);
1255 std::set<FeaturePtr> anObjectsToBeDeleted;
1256 QStringList anObjectsToBeDeletedNames;
1257 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1258 for (; anIt != aLast; anIt++) {
1259 ObjectPtr anObject = *anIt;
1260 bool aCanErase = true;
1261 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1262 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1263 // the result is found between current feature results
1264 if (anOperationResults.find(aResult) != anOperationResults.end())
1267 if (aResult.get()) {
1268 // Display sketcher objects
1269 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1270 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1271 std::list<ResultPtr> aResults = aFeature->results();
1272 std::list<ResultPtr>::const_iterator anIt;
1273 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1274 aCanErase = *anIt != aResult;
1279 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1280 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1281 anObjectsToBeDeleted.insert(aFeature);
1282 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1286 if (!anObjectsToBeDeleted.empty()) {
1287 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1288 QString aMessage = tr("The following features have incorrect presentation and \
1289 will be hidden: %1. Would you like to delete them?")
1290 .arg(aFeatureNames);
1291 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1292 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1293 QMessageBox::Cancel);
1294 if (anAnswer == QMessageBox::Ok) {
1295 QObjectPtrList anObjects;
1296 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1297 aLast = anObjectsToBeDeleted.end();
1298 for (; anIt != aLast; anIt++)
1299 anObjects.append(*anIt);
1300 SessionPtr aMgr = ModelAPI_Session::get();
1301 DocumentPtr aDoc = aMgr->activeDocument();
1302 bool aIsOp = aMgr->isOperation();
1304 aMgr->startOperation();
1305 workshop()->deleteFeatures(anObjects);
1306 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1307 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1308 //Events_Loop::loop()->flush(aDeletedEvent);
1309 //Events_Loop::loop()->flush(aRedispEvent);
1312 aMgr->finishOperation();
1318 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1320 bool aCanDisplay = myIsMouseOverWindow;
1322 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1324 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1329 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1331 return isNestedCreateOperation(theOperation) ||
1332 myModule->sketchReentranceMgr()->isInternalEditActive();
1335 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1337 return myIsConstraintsShown;
1340 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1342 bool isFoundObject = false;
1344 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1345 if (anObjectFeature.get()) {
1346 int aSize = myCurrentSketch->numberOfSubs();
1347 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1348 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1349 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1352 return isFoundObject;
1355 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1357 if (myPlaneFilter.IsNull())
1358 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1360 myPlaneFilter->setPlane(thePln);
1363 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1364 const FeaturePtr& theSketch,
1365 ModuleBase_IWorkshop* theWorkshop,
1366 FeatureToSelectionMap& theSelection)
1368 if (theFeature.get() == NULL)
1371 std::set<AttributePtr> aSelectedAttributes;
1372 std::set<ResultPtr> aSelectedResults;
1374 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1375 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1376 if (!aContext.IsNull()) {
1377 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1378 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1380 std::list<ResultPtr> aResults = theFeature->results();
1381 std::list<ResultPtr>::const_iterator aIt;
1382 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1384 ResultPtr aResult = *aIt;
1385 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1386 if (aAISObj.get() == NULL)
1388 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1389 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1391 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1392 if (anOwner->Selectable() != anAISIO)
1394 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1395 aSelectedAttributes, aSelectedResults);
1397 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1398 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1399 if (anOwner.IsNull())
1401 if (anOwner->Selectable() != anAISIO)
1403 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1404 aSelectedAttributes, aSelectedResults);
1408 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1411 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1412 const FeaturePtr& theSketch,
1413 ModuleBase_IWorkshop* theWorkshop,
1414 const FeatureToSelectionMap& theSelection,
1415 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1417 if (theFeature.get() == NULL)
1420 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1421 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1422 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1424 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1426 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1427 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1429 // 1. found the feature's owners. Check the AIS objects of the constructions
1430 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1431 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1432 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1434 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1435 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1436 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1437 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1438 if (!anOwner.IsNull())
1439 theOwnersToSelect.Add(anOwner);
1443 // 2. found the feature results's owners
1444 std::list<ResultPtr> aResults = theFeature->results();
1445 std::list<ResultPtr>::const_iterator aIt;
1446 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1448 ResultPtr aResult = *aIt;
1449 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1450 if (aAISObj.get() == NULL)
1452 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1454 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1455 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1456 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1457 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1458 if ( anOwner.IsNull() || !anOwner->HasShape() )
1460 const TopoDS_Shape& aShape = anOwner->Shape();
1461 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1462 if (aShapeType == TopAbs_VERTEX) {
1463 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1464 if (aPntAttr.get() != NULL &&
1465 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1466 theOwnersToSelect.Add(anOwner);
1469 else if (aShapeType == TopAbs_EDGE) {
1470 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1471 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1472 theOwnersToSelect.FindIndex(anOwner) <= 0)
1473 theOwnersToSelect.Add(anOwner);
1479 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1482 connect(theWidget, SIGNAL(beforeValuesChanged()),
1483 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1484 connect(theWidget, SIGNAL(afterValuesChanged()),
1485 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1488 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1489 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1490 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1491 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1495 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1497 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1498 (getCurrentOperation());
1500 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1501 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1502 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1503 FeaturePtr aFeature = aFOperation->feature();
1504 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1509 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1511 return myModule->workshop()->currentOperation();
1514 //**************************************************************
1515 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1517 ModuleBase_ModelWidget* aWidget = 0;
1518 ModuleBase_Operation* anOperation = getCurrentOperation();
1520 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1522 aWidget = aPanel->activeWidget();
1527 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1528 const bool isEditOperation,
1529 const bool isToDisplay,
1530 const bool isFlushRedisplay)
1532 #ifdef DEBUG_DO_NOT_BY_ENTER
1536 if (isEditOperation || !theFeature.get())
1539 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1540 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1542 // 1. change visibility of the object itself, here the presentable object is processed,
1543 // e.g. constraints features
1544 //FeaturePtr aFeature = aFOperation->feature();
1545 std::list<ResultPtr> aResults = theFeature->results();
1547 theFeature->setDisplayed(true);
1549 theFeature->setDisplayed(false);
1551 // change visibility of the object results, e.g. non-constraint features
1552 std::list<ResultPtr>::const_iterator aIt;
1553 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1555 (*aIt)->setDisplayed(true);
1558 (*aIt)->setDisplayed(false);
1561 if (isFlushRedisplay)
1562 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1565 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1567 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1568 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1569 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1571 QList<FeaturePtr> aFeatureList;
1572 if (theHighlightedOnly) {
1573 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1576 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1578 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1579 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1582 // 1. it is necessary to save current selection in order to restore it after the features moving
1583 myCurrentSelection.clear();
1584 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1585 for (; anIt != aLast; anIt++) {
1586 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1588 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1591 void PartSet_SketcherMgr::restoreSelection()
1593 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1594 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1595 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1596 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1597 aSLast = myCurrentSelection.end();
1598 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1599 for (; aSIt != aSLast; aSIt++) {
1600 anOwnersToSelect.Clear();
1601 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1603 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1607 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1609 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1610 if (myIsConstraintsShown.contains(aType) && myIsConstraintsShown[aType] == theState)
1612 if (myCurrentSketch.get() == NULL)
1615 myIsConstraintsShown[aType] = theState;
1617 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1618 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1620 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1621 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1622 bool aProcessed = false;
1623 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, aType, aProcessed);
1625 aSubFeature->setDisplayed(aConstraintDisplayed);
1627 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1630 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1632 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1633 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1634 return aConnector->workshop();
1637 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1639 return workshop()->operationMgr();