1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_SketcherReetntrantMgr.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_WidgetPoint2d.h"
11 #include "PartSet_WidgetPoint2dDistance.h"
12 #include "PartSet_Tools.h"
13 #include "PartSet_WidgetSketchLabel.h"
15 #include <XGUI_ModuleConnector.h>
16 #include <XGUI_Displayer.h>
17 #include <XGUI_Workshop.h>
18 #include <XGUI_ContextMenuMgr.h>
19 #include <XGUI_Selection.h>
20 #include <XGUI_SelectionMgr.h>
21 #include <XGUI_ModuleConnector.h>
22 #include <XGUI_PropertyPanel.h>
23 #include <XGUI_ViewerProxy.h>
24 #include <XGUI_OperationMgr.h>
26 #include <ModuleBase_IPropertyPanel.h>
27 #include <ModuleBase_ISelection.h>
28 #include <ModuleBase_IViewer.h>
29 #include <ModuleBase_IWorkshop.h>
30 #include <ModuleBase_IViewWindow.h>
31 #include <ModuleBase_ModelWidget.h>
32 #include <ModuleBase_Operation.h>
33 #include <ModuleBase_OperationFeature.h>
34 #include <ModuleBase_Operation.h>
35 #include <ModuleBase_WidgetEditor.h>
37 #include <GeomDataAPI_Point2D.h>
39 #include <Events_Loop.h>
41 #include <SketchPlugin_Line.h>
42 #include <SketchPlugin_Sketch.h>
43 #include <SketchPlugin_Point.h>
44 #include <SketchPlugin_Arc.h>
45 #include <SketchPlugin_Circle.h>
46 #include <SketchPlugin_ConstraintLength.h>
47 #include <SketchPlugin_ConstraintDistance.h>
48 #include <SketchPlugin_ConstraintParallel.h>
49 #include <SketchPlugin_ConstraintPerpendicular.h>
50 #include <SketchPlugin_ConstraintRadius.h>
51 #include <SketchPlugin_ConstraintRigid.h>
52 #include <SketchPlugin_ConstraintHorizontal.h>
53 #include <SketchPlugin_ConstraintVertical.h>
54 #include <SketchPlugin_ConstraintEqual.h>
55 #include <SketchPlugin_ConstraintTangent.h>
56 #include <SketchPlugin_ConstraintCoincidence.h>
57 #include <SketchPlugin_ConstraintFillet.h>
58 #include <SketchPlugin_ConstraintMirror.h>
59 #include <SketchPlugin_ConstraintAngle.h>
60 #include <SketchPlugin_MultiRotation.h>
61 #include <SketchPlugin_MultiTranslation.h>
63 #include <SketcherPrs_Tools.h>
65 #include <SelectMgr_IndexedMapOfOwner.hxx>
66 #include <StdSelect_BRepOwner.hxx>
68 //#include <AIS_DimensionSelectionMode.hxx>
69 #include <AIS_Shape.hxx>
71 #include <ModelAPI_Events.h>
72 #include <ModelAPI_Session.h>
73 #include <ModelAPI_AttributeString.h>
75 #include <QMouseEvent>
76 #include <QApplication>
78 //#define DEBUG_DO_NOT_BY_ENTER
79 //#define DEBUG_MOUSE_OVER_WINDOW_FLAGS
81 /// Returns list of unique objects by sum of objects from List1 and List2
82 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
83 const QList<ModuleBase_ViewerPrs>& theList2)
85 QList<ModuleBase_ViewerPrs> aRes;
86 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
87 if (!aRes.contains(aPrs))
90 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
91 if (!aRes.contains(aPrs))
97 // Fills the list of features the list of selected presentations.
98 // \param theList a list of selected presentations
99 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
100 // and find the corresponded attribute
101 // \param theFeatureList an output list of features
102 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
103 const FeaturePtr theSketch,
104 QList<FeaturePtr>& theFeatureList)
106 QList<ModuleBase_ViewerPrs> aRes;
108 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
109 aLast = theList.end();
110 for (; anIt != aLast; anIt++)
112 ModuleBase_ViewerPrs aPrs = *anIt;
113 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
114 if (aFeature.get() && !theFeatureList.contains(aFeature))
115 theFeatureList.append(aFeature);
119 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
120 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
121 /// result as is to the list of results.
122 /// \param theOwner a viewer selected owner
123 /// \param theFeature a feature, where the attribute is searched
124 /// \param theSketch a current sketch
125 /// \param theSelectedAttribute an output list of attributes
126 /// \param theSelectedResults an output list of edge results
127 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
128 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
129 const ResultPtr& theResult,
130 std::set<AttributePtr>& aSelectedAttributes,
131 std::set<ResultPtr>& aSelectedResults)
133 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
134 if (aBRepOwner.IsNull())
136 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
137 aBRepOwner->Selectable());
138 if (aBRepOwner->HasShape()) {
139 const TopoDS_Shape& aShape = aBRepOwner->Shape();
140 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
141 if (aShapeType == TopAbs_VERTEX) {
142 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
144 if (aPntAttr.get() != NULL)
145 aSelectedAttributes.insert(aPntAttr);
147 else if (aShapeType == TopAbs_EDGE &&
148 aSelectedResults.find(theResult) == aSelectedResults.end()) {
149 aSelectedResults.insert(theResult);
154 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
155 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
156 myIsResetCurrentValue(false), myIsMouseOverWindow(false),
157 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
158 myIsPopupMenuActive(false), myIsConstraintsShown(true)
160 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
161 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
163 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
165 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
166 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
168 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
169 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
171 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
172 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
174 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
175 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
177 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
178 XGUI_Workshop* aWorkshop = aConnector->workshop();
179 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
182 PartSet_SketcherMgr::~PartSet_SketcherMgr()
184 if (!myPlaneFilter.IsNull())
185 myPlaneFilter.Nullify();
188 void PartSet_SketcherMgr::onEnterViewPort()
190 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
191 // created feature because it should be done in onMouseMove(). Some widgets watch
192 // the mouse move and use the cursor position to update own values. If the presentaion is
193 // redisplayed before this update, the feature presentation jumps from reset value to current.
194 myIsMouseOverWindow = true;
195 myIsResetCurrentValue = false;
196 // it is important to validate operation here only if sketch entity create operation is active
197 // because at this operation we reacts to the mouse leave/enter view port
198 //operationMgr()->onValidateOperation();
199 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
200 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
203 #ifdef DEBUG_DO_NOT_BY_ENTER
207 if (!isNestedCreateOperation(getCurrentOperation()))
210 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
211 operationMgr()->onValidateOperation();
213 // we need change displayed state of the current operation feature
214 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
215 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
216 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
217 // presentation becomes valid and redisplay happens
218 //ModuleBase_Operation* aOperation = getCurrentOperation();
219 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
220 (getCurrentOperation());
222 FeaturePtr aFeature = aFOperation->feature();
223 if (aFeature.get() && aFeature->data()->isValid()) {
224 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
229 void PartSet_SketcherMgr::onLeaveViewPort()
231 myIsMouseOverViewProcessed = false;
232 myIsMouseOverWindow = false;
233 // it is important to validate operation here only if sketch entity create operation is active
234 // because at this operation we reacts to the mouse leave/enter view port
235 //operationMgr()->onValidateOperation();
236 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
237 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
240 #ifdef DEBUG_DO_NOT_BY_ENTER
244 if (!isNestedCreateOperation(getCurrentOperation()))
247 QApplication::restoreOverrideCursor();
249 // the method should be performed if the popup menu is called,
250 // the reset of the current widget should not happen
251 if (myIsPopupMenuActive)
254 operationMgr()->onValidateOperation();
256 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
257 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
258 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
259 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
260 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
261 // obtained after reset value
262 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
263 ModuleBase_Operation* aOperation = getCurrentOperation();
264 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
265 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
266 if (aActiveWgt && aActiveWgt->reset()) {
267 myIsResetCurrentValue = true;
269 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
271 // hides the presentation of the current operation feature
272 // the feature is to be erased here, but it is correct to call canDisplayObject because
273 // there can be additional check (e.g. editor widget in distance constraint)
274 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
275 (getCurrentOperation());
277 FeaturePtr aFeature = aFOperation->feature();
278 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
282 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
284 myIsResetCurrentValue = false;
286 if (isNestedCreateOperation(getCurrentOperation()))
288 // it is necessary to save current selection in order to restore it after the values are modifed
291 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
292 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
293 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
294 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
297 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
299 if (isNestedCreateOperation(getCurrentOperation()))
301 // it is necessary to restore current selection in order to restore it after the values are modified
303 myCurrentSelection.clear();
305 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
306 // viewer happens by deselect/select the modified objects. The flag should be restored after
307 // the selection processing. The update viewer should be also called.
308 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
309 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
310 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
311 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
312 aDisplayer->updateViewer();
315 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
317 if (!isNestedCreateOperation(getCurrentOperation()))
320 // visualize the current operation feature
321 //myIsResetCurrentValue = false;
322 operationMgr()->onValidateOperation();
323 // the feature is to be erased here, but it is correct to call canDisplayObject because
324 // there can be additional check (e.g. editor widget in distance constraint)
325 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
326 (getCurrentOperation());
328 FeaturePtr aFeature = aFOperation->feature();
329 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
333 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
335 get2dPoint(theWnd, theEvent, myClickedPoint);
337 if (!(theEvent->buttons() & Qt::LeftButton))
340 if (myModule->sketchReentranceMgr()->processMousePressed())
343 // Clear dragging mode
344 myIsDragging = false;
346 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
347 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
348 if (!aViewer->canDragByMouse())
351 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
352 (getCurrentOperation());
356 if (aFOperation->isEditOperation()) {
357 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
358 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
359 // If the current widget is a selector, do nothing, it processes the mouse press
360 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
365 // Use only for sketch operations
366 if (myCurrentSketch) {
367 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
370 bool isSketcher = isSketchOperation(aFOperation);
371 bool isSketchOpe = isNestedSketchOperation(aFOperation);
373 // Avoid non-sketch operations
374 if ((!isSketchOpe) && (!isSketcher))
377 bool isEditing = aFOperation->isEditOperation();
379 // Ignore creation sketch operation
380 if ((!isSketcher) && (!isEditing))
383 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
384 if (!aContext.IsNull()) {
385 // MoveTo in order to highlight current object
386 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
388 // Remember highlighted objects for editing
389 ModuleBase_ISelection* aSelect = aWorkshop->selection();
391 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
392 storeSelection(!aHasShift);
394 if (myCurrentSelection.empty()) {
395 if (isSketchOpe && (!isSketcher))
396 // commit previous operation
397 if (!aFOperation->commit())
398 aFOperation->abort();
401 // Init flyout point for radius rotation
402 FeaturePtr aFeature = myCurrentSelection.begin().key();
406 get2dPoint(theWnd, theEvent, myCurrentPoint);
408 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
409 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
411 if (aFeature.get() != NULL) {
412 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
413 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
414 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
415 DataPtr aData = aSPFeature->data();
416 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
417 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
418 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
419 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
422 } else if (isSketchOpe && isEditing) {
423 // If selected another object commit current result
424 aFOperation->commit();
427 get2dPoint(theWnd, theEvent, myCurrentPoint);
429 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
430 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
432 // This is necessary in order to finalize previous operation
433 QApplication::processEvents();
439 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
441 if (myModule->sketchReentranceMgr()->processMouseReleased())
444 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
445 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
446 if (!aViewer->canDragByMouse())
448 ModuleBase_Operation* aOp = getCurrentOperation();
450 if (isNestedSketchOperation(aOp)) {
451 get2dPoint(theWnd, theEvent, myClickedPoint);
453 // Only for sketcher operations
457 myCurrentSelection.clear();
458 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
459 if (!aContext.IsNull()) {
460 // Reselect edited object
461 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
462 if (theEvent->modifiers() & Qt::ShiftModifier)
463 aContext->ShiftSelect();
471 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
472 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
473 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
474 myIsDragging = false;
477 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
479 if (myModule->sketchReentranceMgr()->processMouseMoved())
482 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
483 myIsMouseOverViewProcessed = true;
484 // 1. perform the widget mouse move functionality and display the presentation
485 ModuleBase_Operation* aOperation = getCurrentOperation();
486 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
487 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
488 // the mouse move should be processed in the widget, if it can in order to visualize correct
489 // presentation. These widgets correct the feature attribute according to the mouse position
490 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
492 aPoint2DWdg->onMouseMove(theWnd, theEvent);
494 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
497 aDistanceWdg->onMouseMove(theWnd, theEvent);
499 // the feature is to be erased here, but it is correct to call canDisplayObject because
500 // there can be additional check (e.g. editor widget in distance constraint)
501 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
502 (getCurrentOperation());
504 FeaturePtr aFeature = aFOperation->feature();
505 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
509 myClickedPoint.clear();
512 // 1. the current selection is saved in the mouse press method in order to restore it after moving
513 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
514 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
515 // deselected). This flag should be restored in the slot, processed the mouse release signal.
517 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
518 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
519 //aViewer->enableSelection(false);
521 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
522 if (!aCurrentOperation)
524 if (isSketchOperation(aCurrentOperation))
525 return; // No edit operation activated
527 Handle(V3d_View) aView = theWnd->v3dView();
528 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
530 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
531 double dX = aX - myCurrentPoint.myCurX;
532 double dY = aY - myCurrentPoint.myCurY;
534 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
535 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
536 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
537 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
538 // viewer happens by deselect/select the modified objects. The flag should be restored after
539 // the selection processing. The update viewer should be also called.
540 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
542 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
543 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
544 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
545 aLast = myCurrentSelection.end();
546 // 4. the features and attributes modification(move)
547 bool isModified = false;
548 for (; anIt != aLast; anIt++) {
549 FeaturePtr aFeature = anIt.key();
551 std::set<AttributePtr> anAttributes = anIt.value().first;
552 // Process selection by attribute: the priority to the attribute
553 if (!anAttributes.empty()) {
554 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
555 anAttLast = anAttributes.end();
556 for (; anAttIt != anAttLast; anAttIt++) {
557 AttributePtr anAttr = *anAttIt;
558 if (anAttr.get() == NULL)
560 std::string aAttrId = anAttr->id();
561 DataPtr aData = aFeature->data();
562 if (aData->isValid()) {
563 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
564 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
565 if (aPoint.get() != NULL) {
566 bool isImmutable = aPoint->setImmutable(true);
567 aPoint->move(dX, dY);
569 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
570 aPoint->setImmutable(isImmutable);
575 // Process selection by feature
576 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
577 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
578 if (aSketchFeature) {
579 aSketchFeature->move(dX, dY);
581 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
585 // the modified state of the current operation should be updated if there are features, which
588 aCurrentOperation->onValuesChanged();
590 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
591 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
593 // 5. it is necessary to save current selection in order to restore it after the features moving
595 // 6. restore the update viewer flag and call this update
596 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
597 aDisplayer->updateViewer();
600 myCurrentPoint.setValue(aX, aY);
604 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
606 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
607 (getCurrentOperation());
608 if (aFOperation && aFOperation->isEditOperation()) {
609 std::string aId = aFOperation->id().toStdString();
610 if (isDistanceOperation(aFOperation))
612 // Activate dimension value editing on double click
613 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
614 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
615 // Find corresponded widget to activate value editing
616 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
617 if (aWgt->attributeID() == "ConstraintValue") {
626 void PartSet_SketcherMgr::onApplicationStarted()
628 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
629 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
630 XGUI_Workshop* aWorkshop = aConnector->workshop();
631 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
632 if (aPropertyPanel) {
633 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
634 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
637 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
638 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
639 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
641 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
642 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
643 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
646 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
648 if (!myClickedPoint.myIsInitialized)
651 ModuleBase_Operation* aOperation = getCurrentOperation();
652 // the distance constraint feature should not use the clickedd point
653 // this is workaround in order to don't throw down the flyout point value,
654 // set by execute() method of these type of features
655 if (isDistanceOperation(aOperation))
658 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
660 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
664 void PartSet_SketcherMgr::onBeforeContextMenu()
666 myIsPopupMenuActive = true;
669 void PartSet_SketcherMgr::onAfterContextMenu()
671 myIsPopupMenuActive = false;
674 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
677 Handle(V3d_View) aView = theWnd->v3dView();
678 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
680 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
681 thePoint.setValue(aX, anY);
684 void PartSet_SketcherMgr::launchEditing()
686 if (!myCurrentSelection.empty()) {
687 FeaturePtr aFeature = myCurrentSelection.begin().key();
688 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
689 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
691 myModule->editFeature(aSPFeature);
696 bool PartSet_SketcherMgr::sketchSolverError()
698 bool anError = false;
699 CompositeFeaturePtr aSketch = activeSketch();
701 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
702 anError = !aAttributeString->value().empty();
707 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
709 QString anError = "";
710 if (!theFeature.get() || !theFeature->data()->isValid())
713 CompositeFeaturePtr aSketch = activeSketch();
714 if (aSketch.get() && aSketch == theFeature) {
715 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
716 anError = aAttributeString->value().c_str();
718 else if (myIsResetCurrentValue) { // this flag do not allow commit of the current operation
719 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
720 (getCurrentOperation());
722 FeaturePtr aFeature = aFOperation->feature();
723 if (aFeature.get() && aFeature == theFeature && isNestedCreateOperation(aFOperation)) {
724 QString anAttributeName = "";
725 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
726 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
728 AttributePtr anAttr = aFeature->attribute(anActiveWgt->attributeID());
730 anAttributeName = anAttr->id().c_str();
732 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
739 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
741 static QStringList aIds;
742 if (aIds.size() == 0) {
743 aIds << SketchPlugin_Line::ID().c_str();
744 aIds << SketchPlugin_Point::ID().c_str();
745 aIds << SketchPlugin_Arc::ID().c_str();
746 aIds << SketchPlugin_Circle::ID().c_str();
747 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
748 aIds.append(constraintsIdList());
753 const QStringList& PartSet_SketcherMgr::constraintsIdList()
755 static QStringList aIds;
756 if (aIds.size() == 0) {
757 aIds << SketchPlugin_ConstraintLength::ID().c_str();
758 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
759 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
760 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
761 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
762 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
763 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
764 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
765 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
766 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
767 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
768 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
769 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
770 aIds << SketchPlugin_MultiRotation::ID().c_str();
771 aIds << SketchPlugin_MultiTranslation::ID().c_str();
776 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
780 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
781 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
782 theModes.append(SketcherPrs_Tools::Sel_Constraint);
783 theModes.append(TopAbs_VERTEX);
784 theModes.append(TopAbs_EDGE);
787 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
789 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
792 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
794 return theOperation &&
795 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
798 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
800 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
802 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
805 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
807 return (theId == SketchPlugin_Line::ID()) ||
808 (theId == SketchPlugin_Point::ID()) ||
809 (theId == SketchPlugin_Arc::ID()) ||
810 (theId == SketchPlugin_Circle::ID());
813 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
815 std::string aId = theOperation ? theOperation->id().toStdString() : "";
817 return (aId == SketchPlugin_ConstraintLength::ID()) ||
818 (aId == SketchPlugin_ConstraintDistance::ID()) ||
819 (aId == SketchPlugin_ConstraintRadius::ID()) ||
820 (aId == SketchPlugin_ConstraintAngle::ID());
823 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
825 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
826 (getCurrentOperation());
830 myModule->onViewTransformed();
832 // Display all sketcher sub-Objects
833 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
834 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
836 // Hide sketcher result
837 std::list<ResultPtr> aResults = myCurrentSketch->results();
838 std::list<ResultPtr>::const_iterator aIt;
839 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
840 (*aIt)->setDisplayed(false);
842 myCurrentSketch->setDisplayed(false);
844 // Display sketcher objects
845 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
846 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
847 std::list<ResultPtr> aResults = aFeature->results();
848 std::list<ResultPtr>::const_iterator aIt;
849 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
850 (*aIt)->setDisplayed(true);
852 aFeature->setDisplayed(true);
855 if (myPlaneFilter.IsNull())
856 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
858 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
860 bool aHasPlane = false;
861 std::shared_ptr<GeomAPI_Pln> aPln;
862 if (aFOperation->isEditOperation()) {
863 // If it is editing of sketch then it means that plane is already defined
864 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
868 myPlaneFilter->setPlane(aPln);
870 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
871 // all sketch objects should be activated in the sketch selection modes by edit operation start
872 // in case of creation operation, there is an active widget, which activates own selection mode
873 if (aFOperation->isEditOperation() && aHasPlane)
874 aConnector->activateModuleSelectionModes();
877 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
879 myIsMouseOverWindow = false;
880 myIsConstraintsShown = true;
881 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
882 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
884 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
886 DataPtr aData = myCurrentSketch->data();
887 if (!aData->isValid()) {
888 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
889 // The sketch was aborted
890 myCurrentSketch = CompositeFeaturePtr();
891 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
893 // Erase all sketcher objects
894 QStringList aSketchIds = sketchOperationIdList();
895 QObjectPtrList aObjects = aDisplayer->displayedObjects();
896 foreach (ObjectPtr aObj, aObjects) {
897 DataPtr aObjData = aObj->data();
898 if (!aObjData->isValid())
899 aObj->setDisplayed(false);
903 // Hide all sketcher sub-Objects
904 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
905 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
906 std::list<ResultPtr> aResults = aFeature->results();
907 std::list<ResultPtr>::const_iterator aIt;
908 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
909 (*aIt)->setDisplayed(false);
911 aFeature->setDisplayed(false);
913 // Display sketcher result
914 std::list<ResultPtr> aResults = myCurrentSketch->results();
915 std::list<ResultPtr>::const_iterator aIt;
916 Events_Loop* aLoop = Events_Loop::loop();
917 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
919 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
921 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
922 if (!aFOperation->isDisplayedOnStart(*aIt)) {
923 (*aIt)->setDisplayed(true);
924 // this display event is needed because sketch already may have "displayed" state,
925 // but not displayed while it is still active (issue 613, abort of existing sketch)
926 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
929 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
930 myCurrentSketch->setDisplayed(true);
932 myCurrentSketch = CompositeFeaturePtr();
933 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
935 Events_Loop::loop()->flush(aDispEvent);
937 // restore the module selection modes, which were changed on startSketch
938 aConnector->activateModuleSelectionModes();
941 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
943 connectToPropertyPanel(true);
944 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
945 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
948 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
950 connectToPropertyPanel(false);
951 myIsResetCurrentValue = false;
952 myIsMouseOverViewProcessed = true;
953 operationMgr()->onValidateOperation();
954 if (isNestedCreateOperation(theOp))
955 QApplication::restoreOverrideCursor();
958 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
960 if (isNestedCreateOperation(theOperation)) {
961 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
964 FeaturePtr aFeature = aFOperation->feature();
965 // it is necessary to check the the feature data validity because
966 // some kind of features are removed by an operation commit(the macro state of a feature)
967 if (aFeature.get() && aFeature->data()->isValid()) {
968 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
974 bool PartSet_SketcherMgr::canUndo() const
976 return isNestedCreateOperation(getCurrentOperation());
979 bool PartSet_SketcherMgr::canRedo() const
981 return isNestedCreateOperation(getCurrentOperation());
984 bool PartSet_SketcherMgr::canCommitOperation() const
986 bool aCanCommit = true;
988 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
994 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
996 bool aCanErase = true;
997 // when the sketch operation is active, results of sketch sub-feature can not be hidden
998 if (myCurrentSketch.get()) {
999 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1000 if (aResult.get()) {
1001 // Display sketcher objects
1002 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1004 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1005 std::list<ResultPtr> aResults = aFeature->results();
1006 std::list<ResultPtr>::const_iterator anIt;
1007 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1008 aCanErase = *anIt != aResult;
1016 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1018 bool aCanDisplay = true;
1020 bool aHasActiveSketch = activeSketch().get() != NULL;
1021 if (aHasActiveSketch) {
1022 // 1. the sketch feature should not be displayed during the sketch active operation
1023 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1024 // nested features can be visualized
1025 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1026 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1027 aCanDisplay = false;
1030 else { // there are no an active sketch
1031 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1032 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1033 if (aFeature.get() != NULL) {
1034 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1035 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1036 if (aSketchFeature.get()) {
1037 aCanDisplay = false;
1042 // 3. the method should not filter the objects, which are not related to the current operation.
1043 // The object is filtered just if it is a current operation feature or this feature result
1044 bool isObjectFound = false;
1045 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1046 (getCurrentOperation());
1048 FeaturePtr aFeature = aFOperation->feature();
1049 if (aFeature.get()) {
1050 std::list<ResultPtr> aResults = aFeature->results();
1051 if (theObject == aFeature)
1052 isObjectFound = true;
1054 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1055 for (; anIt != aLast && !isObjectFound; anIt++) {
1056 isObjectFound = *anIt == theObject;
1064 // 4. For created nested feature operation do not display the created feature if
1065 // the mouse curstor leaves the OCC window.
1066 // The correction cases, which ignores this condition:
1067 // a. the property panel values modification
1068 // b. the popup menu activated
1069 // c. widget editor control
1070 #ifndef DEBUG_DO_NOT_BY_ENTER
1071 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1072 ModuleBase_Operation* aOperation = getCurrentOperation();
1073 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1074 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
1075 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
1076 // the active widget editor should not influence here. The presentation should be visible always
1077 // when this widget is active.
1078 if (!anEditorWdg && !myIsPopupMenuActive) {
1079 // during a nested create operation, the feature is redisplayed only if the mouse over view
1080 // of there was a value modified in the property panel after the mouse left the view
1081 aCanDisplay = canDisplayCurrentCreatedFeature();
1088 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1090 return myIsMouseOverWindow || !myIsResetCurrentValue;
1091 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1092 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1096 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1098 bool isFoundObject = false;
1100 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1101 if (anObjectFeature.get()) {
1102 int aSize = myCurrentSketch->numberOfSubs();
1103 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1104 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1105 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1108 return isFoundObject;
1111 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1113 if (myPlaneFilter.IsNull())
1114 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1116 myPlaneFilter->setPlane(thePln);
1119 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1120 const FeaturePtr& theSketch,
1121 ModuleBase_IWorkshop* theWorkshop,
1122 FeatureToSelectionMap& theSelection)
1124 if (theFeature.get() == NULL)
1127 std::set<AttributePtr> aSelectedAttributes;
1128 std::set<ResultPtr> aSelectedResults;
1130 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1131 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1132 if (!aContext.IsNull()) {
1133 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1134 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1136 std::list<ResultPtr> aResults = theFeature->results();
1137 std::list<ResultPtr>::const_iterator aIt;
1138 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1140 ResultPtr aResult = *aIt;
1141 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1142 if (aAISObj.get() == NULL)
1144 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1145 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1147 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1148 if (anOwner->Selectable() != anAISIO)
1150 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1151 aSelectedAttributes, aSelectedResults);
1153 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1154 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1155 if (anOwner.IsNull())
1157 if (anOwner->Selectable() != anAISIO)
1159 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1160 aSelectedAttributes, aSelectedResults);
1164 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1167 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1168 const FeaturePtr& theSketch,
1169 ModuleBase_IWorkshop* theWorkshop,
1170 const FeatureToSelectionMap& theSelection,
1171 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1173 if (theFeature.get() == NULL)
1176 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1177 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1178 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1180 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1182 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1183 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1185 // 1. found the feature's owners. Check the AIS objects of the constructions
1186 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1187 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1188 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1190 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1191 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1192 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1193 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1194 if (!anOwner.IsNull())
1195 theOwnersToSelect.Add(anOwner);
1199 // 2. found the feature results's owners
1200 std::list<ResultPtr> aResults = theFeature->results();
1201 std::list<ResultPtr>::const_iterator aIt;
1202 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1204 ResultPtr aResult = *aIt;
1205 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1206 if (aAISObj.get() == NULL)
1208 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1210 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1211 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1212 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1213 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1214 if ( anOwner.IsNull() || !anOwner->HasShape() )
1216 const TopoDS_Shape& aShape = anOwner->Shape();
1217 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1218 if (aShapeType == TopAbs_VERTEX) {
1219 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1220 if (aPntAttr.get() != NULL &&
1221 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1222 theOwnersToSelect.Add(anOwner);
1225 else if (aShapeType == TopAbs_EDGE) {
1226 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1227 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1228 theOwnersToSelect.FindIndex(anOwner) <= 0)
1229 theOwnersToSelect.Add(anOwner);
1235 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1237 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1238 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1239 XGUI_Workshop* aWorkshop = aConnector->workshop();
1240 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1241 if (aPropertyPanel) {
1242 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1243 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1245 connect(aWidget, SIGNAL(beforeValuesChanged()),
1246 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1247 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1248 connect(aWidget, SIGNAL(afterValuesChanged()),
1249 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1252 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1253 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1254 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1255 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1256 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1262 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1264 return myModule->workshop()->currentOperation();
1267 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1268 const bool isEditOperation,
1269 const bool isToDisplay,
1270 const bool isFlushRedisplay)
1272 #ifdef DEBUG_DO_NOT_BY_ENTER
1276 if (isEditOperation || !theFeature.get())
1279 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1280 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1282 // 1. change visibility of the object itself, here the presentable object is processed,
1283 // e.g. constraints features
1284 //FeaturePtr aFeature = aFOperation->feature();
1285 std::list<ResultPtr> aResults = theFeature->results();
1287 theFeature->setDisplayed(true);
1289 theFeature->setDisplayed(false);
1291 // change visibility of the object results, e.g. non-constraint features
1292 std::list<ResultPtr>::const_iterator aIt;
1293 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1295 (*aIt)->setDisplayed(true);
1298 (*aIt)->setDisplayed(false);
1301 if (isFlushRedisplay)
1302 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1305 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1307 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1308 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1309 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1311 QList<FeaturePtr> aFeatureList;
1312 if (theHighlightedOnly) {
1313 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1316 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1318 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1319 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1322 // 1. it is necessary to save current selection in order to restore it after the features moving
1323 myCurrentSelection.clear();
1324 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1325 for (; anIt != aLast; anIt++) {
1326 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1328 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1331 void PartSet_SketcherMgr::restoreSelection()
1333 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1334 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1335 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1336 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1337 aSLast = myCurrentSelection.end();
1338 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1339 for (; aSIt != aSLast; aSIt++) {
1340 anOwnersToSelect.Clear();
1341 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1343 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1347 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1349 if (myIsConstraintsShown == theOn)
1351 if (myCurrentSketch.get() == NULL)
1354 myIsConstraintsShown = theOn;
1356 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1357 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1359 const QStringList& aConstrIds = constraintsIdList();
1360 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1361 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1362 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1363 if (myIsConstraintsShown)
1364 aSubFeature->setDisplayed(true);
1366 aSubFeature->setDisplayed(false);
1369 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1372 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1374 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1375 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1378 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1380 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1381 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1382 XGUI_Workshop* aWorkshop = aConnector->workshop();
1384 return aWorkshop->operationMgr();