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"
15 #include <XGUI_ModuleConnector.h>
16 #include <XGUI_Displayer.h>
17 #include <XGUI_Workshop.h>
18 #include <XGUI_ContextMenuMgr.h>
19 #include <XGUI_Selection.h>
20 #include <XGUI_SelectionMgr.h>
21 #include <XGUI_ModuleConnector.h>
22 #include <XGUI_PropertyPanel.h>
23 #include <XGUI_ViewerProxy.h>
24 #include <XGUI_OperationMgr.h>
26 #include <ModuleBase_IPropertyPanel.h>
27 #include <ModuleBase_ISelection.h>
28 #include <ModuleBase_IViewer.h>
29 #include <ModuleBase_IWorkshop.h>
30 #include <ModuleBase_IViewWindow.h>
31 #include <ModuleBase_ModelWidget.h>
32 #include <ModuleBase_Operation.h>
33 #include <ModuleBase_OperationFeature.h>
34 #include <ModuleBase_Operation.h>
35 #include <ModuleBase_WidgetEditor.h>
37 #include <GeomDataAPI_Point2D.h>
39 #include <Events_Loop.h>
41 #include <SketchPlugin_Line.h>
42 #include <SketchPlugin_Sketch.h>
43 #include <SketchPlugin_Point.h>
44 #include <SketchPlugin_Arc.h>
45 #include <SketchPlugin_Circle.h>
46 #include <SketchPlugin_ConstraintLength.h>
47 #include <SketchPlugin_ConstraintDistance.h>
48 #include <SketchPlugin_ConstraintParallel.h>
49 #include <SketchPlugin_ConstraintPerpendicular.h>
50 #include <SketchPlugin_ConstraintRadius.h>
51 #include <SketchPlugin_ConstraintRigid.h>
52 #include <SketchPlugin_ConstraintHorizontal.h>
53 #include <SketchPlugin_ConstraintVertical.h>
54 #include <SketchPlugin_ConstraintEqual.h>
55 #include <SketchPlugin_ConstraintTangent.h>
56 #include <SketchPlugin_ConstraintCoincidence.h>
57 #include <SketchPlugin_ConstraintFillet.h>
58 #include <SketchPlugin_ConstraintMirror.h>
59 #include <SketchPlugin_ConstraintAngle.h>
60 #include <SketchPlugin_MultiRotation.h>
61 #include <SketchPlugin_MultiTranslation.h>
63 #include <SketcherPrs_Tools.h>
65 #include <SelectMgr_IndexedMapOfOwner.hxx>
66 #include <StdSelect_BRepOwner.hxx>
68 //#include <AIS_DimensionSelectionMode.hxx>
69 #include <AIS_Shape.hxx>
71 #include <ModelAPI_Events.h>
72 #include <ModelAPI_Session.h>
73 #include <ModelAPI_AttributeString.h>
75 #include <QMouseEvent>
76 #include <QApplication>
78 //#define DEBUG_DO_NOT_BY_ENTER
80 /// Returns list of unique objects by sum of objects from List1 and List2
81 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
82 const QList<ModuleBase_ViewerPrs>& theList2)
84 QList<ModuleBase_ViewerPrs> aRes;
85 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
86 if (!aRes.contains(aPrs))
89 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
90 if (!aRes.contains(aPrs))
96 // Fills the list of features the list of selected presentations.
97 // \param theList a list of selected presentations
98 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
99 // and find the corresponded attribute
100 // \param theFeatureList an output list of features
101 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
102 const FeaturePtr theSketch,
103 QList<FeaturePtr>& theFeatureList)
105 QList<ModuleBase_ViewerPrs> aRes;
107 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
108 aLast = theList.end();
109 for (; anIt != aLast; anIt++)
111 ModuleBase_ViewerPrs aPrs = *anIt;
112 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
113 if (aFeature.get() && !theFeatureList.contains(aFeature))
114 theFeatureList.append(aFeature);
118 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
119 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
120 /// result as is to the list of results.
121 /// \param theOwner a viewer selected owner
122 /// \param theFeature a feature, where the attribute is searched
123 /// \param theSketch a current sketch
124 /// \param theSelectedAttribute an output list of attributes
125 /// \param theSelectedResults an output list of edge results
126 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
127 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
128 const ResultPtr& theResult,
129 std::set<AttributePtr>& aSelectedAttributes,
130 std::set<ResultPtr>& aSelectedResults)
132 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
133 if (aBRepOwner.IsNull())
135 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
136 aBRepOwner->Selectable());
137 if (aBRepOwner->HasShape()) {
138 const TopoDS_Shape& aShape = aBRepOwner->Shape();
139 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
140 if (aShapeType == TopAbs_VERTEX) {
141 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
143 if (aPntAttr.get() != NULL)
144 aSelectedAttributes.insert(aPntAttr);
146 else if (aShapeType == TopAbs_EDGE &&
147 aSelectedResults.find(theResult) == aSelectedResults.end()) {
148 aSelectedResults.insert(theResult);
153 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
154 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
155 myIsMouseOverWindow(false),
156 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
157 myIsPopupMenuActive(false), myIsConstraintsShown(true)
159 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
160 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
162 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
164 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
165 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
167 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
168 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
170 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
171 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
173 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
174 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
176 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
177 XGUI_Workshop* aWorkshop = aConnector->workshop();
178 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
181 PartSet_SketcherMgr::~PartSet_SketcherMgr()
183 if (!myPlaneFilter.IsNull())
184 myPlaneFilter.Nullify();
187 void PartSet_SketcherMgr::onEnterViewPort()
189 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
190 // created feature because it should be done in onMouseMove(). Some widgets watch
191 // the mouse move and use the cursor position to update own values. If the presentaion is
192 // redisplayed before this update, the feature presentation jumps from reset value to current.
193 myIsMouseOverWindow = true;
195 #ifdef DEBUG_DO_NOT_BY_ENTER
199 if (!isNestedCreateOperation(getCurrentOperation()))
202 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
204 operationMgr()->onValidateOperation();
206 // we need change displayed state of the current operation feature
207 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
208 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
209 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
210 // presentation becomes valid and redisplay happens
211 //ModuleBase_Operation* aOperation = getCurrentOperation();
212 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
213 (getCurrentOperation());
215 FeaturePtr aFeature = aFOperation->feature();
216 if (aFeature.get() && aFeature->data()->isValid()) {
217 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
222 void PartSet_SketcherMgr::onLeaveViewPort()
224 myIsMouseOverViewProcessed = false;
225 myIsMouseOverWindow = false;
226 // it is important to validate operation here only if sketch entity create operation is active
227 // because at this operation we reacts to the mouse leave/enter view port
228 //operationMgr()->onValidateOperation();
230 #ifdef DEBUG_DO_NOT_BY_ENTER
234 if (!isNestedCreateOperation(getCurrentOperation()))
237 QApplication::restoreOverrideCursor();
239 // the method should be performed if the popup menu is called,
240 // the reset of the current widget should not happen
241 if (myIsPopupMenuActive)
244 operationMgr()->onValidateOperation();
246 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
247 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
248 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
249 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
250 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
251 // obtained after reset value
252 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
253 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
255 anActiveWidget->reset();
256 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
258 // hides the presentation of the current operation feature
259 // the feature is to be erased here, but it is correct to call canDisplayObject because
260 // there can be additional check (e.g. editor widget in distance constraint)
261 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
262 (getCurrentOperation());
264 FeaturePtr aFeature = aFOperation->feature();
265 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
269 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
271 if (isNestedCreateOperation(getCurrentOperation()))
273 // it is necessary to save current selection in order to restore it after the values are modifed
276 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
277 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
278 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
279 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
282 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
284 if (isNestedCreateOperation(getCurrentOperation()))
286 // it is necessary to restore current selection in order to restore it after the values are modified
288 myCurrentSelection.clear();
290 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
291 // viewer happens by deselect/select the modified objects. The flag should be restored after
292 // the selection processing. The update viewer should be also called.
293 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
294 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
295 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
296 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
297 aDisplayer->updateViewer();
300 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
302 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
305 get2dPoint(theWnd, theEvent, myClickedPoint);
307 if (!(theEvent->buttons() & Qt::LeftButton))
310 // Clear dragging mode
311 myIsDragging = false;
313 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
314 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
315 if (!aViewer->canDragByMouse())
318 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
319 (getCurrentOperation());
323 if (aFOperation->isEditOperation()) {
324 // If the current widget is a selector, do nothing, it processes the mouse press
325 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
326 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
331 // Use only for sketch operations
332 if (myCurrentSketch) {
333 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
336 bool isSketcher = isSketchOperation(aFOperation);
337 bool isSketchOpe = isNestedSketchOperation(aFOperation);
339 // Avoid non-sketch operations
340 if ((!isSketchOpe) && (!isSketcher))
343 bool isEditing = aFOperation->isEditOperation();
345 // Ignore creation sketch operation
346 if ((!isSketcher) && (!isEditing))
349 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
350 if (!aContext.IsNull()) {
351 // MoveTo in order to highlight current object
352 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
354 // Remember highlighted objects for editing
355 ModuleBase_ISelection* aSelect = aWorkshop->selection();
357 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
358 storeSelection(!aHasShift);
360 if (myCurrentSelection.empty()) {
361 if (isSketchOpe && (!isSketcher))
362 // commit previous operation
363 if (!aFOperation->commit())
364 aFOperation->abort();
367 // Init flyout point for radius rotation
368 FeaturePtr aFeature = myCurrentSelection.begin().key();
372 get2dPoint(theWnd, theEvent, myCurrentPoint);
374 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
375 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
377 if (aFeature.get() != NULL) {
378 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
379 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
380 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
381 DataPtr aData = aSPFeature->data();
382 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
383 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
384 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
385 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
388 } else if (isSketchOpe && isEditing) {
389 // If selected another object commit current result
390 aFOperation->commit();
393 get2dPoint(theWnd, theEvent, myCurrentPoint);
395 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
396 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
398 // This is necessary in order to finalize previous operation
399 QApplication::processEvents();
405 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
407 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
410 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
411 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
412 if (!aViewer->canDragByMouse())
414 ModuleBase_Operation* aOp = getCurrentOperation();
416 if (isNestedSketchOperation(aOp)) {
417 get2dPoint(theWnd, theEvent, myClickedPoint);
419 // Only for sketcher operations
423 myCurrentSelection.clear();
424 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
425 if (!aContext.IsNull()) {
426 // Reselect edited object
427 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
428 if (theEvent->modifiers() & Qt::ShiftModifier)
429 aContext->ShiftSelect();
437 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
438 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
439 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
440 myIsDragging = false;
443 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
445 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
448 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
449 myIsMouseOverViewProcessed = true;
450 // 1. perform the widget mouse move functionality and display the presentation
451 // the mouse move should be processed in the widget, if it can in order to visualize correct
452 // presentation. These widgets correct the feature attribute according to the mouse position
453 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
454 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
456 aPoint2DWdg->onMouseMove(theWnd, theEvent);
458 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
461 aDistanceWdg->onMouseMove(theWnd, theEvent);
463 // the feature is to be erased here, but it is correct to call canDisplayObject because
464 // there can be additional check (e.g. editor widget in distance constraint)
465 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
466 (getCurrentOperation());
468 FeaturePtr aFeature = aFOperation->feature();
469 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
473 myClickedPoint.clear();
476 // 1. the current selection is saved in the mouse press method in order to restore it after moving
477 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
478 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
479 // deselected). This flag should be restored in the slot, processed the mouse release signal.
481 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
482 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
483 //aViewer->enableSelection(false);
485 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
486 if (!aCurrentOperation)
488 if (isSketchOperation(aCurrentOperation))
489 return; // No edit operation activated
491 Handle(V3d_View) aView = theWnd->v3dView();
492 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
494 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
495 double dX = aX - myCurrentPoint.myCurX;
496 double dY = aY - myCurrentPoint.myCurY;
498 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
499 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
500 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
501 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
502 // viewer happens by deselect/select the modified objects. The flag should be restored after
503 // the selection processing. The update viewer should be also called.
504 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
506 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
507 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
508 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
509 aLast = myCurrentSelection.end();
510 // 4. the features and attributes modification(move)
511 bool isModified = false;
512 for (; anIt != aLast; anIt++) {
513 FeaturePtr aFeature = anIt.key();
515 std::set<AttributePtr> anAttributes = anIt.value().first;
516 // Process selection by attribute: the priority to the attribute
517 if (!anAttributes.empty()) {
518 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
519 anAttLast = anAttributes.end();
520 for (; anAttIt != anAttLast; anAttIt++) {
521 AttributePtr anAttr = *anAttIt;
522 if (anAttr.get() == NULL)
524 std::string aAttrId = anAttr->id();
525 DataPtr aData = aFeature->data();
526 if (aData->isValid()) {
527 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
528 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
529 if (aPoint.get() != NULL) {
530 bool isImmutable = aPoint->setImmutable(true);
531 aPoint->move(dX, dY);
533 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
534 aPoint->setImmutable(isImmutable);
539 // Process selection by feature
540 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
541 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
542 if (aSketchFeature) {
543 aSketchFeature->move(dX, dY);
545 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
549 // the modified state of the current operation should be updated if there are features, which
552 aCurrentOperation->onValuesChanged();
554 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
555 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
557 // 5. it is necessary to save current selection in order to restore it after the features moving
559 // 6. restore the update viewer flag and call this update
560 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
561 aDisplayer->updateViewer();
564 myCurrentPoint.setValue(aX, aY);
568 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
570 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
571 (getCurrentOperation());
572 if (aFOperation && aFOperation->isEditOperation()) {
573 std::string aId = aFOperation->id().toStdString();
574 if (isDistanceOperation(aFOperation))
576 // Activate dimension value editing on double click
577 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
578 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
579 // Find corresponded widget to activate value editing
580 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
581 if (aWgt->attributeID() == "ConstraintValue") {
590 void PartSet_SketcherMgr::onApplicationStarted()
592 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
593 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
594 XGUI_Workshop* aWorkshop = aConnector->workshop();
595 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
597 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
598 if (aPropertyPanel) {
599 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
600 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
602 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
603 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
604 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
605 aReentranceMgr, SLOT(onWidgetActivated()));
608 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
609 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
610 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
612 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
613 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
614 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
617 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
619 if (!myClickedPoint.myIsInitialized)
622 ModuleBase_Operation* aOperation = getCurrentOperation();
623 // the distance constraint feature should not use the clickedd point
624 // this is workaround in order to don't throw down the flyout point value,
625 // set by execute() method of these type of features
626 if (isDistanceOperation(aOperation))
629 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
631 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
635 void PartSet_SketcherMgr::onBeforeContextMenu()
637 myIsPopupMenuActive = true;
640 void PartSet_SketcherMgr::onAfterContextMenu()
642 myIsPopupMenuActive = false;
645 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
648 Handle(V3d_View) aView = theWnd->v3dView();
649 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
651 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
652 thePoint.setValue(aX, anY);
655 void PartSet_SketcherMgr::launchEditing()
657 if (!myCurrentSelection.empty()) {
658 FeaturePtr aFeature = myCurrentSelection.begin().key();
659 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
660 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
662 myModule->editFeature(aSPFeature);
667 bool PartSet_SketcherMgr::sketchSolverError()
669 bool anError = false;
670 CompositeFeaturePtr aSketch = activeSketch();
672 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
673 anError = !aAttributeString->value().empty();
678 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
680 QString anError = "";
681 if (!theFeature.get() || !theFeature->data()->isValid())
684 CompositeFeaturePtr aSketch = activeSketch();
685 if (aSketch.get() && aSketch == theFeature) {
686 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
687 anError = aAttributeString->value().c_str();
690 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
691 if (isCheckGUI && anActiveWidget) {
692 ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState();
693 if (aState != ModuleBase_ModelWidget::Stored) {
694 AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
696 QString anAttributeName = anAttr->id().c_str();
698 case ModuleBase_ModelWidget::ModifiedInPP:
699 anError = "Attribute \"" + anAttributeName +
700 "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
702 case ModuleBase_ModelWidget::ModifiedInViewer:
703 anError = "Attribute \"" + anAttributeName +
704 "\" is locked by modification value in the viewer.";
706 case ModuleBase_ModelWidget::Reset:
707 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
717 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
719 static QStringList aIds;
720 if (aIds.size() == 0) {
721 aIds << SketchPlugin_Line::ID().c_str();
722 aIds << SketchPlugin_Point::ID().c_str();
723 aIds << SketchPlugin_Arc::ID().c_str();
724 aIds << SketchPlugin_Circle::ID().c_str();
725 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
726 aIds.append(constraintsIdList());
731 const QStringList& PartSet_SketcherMgr::constraintsIdList()
733 static QStringList aIds;
734 if (aIds.size() == 0) {
735 aIds << SketchPlugin_ConstraintLength::ID().c_str();
736 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
737 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
738 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
739 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
740 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
741 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
742 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
743 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
744 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
745 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
746 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
747 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
748 aIds << SketchPlugin_MultiRotation::ID().c_str();
749 aIds << SketchPlugin_MultiTranslation::ID().c_str();
754 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
758 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
759 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
760 theModes.append(SketcherPrs_Tools::Sel_Constraint);
761 theModes.append(TopAbs_VERTEX);
762 theModes.append(TopAbs_EDGE);
765 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
767 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
770 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
772 return theOperation &&
773 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
776 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
778 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
780 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
783 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
785 return (theId == SketchPlugin_Line::ID()) ||
786 (theId == SketchPlugin_Point::ID()) ||
787 (theId == SketchPlugin_Arc::ID()) ||
788 (theId == SketchPlugin_Circle::ID());
791 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
793 std::string aId = theOperation ? theOperation->id().toStdString() : "";
795 return (aId == SketchPlugin_ConstraintLength::ID()) ||
796 (aId == SketchPlugin_ConstraintDistance::ID()) ||
797 (aId == SketchPlugin_ConstraintRadius::ID()) ||
798 (aId == SketchPlugin_ConstraintAngle::ID());
801 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
803 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
804 (getCurrentOperation());
808 myModule->onViewTransformed();
810 // Display all sketcher sub-Objects
811 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
812 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
814 // Hide sketcher result
815 std::list<ResultPtr> aResults = myCurrentSketch->results();
816 std::list<ResultPtr>::const_iterator aIt;
817 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
818 (*aIt)->setDisplayed(false);
820 myCurrentSketch->setDisplayed(false);
822 // Display sketcher objects
823 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
824 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
825 std::list<ResultPtr> aResults = aFeature->results();
826 std::list<ResultPtr>::const_iterator aIt;
827 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
828 (*aIt)->setDisplayed(true);
830 aFeature->setDisplayed(true);
833 if (myPlaneFilter.IsNull())
834 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
836 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
838 bool aHasPlane = false;
839 std::shared_ptr<GeomAPI_Pln> aPln;
840 if (aFOperation->isEditOperation()) {
841 // If it is editing of sketch then it means that plane is already defined
842 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
846 myPlaneFilter->setPlane(aPln);
848 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
849 // all sketch objects should be activated in the sketch selection modes by edit operation start
850 // in case of creation operation, there is an active widget, which activates own selection mode
851 if (aFOperation->isEditOperation() && aHasPlane)
852 aConnector->activateModuleSelectionModes();
855 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
857 myIsMouseOverWindow = false;
858 myIsConstraintsShown = true;
860 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
862 DataPtr aData = myCurrentSketch->data();
863 if (!aData->isValid()) {
864 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
865 // The sketch was aborted
866 myCurrentSketch = CompositeFeaturePtr();
867 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
869 // Erase all sketcher objects
870 QStringList aSketchIds = sketchOperationIdList();
871 QObjectPtrList aObjects = aDisplayer->displayedObjects();
872 foreach (ObjectPtr aObj, aObjects) {
873 DataPtr aObjData = aObj->data();
874 if (!aObjData->isValid())
875 aObj->setDisplayed(false);
879 // Hide all sketcher sub-Objects
880 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
881 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
882 std::list<ResultPtr> aResults = aFeature->results();
883 std::list<ResultPtr>::const_iterator aIt;
884 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
885 (*aIt)->setDisplayed(false);
887 aFeature->setDisplayed(false);
889 // Display sketcher result
890 std::list<ResultPtr> aResults = myCurrentSketch->results();
891 std::list<ResultPtr>::const_iterator aIt;
892 Events_Loop* aLoop = Events_Loop::loop();
893 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
895 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
897 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
898 if (!aFOperation->isDisplayedOnStart(*aIt)) {
899 (*aIt)->setDisplayed(true);
900 // this display event is needed because sketch already may have "displayed" state,
901 // but not displayed while it is still active (issue 613, abort of existing sketch)
902 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
905 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
906 myCurrentSketch->setDisplayed(true);
908 myCurrentSketch = CompositeFeaturePtr();
909 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
911 Events_Loop::loop()->flush(aDispEvent);
913 // restore the module selection modes, which were changed on startSketch
914 aConnector->activateModuleSelectionModes();
917 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
919 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
920 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
923 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
925 myIsMouseOverViewProcessed = true;
926 operationMgr()->onValidateOperation();
927 if (isNestedCreateOperation(theOp) || myModule->sketchReentranceMgr()->isInternalEditActive())
928 QApplication::restoreOverrideCursor();
931 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
933 if (isNestedCreateOperation(theOperation)) {
934 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
937 FeaturePtr aFeature = aFOperation->feature();
938 // it is necessary to check the the feature data validity because
939 // some kind of features are removed by an operation commit(the macro state of a feature)
940 if (aFeature.get() && aFeature->data()->isValid()) {
941 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
947 bool PartSet_SketcherMgr::canUndo() const
949 return isNestedCreateOperation(getCurrentOperation());
952 bool PartSet_SketcherMgr::canRedo() const
954 return isNestedCreateOperation(getCurrentOperation());
957 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
959 bool aCanErase = true;
960 // when the sketch operation is active, results of sketch sub-feature can not be hidden
961 if (myCurrentSketch.get()) {
962 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
964 // Display sketcher objects
965 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
967 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
968 std::list<ResultPtr> aResults = aFeature->results();
969 std::list<ResultPtr>::const_iterator anIt;
970 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
971 aCanErase = *anIt != aResult;
979 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
981 bool aCanDisplay = true;
983 bool aHasActiveSketch = activeSketch().get() != NULL;
984 if (aHasActiveSketch) {
985 // 1. the sketch feature should not be displayed during the sketch active operation
986 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
987 // nested features can be visualized
988 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
989 if (aFeature.get() != NULL && aFeature == activeSketch()) {
993 else { // there are no an active sketch
994 // 2. sketch sub-features should not be visualized if the sketch operation is not active
995 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
996 if (aFeature.get() != NULL) {
997 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
998 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
999 if (aSketchFeature.get()) {
1000 aCanDisplay = false;
1005 // 3. the method should not filter the objects, which are not related to the current operation.
1006 // The object is filtered just if it is a current operation feature or this feature result
1007 bool isObjectFound = false;
1008 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1009 (getCurrentOperation());
1011 FeaturePtr aFeature = aFOperation->feature();
1012 if (aFeature.get()) {
1013 std::list<ResultPtr> aResults = aFeature->results();
1014 if (theObject == aFeature)
1015 isObjectFound = true;
1017 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1018 for (; anIt != aLast && !isObjectFound; anIt++) {
1019 isObjectFound = *anIt == theObject;
1027 // 4. For created nested feature operation do not display the created feature if
1028 // the mouse curstor leaves the OCC window.
1029 // The correction cases, which ignores this condition:
1030 // a. the property panel values modification
1031 // b. the popup menu activated
1032 // c. widget editor control
1033 #ifndef DEBUG_DO_NOT_BY_ENTER
1034 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1035 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1036 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1037 // the active widget editor should not influence here. The presentation should be visible always
1038 // when this widget is active.
1039 if (!anEditorWdg && !myIsPopupMenuActive) {
1040 // during a nested create operation, the feature is redisplayed only if the mouse over view
1041 // of there was a value modified in the property panel after the mouse left the view
1042 aCanDisplay = canDisplayCurrentCreatedFeature();
1049 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1051 bool aCanDisplay = myIsMouseOverWindow;
1053 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1055 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1060 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1062 bool isFoundObject = false;
1064 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1065 if (anObjectFeature.get()) {
1066 int aSize = myCurrentSketch->numberOfSubs();
1067 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1068 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1069 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1072 return isFoundObject;
1075 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1077 if (myPlaneFilter.IsNull())
1078 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1080 myPlaneFilter->setPlane(thePln);
1083 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1084 const FeaturePtr& theSketch,
1085 ModuleBase_IWorkshop* theWorkshop,
1086 FeatureToSelectionMap& theSelection)
1088 if (theFeature.get() == NULL)
1091 std::set<AttributePtr> aSelectedAttributes;
1092 std::set<ResultPtr> aSelectedResults;
1094 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1095 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1096 if (!aContext.IsNull()) {
1097 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1098 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1100 std::list<ResultPtr> aResults = theFeature->results();
1101 std::list<ResultPtr>::const_iterator aIt;
1102 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1104 ResultPtr aResult = *aIt;
1105 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1106 if (aAISObj.get() == NULL)
1108 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1109 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1111 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1112 if (anOwner->Selectable() != anAISIO)
1114 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1115 aSelectedAttributes, aSelectedResults);
1117 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1118 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1119 if (anOwner.IsNull())
1121 if (anOwner->Selectable() != anAISIO)
1123 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1124 aSelectedAttributes, aSelectedResults);
1128 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1131 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1132 const FeaturePtr& theSketch,
1133 ModuleBase_IWorkshop* theWorkshop,
1134 const FeatureToSelectionMap& theSelection,
1135 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1137 if (theFeature.get() == NULL)
1140 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1141 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1142 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1144 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1146 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1147 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1149 // 1. found the feature's owners. Check the AIS objects of the constructions
1150 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1151 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1152 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1154 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1155 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1156 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1157 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1158 if (!anOwner.IsNull())
1159 theOwnersToSelect.Add(anOwner);
1163 // 2. found the feature results's owners
1164 std::list<ResultPtr> aResults = theFeature->results();
1165 std::list<ResultPtr>::const_iterator aIt;
1166 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1168 ResultPtr aResult = *aIt;
1169 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1170 if (aAISObj.get() == NULL)
1172 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1174 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1175 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1176 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1177 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1178 if ( anOwner.IsNull() || !anOwner->HasShape() )
1180 const TopoDS_Shape& aShape = anOwner->Shape();
1181 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1182 if (aShapeType == TopAbs_VERTEX) {
1183 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1184 if (aPntAttr.get() != NULL &&
1185 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1186 theOwnersToSelect.Add(anOwner);
1189 else if (aShapeType == TopAbs_EDGE) {
1190 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1191 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1192 theOwnersToSelect.FindIndex(anOwner) <= 0)
1193 theOwnersToSelect.Add(anOwner);
1199 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1202 connect(theWidget, SIGNAL(beforeValuesChanged()),
1203 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1204 connect(theWidget, SIGNAL(afterValuesChanged()),
1205 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1208 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1209 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1210 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1211 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1215 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1217 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1218 (getCurrentOperation());
1220 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1221 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1222 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1223 FeaturePtr aFeature = aFOperation->feature();
1224 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1229 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1231 return myModule->workshop()->currentOperation();
1234 //**************************************************************
1235 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1237 ModuleBase_ModelWidget* aWidget = 0;
1238 ModuleBase_Operation* anOperation = getCurrentOperation();
1240 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1242 aWidget = aPanel->activeWidget();
1247 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1248 const bool isEditOperation,
1249 const bool isToDisplay,
1250 const bool isFlushRedisplay)
1252 #ifdef DEBUG_DO_NOT_BY_ENTER
1256 if (isEditOperation || !theFeature.get())
1259 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1260 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1262 // 1. change visibility of the object itself, here the presentable object is processed,
1263 // e.g. constraints features
1264 //FeaturePtr aFeature = aFOperation->feature();
1265 std::list<ResultPtr> aResults = theFeature->results();
1267 theFeature->setDisplayed(true);
1269 theFeature->setDisplayed(false);
1271 // change visibility of the object results, e.g. non-constraint features
1272 std::list<ResultPtr>::const_iterator aIt;
1273 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1275 (*aIt)->setDisplayed(true);
1278 (*aIt)->setDisplayed(false);
1281 if (isFlushRedisplay)
1282 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1285 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1287 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1288 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1289 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1291 QList<FeaturePtr> aFeatureList;
1292 if (theHighlightedOnly) {
1293 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1296 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1298 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1299 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1302 // 1. it is necessary to save current selection in order to restore it after the features moving
1303 myCurrentSelection.clear();
1304 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1305 for (; anIt != aLast; anIt++) {
1306 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1308 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1311 void PartSet_SketcherMgr::restoreSelection()
1313 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1314 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1315 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1316 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1317 aSLast = myCurrentSelection.end();
1318 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1319 for (; aSIt != aSLast; aSIt++) {
1320 anOwnersToSelect.Clear();
1321 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1323 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1327 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1329 if (myIsConstraintsShown == theOn)
1331 if (myCurrentSketch.get() == NULL)
1334 myIsConstraintsShown = theOn;
1336 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1337 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1339 const QStringList& aConstrIds = constraintsIdList();
1340 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1341 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1342 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1343 if (myIsConstraintsShown)
1344 aSubFeature->setDisplayed(true);
1346 aSubFeature->setDisplayed(false);
1349 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1352 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1354 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1355 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1356 XGUI_Workshop* aWorkshop = aConnector->workshop();
1358 return aWorkshop->operationMgr();