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 <XGUI_ModuleConnector.h>
15 #include <XGUI_Displayer.h>
16 #include <XGUI_Workshop.h>
17 #include <XGUI_ContextMenuMgr.h>
18 #include <XGUI_Selection.h>
19 #include <XGUI_SelectionMgr.h>
20 #include <XGUI_ModuleConnector.h>
21 #include <XGUI_PropertyPanel.h>
22 #include <XGUI_ViewerProxy.h>
23 #include <XGUI_OperationMgr.h>
25 #include <ModuleBase_IPropertyPanel.h>
26 #include <ModuleBase_ISelection.h>
27 #include <ModuleBase_IViewer.h>
28 #include <ModuleBase_IWorkshop.h>
29 #include <ModuleBase_IViewWindow.h>
30 #include <ModuleBase_ModelWidget.h>
31 #include <ModuleBase_Operation.h>
32 #include <ModuleBase_OperationFeature.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_WidgetEditor.h>
36 #include <GeomDataAPI_Point2D.h>
38 #include <Events_Loop.h>
40 #include <SketchPlugin_Line.h>
41 #include <SketchPlugin_Sketch.h>
42 #include <SketchPlugin_Point.h>
43 #include <SketchPlugin_Arc.h>
44 #include <SketchPlugin_Circle.h>
45 #include <SketchPlugin_ConstraintLength.h>
46 #include <SketchPlugin_ConstraintDistance.h>
47 #include <SketchPlugin_ConstraintParallel.h>
48 #include <SketchPlugin_ConstraintPerpendicular.h>
49 #include <SketchPlugin_ConstraintRadius.h>
50 #include <SketchPlugin_ConstraintRigid.h>
51 #include <SketchPlugin_ConstraintHorizontal.h>
52 #include <SketchPlugin_ConstraintVertical.h>
53 #include <SketchPlugin_ConstraintEqual.h>
54 #include <SketchPlugin_ConstraintTangent.h>
55 #include <SketchPlugin_ConstraintCoincidence.h>
56 #include <SketchPlugin_ConstraintFillet.h>
57 #include <SketchPlugin_ConstraintMirror.h>
58 #include <SketchPlugin_ConstraintAngle.h>
59 #include <SketchPlugin_MultiRotation.h>
60 #include <SketchPlugin_MultiTranslation.h>
62 #include <SketcherPrs_Tools.h>
64 #include <SelectMgr_IndexedMapOfOwner.hxx>
65 #include <StdSelect_BRepOwner.hxx>
67 //#include <AIS_DimensionSelectionMode.hxx>
68 #include <AIS_Shape.hxx>
70 #include <ModelAPI_Events.h>
71 #include <ModelAPI_Session.h>
72 #include <ModelAPI_AttributeString.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 myIsResetCurrentValue = false;
280 if (isNestedCreateOperation(getCurrentOperation()))
282 // it is necessary to save current selection in order to restore it after the values are modifed
285 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
286 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
287 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
288 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
291 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
293 if (isNestedCreateOperation(getCurrentOperation()))
295 // it is necessary to restore current selection in order to restore it after the values are modified
297 myCurrentSelection.clear();
299 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
300 // viewer happens by deselect/select the modified objects. The flag should be restored after
301 // the selection processing. The update viewer should be also called.
302 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
303 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
304 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
305 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
306 aDisplayer->updateViewer();
309 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
311 if (!isNestedCreateOperation(getCurrentOperation()))
314 // visualize the current operation feature
315 //myIsResetCurrentValue = false;
316 operationMgr()->onValidateOperation();
317 // the feature is to be erased here, but it is correct to call canDisplayObject because
318 // there can be additional check (e.g. editor widget in distance constraint)
319 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
320 (getCurrentOperation());
322 FeaturePtr aFeature = aFOperation->feature();
323 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
327 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
329 get2dPoint(theWnd, theEvent, myClickedPoint);
331 if (!(theEvent->buttons() & Qt::LeftButton))
334 // Clear dragging mode
335 myIsDragging = false;
337 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
338 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
339 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
340 if (!aViewer->canDragByMouse())
343 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
344 (getCurrentOperation());
348 if (aFOperation->isEditOperation()) {
349 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
350 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
351 // If the current widget is a selector, do nothing, it processes the mouse press
352 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
357 // Use only for sketch operations
358 if (myCurrentSketch) {
359 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
362 bool isSketcher = isSketchOperation(aFOperation);
363 bool isSketchOpe = isNestedSketchOperation(aFOperation);
365 // Avoid non-sketch operations
366 if ((!isSketchOpe) && (!isSketcher))
369 bool isEditing = aFOperation->isEditOperation();
371 // Ignore creation sketch operation
372 if ((!isSketcher) && (!isEditing))
375 // MoveTo in order to highlight current object
376 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
378 // Remember highlighted objects for editing
379 ModuleBase_ISelection* aSelect = aWorkshop->selection();
381 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
382 storeSelection(!aHasShift);
384 if (myCurrentSelection.empty()) {
385 if (isSketchOpe && (!isSketcher))
386 // commit previous operation
387 if (!aFOperation->commit())
388 aFOperation->abort();
391 // Init flyout point for radius rotation
392 FeaturePtr aFeature = myCurrentSelection.begin().key();
396 get2dPoint(theWnd, theEvent, myCurrentPoint);
399 if (aFeature.get() != NULL) {
400 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
401 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
402 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
403 DataPtr aData = aSPFeature->data();
404 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
405 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
406 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
407 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
410 } else if (isSketchOpe && isEditing) {
411 // If selected another object commit current result
412 aFOperation->commit();
415 get2dPoint(theWnd, theEvent, myCurrentPoint);
418 // This is necessary in order to finalize previous operation
419 QApplication::processEvents();
425 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
427 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
428 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
429 if (!aViewer->canDragByMouse())
431 ModuleBase_Operation* aOp = getCurrentOperation();
433 if (isNestedSketchOperation(aOp)) {
434 get2dPoint(theWnd, theEvent, myClickedPoint);
436 // Only for sketcher operations
440 myCurrentSelection.clear();
441 // Reselect edited object
442 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
443 if (theEvent->modifiers() & Qt::ShiftModifier)
444 aViewer->AISContext()->ShiftSelect();
446 aViewer->AISContext()->Select();
452 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
453 myIsDragging = false;
456 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
458 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
459 myIsMouseOverViewProcessed = true;
460 // 1. perform the widget mouse move functionality and display the presentation
461 ModuleBase_Operation* aOperation = getCurrentOperation();
462 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
463 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
464 // the mouse move should be processed in the widget, if it can in order to visualize correct
465 // presentation. These widgets correct the feature attribute according to the mouse position
466 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
468 aPoint2DWdg->onMouseMove(theWnd, theEvent);
470 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
473 aDistanceWdg->onMouseMove(theWnd, theEvent);
475 // the feature is to be erased here, but it is correct to call canDisplayObject because
476 // there can be additional check (e.g. editor widget in distance constraint)
477 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
478 (getCurrentOperation());
480 FeaturePtr aFeature = aFOperation->feature();
481 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
485 myClickedPoint.clear();
488 // 1. the current selection is saved in the mouse press method in order to restore it after moving
489 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
490 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
491 // deselected). This flag should be restored in the slot, processed the mouse release signal.
492 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
493 aViewer->enableSelection(false);
495 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
496 if (!aCurrentOperation)
498 if (isSketchOperation(aCurrentOperation))
499 return; // No edit operation activated
501 Handle(V3d_View) aView = theWnd->v3dView();
502 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
504 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
505 double dX = aX - myCurrentPoint.myCurX;
506 double dY = aY - myCurrentPoint.myCurY;
508 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
509 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
510 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
511 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
512 // viewer happens by deselect/select the modified objects. The flag should be restored after
513 // the selection processing. The update viewer should be also called.
514 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
516 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
517 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
518 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
519 aLast = myCurrentSelection.end();
520 // 4. the features and attributes modification(move)
521 bool isModified = false;
522 for (; anIt != aLast; anIt++) {
523 FeaturePtr aFeature = anIt.key();
525 std::set<AttributePtr> anAttributes = anIt.value().first;
526 // Process selection by attribute: the priority to the attribute
527 if (!anAttributes.empty()) {
528 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
529 anAttLast = anAttributes.end();
530 for (; anAttIt != anAttLast; anAttIt++) {
531 AttributePtr anAttr = *anAttIt;
532 if (anAttr.get() == NULL)
534 std::string aAttrId = anAttr->id();
535 DataPtr aData = aFeature->data();
536 if (aData->isValid()) {
537 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
538 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
539 if (aPoint.get() != NULL) {
540 bool isImmutable = aPoint->setImmutable(true);
541 aPoint->move(dX, dY);
543 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
544 aPoint->setImmutable(isImmutable);
549 // Process selection by feature
550 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
551 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
552 if (aSketchFeature) {
553 aSketchFeature->move(dX, dY);
555 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
559 // the modified state of the current operation should be updated if there are features, which
562 aCurrentOperation->onValuesChanged();
564 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
565 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
567 // 5. it is necessary to save current selection in order to restore it after the features moving
569 // 6. restore the update viewer flag and call this update
570 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
571 aDisplayer->updateViewer();
574 myCurrentPoint.setValue(aX, aY);
578 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
580 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
581 (getCurrentOperation());
582 if (aFOperation && aFOperation->isEditOperation()) {
583 std::string aId = aFOperation->id().toStdString();
584 if (isDistanceOperation(aFOperation))
586 // Activate dimension value editing on double click
587 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
588 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
589 // Find corresponded widget to activate value editing
590 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
591 if (aWgt->attributeID() == "ConstraintValue") {
600 void PartSet_SketcherMgr::onApplicationStarted()
602 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
603 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
604 XGUI_Workshop* aWorkshop = aConnector->workshop();
605 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
606 if (aPropertyPanel) {
607 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
608 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
611 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
612 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
613 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
615 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
616 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
617 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
620 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
622 if (!myClickedPoint.myIsInitialized)
625 ModuleBase_Operation* aOperation = getCurrentOperation();
626 // the distance constraint feature should not use the clickedd point
627 // this is workaround in order to don't throw down the flyout point value,
628 // set by execute() method of these type of features
629 if (isDistanceOperation(aOperation))
632 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
634 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
638 void PartSet_SketcherMgr::onBeforeContextMenu()
640 myIsPopupMenuActive = true;
643 void PartSet_SketcherMgr::onAfterContextMenu()
645 myIsPopupMenuActive = false;
648 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
651 Handle(V3d_View) aView = theWnd->v3dView();
652 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
654 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
655 thePoint.setValue(aX, anY);
658 void PartSet_SketcherMgr::launchEditing()
660 if (!myCurrentSelection.empty()) {
661 FeaturePtr aFeature = myCurrentSelection.begin().key();
662 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
663 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
665 myModule->editFeature(aSPFeature);
670 bool PartSet_SketcherMgr::sketchSolverError()
672 bool anError = false;
673 CompositeFeaturePtr aSketch = activeSketch();
675 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
676 anError = !aAttributeString->value().empty();
681 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
683 QString anError = "";
684 if (!theFeature.get() || !theFeature->data()->isValid())
687 CompositeFeaturePtr aSketch = activeSketch();
688 if (aSketch.get() && aSketch == theFeature) {
689 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
690 anError = aAttributeString->value().c_str();
692 else if (myIsResetCurrentValue) { // this flag do not allow commit of the current operation
693 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
694 (getCurrentOperation());
696 FeaturePtr aFeature = aFOperation->feature();
697 if (aFeature.get() && aFeature == theFeature && isNestedCreateOperation(aFOperation)) {
698 QString anAttributeName = "";
699 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
700 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
702 AttributePtr anAttr = aFeature->attribute(anActiveWgt->attributeID());
704 anAttributeName = anAttr->id().c_str();
706 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
713 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
715 static QStringList aIds;
716 if (aIds.size() == 0) {
717 aIds << SketchPlugin_Line::ID().c_str();
718 aIds << SketchPlugin_Point::ID().c_str();
719 aIds << SketchPlugin_Arc::ID().c_str();
720 aIds << SketchPlugin_Circle::ID().c_str();
721 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
722 aIds.append(constraintsIdList());
727 const QStringList& PartSet_SketcherMgr::constraintsIdList()
729 static QStringList aIds;
730 if (aIds.size() == 0) {
731 aIds << SketchPlugin_ConstraintLength::ID().c_str();
732 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
733 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
734 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
735 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
736 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
737 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
738 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
739 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
740 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
741 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
742 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
743 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
744 aIds << SketchPlugin_MultiRotation::ID().c_str();
745 aIds << SketchPlugin_MultiTranslation::ID().c_str();
750 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
754 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
755 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
756 theModes.append(SketcherPrs_Tools::Sel_Constraint);
757 theModes.append(TopAbs_VERTEX);
758 theModes.append(TopAbs_EDGE);
761 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
763 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
766 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
768 return theOperation &&
769 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
772 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
774 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
776 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
779 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
781 return (theId == SketchPlugin_Line::ID()) ||
782 (theId == SketchPlugin_Point::ID()) ||
783 (theId == SketchPlugin_Arc::ID()) ||
784 (theId == SketchPlugin_Circle::ID());
787 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
789 std::string aId = theOperation ? theOperation->id().toStdString() : "";
791 return (aId == SketchPlugin_ConstraintLength::ID()) ||
792 (aId == SketchPlugin_ConstraintDistance::ID()) ||
793 (aId == SketchPlugin_ConstraintRadius::ID()) ||
794 (aId == SketchPlugin_ConstraintAngle::ID());
797 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
799 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
800 (getCurrentOperation());
804 myModule->onViewTransformed();
806 // Display all sketcher sub-Objects
807 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
808 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
810 // Hide sketcher result
811 std::list<ResultPtr> aResults = myCurrentSketch->results();
812 std::list<ResultPtr>::const_iterator aIt;
813 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
814 (*aIt)->setDisplayed(false);
816 myCurrentSketch->setDisplayed(false);
818 // Display sketcher objects
819 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
820 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
821 std::list<ResultPtr> aResults = aFeature->results();
822 std::list<ResultPtr>::const_iterator aIt;
823 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
824 (*aIt)->setDisplayed(true);
826 aFeature->setDisplayed(true);
829 if (myPlaneFilter.IsNull())
830 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
832 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
834 bool aHasPlane = false;
835 std::shared_ptr<GeomAPI_Pln> aPln;
836 if (aFOperation->isEditOperation()) {
837 // If it is editing of sketch then it means that plane is already defined
838 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
842 myPlaneFilter->setPlane(aPln);
844 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
845 // all sketch objects should be activated in the sketch selection modes by edit operation start
846 // in case of creation operation, there is an active widget, which activates own selection mode
847 if (aFOperation->isEditOperation() && aHasPlane)
848 aConnector->activateModuleSelectionModes();
851 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* /* theOperation*/)
853 myIsMouseOverWindow = false;
854 myIsConstraintsShown = true;
855 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
856 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
858 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
860 DataPtr aData = myCurrentSketch->data();
861 if (!aData->isValid()) {
862 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
863 // The sketch was aborted
864 myCurrentSketch = CompositeFeaturePtr();
865 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
867 // Erase all sketcher objects
868 QStringList aSketchIds = sketchOperationIdList();
869 QObjectPtrList aObjects = aDisplayer->displayedObjects();
870 foreach (ObjectPtr aObj, aObjects) {
871 DataPtr aObjData = aObj->data();
872 if (!aObjData->isValid())
873 aObj->setDisplayed(false);
877 // Hide all sketcher sub-Objects
878 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
879 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
880 std::list<ResultPtr> aResults = aFeature->results();
881 std::list<ResultPtr>::const_iterator aIt;
882 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
883 (*aIt)->setDisplayed(false);
885 aFeature->setDisplayed(false);
887 // Display sketcher result
888 std::list<ResultPtr> aResults = myCurrentSketch->results();
889 std::list<ResultPtr>::const_iterator aIt;
890 Events_Loop* aLoop = Events_Loop::loop();
891 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
892 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
893 (*aIt)->setDisplayed(true);
894 // this display event is needed because sketch already may have "displayed" state,
895 // but not displayed while it is still active (issue 613, abort of existing sketch)
896 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
898 myCurrentSketch->setDisplayed(true);
900 myCurrentSketch = CompositeFeaturePtr();
901 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
903 Events_Loop::loop()->flush(aDispEvent);
905 // restore the module selection modes, which were changed on startSketch
906 aConnector->activateModuleSelectionModes();
909 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
911 connectToPropertyPanel(true);
914 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
916 connectToPropertyPanel(false);
917 myIsResetCurrentValue = false;
918 myIsMouseOverViewProcessed = true;
919 operationMgr()->onValidateOperation();
922 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
924 if (isNestedCreateOperation(theOperation)) {
925 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
928 FeaturePtr aFeature = aFOperation->feature();
929 // it is necessary to check the the feature data validity because
930 // some kind of features are removed by an operation commit(the macro state of a feature)
931 if (aFeature.get() && aFeature->data()->isValid()) {
932 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
938 bool PartSet_SketcherMgr::canUndo() const
940 return isNestedCreateOperation(getCurrentOperation());
943 bool PartSet_SketcherMgr::canRedo() const
945 return isNestedCreateOperation(getCurrentOperation());
948 bool PartSet_SketcherMgr::canCommitOperation() const
950 bool aCanCommit = true;
952 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
958 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
960 bool aCanErase = true;
961 // when the sketch operation is active, results of sketch sub-feature can not be hidden
962 if (myCurrentSketch.get()) {
963 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
965 // Display sketcher objects
966 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
968 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
969 std::list<ResultPtr> aResults = aFeature->results();
970 std::list<ResultPtr>::const_iterator anIt;
971 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
972 aCanErase = *anIt != aResult;
980 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
982 bool aCanDisplay = true;
984 bool aHasActiveSketch = activeSketch().get() != NULL;
985 if (aHasActiveSketch) {
986 // 1. the sketch feature should not be displayed during the sketch active operation
987 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
988 // nested features can be visualized
989 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
990 if (aFeature.get() != NULL && aFeature == activeSketch()) {
994 else { // there are no an active sketch
995 // 2. sketch sub-features should not be visualized if the sketch operation is not active
996 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
997 if (aFeature.get() != NULL) {
998 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
999 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1000 if (aSketchFeature.get()) {
1001 aCanDisplay = false;
1006 // 3. the method should not filter the objects, which are not related to the current operation.
1007 // The object is filtered just if it is a current operation feature or this feature result
1008 bool isObjectFound = false;
1009 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1010 (getCurrentOperation());
1012 FeaturePtr aFeature = aFOperation->feature();
1013 if (aFeature.get()) {
1014 std::list<ResultPtr> aResults = aFeature->results();
1015 if (theObject == aFeature)
1016 isObjectFound = true;
1018 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1019 for (; anIt != aLast; anIt++) {
1020 isObjectFound = *anIt == theObject;
1028 // 4. For created nested feature operation do not display the created feature if
1029 // the mouse curstor leaves the OCC window.
1030 // The correction cases, which ignores this condition:
1031 // a. the property panel values modification
1032 // b. the popup menu activated
1033 // c. widget editor control
1034 #ifndef DEBUG_DO_NOT_BY_ENTER
1035 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1036 ModuleBase_Operation* aOperation = getCurrentOperation();
1037 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1038 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
1039 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
1040 // the active widget editor should not influence here. The presentation should be visible always
1041 // when this widget is active.
1042 if (!anEditorWdg && !myIsPopupMenuActive) {
1043 // during a nested create operation, the feature is redisplayed only if the mouse over view
1044 // of there was a value modified in the property panel after the mouse left the view
1045 aCanDisplay = canDisplayCurrentCreatedFeature();
1052 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1054 return myIsMouseOverWindow || !myIsResetCurrentValue;
1055 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1056 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1060 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1062 bool isFoundObject = false;
1064 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1065 if (anObjectFeature.get()) {
1066 int aSize = myCurrentSketch->numberOfSubs();
1067 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1068 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1069 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1072 return isFoundObject;
1075 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1077 if (myPlaneFilter.IsNull())
1078 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1080 myPlaneFilter->setPlane(thePln);
1083 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1084 const FeaturePtr& theSketch,
1085 ModuleBase_IWorkshop* theWorkshop,
1086 FeatureToSelectionMap& theSelection)
1088 if (theFeature.get() == NULL)
1091 std::set<AttributePtr> aSelectedAttributes;
1092 std::set<ResultPtr> aSelectedResults;
1094 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1095 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1096 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1097 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1099 std::list<ResultPtr> aResults = theFeature->results();
1100 std::list<ResultPtr>::const_iterator aIt;
1101 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1103 ResultPtr aResult = *aIt;
1104 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1105 if (aAISObj.get() == NULL)
1107 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1108 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1110 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1111 if (anOwner->Selectable() != anAISIO)
1113 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1114 aSelectedAttributes, aSelectedResults);
1116 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1117 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1118 if (anOwner.IsNull())
1120 if (anOwner->Selectable() != anAISIO)
1122 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1123 aSelectedAttributes, aSelectedResults);
1126 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1129 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1130 const FeaturePtr& theSketch,
1131 ModuleBase_IWorkshop* theWorkshop,
1132 const FeatureToSelectionMap& theSelection,
1133 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
1135 if (theFeature.get() == NULL)
1138 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1139 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1140 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1142 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1143 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1144 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1145 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1147 // 1. found the feature's owners. Check the AIS objects of the constructions
1148 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1149 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1150 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1152 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1153 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1154 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1155 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1156 if (!anOwner.IsNull())
1157 anOwnersToSelect.Add(anOwner);
1161 // 2. found the feature results's owners
1162 std::list<ResultPtr> aResults = theFeature->results();
1163 std::list<ResultPtr>::const_iterator aIt;
1164 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1166 ResultPtr aResult = *aIt;
1167 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1168 if (aAISObj.get() == NULL)
1170 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1172 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1173 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1174 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1175 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1176 if ( anOwner.IsNull() || !anOwner->HasShape() )
1178 const TopoDS_Shape& aShape = anOwner->Shape();
1179 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1180 if (aShapeType == TopAbs_VERTEX) {
1181 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1182 if (aPntAttr.get() != NULL &&
1183 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1184 anOwnersToSelect.Add(anOwner);
1187 else if (aShapeType == TopAbs_EDGE) {
1188 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1189 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1190 anOwnersToSelect.FindIndex(anOwner) <= 0)
1191 anOwnersToSelect.Add(anOwner);
1197 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1199 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1200 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1201 XGUI_Workshop* aWorkshop = aConnector->workshop();
1202 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1203 if (aPropertyPanel) {
1204 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1205 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1207 connect(aWidget, SIGNAL(beforeValuesChanged()),
1208 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1209 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1210 connect(aWidget, SIGNAL(afterValuesChanged()),
1211 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1214 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1215 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1216 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1217 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1218 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1224 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1226 return myModule->workshop()->currentOperation();
1229 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1230 const bool isEditOperation,
1231 const bool isToDisplay,
1232 const bool isFlushRedisplay)
1234 #ifdef DEBUG_DO_NOT_BY_ENTER
1238 if (isEditOperation || !theFeature.get())
1241 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1242 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1244 // 1. change visibility of the object itself, here the presentable object is processed,
1245 // e.g. constraints features
1246 //FeaturePtr aFeature = aFOperation->feature();
1247 std::list<ResultPtr> aResults = theFeature->results();
1249 theFeature->setDisplayed(true);
1251 theFeature->setDisplayed(false);
1253 // change visibility of the object results, e.g. non-constraint features
1254 std::list<ResultPtr>::const_iterator aIt;
1255 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1257 (*aIt)->setDisplayed(true);
1260 (*aIt)->setDisplayed(false);
1263 if (isFlushRedisplay)
1264 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1267 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1269 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1270 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1271 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1273 QList<FeaturePtr> aFeatureList;
1274 if (theHighlightedOnly) {
1275 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1278 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1280 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1281 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1284 // 1. it is necessary to save current selection in order to restore it after the features moving
1285 myCurrentSelection.clear();
1286 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1287 for (; anIt != aLast; anIt++) {
1288 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1290 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1293 void PartSet_SketcherMgr::restoreSelection()
1295 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1296 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1297 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1298 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1299 aSLast = myCurrentSelection.end();
1300 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1301 for (; aSIt != aSLast; aSIt++) {
1302 anOwnersToSelect.Clear();
1303 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1305 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1309 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1311 if (myIsConstraintsShown == theOn)
1313 if (myCurrentSketch.get() == NULL)
1316 myIsConstraintsShown = theOn;
1318 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1319 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1321 const QStringList& aConstrIds = constraintsIdList();
1322 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1323 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1324 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1325 if (myIsConstraintsShown)
1326 aSubFeature->setDisplayed(true);
1328 aSubFeature->setDisplayed(false);
1331 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1334 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1336 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1337 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1340 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1342 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1343 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1344 XGUI_Workshop* aWorkshop = aConnector->workshop();
1346 return aWorkshop->operationMgr();