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 operationMgr()->onValidateOperation();
231 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
232 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
235 #ifdef DEBUG_DO_NOT_BY_ENTER
239 if (!isNestedCreateOperation(getCurrentOperation()))
241 // the method should be performed if the popup menu is called,
242 // the reset of the current widget should not happen
243 if (myIsPopupMenuActive)
246 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
247 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
248 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
249 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
250 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
251 // obtained after reset value
252 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
253 ModuleBase_Operation* aOperation = getCurrentOperation();
254 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
255 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
256 if (aActiveWgt && aActiveWgt->reset()) {
257 myIsResetCurrentValue = true;
259 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
261 // hides the presentation of the current operation feature
262 // the feature is to be erased here, but it is correct to call canDisplayObject because
263 // there can be additional check (e.g. editor widget in distance constraint)
264 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
265 (getCurrentOperation());
267 FeaturePtr aFeature = aFOperation->feature();
268 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
272 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
274 if (isNestedCreateOperation(getCurrentOperation()))
276 // it is necessary to save current selection in order to restore it after the values are modifed
279 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
280 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
281 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
282 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
285 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
287 if (isNestedCreateOperation(getCurrentOperation()))
289 // it is necessary to restore current selection in order to restore it after the values are modified
291 myCurrentSelection.clear();
293 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
294 // viewer happens by deselect/select the modified objects. The flag should be restored after
295 // the selection processing. The update viewer should be also called.
296 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
297 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
298 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
299 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
300 aDisplayer->updateViewer();
303 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
305 if (!isNestedCreateOperation(getCurrentOperation()))
308 // visualize the current operation feature
309 myIsResetCurrentValue = false;
310 operationMgr()->onValidateOperation();
311 // the feature is to be erased here, but it is correct to call canDisplayObject because
312 // there can be additional check (e.g. editor widget in distance constraint)
313 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
314 (getCurrentOperation());
316 FeaturePtr aFeature = aFOperation->feature();
317 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
321 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
323 get2dPoint(theWnd, theEvent, myClickedPoint);
325 if (!(theEvent->buttons() & Qt::LeftButton))
328 // Clear dragging mode
329 myIsDragging = false;
331 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
332 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
333 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
334 if (!aViewer->canDragByMouse())
337 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
338 (getCurrentOperation());
342 if (aFOperation->isEditOperation()) {
343 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
344 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
345 // If the current widget is a selector, do nothing, it processes the mouse press
346 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
351 // Use only for sketch operations
352 if (myCurrentSketch) {
353 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
356 bool isSketcher = isSketchOperation(aFOperation);
357 bool isSketchOpe = isNestedSketchOperation(aFOperation);
359 // Avoid non-sketch operations
360 if ((!isSketchOpe) && (!isSketcher))
363 bool isEditing = aFOperation->isEditOperation();
365 // Ignore creation sketch operation
366 if ((!isSketcher) && (!isEditing))
369 // MoveTo in order to highlight current object
370 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
372 // Remember highlighted objects for editing
373 ModuleBase_ISelection* aSelect = aWorkshop->selection();
375 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
376 storeSelection(!aHasShift);
378 if (myCurrentSelection.empty()) {
379 if (isSketchOpe && (!isSketcher))
380 // commit previous operation
381 if (!aFOperation->commit())
382 aFOperation->abort();
385 // Init flyout point for radius rotation
386 FeaturePtr aFeature = myCurrentSelection.begin().key();
390 get2dPoint(theWnd, theEvent, myCurrentPoint);
393 if (aFeature.get() != NULL) {
394 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
395 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
396 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
397 DataPtr aData = aSPFeature->data();
398 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
399 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
400 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
401 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
404 } else if (isSketchOpe && isEditing) {
405 // If selected another object commit current result
406 aFOperation->commit();
409 get2dPoint(theWnd, theEvent, myCurrentPoint);
412 // This is necessary in order to finalize previous operation
413 QApplication::processEvents();
419 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
421 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
422 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
423 if (!aViewer->canDragByMouse())
425 ModuleBase_Operation* aOp = getCurrentOperation();
427 if (isNestedSketchOperation(aOp)) {
428 get2dPoint(theWnd, theEvent, myClickedPoint);
430 // Only for sketcher operations
434 myCurrentSelection.clear();
435 // Reselect edited object
436 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
437 if (theEvent->modifiers() & Qt::ShiftModifier)
438 aViewer->AISContext()->ShiftSelect();
440 aViewer->AISContext()->Select();
446 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
447 myIsDragging = false;
450 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
452 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
453 myIsMouseOverViewProcessed = true;
454 // 1. perform the widget mouse move functionality and display the presentation
455 ModuleBase_Operation* aOperation = getCurrentOperation();
456 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
457 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
458 // the mouse move should be processed in the widget, if it can in order to visualize correct
459 // presentation. These widgets correct the feature attribute according to the mouse position
460 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
462 aPoint2DWdg->onMouseMove(theWnd, theEvent);
464 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
467 aDistanceWdg->onMouseMove(theWnd, theEvent);
469 // the feature is to be erased here, but it is correct to call canDisplayObject because
470 // there can be additional check (e.g. editor widget in distance constraint)
471 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
472 (getCurrentOperation());
474 FeaturePtr aFeature = aFOperation->feature();
475 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
479 myClickedPoint.clear();
482 // 1. the current selection is saved in the mouse press method in order to restore it after moving
483 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
484 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
485 // deselected). This flag should be restored in the slot, processed the mouse release signal.
486 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
487 aViewer->enableSelection(false);
489 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
490 if (!aCurrentOperation)
492 if (isSketchOperation(aCurrentOperation))
493 return; // No edit operation activated
495 Handle(V3d_View) aView = theWnd->v3dView();
496 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
498 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
499 double dX = aX - myCurrentPoint.myCurX;
500 double dY = aY - myCurrentPoint.myCurY;
502 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
503 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
504 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
505 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
506 // viewer happens by deselect/select the modified objects. The flag should be restored after
507 // the selection processing. The update viewer should be also called.
508 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
510 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
511 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
512 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
513 aLast = myCurrentSelection.end();
514 // 4. the features and attributes modification(move)
515 bool isModified = false;
516 for (; anIt != aLast; anIt++) {
517 FeaturePtr aFeature = anIt.key();
519 std::set<AttributePtr> anAttributes = anIt.value().first;
520 // Process selection by attribute: the priority to the attribute
521 if (!anAttributes.empty()) {
522 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
523 anAttLast = anAttributes.end();
524 for (; anAttIt != anAttLast; anAttIt++) {
525 AttributePtr anAttr = *anAttIt;
526 if (anAttr.get() == NULL)
528 std::string aAttrId = anAttr->id();
529 DataPtr aData = aFeature->data();
530 if (aData->isValid()) {
531 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
532 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
533 if (aPoint.get() != NULL) {
534 bool isImmutable = aPoint->setImmutable(true);
535 aPoint->move(dX, dY);
537 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
538 aPoint->setImmutable(isImmutable);
543 // Process selection by feature
544 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
545 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
546 if (aSketchFeature) {
547 aSketchFeature->move(dX, dY);
549 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
553 // the modified state of the current operation should be updated if there are features, which
556 aCurrentOperation->onValuesChanged();
558 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
559 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
561 // 5. it is necessary to save current selection in order to restore it after the features moving
563 // 6. restore the update viewer flag and call this update
564 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
565 aDisplayer->updateViewer();
568 myCurrentPoint.setValue(aX, aY);
572 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
574 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
575 (getCurrentOperation());
576 if (aFOperation && aFOperation->isEditOperation()) {
577 std::string aId = aFOperation->id().toStdString();
578 if (isDistanceOperation(aFOperation))
580 // Activate dimension value editing on double click
581 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
582 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
583 // Find corresponded widget to activate value editing
584 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
585 if (aWgt->attributeID() == "ConstraintValue") {
594 void PartSet_SketcherMgr::onApplicationStarted()
596 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
597 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
598 XGUI_Workshop* aWorkshop = aConnector->workshop();
599 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
600 if (aPropertyPanel) {
601 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
602 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
605 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
606 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
607 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
609 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
610 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
611 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
614 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
616 if (!myClickedPoint.myIsInitialized)
619 ModuleBase_Operation* aOperation = getCurrentOperation();
620 // the distance constraint feature should not use the clickedd point
621 // this is workaround in order to don't throw down the flyout point value,
622 // set by execute() method of these type of features
623 if (isDistanceOperation(aOperation))
626 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
628 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
632 void PartSet_SketcherMgr::onBeforeContextMenu()
634 myIsPopupMenuActive = true;
637 void PartSet_SketcherMgr::onAfterContextMenu()
639 myIsPopupMenuActive = false;
642 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
645 Handle(V3d_View) aView = theWnd->v3dView();
646 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
648 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
649 thePoint.setValue(aX, anY);
652 void PartSet_SketcherMgr::launchEditing()
654 if (!myCurrentSelection.empty()) {
655 FeaturePtr aFeature = myCurrentSelection.begin().key();
656 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
657 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
659 myModule->editFeature(aSPFeature);
665 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
667 static QStringList aIds;
668 if (aIds.size() == 0) {
669 aIds << SketchPlugin_Line::ID().c_str();
670 aIds << SketchPlugin_Point::ID().c_str();
671 aIds << SketchPlugin_Arc::ID().c_str();
672 aIds << SketchPlugin_Circle::ID().c_str();
673 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
674 aIds.append(constraintsIdList());
679 const QStringList& PartSet_SketcherMgr::constraintsIdList()
681 static QStringList aIds;
682 if (aIds.size() == 0) {
683 aIds << SketchPlugin_ConstraintLength::ID().c_str();
684 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
685 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
686 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
687 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
688 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
689 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
690 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
691 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
692 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
693 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
694 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
695 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
696 aIds << SketchPlugin_MultiRotation::ID().c_str();
697 aIds << SketchPlugin_MultiTranslation::ID().c_str();
702 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
706 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
707 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
708 theModes.append(SketcherPrs_Tools::Sel_Constraint);
709 theModes.append(TopAbs_VERTEX);
710 theModes.append(TopAbs_EDGE);
713 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
715 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
718 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
720 return theOperation &&
721 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
724 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
726 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
728 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
731 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
733 return (theId == SketchPlugin_Line::ID()) ||
734 (theId == SketchPlugin_Point::ID()) ||
735 (theId == SketchPlugin_Arc::ID()) ||
736 (theId == SketchPlugin_Circle::ID());
739 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
741 std::string aId = theOperation ? theOperation->id().toStdString() : "";
743 return (aId == SketchPlugin_ConstraintLength::ID()) ||
744 (aId == SketchPlugin_ConstraintDistance::ID()) ||
745 (aId == SketchPlugin_ConstraintRadius::ID()) ||
746 (aId == SketchPlugin_ConstraintAngle::ID());
749 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
751 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
752 (getCurrentOperation());
756 myModule->onViewTransformed();
758 // Display all sketcher sub-Objects
759 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
760 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
762 // Hide sketcher result
763 std::list<ResultPtr> aResults = myCurrentSketch->results();
764 std::list<ResultPtr>::const_iterator aIt;
765 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
766 (*aIt)->setDisplayed(false);
768 myCurrentSketch->setDisplayed(false);
770 // Display sketcher objects
771 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
772 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
773 std::list<ResultPtr> aResults = aFeature->results();
774 std::list<ResultPtr>::const_iterator aIt;
775 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
776 (*aIt)->setDisplayed(true);
778 aFeature->setDisplayed(true);
781 if (myPlaneFilter.IsNull())
782 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
784 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
786 bool aHasPlane = false;
787 std::shared_ptr<GeomAPI_Pln> aPln;
788 if (aFOperation->isEditOperation()) {
789 // If it is editing of sketch then it means that plane is already defined
790 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
794 myPlaneFilter->setPlane(aPln);
796 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
797 // all sketch objects should be activated in the sketch selection modes by edit operation start
798 // in case of creation operation, there is an active widget, which activates own selection mode
799 if (aFOperation->isEditOperation() && aHasPlane)
800 aConnector->activateModuleSelectionModes();
803 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation*/* theOperation*/)
805 myIsMouseOverWindow = false;
806 myIsConstraintsShown = true;
807 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
808 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
810 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
812 DataPtr aData = myCurrentSketch->data();
813 if (!aData->isValid()) {
814 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
815 // The sketch was aborted
816 myCurrentSketch = CompositeFeaturePtr();
817 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
819 // Erase all sketcher objects
820 QStringList aSketchIds = sketchOperationIdList();
821 QObjectPtrList aObjects = aDisplayer->displayedObjects();
822 foreach (ObjectPtr aObj, aObjects) {
823 DataPtr aObjData = aObj->data();
824 if (!aObjData->isValid())
825 aObj->setDisplayed(false);
829 // Hide all sketcher sub-Objects
830 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
831 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
832 std::list<ResultPtr> aResults = aFeature->results();
833 std::list<ResultPtr>::const_iterator aIt;
834 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
835 (*aIt)->setDisplayed(false);
837 aFeature->setDisplayed(false);
839 // Display sketcher result
840 std::list<ResultPtr> aResults = myCurrentSketch->results();
841 std::list<ResultPtr>::const_iterator aIt;
842 Events_Loop* aLoop = Events_Loop::loop();
843 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
844 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
845 (*aIt)->setDisplayed(true);
846 // this display event is needed because sketch already may have "displayed" state,
847 // but not displayed while it is still active (issue 613, abort of existing sketch)
848 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
850 myCurrentSketch->setDisplayed(true);
852 myCurrentSketch = CompositeFeaturePtr();
853 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
855 Events_Loop::loop()->flush(aDispEvent);
857 // restore the module selection modes, which were changed on startSketch
858 aConnector->activateModuleSelectionModes();
861 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
863 if (constraintsIdList().contains(theOperation->id())) {
864 // Show constraints if a constraint was created
865 onShowConstraintsToggle(true);
867 connectToPropertyPanel(true);
870 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
872 connectToPropertyPanel(false);
873 myIsResetCurrentValue = false;
874 myIsMouseOverViewProcessed = true;
875 operationMgr()->onValidateOperation();
878 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
880 if (isNestedCreateOperation(theOperation)) {
881 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
884 FeaturePtr aFeature = aFOperation->feature();
885 // it is necessary to check the the feature data validity because
886 // some kind of features are removed by an operation commit(the macro state of a feature)
887 if (aFeature.get() && aFeature->data()->isValid()) {
888 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
894 bool PartSet_SketcherMgr::canUndo() const
896 return isNestedCreateOperation(getCurrentOperation());
899 bool PartSet_SketcherMgr::canRedo() const
901 return isNestedCreateOperation(getCurrentOperation());
904 bool PartSet_SketcherMgr::canCommitOperation() const
906 bool aCanCommit = true;
908 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
914 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
916 bool aCanErase = true;
917 // when the sketch operation is active, results of sketch sub-feature can not be hidden
918 if (myCurrentSketch.get()) {
919 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
921 // Display sketcher objects
922 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
924 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
925 std::list<ResultPtr> aResults = aFeature->results();
926 std::list<ResultPtr>::const_iterator anIt;
927 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
928 aCanErase = *anIt != aResult;
936 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
938 bool aCanDisplay = true;
940 bool aHasActiveSketch = activeSketch().get() != NULL;
941 if (aHasActiveSketch) {
942 // 1. the sketch feature should not be displayed during the sketch active operation
943 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
944 // nested features can be visualized
945 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
946 if (aFeature.get() != NULL && aFeature == activeSketch()) {
950 else { // there are no an active sketch
951 // 2. sketch sub-features should not be visualized if the sketch operation is not active
952 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
953 if (aFeature.get() != NULL) {
954 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
955 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
956 if (aSketchFeature.get()) {
962 // 3. the method should not filter the objects, which are not related to the current operation.
963 // The object is filtered just if it is a current operation feature or this feature result
964 bool isObjectFound = false;
965 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
966 (getCurrentOperation());
968 FeaturePtr aFeature = aFOperation->feature();
969 if (aFeature.get()) {
970 std::list<ResultPtr> aResults = aFeature->results();
971 if (theObject == aFeature)
972 isObjectFound = true;
974 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
975 for (; anIt != aLast; anIt++) {
976 isObjectFound = *anIt == theObject;
984 // 4. For created nested feature operation do not display the created feature if
985 // the mouse curstor leaves the OCC window.
986 // The correction cases, which ignores this condition:
987 // a. the property panel values modification
988 // b. the popup menu activated
989 // c. widget editor control
990 #ifndef DEBUG_DO_NOT_BY_ENTER
991 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
992 ModuleBase_Operation* aOperation = getCurrentOperation();
993 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
994 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
995 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
996 // the active widget editor should not influence here. The presentation should be visible always
997 // when this widget is active.
998 if (!anEditorWdg && !myIsPopupMenuActive) {
999 // during a nested create operation, the feature is redisplayed only if the mouse over view
1000 // of there was a value modified in the property panel after the mouse left the view
1001 aCanDisplay = canDisplayCurrentCreatedFeature();
1008 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1010 return myIsMouseOverWindow || !myIsResetCurrentValue;
1011 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1012 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1016 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1018 bool isFoundObject = false;
1020 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1021 if (anObjectFeature.get()) {
1022 int aSize = myCurrentSketch->numberOfSubs();
1023 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1024 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1025 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1028 return isFoundObject;
1031 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1033 if (myPlaneFilter.IsNull())
1034 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1036 myPlaneFilter->setPlane(thePln);
1039 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1040 const FeaturePtr& theSketch,
1041 ModuleBase_IWorkshop* theWorkshop,
1042 FeatureToSelectionMap& theSelection)
1044 if (theFeature.get() == NULL)
1047 std::set<AttributePtr> aSelectedAttributes;
1048 std::set<ResultPtr> aSelectedResults;
1050 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1051 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1052 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1053 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1055 std::list<ResultPtr> aResults = theFeature->results();
1056 std::list<ResultPtr>::const_iterator aIt;
1057 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1059 ResultPtr aResult = *aIt;
1060 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1061 if (aAISObj.get() == NULL)
1063 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1064 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1066 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1067 if (anOwner->Selectable() != anAISIO)
1069 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1070 aSelectedAttributes, aSelectedResults);
1072 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1073 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1074 if (anOwner.IsNull())
1076 if (anOwner->Selectable() != anAISIO)
1078 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1079 aSelectedAttributes, aSelectedResults);
1082 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1085 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1086 const FeaturePtr& theSketch,
1087 ModuleBase_IWorkshop* theWorkshop,
1088 const FeatureToSelectionMap& theSelection,
1089 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1091 if (theFeature.get() == NULL)
1094 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1095 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1096 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1098 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1099 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1100 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1101 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1103 // 1. found the feature's owners. Check the AIS objects of the constructions
1104 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1105 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1106 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1108 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1109 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1110 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1111 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1112 if (!anOwner.IsNull())
1113 anOwnersToSelect.Add(anOwner);
1117 // 2. found the feature results's owners
1118 std::list<ResultPtr> aResults = theFeature->results();
1119 std::list<ResultPtr>::const_iterator aIt;
1120 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1122 ResultPtr aResult = *aIt;
1123 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1124 if (aAISObj.get() == NULL)
1126 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1128 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1129 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1130 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1131 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1132 if ( anOwner.IsNull() || !anOwner->HasShape() )
1134 const TopoDS_Shape& aShape = anOwner->Shape();
1135 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1136 if (aShapeType == TopAbs_VERTEX) {
1137 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1138 if (aPntAttr.get() != NULL &&
1139 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1140 anOwnersToSelect.Add(anOwner);
1143 else if (aShapeType == TopAbs_EDGE) {
1144 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1145 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1146 anOwnersToSelect.FindIndex(anOwner) <= 0)
1147 anOwnersToSelect.Add(anOwner);
1153 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1155 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1156 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1157 XGUI_Workshop* aWorkshop = aConnector->workshop();
1158 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1159 if (aPropertyPanel) {
1160 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1161 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1163 connect(aWidget, SIGNAL(beforeValuesChanged()),
1164 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1165 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1166 connect(aWidget, SIGNAL(afterValuesChanged()),
1167 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1170 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1171 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1172 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1173 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1174 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1180 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1182 return myModule->workshop()->currentOperation();
1185 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1186 const bool isEditOperation,
1187 const bool isToDisplay,
1188 const bool isFlushRedisplay)
1190 #ifdef DEBUG_DO_NOT_BY_ENTER
1194 if (isEditOperation || !theFeature.get())
1197 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1198 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1200 // 1. change visibility of the object itself, here the presentable object is processed,
1201 // e.g. constraints features
1202 //FeaturePtr aFeature = aFOperation->feature();
1203 std::list<ResultPtr> aResults = theFeature->results();
1205 theFeature->setDisplayed(true);
1207 theFeature->setDisplayed(false);
1209 // change visibility of the object results, e.g. non-constraint features
1210 std::list<ResultPtr>::const_iterator aIt;
1211 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1213 (*aIt)->setDisplayed(true);
1216 (*aIt)->setDisplayed(false);
1219 if (isFlushRedisplay)
1220 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1223 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1225 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1226 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1227 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1229 QList<FeaturePtr> aFeatureList;
1230 if (theHighlightedOnly) {
1231 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1234 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1236 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1237 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1240 // 1. it is necessary to save current selection in order to restore it after the features moving
1241 myCurrentSelection.clear();
1242 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1243 for (; anIt != aLast; anIt++) {
1244 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1246 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1249 void PartSet_SketcherMgr::restoreSelection()
1251 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1252 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1253 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1254 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1255 aSLast = myCurrentSelection.end();
1256 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1257 for (; aSIt != aSLast; aSIt++) {
1258 anOwnersToSelect.Clear();
1259 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1261 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1265 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1267 if (myIsConstraintsShown == theOn)
1269 if (myCurrentSketch.get() == NULL)
1272 myIsConstraintsShown = theOn;
1274 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1275 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1277 const QStringList& aConstrIds = constraintsIdList();
1278 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1279 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1280 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1281 if (myIsConstraintsShown)
1282 aSubFeature->setDisplayed(true);
1284 aSubFeature->setDisplayed(false);
1287 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1290 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1292 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1293 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1296 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1298 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1299 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1300 XGUI_Workshop* aWorkshop = aConnector->workshop();
1302 return aWorkshop->operationMgr();