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_MultiRotation.h>
62 #include <SketchPlugin_MultiTranslation.h>
64 #include <SketcherPrs_Tools.h>
66 #include <SelectMgr_IndexedMapOfOwner.hxx>
67 #include <StdSelect_BRepOwner.hxx>
69 //#include <AIS_DimensionSelectionMode.hxx>
70 #include <AIS_Shape.hxx>
72 #include <ModelAPI_Events.h>
73 #include <ModelAPI_Session.h>
74 #include <ModelAPI_AttributeString.h>
76 #include <QMouseEvent>
77 #include <QApplication>
79 //#define DEBUG_DO_NOT_BY_ENTER
81 /// Returns list of unique objects by sum of objects from List1 and List2
82 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
83 const QList<ModuleBase_ViewerPrs>& theList2)
85 QList<ModuleBase_ViewerPrs> aRes;
86 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
87 if (!aRes.contains(aPrs))
90 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
91 if (!aRes.contains(aPrs))
97 // Fills the list of features the list of selected presentations.
98 // \param theList a list of selected presentations
99 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
100 // and find the corresponded attribute
101 // \param theFeatureList an output list of features
102 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
103 const FeaturePtr theSketch,
104 QList<FeaturePtr>& theFeatureList)
106 QList<ModuleBase_ViewerPrs> aRes;
108 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
109 aLast = theList.end();
110 for (; anIt != aLast; anIt++)
112 ModuleBase_ViewerPrs aPrs = *anIt;
113 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
114 if (aFeature.get() && !theFeatureList.contains(aFeature))
115 theFeatureList.append(aFeature);
119 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
120 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
121 /// result as is to the list of results.
122 /// \param theOwner a viewer selected owner
123 /// \param theFeature a feature, where the attribute is searched
124 /// \param theSketch a current sketch
125 /// \param theSelectedAttribute an output list of attributes
126 /// \param theSelectedResults an output list of edge results
127 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
128 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
129 const ResultPtr& theResult,
130 std::set<AttributePtr>& aSelectedAttributes,
131 std::set<ResultPtr>& aSelectedResults)
133 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
134 if (aBRepOwner.IsNull())
136 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
137 aBRepOwner->Selectable());
138 if (aBRepOwner->HasShape()) {
139 const TopoDS_Shape& aShape = aBRepOwner->Shape();
140 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
141 if (aShapeType == TopAbs_VERTEX) {
142 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
144 if (aPntAttr.get() != NULL)
145 aSelectedAttributes.insert(aPntAttr);
147 else if (aShapeType == TopAbs_EDGE &&
148 aSelectedResults.find(theResult) == aSelectedResults.end()) {
149 aSelectedResults.insert(theResult);
154 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
155 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
156 myIsMouseOverWindow(false),
157 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
158 myIsPopupMenuActive(false), myIsConstraintsShown(true)
160 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
161 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
163 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
165 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
166 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
168 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
169 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
171 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
172 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
174 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
175 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
177 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
178 XGUI_Workshop* aWorkshop = aConnector->workshop();
179 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
182 PartSet_SketcherMgr::~PartSet_SketcherMgr()
184 if (!myPlaneFilter.IsNull())
185 myPlaneFilter.Nullify();
188 void PartSet_SketcherMgr::onEnterViewPort()
190 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
191 // created feature because it should be done in onMouseMove(). Some widgets watch
192 // the mouse move and use the cursor position to update own values. If the presentaion is
193 // redisplayed before this update, the feature presentation jumps from reset value to current.
194 myIsMouseOverWindow = true;
196 #ifdef DEBUG_DO_NOT_BY_ENTER
200 if (canChangeCursor(getCurrentOperation()))
201 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
203 if (!isNestedCreateOperation(getCurrentOperation()))
206 operationMgr()->onValidateOperation();
208 // we need change displayed state of the current operation feature
209 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
210 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
211 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
212 // presentation becomes valid and redisplay happens
213 //ModuleBase_Operation* aOperation = getCurrentOperation();
214 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
215 (getCurrentOperation());
217 FeaturePtr aFeature = aFOperation->feature();
218 if (aFeature.get() && aFeature->data()->isValid()) {
219 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
224 void PartSet_SketcherMgr::onLeaveViewPort()
226 myIsMouseOverViewProcessed = false;
227 myIsMouseOverWindow = false;
228 // it is important to validate operation here only if sketch entity create operation is active
229 // because at this operation we reacts to the mouse leave/enter view port
230 //operationMgr()->onValidateOperation();
232 #ifdef DEBUG_DO_NOT_BY_ENTER
236 if (canChangeCursor(getCurrentOperation()))
237 QApplication::restoreOverrideCursor();
239 if (!isNestedCreateOperation(getCurrentOperation()))
242 // the method should be performed if the popup menu is called,
243 // the reset of the current widget should not happen
244 if (myIsPopupMenuActive)
247 operationMgr()->onValidateOperation();
249 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
250 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
251 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
252 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
253 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
254 // obtained after reset value
255 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
256 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
258 anActiveWidget->reset();
259 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
261 // hides the presentation of the current operation feature
262 // the feature is to be erased here, but it is correct to call canDisplayObject because
263 // there can be additional check (e.g. editor widget in distance constraint)
264 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
265 (getCurrentOperation());
267 FeaturePtr aFeature = aFOperation->feature();
268 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
272 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
274 if (isNestedCreateOperation(getCurrentOperation()))
276 // it is necessary to save current selection in order to restore it after the values are modifed
279 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
280 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
281 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
282 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
285 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
287 if (isNestedCreateOperation(getCurrentOperation()))
289 // it is necessary to restore current selection in order to restore it after the values are modified
291 myCurrentSelection.clear();
293 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
294 // viewer happens by deselect/select the modified objects. The flag should be restored after
295 // the selection processing. The update viewer should be also called.
296 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
297 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
298 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
299 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
300 aDisplayer->updateViewer();
303 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
305 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
308 get2dPoint(theWnd, theEvent, myClickedPoint);
310 if (!(theEvent->buttons() & Qt::LeftButton))
313 // Clear dragging mode
314 myIsDragging = false;
316 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
317 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
318 if (!aViewer->canDragByMouse())
321 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
322 (getCurrentOperation());
326 if (aFOperation->isEditOperation()) {
327 // If the current widget is a selector, do nothing, it processes the mouse press
328 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
329 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
334 // Use only for sketch operations
335 if (myCurrentSketch) {
336 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
339 bool isSketcher = isSketchOperation(aFOperation);
340 bool isSketchOpe = isNestedSketchOperation(aFOperation);
342 // Avoid non-sketch operations
343 if ((!isSketchOpe) && (!isSketcher))
346 bool isEditing = aFOperation->isEditOperation();
348 // Ignore creation sketch operation
349 if ((!isSketcher) && (!isEditing))
352 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
353 if (!aContext.IsNull()) {
354 // MoveTo in order to highlight current object
355 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
357 // Remember highlighted objects for editing
358 ModuleBase_ISelection* aSelect = aWorkshop->selection();
360 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
361 storeSelection(!aHasShift);
363 if (myCurrentSelection.empty()) {
364 if (isSketchOpe && (!isSketcher))
365 // commit previous operation
366 if (!aFOperation->commit())
367 aFOperation->abort();
370 // Init flyout point for radius rotation
371 FeaturePtr aFeature = myCurrentSelection.begin().key();
375 get2dPoint(theWnd, theEvent, myCurrentPoint);
377 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
378 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
380 if (aFeature.get() != NULL) {
381 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
382 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
383 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
384 DataPtr aData = aSPFeature->data();
385 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
386 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
387 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
388 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
391 } else if (isSketchOpe && isEditing) {
392 // If selected another object commit current result
393 aFOperation->commit();
396 get2dPoint(theWnd, theEvent, myCurrentPoint);
398 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
399 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
401 // This is necessary in order to finalize previous operation
402 QApplication::processEvents();
408 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
410 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
413 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
414 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
415 if (!aViewer->canDragByMouse())
417 ModuleBase_Operation* aOp = getCurrentOperation();
419 if (isNestedSketchOperation(aOp)) {
420 get2dPoint(theWnd, theEvent, myClickedPoint);
422 // Only for sketcher operations
426 myCurrentSelection.clear();
427 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
428 if (!aContext.IsNull()) {
429 // Reselect edited object
430 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
431 if (theEvent->modifiers() & Qt::ShiftModifier)
432 aContext->ShiftSelect();
440 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
441 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
442 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
443 myIsDragging = false;
446 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
448 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
451 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
452 myIsMouseOverViewProcessed = true;
453 // 1. perform the widget mouse move functionality and display the presentation
454 // the mouse move should be processed in the widget, if it can in order to visualize correct
455 // presentation. These widgets correct the feature attribute according to the mouse position
456 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
457 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
459 aPoint2DWdg->onMouseMove(theWnd, theEvent);
461 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
464 aDistanceWdg->onMouseMove(theWnd, theEvent);
466 // the feature is to be erased here, but it is correct to call canDisplayObject because
467 // there can be additional check (e.g. editor widget in distance constraint)
468 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
469 (getCurrentOperation());
471 FeaturePtr aFeature = aFOperation->feature();
472 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
476 myClickedPoint.clear();
479 // 1. the current selection is saved in the mouse press method in order to restore it after moving
480 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
481 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
482 // deselected). This flag should be restored in the slot, processed the mouse release signal.
484 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
485 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
486 //aViewer->enableSelection(false);
488 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
489 if (!aCurrentOperation)
491 if (isSketchOperation(aCurrentOperation))
492 return; // No edit operation activated
494 Handle(V3d_View) aView = theWnd->v3dView();
495 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
497 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
498 double dX = aX - myCurrentPoint.myCurX;
499 double dY = aY - myCurrentPoint.myCurY;
501 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
502 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
503 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
504 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
505 // viewer happens by deselect/select the modified objects. The flag should be restored after
506 // the selection processing. The update viewer should be also called.
507 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
509 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
510 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
511 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
512 aLast = myCurrentSelection.end();
513 // 4. the features and attributes modification(move)
514 bool isModified = false;
515 for (; anIt != aLast; anIt++) {
516 FeaturePtr aFeature = anIt.key();
518 std::set<AttributePtr> anAttributes = anIt.value().first;
519 // Process selection by attribute: the priority to the attribute
520 if (!anAttributes.empty()) {
521 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
522 anAttLast = anAttributes.end();
523 for (; anAttIt != anAttLast; anAttIt++) {
524 AttributePtr anAttr = *anAttIt;
525 if (anAttr.get() == NULL)
527 std::string aAttrId = anAttr->id();
528 DataPtr aData = aFeature->data();
529 if (aData->isValid()) {
530 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
531 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
532 if (aPoint.get() != NULL) {
533 bool isImmutable = aPoint->setImmutable(true);
534 aPoint->move(dX, dY);
536 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
537 aPoint->setImmutable(isImmutable);
542 // Process selection by feature
543 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
544 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
545 if (aSketchFeature) {
546 aSketchFeature->move(dX, dY);
548 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
552 // the modified state of the current operation should be updated if there are features, which
555 aCurrentOperation->onValuesChanged();
557 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
558 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
560 // 5. it is necessary to save current selection in order to restore it after the features moving
562 // 6. restore the update viewer flag and call this update
563 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
564 aDisplayer->updateViewer();
567 myCurrentPoint.setValue(aX, aY);
571 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
573 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
574 (getCurrentOperation());
575 if (aFOperation && aFOperation->isEditOperation()) {
576 std::string aId = aFOperation->id().toStdString();
577 if (isDistanceOperation(aFOperation))
579 // Activate dimension value editing on double click
580 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
581 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
582 // Find corresponded widget to activate value editing
583 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
584 if (aWgt->attributeID() == "ConstraintValue") {
585 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
587 anEditor->showPopupEditor();
595 void PartSet_SketcherMgr::onApplicationStarted()
597 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
598 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
599 XGUI_Workshop* aWorkshop = aConnector->workshop();
600 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
602 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
603 if (aPropertyPanel) {
604 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
605 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
607 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
608 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
609 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
610 aReentranceMgr, SLOT(onWidgetActivated()));
613 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
614 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
615 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
617 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
618 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
619 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
622 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
624 if (!myClickedPoint.myIsInitialized)
627 ModuleBase_Operation* aOperation = getCurrentOperation();
628 // the distance constraint feature should not use the clickedd point
629 // this is workaround in order to don't throw down the flyout point value,
630 // set by execute() method of these type of features
631 if (isDistanceOperation(aOperation))
634 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
636 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
640 void PartSet_SketcherMgr::onBeforeContextMenu()
642 myIsPopupMenuActive = true;
645 void PartSet_SketcherMgr::onAfterContextMenu()
647 myIsPopupMenuActive = false;
650 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
653 Handle(V3d_View) aView = theWnd->v3dView();
654 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
656 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
657 thePoint.setValue(aX, anY);
660 void PartSet_SketcherMgr::launchEditing()
662 if (!myCurrentSelection.empty()) {
663 FeaturePtr aFeature = myCurrentSelection.begin().key();
664 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
665 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
667 myModule->editFeature(aSPFeature);
672 bool PartSet_SketcherMgr::sketchSolverError()
674 bool anError = false;
675 CompositeFeaturePtr aSketch = activeSketch();
677 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
678 anError = !aAttributeString->value().empty();
683 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
685 QString anError = "";
686 if (!theFeature.get() || !theFeature->data()->isValid())
689 CompositeFeaturePtr aSketch = activeSketch();
690 if (aSketch.get() && aSketch == theFeature) {
691 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
692 anError = aAttributeString->value().c_str();
695 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
696 if (isCheckGUI && anActiveWidget) {
697 ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState();
698 if (aState != ModuleBase_ModelWidget::Stored) {
699 AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
701 QString anAttributeName = anAttr->id().c_str();
703 case ModuleBase_ModelWidget::ModifiedInPP:
704 anError = "Attribute \"" + anAttributeName +
705 "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
707 case ModuleBase_ModelWidget::ModifiedInViewer:
708 anError = "Attribute \"" + anAttributeName +
709 "\" is locked by modification value in the viewer.";
711 case ModuleBase_ModelWidget::Reset:
712 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
722 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
724 static QStringList aIds;
725 if (aIds.size() == 0) {
726 aIds << SketchPlugin_Line::ID().c_str();
727 aIds << SketchPlugin_Point::ID().c_str();
728 aIds << SketchPlugin_Arc::ID().c_str();
729 aIds << SketchPlugin_Circle::ID().c_str();
730 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
731 aIds.append(constraintsIdList());
736 const QStringList& PartSet_SketcherMgr::constraintsIdList()
738 static QStringList aIds;
739 if (aIds.size() == 0) {
740 aIds << SketchPlugin_ConstraintLength::ID().c_str();
741 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
742 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
743 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
744 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
745 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
746 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
747 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
748 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
749 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
750 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
751 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
752 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
753 aIds << SketchPlugin_MultiRotation::ID().c_str();
754 aIds << SketchPlugin_MultiTranslation::ID().c_str();
759 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
763 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
764 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
765 theModes.append(SketcherPrs_Tools::Sel_Constraint);
766 theModes.append(TopAbs_VERTEX);
767 theModes.append(TopAbs_EDGE);
770 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
772 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
775 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
777 return theOperation &&
778 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
781 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
783 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
785 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
788 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
790 return (theId == SketchPlugin_Line::ID()) ||
791 (theId == SketchPlugin_Point::ID()) ||
792 (theId == SketchPlugin_Arc::ID()) ||
793 (theId == SketchPlugin_Circle::ID());
796 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
798 std::string aId = theOperation ? theOperation->id().toStdString() : "";
800 return (aId == SketchPlugin_ConstraintLength::ID()) ||
801 (aId == SketchPlugin_ConstraintDistance::ID()) ||
802 (aId == SketchPlugin_ConstraintRadius::ID()) ||
803 (aId == SketchPlugin_ConstraintAngle::ID());
806 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
808 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
809 (getCurrentOperation());
813 myModule->onViewTransformed();
815 // Display all sketcher sub-Objects
816 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
817 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
819 // Hide sketcher result
820 std::list<ResultPtr> aResults = myCurrentSketch->results();
821 std::list<ResultPtr>::const_iterator aIt;
822 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
823 (*aIt)->setDisplayed(false);
825 myCurrentSketch->setDisplayed(false);
827 // Display sketcher objects
828 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
829 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
830 std::list<ResultPtr> aResults = aFeature->results();
831 std::list<ResultPtr>::const_iterator aIt;
832 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
833 (*aIt)->setDisplayed(true);
835 aFeature->setDisplayed(true);
838 if (myPlaneFilter.IsNull())
839 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
841 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
843 bool aHasPlane = false;
844 std::shared_ptr<GeomAPI_Pln> aPln;
845 if (aFOperation->isEditOperation()) {
846 // If it is editing of sketch then it means that plane is already defined
847 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
851 myPlaneFilter->setPlane(aPln);
853 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
854 // all sketch objects should be activated in the sketch selection modes by edit operation start
855 // in case of creation operation, there is an active widget, which activates own selection mode
856 if (aFOperation->isEditOperation() && aHasPlane)
857 aConnector->activateModuleSelectionModes();
860 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
862 myIsMouseOverWindow = false;
863 myIsConstraintsShown = true;
865 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
867 DataPtr aData = myCurrentSketch->data();
868 if (!aData->isValid()) {
869 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
870 // The sketch was aborted
871 myCurrentSketch = CompositeFeaturePtr();
872 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
874 // Erase all sketcher objects
875 QStringList aSketchIds = sketchOperationIdList();
876 QObjectPtrList aObjects = aDisplayer->displayedObjects();
877 foreach (ObjectPtr aObj, aObjects) {
878 DataPtr aObjData = aObj->data();
879 if (!aObjData->isValid())
880 aObj->setDisplayed(false);
884 // Hide all sketcher sub-Objects
885 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
886 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
887 std::list<ResultPtr> aResults = aFeature->results();
888 std::list<ResultPtr>::const_iterator aIt;
889 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
890 (*aIt)->setDisplayed(false);
892 aFeature->setDisplayed(false);
894 // Display sketcher result
895 std::list<ResultPtr> aResults = myCurrentSketch->results();
896 std::list<ResultPtr>::const_iterator aIt;
897 Events_Loop* aLoop = Events_Loop::loop();
898 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
900 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
902 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
903 if (!aFOperation->isDisplayedOnStart(*aIt)) {
904 (*aIt)->setDisplayed(true);
905 // this display event is needed because sketch already may have "displayed" state,
906 // but not displayed while it is still active (issue 613, abort of existing sketch)
907 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
910 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
911 myCurrentSketch->setDisplayed(true);
913 myCurrentSketch = CompositeFeaturePtr();
914 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
916 Events_Loop::loop()->flush(aDispEvent);
918 // restore the module selection modes, which were changed on startSketch
919 aConnector->activateModuleSelectionModes();
922 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
924 if (canChangeCursor(theOperation) && myIsMouseOverWindow)
925 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
928 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
930 myIsMouseOverViewProcessed = true;
931 operationMgr()->onValidateOperation();
932 if (canChangeCursor(theOperation))
933 QApplication::restoreOverrideCursor();
936 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
938 if (isNestedCreateOperation(theOperation)) {
939 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
942 FeaturePtr aFeature = aFOperation->feature();
943 // it is necessary to check the the feature data validity because
944 // some kind of features are removed by an operation commit(the macro state of a feature)
945 if (aFeature.get() && aFeature->data()->isValid()) {
946 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
952 bool PartSet_SketcherMgr::canUndo() const
954 return isNestedCreateOperation(getCurrentOperation());
957 bool PartSet_SketcherMgr::canRedo() const
959 return isNestedCreateOperation(getCurrentOperation());
962 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
964 bool aCanErase = true;
965 // when the sketch operation is active, results of sketch sub-feature can not be hidden
966 if (myCurrentSketch.get()) {
967 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
969 // Display sketcher objects
970 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
972 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
973 std::list<ResultPtr> aResults = aFeature->results();
974 std::list<ResultPtr>::const_iterator anIt;
975 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
976 aCanErase = *anIt != aResult;
984 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
986 bool aCanDisplay = true;
988 bool aHasActiveSketch = activeSketch().get() != NULL;
989 if (aHasActiveSketch) {
990 // 1. the sketch feature should not be displayed during the sketch active operation
991 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
992 // nested features can be visualized
993 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
994 if (aFeature.get() != NULL && aFeature == activeSketch()) {
998 else { // there are no an active sketch
999 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1000 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1001 if (aFeature.get() != NULL) {
1002 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1003 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1004 if (aSketchFeature.get()) {
1005 aCanDisplay = false;
1010 // 3. the method should not filter the objects, which are not related to the current operation.
1011 // The object is filtered just if it is a current operation feature or this feature result
1012 bool isObjectFound = false;
1013 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1014 (getCurrentOperation());
1016 FeaturePtr aFeature = aFOperation->feature();
1017 if (aFeature.get()) {
1018 std::list<ResultPtr> aResults = aFeature->results();
1019 if (theObject == aFeature)
1020 isObjectFound = true;
1022 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1023 for (; anIt != aLast && !isObjectFound; anIt++) {
1024 isObjectFound = *anIt == theObject;
1032 // 4. For created nested feature operation do not display the created feature if
1033 // the mouse curstor leaves the OCC window.
1034 // The correction cases, which ignores this condition:
1035 // a. the property panel values modification
1036 // b. the popup menu activated
1037 // c. widget editor control
1038 #ifndef DEBUG_DO_NOT_BY_ENTER
1039 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1040 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1041 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1042 // the active widget editor should not influence here. The presentation should be visible always
1043 // when this widget is active.
1044 if (!anEditorWdg && !myIsPopupMenuActive) {
1045 // during a nested create operation, the feature is redisplayed only if the mouse over view
1046 // of there was a value modified in the property panel after the mouse left the view
1047 aCanDisplay = canDisplayCurrentCreatedFeature();
1054 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1056 bool aCanDisplay = myIsMouseOverWindow;
1058 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1060 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1065 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1067 return isNestedCreateOperation(theOperation) ||
1068 myModule->sketchReentranceMgr()->isInternalEditActive();
1071 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1073 bool isFoundObject = false;
1075 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1076 if (anObjectFeature.get()) {
1077 int aSize = myCurrentSketch->numberOfSubs();
1078 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1079 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1080 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1083 return isFoundObject;
1086 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1088 if (myPlaneFilter.IsNull())
1089 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1091 myPlaneFilter->setPlane(thePln);
1094 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1095 const FeaturePtr& theSketch,
1096 ModuleBase_IWorkshop* theWorkshop,
1097 FeatureToSelectionMap& theSelection)
1099 if (theFeature.get() == NULL)
1102 std::set<AttributePtr> aSelectedAttributes;
1103 std::set<ResultPtr> aSelectedResults;
1105 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1106 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1107 if (!aContext.IsNull()) {
1108 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1109 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1111 std::list<ResultPtr> aResults = theFeature->results();
1112 std::list<ResultPtr>::const_iterator aIt;
1113 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1115 ResultPtr aResult = *aIt;
1116 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1117 if (aAISObj.get() == NULL)
1119 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1120 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1122 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1123 if (anOwner->Selectable() != anAISIO)
1125 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1126 aSelectedAttributes, aSelectedResults);
1128 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1129 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1130 if (anOwner.IsNull())
1132 if (anOwner->Selectable() != anAISIO)
1134 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1135 aSelectedAttributes, aSelectedResults);
1139 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1142 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1143 const FeaturePtr& theSketch,
1144 ModuleBase_IWorkshop* theWorkshop,
1145 const FeatureToSelectionMap& theSelection,
1146 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1148 if (theFeature.get() == NULL)
1151 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1152 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1153 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1155 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1157 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1158 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1160 // 1. found the feature's owners. Check the AIS objects of the constructions
1161 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1162 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1163 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1165 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1166 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1167 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1168 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1169 if (!anOwner.IsNull())
1170 theOwnersToSelect.Add(anOwner);
1174 // 2. found the feature results's owners
1175 std::list<ResultPtr> aResults = theFeature->results();
1176 std::list<ResultPtr>::const_iterator aIt;
1177 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1179 ResultPtr aResult = *aIt;
1180 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1181 if (aAISObj.get() == NULL)
1183 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1185 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1186 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1187 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1188 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1189 if ( anOwner.IsNull() || !anOwner->HasShape() )
1191 const TopoDS_Shape& aShape = anOwner->Shape();
1192 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1193 if (aShapeType == TopAbs_VERTEX) {
1194 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1195 if (aPntAttr.get() != NULL &&
1196 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1197 theOwnersToSelect.Add(anOwner);
1200 else if (aShapeType == TopAbs_EDGE) {
1201 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1202 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1203 theOwnersToSelect.FindIndex(anOwner) <= 0)
1204 theOwnersToSelect.Add(anOwner);
1210 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1213 connect(theWidget, SIGNAL(beforeValuesChanged()),
1214 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1215 connect(theWidget, SIGNAL(afterValuesChanged()),
1216 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1219 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1220 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1221 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1222 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1226 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1228 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1229 (getCurrentOperation());
1231 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1232 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1233 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1234 FeaturePtr aFeature = aFOperation->feature();
1235 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1240 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1242 return myModule->workshop()->currentOperation();
1245 //**************************************************************
1246 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1248 ModuleBase_ModelWidget* aWidget = 0;
1249 ModuleBase_Operation* anOperation = getCurrentOperation();
1251 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1253 aWidget = aPanel->activeWidget();
1258 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1259 const bool isEditOperation,
1260 const bool isToDisplay,
1261 const bool isFlushRedisplay)
1263 #ifdef DEBUG_DO_NOT_BY_ENTER
1267 if (isEditOperation || !theFeature.get())
1270 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1271 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1273 // 1. change visibility of the object itself, here the presentable object is processed,
1274 // e.g. constraints features
1275 //FeaturePtr aFeature = aFOperation->feature();
1276 std::list<ResultPtr> aResults = theFeature->results();
1278 theFeature->setDisplayed(true);
1280 theFeature->setDisplayed(false);
1282 // change visibility of the object results, e.g. non-constraint features
1283 std::list<ResultPtr>::const_iterator aIt;
1284 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1286 (*aIt)->setDisplayed(true);
1289 (*aIt)->setDisplayed(false);
1292 if (isFlushRedisplay)
1293 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1296 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1298 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1299 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1300 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1302 QList<FeaturePtr> aFeatureList;
1303 if (theHighlightedOnly) {
1304 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1307 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1309 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1310 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1313 // 1. it is necessary to save current selection in order to restore it after the features moving
1314 myCurrentSelection.clear();
1315 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1316 for (; anIt != aLast; anIt++) {
1317 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1319 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1322 void PartSet_SketcherMgr::restoreSelection()
1324 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1325 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1326 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1327 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1328 aSLast = myCurrentSelection.end();
1329 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1330 for (; aSIt != aSLast; aSIt++) {
1331 anOwnersToSelect.Clear();
1332 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1334 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1338 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1340 if (myIsConstraintsShown == theOn)
1342 if (myCurrentSketch.get() == NULL)
1345 myIsConstraintsShown = theOn;
1347 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1348 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1350 const QStringList& aConstrIds = constraintsIdList();
1351 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1352 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1353 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1354 if (myIsConstraintsShown)
1355 aSubFeature->setDisplayed(true);
1357 aSubFeature->setDisplayed(false);
1360 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1363 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1365 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1366 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1367 XGUI_Workshop* aWorkshop = aConnector->workshop();
1369 return aWorkshop->operationMgr();