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 // it is important to validate operation here only if sketch entity create operation is active
196 // because at this operation we reacts to the mouse leave/enter view port
197 //operationMgr()->onValidateOperation();
198 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
199 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
202 #ifdef DEBUG_DO_NOT_BY_ENTER
206 if (!isNestedCreateOperation(getCurrentOperation()))
208 operationMgr()->onValidateOperation();
210 // we need change displayed state of the current operation feature
211 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
212 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
213 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
214 // presentation becomes valid and redisplay happens
215 //ModuleBase_Operation* aOperation = getCurrentOperation();
216 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
217 (getCurrentOperation());
219 FeaturePtr aFeature = aFOperation->feature();
220 if (aFeature.get() && aFeature->data()->isValid()) {
221 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
226 void PartSet_SketcherMgr::onLeaveViewPort()
228 myIsMouseOverViewProcessed = false;
229 myIsMouseOverWindow = false;
230 // it is important to validate operation here only if sketch entity create operation is active
231 // because at this operation we reacts to the mouse leave/enter view port
232 //operationMgr()->onValidateOperation();
233 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
234 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
237 #ifdef DEBUG_DO_NOT_BY_ENTER
241 if (!isNestedCreateOperation(getCurrentOperation()))
243 // the method should be performed if the popup menu is called,
244 // the reset of the current widget should not happen
245 if (myIsPopupMenuActive)
248 operationMgr()->onValidateOperation();
250 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
251 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
252 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
253 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
254 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
255 // obtained after reset value
256 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
257 ModuleBase_Operation* aOperation = getCurrentOperation();
258 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
259 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
260 if (aActiveWgt && aActiveWgt->reset()) {
261 myIsResetCurrentValue = true;
263 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
265 // hides the presentation of the current operation feature
266 // the feature is to be erased here, but it is correct to call canDisplayObject because
267 // there can be additional check (e.g. editor widget in distance constraint)
268 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
269 (getCurrentOperation());
271 FeaturePtr aFeature = aFOperation->feature();
272 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
276 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
278 if (isNestedCreateOperation(getCurrentOperation()))
280 // it is necessary to save current selection in order to restore it after the values are modifed
283 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
284 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
285 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
286 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
289 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
291 if (isNestedCreateOperation(getCurrentOperation()))
293 // it is necessary to restore current selection in order to restore it after the values are modified
295 myCurrentSelection.clear();
297 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
298 // viewer happens by deselect/select the modified objects. The flag should be restored after
299 // the selection processing. The update viewer should be also called.
300 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
301 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
302 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
303 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
304 aDisplayer->updateViewer();
307 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
309 if (!isNestedCreateOperation(getCurrentOperation()))
312 // visualize the current operation feature
313 myIsResetCurrentValue = false;
314 operationMgr()->onValidateOperation();
315 // the feature is to be erased here, but it is correct to call canDisplayObject because
316 // there can be additional check (e.g. editor widget in distance constraint)
317 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
318 (getCurrentOperation());
320 FeaturePtr aFeature = aFOperation->feature();
321 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
325 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
327 get2dPoint(theWnd, theEvent, myClickedPoint);
329 if (!(theEvent->buttons() & Qt::LeftButton))
332 // Clear dragging mode
333 myIsDragging = false;
335 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
336 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
337 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
338 if (!aViewer->canDragByMouse())
341 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
342 (getCurrentOperation());
346 if (aFOperation->isEditOperation()) {
347 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
348 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
349 // If the current widget is a selector, do nothing, it processes the mouse press
350 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
355 // Use only for sketch operations
356 if (myCurrentSketch) {
357 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
360 bool isSketcher = isSketchOperation(aFOperation);
361 bool isSketchOpe = isNestedSketchOperation(aFOperation);
363 // Avoid non-sketch operations
364 if ((!isSketchOpe) && (!isSketcher))
367 bool isEditing = aFOperation->isEditOperation();
369 // Ignore creation sketch operation
370 if ((!isSketcher) && (!isEditing))
373 // MoveTo in order to highlight current object
374 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
376 // Remember highlighted objects for editing
377 ModuleBase_ISelection* aSelect = aWorkshop->selection();
379 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
380 storeSelection(!aHasShift);
382 if (myCurrentSelection.empty()) {
383 if (isSketchOpe && (!isSketcher))
384 // commit previous operation
385 if (!aFOperation->commit())
386 aFOperation->abort();
389 // Init flyout point for radius rotation
390 FeaturePtr aFeature = myCurrentSelection.begin().key();
394 get2dPoint(theWnd, theEvent, myCurrentPoint);
397 if (aFeature.get() != NULL) {
398 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
399 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
400 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
401 DataPtr aData = aSPFeature->data();
402 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
403 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
404 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
405 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
408 } else if (isSketchOpe && isEditing) {
409 // If selected another object commit current result
410 aFOperation->commit();
413 get2dPoint(theWnd, theEvent, myCurrentPoint);
416 // This is necessary in order to finalize previous operation
417 QApplication::processEvents();
423 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
425 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
426 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
427 if (!aViewer->canDragByMouse())
429 ModuleBase_Operation* aOp = getCurrentOperation();
431 if (isNestedSketchOperation(aOp)) {
432 get2dPoint(theWnd, theEvent, myClickedPoint);
434 // Only for sketcher operations
438 myCurrentSelection.clear();
439 // Reselect edited object
440 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
441 if (theEvent->modifiers() & Qt::ShiftModifier)
442 aViewer->AISContext()->ShiftSelect();
444 aViewer->AISContext()->Select();
450 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
451 myIsDragging = false;
454 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
456 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
457 myIsMouseOverViewProcessed = true;
458 // 1. perform the widget mouse move functionality and display the presentation
459 ModuleBase_Operation* aOperation = getCurrentOperation();
460 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
461 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
462 // the mouse move should be processed in the widget, if it can in order to visualize correct
463 // presentation. These widgets correct the feature attribute according to the mouse position
464 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
466 aPoint2DWdg->onMouseMove(theWnd, theEvent);
468 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
471 aDistanceWdg->onMouseMove(theWnd, theEvent);
473 // the feature is to be erased here, but it is correct to call canDisplayObject because
474 // there can be additional check (e.g. editor widget in distance constraint)
475 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
476 (getCurrentOperation());
478 FeaturePtr aFeature = aFOperation->feature();
479 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
483 myClickedPoint.clear();
486 // 1. the current selection is saved in the mouse press method in order to restore it after moving
487 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
488 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
489 // deselected). This flag should be restored in the slot, processed the mouse release signal.
490 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
491 aViewer->enableSelection(false);
493 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
494 if (!aCurrentOperation)
496 if (isSketchOperation(aCurrentOperation))
497 return; // No edit operation activated
499 Handle(V3d_View) aView = theWnd->v3dView();
500 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
502 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
503 double dX = aX - myCurrentPoint.myCurX;
504 double dY = aY - myCurrentPoint.myCurY;
506 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
507 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
508 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
509 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
510 // viewer happens by deselect/select the modified objects. The flag should be restored after
511 // the selection processing. The update viewer should be also called.
512 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
514 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
515 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
516 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
517 aLast = myCurrentSelection.end();
518 // 4. the features and attributes modification(move)
519 bool isModified = false;
520 for (; anIt != aLast; anIt++) {
521 FeaturePtr aFeature = anIt.key();
523 std::set<AttributePtr> anAttributes = anIt.value().first;
524 // Process selection by attribute: the priority to the attribute
525 if (!anAttributes.empty()) {
526 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
527 anAttLast = anAttributes.end();
528 for (; anAttIt != anAttLast; anAttIt++) {
529 AttributePtr anAttr = *anAttIt;
530 if (anAttr.get() == NULL)
532 std::string aAttrId = anAttr->id();
533 DataPtr aData = aFeature->data();
534 if (aData->isValid()) {
535 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
536 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
537 if (aPoint.get() != NULL) {
538 bool isImmutable = aPoint->setImmutable(true);
539 aPoint->move(dX, dY);
541 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
542 aPoint->setImmutable(isImmutable);
547 // Process selection by feature
548 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
549 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
550 if (aSketchFeature) {
551 aSketchFeature->move(dX, dY);
553 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
557 // the modified state of the current operation should be updated if there are features, which
560 aCurrentOperation->onValuesChanged();
562 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
563 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
565 // 5. it is necessary to save current selection in order to restore it after the features moving
567 // 6. restore the update viewer flag and call this update
568 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
569 aDisplayer->updateViewer();
572 myCurrentPoint.setValue(aX, aY);
576 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
578 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
579 (getCurrentOperation());
580 if (aFOperation && aFOperation->isEditOperation()) {
581 std::string aId = aFOperation->id().toStdString();
582 if (isDistanceOperation(aFOperation))
584 // Activate dimension value editing on double click
585 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
586 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
587 // Find corresponded widget to activate value editing
588 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
589 if (aWgt->attributeID() == "ConstraintValue") {
598 void PartSet_SketcherMgr::onApplicationStarted()
600 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
601 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
602 XGUI_Workshop* aWorkshop = aConnector->workshop();
603 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
604 if (aPropertyPanel) {
605 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
606 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
609 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
610 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
611 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
613 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
614 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
615 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
618 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
620 if (!myClickedPoint.myIsInitialized)
623 ModuleBase_Operation* aOperation = getCurrentOperation();
624 // the distance constraint feature should not use the clickedd point
625 // this is workaround in order to don't throw down the flyout point value,
626 // set by execute() method of these type of features
627 if (isDistanceOperation(aOperation))
630 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
632 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
636 void PartSet_SketcherMgr::onBeforeContextMenu()
638 myIsPopupMenuActive = true;
641 void PartSet_SketcherMgr::onAfterContextMenu()
643 myIsPopupMenuActive = false;
646 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
649 Handle(V3d_View) aView = theWnd->v3dView();
650 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
652 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
653 thePoint.setValue(aX, anY);
656 void PartSet_SketcherMgr::launchEditing()
658 if (!myCurrentSelection.empty()) {
659 FeaturePtr aFeature = myCurrentSelection.begin().key();
660 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
661 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
663 myModule->editFeature(aSPFeature);
669 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
671 static QStringList aIds;
672 if (aIds.size() == 0) {
673 aIds << SketchPlugin_Line::ID().c_str();
674 aIds << SketchPlugin_Point::ID().c_str();
675 aIds << SketchPlugin_Arc::ID().c_str();
676 aIds << SketchPlugin_Circle::ID().c_str();
677 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
678 aIds.append(constraintsIdList());
683 const QStringList& PartSet_SketcherMgr::constraintsIdList()
685 static QStringList aIds;
686 if (aIds.size() == 0) {
687 aIds << SketchPlugin_ConstraintLength::ID().c_str();
688 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
689 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
690 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
691 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
692 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
693 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
694 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
695 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
696 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
697 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
698 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
699 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
700 aIds << SketchPlugin_MultiRotation::ID().c_str();
701 aIds << SketchPlugin_MultiTranslation::ID().c_str();
706 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
710 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
711 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
712 theModes.append(SketcherPrs_Tools::Sel_Constraint);
713 theModes.append(TopAbs_VERTEX);
714 theModes.append(TopAbs_EDGE);
717 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
719 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
722 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
724 return theOperation &&
725 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
728 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
730 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
732 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
735 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
737 return (theId == SketchPlugin_Line::ID()) ||
738 (theId == SketchPlugin_Point::ID()) ||
739 (theId == SketchPlugin_Arc::ID()) ||
740 (theId == SketchPlugin_Circle::ID());
743 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
745 std::string aId = theOperation ? theOperation->id().toStdString() : "";
747 return (aId == SketchPlugin_ConstraintLength::ID()) ||
748 (aId == SketchPlugin_ConstraintDistance::ID()) ||
749 (aId == SketchPlugin_ConstraintRadius::ID()) ||
750 (aId == SketchPlugin_ConstraintAngle::ID());
753 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
755 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
756 (getCurrentOperation());
760 myModule->onViewTransformed();
762 // Display all sketcher sub-Objects
763 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
764 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
766 // Hide sketcher result
767 std::list<ResultPtr> aResults = myCurrentSketch->results();
768 std::list<ResultPtr>::const_iterator aIt;
769 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
770 (*aIt)->setDisplayed(false);
772 myCurrentSketch->setDisplayed(false);
774 // Display sketcher objects
775 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
776 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
777 std::list<ResultPtr> aResults = aFeature->results();
778 std::list<ResultPtr>::const_iterator aIt;
779 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
780 (*aIt)->setDisplayed(true);
782 aFeature->setDisplayed(true);
785 if (myPlaneFilter.IsNull())
786 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
788 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
790 bool aHasPlane = false;
791 std::shared_ptr<GeomAPI_Pln> aPln;
792 if (aFOperation->isEditOperation()) {
793 // If it is editing of sketch then it means that plane is already defined
794 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
798 myPlaneFilter->setPlane(aPln);
800 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
801 // all sketch objects should be activated in the sketch selection modes by edit operation start
802 // in case of creation operation, there is an active widget, which activates own selection mode
803 if (aFOperation->isEditOperation() && aHasPlane)
804 aConnector->activateModuleSelectionModes();
807 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* /* theOperation*/)
809 myIsMouseOverWindow = false;
810 myIsConstraintsShown = true;
811 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
812 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
814 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
816 DataPtr aData = myCurrentSketch->data();
817 if (!aData->isValid()) {
818 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
819 // The sketch was aborted
820 myCurrentSketch = CompositeFeaturePtr();
821 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
823 // Erase all sketcher objects
824 QStringList aSketchIds = sketchOperationIdList();
825 QObjectPtrList aObjects = aDisplayer->displayedObjects();
826 foreach (ObjectPtr aObj, aObjects) {
827 DataPtr aObjData = aObj->data();
828 if (!aObjData->isValid())
829 aObj->setDisplayed(false);
833 // Hide all sketcher sub-Objects
834 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
835 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
836 std::list<ResultPtr> aResults = aFeature->results();
837 std::list<ResultPtr>::const_iterator aIt;
838 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
839 (*aIt)->setDisplayed(false);
841 aFeature->setDisplayed(false);
843 // Display sketcher result
844 std::list<ResultPtr> aResults = myCurrentSketch->results();
845 std::list<ResultPtr>::const_iterator aIt;
846 Events_Loop* aLoop = Events_Loop::loop();
847 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
848 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
849 (*aIt)->setDisplayed(true);
850 // this display event is needed because sketch already may have "displayed" state,
851 // but not displayed while it is still active (issue 613, abort of existing sketch)
852 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
854 myCurrentSketch->setDisplayed(true);
856 myCurrentSketch = CompositeFeaturePtr();
857 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
859 Events_Loop::loop()->flush(aDispEvent);
861 // restore the module selection modes, which were changed on startSketch
862 aConnector->activateModuleSelectionModes();
865 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
867 if (constraintsIdList().contains(theOperation->id())) {
868 // Show constraints if a constraint was created
869 onShowConstraintsToggle(true);
871 connectToPropertyPanel(true);
874 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
876 connectToPropertyPanel(false);
877 myIsResetCurrentValue = false;
878 myIsMouseOverViewProcessed = true;
879 operationMgr()->onValidateOperation();
882 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
884 if (isNestedCreateOperation(theOperation)) {
885 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
888 FeaturePtr aFeature = aFOperation->feature();
889 // it is necessary to check the the feature data validity because
890 // some kind of features are removed by an operation commit(the macro state of a feature)
891 if (aFeature.get() && aFeature->data()->isValid()) {
892 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
898 bool PartSet_SketcherMgr::canUndo() const
900 return isNestedCreateOperation(getCurrentOperation());
903 bool PartSet_SketcherMgr::canRedo() const
905 return isNestedCreateOperation(getCurrentOperation());
908 bool PartSet_SketcherMgr::canCommitOperation() const
910 bool aCanCommit = true;
912 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
918 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
920 bool aCanErase = true;
921 // when the sketch operation is active, results of sketch sub-feature can not be hidden
922 if (myCurrentSketch.get()) {
923 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
925 // Display sketcher objects
926 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
928 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
929 std::list<ResultPtr> aResults = aFeature->results();
930 std::list<ResultPtr>::const_iterator anIt;
931 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
932 aCanErase = *anIt != aResult;
940 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
942 bool aCanDisplay = true;
944 bool aHasActiveSketch = activeSketch().get() != NULL;
945 if (aHasActiveSketch) {
946 // 1. the sketch feature should not be displayed during the sketch active operation
947 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
948 // nested features can be visualized
949 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
950 if (aFeature.get() != NULL && aFeature == activeSketch()) {
954 else { // there are no an active sketch
955 // 2. sketch sub-features should not be visualized if the sketch operation is not active
956 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
957 if (aFeature.get() != NULL) {
958 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
959 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
960 if (aSketchFeature.get()) {
966 // 3. the method should not filter the objects, which are not related to the current operation.
967 // The object is filtered just if it is a current operation feature or this feature result
968 bool isObjectFound = false;
969 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
970 (getCurrentOperation());
972 FeaturePtr aFeature = aFOperation->feature();
973 if (aFeature.get()) {
974 std::list<ResultPtr> aResults = aFeature->results();
975 if (theObject == aFeature)
976 isObjectFound = true;
978 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
979 for (; anIt != aLast; anIt++) {
980 isObjectFound = *anIt == theObject;
988 // 4. For created nested feature operation do not display the created feature if
989 // the mouse curstor leaves the OCC window.
990 // The correction cases, which ignores this condition:
991 // a. the property panel values modification
992 // b. the popup menu activated
993 // c. widget editor control
994 #ifndef DEBUG_DO_NOT_BY_ENTER
995 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
996 ModuleBase_Operation* aOperation = getCurrentOperation();
997 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
998 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
999 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
1000 // the active widget editor should not influence here. The presentation should be visible always
1001 // when this widget is active.
1002 if (!anEditorWdg && !myIsPopupMenuActive) {
1003 // during a nested create operation, the feature is redisplayed only if the mouse over view
1004 // of there was a value modified in the property panel after the mouse left the view
1005 aCanDisplay = canDisplayCurrentCreatedFeature();
1012 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1014 return myIsMouseOverWindow || !myIsResetCurrentValue;
1015 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1016 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1020 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1022 bool isFoundObject = false;
1024 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1025 if (anObjectFeature.get()) {
1026 int aSize = myCurrentSketch->numberOfSubs();
1027 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1028 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1029 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1032 return isFoundObject;
1035 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1037 if (myPlaneFilter.IsNull())
1038 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1040 myPlaneFilter->setPlane(thePln);
1043 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1044 const FeaturePtr& theSketch,
1045 ModuleBase_IWorkshop* theWorkshop,
1046 FeatureToSelectionMap& theSelection)
1048 if (theFeature.get() == NULL)
1051 std::set<AttributePtr> aSelectedAttributes;
1052 std::set<ResultPtr> aSelectedResults;
1054 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1055 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1056 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1057 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1059 std::list<ResultPtr> aResults = theFeature->results();
1060 std::list<ResultPtr>::const_iterator aIt;
1061 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1063 ResultPtr aResult = *aIt;
1064 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1065 if (aAISObj.get() == NULL)
1067 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1068 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1070 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1071 if (anOwner->Selectable() != anAISIO)
1073 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1074 aSelectedAttributes, aSelectedResults);
1076 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1077 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1078 if (anOwner.IsNull())
1080 if (anOwner->Selectable() != anAISIO)
1082 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1083 aSelectedAttributes, aSelectedResults);
1086 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1089 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1090 const FeaturePtr& theSketch,
1091 ModuleBase_IWorkshop* theWorkshop,
1092 const FeatureToSelectionMap& theSelection,
1093 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1095 if (theFeature.get() == NULL)
1098 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1099 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1100 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1102 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1103 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1104 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1105 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1107 // 1. found the feature's owners. Check the AIS objects of the constructions
1108 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1109 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1110 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1112 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1113 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1114 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1115 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1116 if (!anOwner.IsNull())
1117 anOwnersToSelect.Add(anOwner);
1121 // 2. found the feature results's owners
1122 std::list<ResultPtr> aResults = theFeature->results();
1123 std::list<ResultPtr>::const_iterator aIt;
1124 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1126 ResultPtr aResult = *aIt;
1127 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1128 if (aAISObj.get() == NULL)
1130 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1132 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1133 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1134 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1135 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1136 if ( anOwner.IsNull() || !anOwner->HasShape() )
1138 const TopoDS_Shape& aShape = anOwner->Shape();
1139 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1140 if (aShapeType == TopAbs_VERTEX) {
1141 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1142 if (aPntAttr.get() != NULL &&
1143 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1144 anOwnersToSelect.Add(anOwner);
1147 else if (aShapeType == TopAbs_EDGE) {
1148 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1149 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1150 anOwnersToSelect.FindIndex(anOwner) <= 0)
1151 anOwnersToSelect.Add(anOwner);
1157 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1159 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1160 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1161 XGUI_Workshop* aWorkshop = aConnector->workshop();
1162 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1163 if (aPropertyPanel) {
1164 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1165 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1167 connect(aWidget, SIGNAL(beforeValuesChanged()),
1168 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1169 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1170 connect(aWidget, SIGNAL(afterValuesChanged()),
1171 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1174 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1175 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1176 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1177 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1178 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1184 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1186 return myModule->workshop()->currentOperation();
1189 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1190 const bool isEditOperation,
1191 const bool isToDisplay,
1192 const bool isFlushRedisplay)
1194 #ifdef DEBUG_DO_NOT_BY_ENTER
1198 if (isEditOperation || !theFeature.get())
1201 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1202 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1204 // 1. change visibility of the object itself, here the presentable object is processed,
1205 // e.g. constraints features
1206 //FeaturePtr aFeature = aFOperation->feature();
1207 std::list<ResultPtr> aResults = theFeature->results();
1209 theFeature->setDisplayed(true);
1211 theFeature->setDisplayed(false);
1213 // change visibility of the object results, e.g. non-constraint features
1214 std::list<ResultPtr>::const_iterator aIt;
1215 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1217 (*aIt)->setDisplayed(true);
1220 (*aIt)->setDisplayed(false);
1223 if (isFlushRedisplay)
1224 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1227 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1229 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1230 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1231 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1233 QList<FeaturePtr> aFeatureList;
1234 if (theHighlightedOnly) {
1235 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1238 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1240 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1241 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1244 // 1. it is necessary to save current selection in order to restore it after the features moving
1245 myCurrentSelection.clear();
1246 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1247 for (; anIt != aLast; anIt++) {
1248 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1250 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1253 void PartSet_SketcherMgr::restoreSelection()
1255 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1256 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1257 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1258 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1259 aSLast = myCurrentSelection.end();
1260 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1261 for (; aSIt != aSLast; aSIt++) {
1262 anOwnersToSelect.Clear();
1263 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1265 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1269 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1271 if (myIsConstraintsShown == theOn)
1273 if (myCurrentSketch.get() == NULL)
1276 myIsConstraintsShown = theOn;
1278 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1279 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1281 const QStringList& aConstrIds = constraintsIdList();
1282 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1283 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1284 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1285 if (myIsConstraintsShown)
1286 aSubFeature->setDisplayed(true);
1288 aSubFeature->setDisplayed(false);
1291 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1294 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1296 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1297 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1300 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1302 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1303 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1304 XGUI_Workshop* aWorkshop = aConnector->workshop();
1306 return aWorkshop->operationMgr();