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(theWnd, theEvent))
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(theWnd, theEvent))
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(theWnd, theEvent))
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*)));
636 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
637 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
638 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
639 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
640 aReentranceMgr, SLOT(onWidgetActivated()));
643 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
644 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
645 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
647 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
648 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
649 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
652 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
654 if (!myClickedPoint.myIsInitialized)
657 ModuleBase_Operation* aOperation = getCurrentOperation();
658 // the distance constraint feature should not use the clickedd point
659 // this is workaround in order to don't throw down the flyout point value,
660 // set by execute() method of these type of features
661 if (isDistanceOperation(aOperation))
664 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
666 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
670 void PartSet_SketcherMgr::onBeforeContextMenu()
672 myIsPopupMenuActive = true;
675 void PartSet_SketcherMgr::onAfterContextMenu()
677 myIsPopupMenuActive = false;
680 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
683 Handle(V3d_View) aView = theWnd->v3dView();
684 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
686 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
687 thePoint.setValue(aX, anY);
690 void PartSet_SketcherMgr::launchEditing()
692 if (!myCurrentSelection.empty()) {
693 FeaturePtr aFeature = myCurrentSelection.begin().key();
694 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
695 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
697 myModule->editFeature(aSPFeature);
702 bool PartSet_SketcherMgr::sketchSolverError()
704 bool anError = false;
705 CompositeFeaturePtr aSketch = activeSketch();
707 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
708 anError = !aAttributeString->value().empty();
713 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
715 QString anError = "";
716 if (!theFeature.get() || !theFeature->data()->isValid())
719 CompositeFeaturePtr aSketch = activeSketch();
720 if (aSketch.get() && aSketch == theFeature) {
721 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
722 anError = aAttributeString->value().c_str();
724 else if (myIsResetCurrentValue) { // this flag do not allow commit of the current operation
725 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
726 (getCurrentOperation());
728 FeaturePtr aFeature = aFOperation->feature();
729 if (aFeature.get() && aFeature == theFeature && isNestedCreateOperation(aFOperation)) {
730 QString anAttributeName = "";
731 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
732 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
734 AttributePtr anAttr = aFeature->attribute(anActiveWgt->attributeID());
736 anAttributeName = anAttr->id().c_str();
738 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
745 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
747 static QStringList aIds;
748 if (aIds.size() == 0) {
749 aIds << SketchPlugin_Line::ID().c_str();
750 aIds << SketchPlugin_Point::ID().c_str();
751 aIds << SketchPlugin_Arc::ID().c_str();
752 aIds << SketchPlugin_Circle::ID().c_str();
753 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
754 aIds.append(constraintsIdList());
759 const QStringList& PartSet_SketcherMgr::constraintsIdList()
761 static QStringList aIds;
762 if (aIds.size() == 0) {
763 aIds << SketchPlugin_ConstraintLength::ID().c_str();
764 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
765 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
766 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
767 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
768 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
769 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
770 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
771 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
772 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
773 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
774 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
775 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
776 aIds << SketchPlugin_MultiRotation::ID().c_str();
777 aIds << SketchPlugin_MultiTranslation::ID().c_str();
782 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
786 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
787 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
788 theModes.append(SketcherPrs_Tools::Sel_Constraint);
789 theModes.append(TopAbs_VERTEX);
790 theModes.append(TopAbs_EDGE);
793 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
795 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
798 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
800 return theOperation &&
801 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
804 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
806 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
808 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
811 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
813 return (theId == SketchPlugin_Line::ID()) ||
814 (theId == SketchPlugin_Point::ID()) ||
815 (theId == SketchPlugin_Arc::ID()) ||
816 (theId == SketchPlugin_Circle::ID());
819 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
821 std::string aId = theOperation ? theOperation->id().toStdString() : "";
823 return (aId == SketchPlugin_ConstraintLength::ID()) ||
824 (aId == SketchPlugin_ConstraintDistance::ID()) ||
825 (aId == SketchPlugin_ConstraintRadius::ID()) ||
826 (aId == SketchPlugin_ConstraintAngle::ID());
829 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
831 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
832 (getCurrentOperation());
836 myModule->onViewTransformed();
838 // Display all sketcher sub-Objects
839 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
840 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
842 // Hide sketcher result
843 std::list<ResultPtr> aResults = myCurrentSketch->results();
844 std::list<ResultPtr>::const_iterator aIt;
845 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
846 (*aIt)->setDisplayed(false);
848 myCurrentSketch->setDisplayed(false);
850 // Display sketcher objects
851 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
852 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
853 std::list<ResultPtr> aResults = aFeature->results();
854 std::list<ResultPtr>::const_iterator aIt;
855 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
856 (*aIt)->setDisplayed(true);
858 aFeature->setDisplayed(true);
861 if (myPlaneFilter.IsNull())
862 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
864 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
866 bool aHasPlane = false;
867 std::shared_ptr<GeomAPI_Pln> aPln;
868 if (aFOperation->isEditOperation()) {
869 // If it is editing of sketch then it means that plane is already defined
870 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
874 myPlaneFilter->setPlane(aPln);
876 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
877 // all sketch objects should be activated in the sketch selection modes by edit operation start
878 // in case of creation operation, there is an active widget, which activates own selection mode
879 if (aFOperation->isEditOperation() && aHasPlane)
880 aConnector->activateModuleSelectionModes();
883 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
885 myIsMouseOverWindow = false;
886 myIsConstraintsShown = true;
887 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
888 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
890 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
892 DataPtr aData = myCurrentSketch->data();
893 if (!aData->isValid()) {
894 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
895 // The sketch was aborted
896 myCurrentSketch = CompositeFeaturePtr();
897 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
899 // Erase all sketcher objects
900 QStringList aSketchIds = sketchOperationIdList();
901 QObjectPtrList aObjects = aDisplayer->displayedObjects();
902 foreach (ObjectPtr aObj, aObjects) {
903 DataPtr aObjData = aObj->data();
904 if (!aObjData->isValid())
905 aObj->setDisplayed(false);
909 // Hide all sketcher sub-Objects
910 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
911 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
912 std::list<ResultPtr> aResults = aFeature->results();
913 std::list<ResultPtr>::const_iterator aIt;
914 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
915 (*aIt)->setDisplayed(false);
917 aFeature->setDisplayed(false);
919 // Display sketcher result
920 std::list<ResultPtr> aResults = myCurrentSketch->results();
921 std::list<ResultPtr>::const_iterator aIt;
922 Events_Loop* aLoop = Events_Loop::loop();
923 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
925 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
927 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
928 if (!aFOperation->isDisplayedOnStart(*aIt)) {
929 (*aIt)->setDisplayed(true);
930 // this display event is needed because sketch already may have "displayed" state,
931 // but not displayed while it is still active (issue 613, abort of existing sketch)
932 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
935 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
936 myCurrentSketch->setDisplayed(true);
938 myCurrentSketch = CompositeFeaturePtr();
939 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
941 Events_Loop::loop()->flush(aDispEvent);
943 // restore the module selection modes, which were changed on startSketch
944 aConnector->activateModuleSelectionModes();
947 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
949 connectToPropertyPanel(true);
950 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
951 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
954 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
956 connectToPropertyPanel(false);
957 myIsResetCurrentValue = false;
958 myIsMouseOverViewProcessed = true;
959 operationMgr()->onValidateOperation();
960 if (isNestedCreateOperation(theOp))
961 QApplication::restoreOverrideCursor();
964 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
966 if (isNestedCreateOperation(theOperation)) {
967 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
970 FeaturePtr aFeature = aFOperation->feature();
971 // it is necessary to check the the feature data validity because
972 // some kind of features are removed by an operation commit(the macro state of a feature)
973 if (aFeature.get() && aFeature->data()->isValid()) {
974 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
980 bool PartSet_SketcherMgr::canUndo() const
982 return isNestedCreateOperation(getCurrentOperation());
985 bool PartSet_SketcherMgr::canRedo() const
987 return isNestedCreateOperation(getCurrentOperation());
990 bool PartSet_SketcherMgr::canCommitOperation() const
992 bool aCanCommit = true;
994 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
1000 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1002 bool aCanErase = true;
1003 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1004 if (myCurrentSketch.get()) {
1005 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1006 if (aResult.get()) {
1007 // Display sketcher objects
1008 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1010 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1011 std::list<ResultPtr> aResults = aFeature->results();
1012 std::list<ResultPtr>::const_iterator anIt;
1013 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1014 aCanErase = *anIt != aResult;
1022 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1024 bool aCanDisplay = true;
1026 bool aHasActiveSketch = activeSketch().get() != NULL;
1027 if (aHasActiveSketch) {
1028 // 1. the sketch feature should not be displayed during the sketch active operation
1029 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1030 // nested features can be visualized
1031 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1032 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1033 aCanDisplay = false;
1036 else { // there are no an active sketch
1037 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1038 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1039 if (aFeature.get() != NULL) {
1040 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1041 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1042 if (aSketchFeature.get()) {
1043 aCanDisplay = false;
1048 // 3. the method should not filter the objects, which are not related to the current operation.
1049 // The object is filtered just if it is a current operation feature or this feature result
1050 bool isObjectFound = false;
1051 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1052 (getCurrentOperation());
1054 FeaturePtr aFeature = aFOperation->feature();
1055 if (aFeature.get()) {
1056 std::list<ResultPtr> aResults = aFeature->results();
1057 if (theObject == aFeature)
1058 isObjectFound = true;
1060 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1061 for (; anIt != aLast && !isObjectFound; anIt++) {
1062 isObjectFound = *anIt == theObject;
1070 // 4. For created nested feature operation do not display the created feature if
1071 // the mouse curstor leaves the OCC window.
1072 // The correction cases, which ignores this condition:
1073 // a. the property panel values modification
1074 // b. the popup menu activated
1075 // c. widget editor control
1076 #ifndef DEBUG_DO_NOT_BY_ENTER
1077 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1078 ModuleBase_Operation* aOperation = getCurrentOperation();
1079 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1080 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
1081 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
1082 // the active widget editor should not influence here. The presentation should be visible always
1083 // when this widget is active.
1084 if (!anEditorWdg && !myIsPopupMenuActive) {
1085 // during a nested create operation, the feature is redisplayed only if the mouse over view
1086 // of there was a value modified in the property panel after the mouse left the view
1087 aCanDisplay = canDisplayCurrentCreatedFeature();
1094 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1096 return myIsMouseOverWindow || !myIsResetCurrentValue;
1097 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1098 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1102 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1104 bool isFoundObject = false;
1106 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1107 if (anObjectFeature.get()) {
1108 int aSize = myCurrentSketch->numberOfSubs();
1109 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1110 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1111 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1114 return isFoundObject;
1117 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1119 if (myPlaneFilter.IsNull())
1120 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1122 myPlaneFilter->setPlane(thePln);
1125 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1126 const FeaturePtr& theSketch,
1127 ModuleBase_IWorkshop* theWorkshop,
1128 FeatureToSelectionMap& theSelection)
1130 if (theFeature.get() == NULL)
1133 std::set<AttributePtr> aSelectedAttributes;
1134 std::set<ResultPtr> aSelectedResults;
1136 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1137 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1138 if (!aContext.IsNull()) {
1139 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1140 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1142 std::list<ResultPtr> aResults = theFeature->results();
1143 std::list<ResultPtr>::const_iterator aIt;
1144 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1146 ResultPtr aResult = *aIt;
1147 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1148 if (aAISObj.get() == NULL)
1150 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1151 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1153 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1154 if (anOwner->Selectable() != anAISIO)
1156 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1157 aSelectedAttributes, aSelectedResults);
1159 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1160 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1161 if (anOwner.IsNull())
1163 if (anOwner->Selectable() != anAISIO)
1165 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1166 aSelectedAttributes, aSelectedResults);
1170 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1173 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1174 const FeaturePtr& theSketch,
1175 ModuleBase_IWorkshop* theWorkshop,
1176 const FeatureToSelectionMap& theSelection,
1177 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1179 if (theFeature.get() == NULL)
1182 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1183 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1184 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1186 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1188 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1189 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1191 // 1. found the feature's owners. Check the AIS objects of the constructions
1192 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1193 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1194 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1196 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1197 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1198 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1199 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1200 if (!anOwner.IsNull())
1201 theOwnersToSelect.Add(anOwner);
1205 // 2. found the feature results's owners
1206 std::list<ResultPtr> aResults = theFeature->results();
1207 std::list<ResultPtr>::const_iterator aIt;
1208 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1210 ResultPtr aResult = *aIt;
1211 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1212 if (aAISObj.get() == NULL)
1214 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1216 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1217 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1218 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1219 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1220 if ( anOwner.IsNull() || !anOwner->HasShape() )
1222 const TopoDS_Shape& aShape = anOwner->Shape();
1223 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1224 if (aShapeType == TopAbs_VERTEX) {
1225 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1226 if (aPntAttr.get() != NULL &&
1227 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1228 theOwnersToSelect.Add(anOwner);
1231 else if (aShapeType == TopAbs_EDGE) {
1232 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1233 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1234 theOwnersToSelect.FindIndex(anOwner) <= 0)
1235 theOwnersToSelect.Add(anOwner);
1241 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1243 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1244 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1245 XGUI_Workshop* aWorkshop = aConnector->workshop();
1246 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1247 if (aPropertyPanel) {
1248 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1249 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1251 connect(aWidget, SIGNAL(beforeValuesChanged()),
1252 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1253 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1254 connect(aWidget, SIGNAL(afterValuesChanged()),
1255 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1258 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1259 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1260 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1261 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1262 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1268 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1270 return myModule->workshop()->currentOperation();
1273 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1274 const bool isEditOperation,
1275 const bool isToDisplay,
1276 const bool isFlushRedisplay)
1278 #ifdef DEBUG_DO_NOT_BY_ENTER
1282 if (isEditOperation || !theFeature.get())
1285 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1286 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1288 // 1. change visibility of the object itself, here the presentable object is processed,
1289 // e.g. constraints features
1290 //FeaturePtr aFeature = aFOperation->feature();
1291 std::list<ResultPtr> aResults = theFeature->results();
1293 theFeature->setDisplayed(true);
1295 theFeature->setDisplayed(false);
1297 // change visibility of the object results, e.g. non-constraint features
1298 std::list<ResultPtr>::const_iterator aIt;
1299 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1301 (*aIt)->setDisplayed(true);
1304 (*aIt)->setDisplayed(false);
1307 if (isFlushRedisplay)
1308 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1311 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1313 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1314 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1315 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1317 QList<FeaturePtr> aFeatureList;
1318 if (theHighlightedOnly) {
1319 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1322 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1324 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1325 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1328 // 1. it is necessary to save current selection in order to restore it after the features moving
1329 myCurrentSelection.clear();
1330 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1331 for (; anIt != aLast; anIt++) {
1332 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1334 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1337 void PartSet_SketcherMgr::restoreSelection()
1339 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1340 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1341 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1342 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1343 aSLast = myCurrentSelection.end();
1344 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1345 for (; aSIt != aSLast; aSIt++) {
1346 anOwnersToSelect.Clear();
1347 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1349 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1353 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1355 if (myIsConstraintsShown == theOn)
1357 if (myCurrentSketch.get() == NULL)
1360 myIsConstraintsShown = theOn;
1362 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1363 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1365 const QStringList& aConstrIds = constraintsIdList();
1366 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1367 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1368 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1369 if (myIsConstraintsShown)
1370 aSubFeature->setDisplayed(true);
1372 aSubFeature->setDisplayed(false);
1375 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1378 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1380 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1381 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1384 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1386 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1387 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1388 XGUI_Workshop* aWorkshop = aConnector->workshop();
1390 return aWorkshop->operationMgr();