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_Module.h"
9 #include "PartSet_WidgetPoint2d.h"
10 #include "PartSet_WidgetPoint2dDistance.h"
11 #include "PartSet_Tools.h"
12 #include "PartSet_WidgetSketchLabel.h"
14 #include <ModuleBase_WidgetEditor.h>
15 #include <ModuleBase_ModelWidget.h>
17 #include <XGUI_ModuleConnector.h>
18 #include <XGUI_Displayer.h>
19 #include <XGUI_Workshop.h>
20 #include <XGUI_ContextMenuMgr.h>
21 #include <XGUI_Selection.h>
22 #include <XGUI_SelectionMgr.h>
23 #include <XGUI_ModuleConnector.h>
24 #include <XGUI_PropertyPanel.h>
25 #include <XGUI_ViewerProxy.h>
26 #include <XGUI_OperationMgr.h>
28 #include <ModuleBase_IViewer.h>
29 #include <ModuleBase_IWorkshop.h>
30 #include <ModuleBase_IViewWindow.h>
31 #include <ModuleBase_Operation.h>
32 #include <ModuleBase_OperationFeature.h>
33 #include <ModuleBase_ISelection.h>
34 #include <ModuleBase_IPropertyPanel.h>
35 #include <ModuleBase_Operation.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>
74 #include <QMouseEvent>
75 #include <QApplication>
77 //#define DEBUG_DO_NOT_BY_ENTER
78 //#define DEBUG_MOUSE_OVER_WINDOW_FLAGS
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 myIsResetCurrentValue(false), 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 myPreviousSelectionEnabled = 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;
194 myIsResetCurrentValue = false;
195 operationMgr()->onValidateOperation();
196 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
197 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
200 #ifdef DEBUG_DO_NOT_BY_ENTER
204 if (!isNestedCreateOperation(getCurrentOperation()))
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 operationMgr()->onValidateOperation();
227 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
228 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
231 #ifdef DEBUG_DO_NOT_BY_ENTER
235 if (!isNestedCreateOperation(getCurrentOperation()))
237 // the method should be performed if the popup menu is called,
238 // the reset of the current widget should not happen
239 if (myIsPopupMenuActive)
242 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
243 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
244 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
245 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
246 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
247 // obtained after reset value
248 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
249 ModuleBase_Operation* aOperation = getCurrentOperation();
250 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
251 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
252 if (aActiveWgt && aActiveWgt->reset()) {
253 myIsResetCurrentValue = true;
255 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
257 // hides the presentation of the current operation feature
258 // the feature is to be erased here, but it is correct to call canDisplayObject because
259 // there can be additional check (e.g. editor widget in distance constraint)
260 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
261 (getCurrentOperation());
263 FeaturePtr aFeature = aFOperation->feature();
264 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
268 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
270 if (isNestedCreateOperation(getCurrentOperation()))
272 // it is necessary to save current selection in order to restore it after the values are modifed
275 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
276 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
277 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
278 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
281 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
283 if (isNestedCreateOperation(getCurrentOperation()))
285 // it is necessary to restore current selection in order to restore it after the values are modified
287 myCurrentSelection.clear();
289 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
290 // viewer happens by deselect/select the modified objects. The flag should be restored after
291 // the selection processing. The update viewer should be also called.
292 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
293 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
294 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
295 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
296 aDisplayer->updateViewer();
299 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
301 if (!isNestedCreateOperation(getCurrentOperation()))
304 // visualize the current operation feature
305 myIsResetCurrentValue = false;
306 operationMgr()->onValidateOperation();
307 // the feature is to be erased here, but it is correct to call canDisplayObject because
308 // there can be additional check (e.g. editor widget in distance constraint)
309 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
310 (getCurrentOperation());
312 FeaturePtr aFeature = aFOperation->feature();
313 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
317 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
319 get2dPoint(theWnd, theEvent, myClickedPoint);
321 if (!(theEvent->buttons() & Qt::LeftButton))
324 // Clear dragging mode
325 myIsDragging = false;
327 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
328 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
329 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
330 if (!aViewer->canDragByMouse())
333 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
334 (getCurrentOperation());
338 if (aFOperation->isEditOperation()) {
339 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
340 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
341 // If the current widget is a selector, do nothing, it processes the mouse press
342 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
347 // Use only for sketch operations
348 if (myCurrentSketch) {
349 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
352 bool isSketcher = isSketchOperation(aFOperation);
353 bool isSketchOpe = isNestedSketchOperation(aFOperation);
355 // Avoid non-sketch operations
356 if ((!isSketchOpe) && (!isSketcher))
359 bool isEditing = aFOperation->isEditOperation();
361 // Ignore creation sketch operation
362 if ((!isSketcher) && (!isEditing))
365 // MoveTo in order to highlight current object
366 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
368 // Remember highlighted objects for editing
369 ModuleBase_ISelection* aSelect = aWorkshop->selection();
371 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
372 storeSelection(!aHasShift);
374 if (myCurrentSelection.empty()) {
375 if (isSketchOpe && (!isSketcher))
376 // commit previous operation
377 if (!aFOperation->commit())
378 aFOperation->abort();
381 // Init flyout point for radius rotation
382 FeaturePtr aFeature = myCurrentSelection.begin().key();
386 get2dPoint(theWnd, theEvent, myCurrentPoint);
389 if (aFeature.get() != NULL) {
390 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
391 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
392 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
393 DataPtr aData = aSPFeature->data();
394 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
395 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
396 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
397 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
400 } else if (isSketchOpe && isEditing) {
401 // If selected another object commit current result
402 aFOperation->commit();
405 get2dPoint(theWnd, theEvent, myCurrentPoint);
408 // This is necessary in order to finalize previous operation
409 QApplication::processEvents();
415 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
417 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
418 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
419 if (!aViewer->canDragByMouse())
421 ModuleBase_Operation* aOp = getCurrentOperation();
423 if (isNestedSketchOperation(aOp)) {
424 get2dPoint(theWnd, theEvent, myClickedPoint);
426 // Only for sketcher operations
430 myCurrentSelection.clear();
431 // Reselect edited object
432 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
433 if (theEvent->modifiers() & Qt::ShiftModifier)
434 aViewer->AISContext()->ShiftSelect();
436 aViewer->AISContext()->Select();
442 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
443 myIsDragging = false;
446 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
448 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
449 myIsMouseOverViewProcessed = true;
450 // 1. perform the widget mouse move functionality and display the presentation
451 ModuleBase_Operation* aOperation = getCurrentOperation();
452 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
453 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
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 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
458 aPoint2DWdg->onMouseMove(theWnd, theEvent);
460 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
463 aDistanceWdg->onMouseMove(theWnd, theEvent);
465 // the feature is to be erased here, but it is correct to call canDisplayObject because
466 // there can be additional check (e.g. editor widget in distance constraint)
467 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
468 (getCurrentOperation());
470 FeaturePtr aFeature = aFOperation->feature();
471 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
475 myClickedPoint.clear();
478 // 1. the current selection is saved in the mouse press method in order to restore it after moving
479 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
480 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
481 // deselected). This flag should be restored in the slot, processed the mouse release signal.
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 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
596 if (aPropertyPanel) {
597 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
598 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
601 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
602 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
603 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
605 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
606 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
607 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
610 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
612 if (!myClickedPoint.myIsInitialized)
615 ModuleBase_Operation* aOperation = getCurrentOperation();
616 // the distance constraint feature should not use the clickedd point
617 // this is workaround in order to don't throw down the flyout point value,
618 // set by execute() method of these type of features
619 if (isDistanceOperation(aOperation))
622 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
624 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
628 void PartSet_SketcherMgr::onBeforeContextMenu()
630 myIsPopupMenuActive = true;
633 void PartSet_SketcherMgr::onAfterContextMenu()
635 myIsPopupMenuActive = false;
638 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
641 Handle(V3d_View) aView = theWnd->v3dView();
642 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
644 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
645 thePoint.setValue(aX, anY);
648 void PartSet_SketcherMgr::launchEditing()
650 if (!myCurrentSelection.empty()) {
651 FeaturePtr aFeature = myCurrentSelection.begin().key();
652 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
653 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
655 myModule->editFeature(aSPFeature);
661 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
663 static QStringList aIds;
664 if (aIds.size() == 0) {
665 aIds << SketchPlugin_Line::ID().c_str();
666 aIds << SketchPlugin_Point::ID().c_str();
667 aIds << SketchPlugin_Arc::ID().c_str();
668 aIds << SketchPlugin_Circle::ID().c_str();
669 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
670 aIds.append(constraintsIdList());
675 const QStringList& PartSet_SketcherMgr::constraintsIdList()
677 static QStringList aIds;
678 if (aIds.size() == 0) {
679 aIds << SketchPlugin_ConstraintLength::ID().c_str();
680 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
681 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
682 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
683 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
684 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
685 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
686 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
687 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
688 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
689 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
690 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
691 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
692 aIds << SketchPlugin_MultiRotation::ID().c_str();
693 aIds << SketchPlugin_MultiTranslation::ID().c_str();
698 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
702 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
703 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
704 theModes.append(SketcherPrs_Tools::Sel_Constraint);
705 theModes.append(TopAbs_VERTEX);
706 theModes.append(TopAbs_EDGE);
709 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
711 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
714 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
716 return theOperation &&
717 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
720 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
722 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
724 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
727 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
729 return (theId == SketchPlugin_Line::ID()) ||
730 (theId == SketchPlugin_Point::ID()) ||
731 (theId == SketchPlugin_Arc::ID()) ||
732 (theId == SketchPlugin_Circle::ID());
735 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
737 std::string aId = theOperation ? theOperation->id().toStdString() : "";
739 return (aId == SketchPlugin_ConstraintLength::ID()) ||
740 (aId == SketchPlugin_ConstraintDistance::ID()) ||
741 (aId == SketchPlugin_ConstraintRadius::ID()) ||
742 (aId == SketchPlugin_ConstraintAngle::ID());
745 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
747 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
748 (getCurrentOperation());
752 myModule->onViewTransformed();
754 // Display all sketcher sub-Objects
755 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
756 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
758 // Hide sketcher result
759 std::list<ResultPtr> aResults = myCurrentSketch->results();
760 std::list<ResultPtr>::const_iterator aIt;
761 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
762 (*aIt)->setDisplayed(false);
764 myCurrentSketch->setDisplayed(false);
766 // Display sketcher objects
767 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
768 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
769 std::list<ResultPtr> aResults = aFeature->results();
770 std::list<ResultPtr>::const_iterator aIt;
771 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
772 (*aIt)->setDisplayed(true);
774 aFeature->setDisplayed(true);
777 if (myPlaneFilter.IsNull())
778 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
780 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
782 bool aHasPlane = false;
783 std::shared_ptr<GeomAPI_Pln> aPln;
784 if (aFOperation->isEditOperation()) {
785 // If it is editing of sketch then it means that plane is already defined
786 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
790 myPlaneFilter->setPlane(aPln);
792 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
793 // all sketch objects should be activated in the sketch selection modes by edit operation start
794 // in case of creation operation, there is an active widget, which activates own selection mode
795 if (aFOperation->isEditOperation() && aHasPlane)
796 aConnector->activateModuleSelectionModes();
799 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation*/* theOperation*/)
801 myIsMouseOverWindow = false;
802 myIsConstraintsShown = true;
803 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
804 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
806 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
808 DataPtr aData = myCurrentSketch->data();
809 if (!aData->isValid()) {
810 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
811 // The sketch was aborted
812 myCurrentSketch = CompositeFeaturePtr();
813 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
815 // Erase all sketcher objects
816 QStringList aSketchIds = sketchOperationIdList();
817 QObjectPtrList aObjects = aDisplayer->displayedObjects();
818 foreach (ObjectPtr aObj, aObjects) {
819 DataPtr aObjData = aObj->data();
820 if (!aObjData->isValid())
821 aObj->setDisplayed(false);
825 // Hide all sketcher sub-Objects
826 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
827 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
828 std::list<ResultPtr> aResults = aFeature->results();
829 std::list<ResultPtr>::const_iterator aIt;
830 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
831 (*aIt)->setDisplayed(false);
833 aFeature->setDisplayed(false);
835 // Display sketcher result
836 std::list<ResultPtr> aResults = myCurrentSketch->results();
837 std::list<ResultPtr>::const_iterator aIt;
838 Events_Loop* aLoop = Events_Loop::loop();
839 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
840 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
841 (*aIt)->setDisplayed(true);
842 // this display event is needed because sketch already may have "displayed" state,
843 // but not displayed while it is still active (issue 613, abort of existing sketch)
844 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
846 myCurrentSketch->setDisplayed(true);
848 myCurrentSketch = CompositeFeaturePtr();
849 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
851 Events_Loop::loop()->flush(aDispEvent);
853 // restore the module selection modes, which were changed on startSketch
854 aConnector->activateModuleSelectionModes();
857 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
859 if (constraintsIdList().contains(theOperation->id())) {
860 // Show constraints if a constraint was created
861 onShowConstraintsToggle(true);
863 connectToPropertyPanel(true);
866 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
868 connectToPropertyPanel(false);
869 myIsResetCurrentValue = false;
870 myIsMouseOverViewProcessed = true;
871 operationMgr()->onValidateOperation();
874 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
876 if (isNestedCreateOperation(theOperation)) {
877 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
880 FeaturePtr aFeature = aFOperation->feature();
881 // it is necessary to check the the feature data validity because
882 // some kind of features are removed by an operation commit(the macro state of a feature)
883 if (aFeature.get() && aFeature->data()->isValid()) {
884 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
890 bool PartSet_SketcherMgr::canUndo() const
892 return isNestedCreateOperation(getCurrentOperation());
895 bool PartSet_SketcherMgr::canRedo() const
897 return isNestedCreateOperation(getCurrentOperation());
900 bool PartSet_SketcherMgr::canCommitOperation() const
902 bool aCanCommit = true;
904 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
910 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
912 bool aCanDisplay = true;
914 bool aHasActiveSketch = activeSketch().get() != NULL;
915 if (aHasActiveSketch) {
916 // 1. the sketch feature should not be displayed during the sketch active operation
917 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
918 // nested features can be visualized
919 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
920 if (aFeature.get() != NULL && aFeature == activeSketch()) {
924 else { // there are no an active sketch
925 // 2. sketch sub-features should not be visualized if the sketch operation is not active
926 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
927 if (aFeature.get() != NULL) {
928 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
929 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
930 if (aSketchFeature.get()) {
936 // 3. the method should not filter the objects, which are not related to the current operation.
937 // The object is filtered just if it is a current operation feature or this feature result
938 bool isObjectFound = false;
939 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
940 (getCurrentOperation());
942 FeaturePtr aFeature = aFOperation->feature();
943 if (aFeature.get()) {
944 std::list<ResultPtr> aResults = aFeature->results();
945 if (theObject == aFeature)
946 isObjectFound = true;
948 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
949 for (; anIt != aLast; anIt++) {
950 isObjectFound = *anIt == theObject;
958 // 4. For created nested feature operation do not display the created feature if
959 // the mouse curstor leaves the OCC window.
960 // The correction cases, which ignores this condition:
961 // a. the property panel values modification
962 // b. the popup menu activated
963 // c. widget editor control
964 #ifndef DEBUG_DO_NOT_BY_ENTER
965 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
966 ModuleBase_Operation* aOperation = getCurrentOperation();
967 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
968 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
969 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
970 // the active widget editor should not influence here. The presentation should be visible always
971 // when this widget is active.
972 if (!anEditorWdg && !myIsPopupMenuActive) {
973 // during a nested create operation, the feature is redisplayed only if the mouse over view
974 // of there was a value modified in the property panel after the mouse left the view
975 aCanDisplay = canDisplayCurrentCreatedFeature();
982 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
984 return myIsMouseOverWindow || !myIsResetCurrentValue;
985 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
986 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
990 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
992 bool isFoundObject = false;
994 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
995 if (anObjectFeature.get()) {
996 int aSize = myCurrentSketch->numberOfSubs();
997 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
998 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
999 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1002 return isFoundObject;
1005 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1007 if (myPlaneFilter.IsNull())
1008 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1010 myPlaneFilter->setPlane(thePln);
1013 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1014 const FeaturePtr& theSketch,
1015 ModuleBase_IWorkshop* theWorkshop,
1016 FeatureToSelectionMap& theSelection)
1018 if (theFeature.get() == NULL)
1021 std::set<AttributePtr> aSelectedAttributes;
1022 std::set<ResultPtr> aSelectedResults;
1024 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1025 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1026 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1027 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1029 std::list<ResultPtr> aResults = theFeature->results();
1030 std::list<ResultPtr>::const_iterator aIt;
1031 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1033 ResultPtr aResult = *aIt;
1034 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1035 if (aAISObj.get() == NULL)
1037 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1038 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1040 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1041 if (anOwner->Selectable() != anAISIO)
1043 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1044 aSelectedAttributes, aSelectedResults);
1046 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1047 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1048 if (anOwner.IsNull())
1050 if (anOwner->Selectable() != anAISIO)
1052 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1053 aSelectedAttributes, aSelectedResults);
1056 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1059 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1060 const FeaturePtr& theSketch,
1061 ModuleBase_IWorkshop* theWorkshop,
1062 const FeatureToSelectionMap& theSelection,
1063 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1065 if (theFeature.get() == NULL)
1068 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1069 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1070 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1072 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1073 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1074 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1075 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1077 // 1. found the feature's owners. Check the AIS objects of the constructions
1078 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1079 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1080 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1082 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1083 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1084 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1085 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1086 if (!anOwner.IsNull())
1087 anOwnersToSelect.Add(anOwner);
1091 // 2. found the feature results's owners
1092 std::list<ResultPtr> aResults = theFeature->results();
1093 std::list<ResultPtr>::const_iterator aIt;
1094 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1096 ResultPtr aResult = *aIt;
1097 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1098 if (aAISObj.get() == NULL)
1100 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1102 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1103 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1104 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1105 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1106 if ( anOwner.IsNull() || !anOwner->HasShape() )
1108 const TopoDS_Shape& aShape = anOwner->Shape();
1109 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1110 if (aShapeType == TopAbs_VERTEX) {
1111 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1112 if (aPntAttr.get() != NULL &&
1113 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1114 anOwnersToSelect.Add(anOwner);
1117 else if (aShapeType == TopAbs_EDGE) {
1118 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1119 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1120 anOwnersToSelect.FindIndex(anOwner) <= 0)
1121 anOwnersToSelect.Add(anOwner);
1127 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1129 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1130 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1131 XGUI_Workshop* aWorkshop = aConnector->workshop();
1132 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1133 if (aPropertyPanel) {
1134 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1135 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1137 connect(aWidget, SIGNAL(beforeValuesChanged()),
1138 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1139 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1140 connect(aWidget, SIGNAL(afterValuesChanged()),
1141 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1144 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1145 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1146 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1147 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1148 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1154 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1156 return myModule->workshop()->currentOperation();
1159 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1160 const bool isEditOperation,
1161 const bool isToDisplay,
1162 const bool isFlushRedisplay)
1164 #ifdef DEBUG_DO_NOT_BY_ENTER
1168 if (isEditOperation || !theFeature.get())
1171 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1172 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1174 // 1. change visibility of the object itself, here the presentable object is processed,
1175 // e.g. constraints features
1176 //FeaturePtr aFeature = aFOperation->feature();
1177 std::list<ResultPtr> aResults = theFeature->results();
1179 theFeature->setDisplayed(true);
1181 theFeature->setDisplayed(false);
1183 // change visibility of the object results, e.g. non-constraint features
1184 std::list<ResultPtr>::const_iterator aIt;
1185 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1187 (*aIt)->setDisplayed(true);
1190 (*aIt)->setDisplayed(false);
1193 if (isFlushRedisplay)
1194 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1197 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1199 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1200 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1201 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1203 QList<FeaturePtr> aFeatureList;
1204 if (theHighlightedOnly) {
1205 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1208 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1210 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1211 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1214 // 1. it is necessary to save current selection in order to restore it after the features moving
1215 myCurrentSelection.clear();
1216 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1217 for (; anIt != aLast; anIt++) {
1218 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1220 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1223 void PartSet_SketcherMgr::restoreSelection()
1225 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1226 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1227 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1228 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1229 aSLast = myCurrentSelection.end();
1230 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1231 for (; aSIt != aSLast; aSIt++) {
1232 anOwnersToSelect.Clear();
1233 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1235 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1239 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1241 if (myIsConstraintsShown == theOn)
1243 if (myCurrentSketch.get() == NULL)
1246 myIsConstraintsShown = theOn;
1248 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1249 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1251 const QStringList& aConstrIds = constraintsIdList();
1252 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1253 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1254 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1255 if (myIsConstraintsShown)
1256 aSubFeature->setDisplayed(true);
1258 aSubFeature->setDisplayed(false);
1261 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1264 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1266 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1267 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1270 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1272 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1273 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1274 XGUI_Workshop* aWorkshop = aConnector->workshop();
1276 return aWorkshop->operationMgr();