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"
14 #include "PartSet_WidgetEditor.h"
16 #include <XGUI_ModuleConnector.h>
17 #include <XGUI_Displayer.h>
18 #include <XGUI_Workshop.h>
19 #include <XGUI_ContextMenuMgr.h>
20 #include <XGUI_Selection.h>
21 #include <XGUI_SelectionMgr.h>
22 #include <XGUI_ModuleConnector.h>
23 #include <XGUI_PropertyPanel.h>
24 #include <XGUI_ViewerProxy.h>
25 #include <XGUI_OperationMgr.h>
27 #include <ModuleBase_IPropertyPanel.h>
28 #include <ModuleBase_ISelection.h>
29 #include <ModuleBase_IViewer.h>
30 #include <ModuleBase_IWorkshop.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_ModelWidget.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationFeature.h>
35 #include <ModuleBase_Operation.h>
36 #include <ModuleBase_WidgetEditor.h>
38 #include <GeomDataAPI_Point2D.h>
40 #include <Events_Loop.h>
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Sketch.h>
44 #include <SketchPlugin_Point.h>
45 #include <SketchPlugin_Arc.h>
46 #include <SketchPlugin_Circle.h>
47 #include <SketchPlugin_ConstraintLength.h>
48 #include <SketchPlugin_ConstraintDistance.h>
49 #include <SketchPlugin_ConstraintParallel.h>
50 #include <SketchPlugin_ConstraintPerpendicular.h>
51 #include <SketchPlugin_ConstraintRadius.h>
52 #include <SketchPlugin_ConstraintRigid.h>
53 #include <SketchPlugin_ConstraintHorizontal.h>
54 #include <SketchPlugin_ConstraintVertical.h>
55 #include <SketchPlugin_ConstraintEqual.h>
56 #include <SketchPlugin_ConstraintTangent.h>
57 #include <SketchPlugin_ConstraintCoincidence.h>
58 #include <SketchPlugin_ConstraintFillet.h>
59 #include <SketchPlugin_ConstraintMirror.h>
60 #include <SketchPlugin_ConstraintAngle.h>
61 #include <SketchPlugin_MultiRotation.h>
62 #include <SketchPlugin_MultiTranslation.h>
64 #include <SketcherPrs_Tools.h>
66 #include <SelectMgr_IndexedMapOfOwner.hxx>
67 #include <StdSelect_BRepOwner.hxx>
69 //#include <AIS_DimensionSelectionMode.hxx>
70 #include <AIS_Shape.hxx>
72 #include <ModelAPI_Events.h>
73 #include <ModelAPI_Session.h>
74 #include <ModelAPI_AttributeString.h>
76 #include <QMouseEvent>
77 #include <QApplication>
79 //#define DEBUG_DO_NOT_BY_ENTER
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 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;
196 #ifdef DEBUG_DO_NOT_BY_ENTER
200 if (!isNestedCreateOperation(getCurrentOperation()))
203 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
205 operationMgr()->onValidateOperation();
207 // we need change displayed state of the current operation feature
208 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
209 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
210 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
211 // presentation becomes valid and redisplay happens
212 //ModuleBase_Operation* aOperation = getCurrentOperation();
213 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
214 (getCurrentOperation());
216 FeaturePtr aFeature = aFOperation->feature();
217 if (aFeature.get() && aFeature->data()->isValid()) {
218 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
223 void PartSet_SketcherMgr::onLeaveViewPort()
225 myIsMouseOverViewProcessed = false;
226 myIsMouseOverWindow = false;
227 // it is important to validate operation here only if sketch entity create operation is active
228 // because at this operation we reacts to the mouse leave/enter view port
229 //operationMgr()->onValidateOperation();
231 #ifdef DEBUG_DO_NOT_BY_ENTER
235 if (!isNestedCreateOperation(getCurrentOperation()))
238 QApplication::restoreOverrideCursor();
240 // the method should be performed if the popup menu is called,
241 // the reset of the current widget should not happen
242 if (myIsPopupMenuActive)
245 operationMgr()->onValidateOperation();
247 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
248 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
249 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
250 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
251 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
252 // obtained after reset value
253 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
254 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
256 anActiveWidget->reset();
257 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
259 // hides the presentation of the current operation feature
260 // the feature is to be erased here, but it is correct to call canDisplayObject because
261 // there can be additional check (e.g. editor widget in distance constraint)
262 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
263 (getCurrentOperation());
265 FeaturePtr aFeature = aFOperation->feature();
266 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
270 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
272 if (isNestedCreateOperation(getCurrentOperation()))
274 // it is necessary to save current selection in order to restore it after the values are modifed
277 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
278 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
279 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
280 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
283 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
285 if (isNestedCreateOperation(getCurrentOperation()))
287 // it is necessary to restore current selection in order to restore it after the values are modified
289 myCurrentSelection.clear();
291 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
292 // viewer happens by deselect/select the modified objects. The flag should be restored after
293 // the selection processing. The update viewer should be also called.
294 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
295 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
296 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
297 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
298 aDisplayer->updateViewer();
301 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
303 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
306 get2dPoint(theWnd, theEvent, myClickedPoint);
308 if (!(theEvent->buttons() & Qt::LeftButton))
311 // Clear dragging mode
312 myIsDragging = false;
314 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
315 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
316 if (!aViewer->canDragByMouse())
319 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
320 (getCurrentOperation());
324 if (aFOperation->isEditOperation()) {
325 // If the current widget is a selector, do nothing, it processes the mouse press
326 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
327 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
332 // Use only for sketch operations
333 if (myCurrentSketch) {
334 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
337 bool isSketcher = isSketchOperation(aFOperation);
338 bool isSketchOpe = isNestedSketchOperation(aFOperation);
340 // Avoid non-sketch operations
341 if ((!isSketchOpe) && (!isSketcher))
344 bool isEditing = aFOperation->isEditOperation();
346 // Ignore creation sketch operation
347 if ((!isSketcher) && (!isEditing))
350 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
351 if (!aContext.IsNull()) {
352 // MoveTo in order to highlight current object
353 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
355 // Remember highlighted objects for editing
356 ModuleBase_ISelection* aSelect = aWorkshop->selection();
358 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
359 storeSelection(!aHasShift);
361 if (myCurrentSelection.empty()) {
362 if (isSketchOpe && (!isSketcher))
363 // commit previous operation
364 if (!aFOperation->commit())
365 aFOperation->abort();
368 // Init flyout point for radius rotation
369 FeaturePtr aFeature = myCurrentSelection.begin().key();
373 get2dPoint(theWnd, theEvent, myCurrentPoint);
375 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
376 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
378 if (aFeature.get() != NULL) {
379 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
380 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
381 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
382 DataPtr aData = aSPFeature->data();
383 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
384 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
385 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
386 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
389 } else if (isSketchOpe && isEditing) {
390 // If selected another object commit current result
391 aFOperation->commit();
394 get2dPoint(theWnd, theEvent, myCurrentPoint);
396 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
397 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
399 // This is necessary in order to finalize previous operation
400 QApplication::processEvents();
406 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
408 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
411 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
412 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
413 if (!aViewer->canDragByMouse())
415 ModuleBase_Operation* aOp = getCurrentOperation();
417 if (isNestedSketchOperation(aOp)) {
418 get2dPoint(theWnd, theEvent, myClickedPoint);
420 // Only for sketcher operations
424 myCurrentSelection.clear();
425 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
426 if (!aContext.IsNull()) {
427 // Reselect edited object
428 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
429 if (theEvent->modifiers() & Qt::ShiftModifier)
430 aContext->ShiftSelect();
438 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
439 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
440 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
441 myIsDragging = false;
444 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
446 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
449 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
450 myIsMouseOverViewProcessed = true;
451 // 1. perform the widget mouse move functionality and display the presentation
452 // the mouse move should be processed in the widget, if it can in order to visualize correct
453 // presentation. These widgets correct the feature attribute according to the mouse position
454 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
455 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
457 aPoint2DWdg->onMouseMove(theWnd, theEvent);
459 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
462 aDistanceWdg->onMouseMove(theWnd, theEvent);
464 // the feature is to be erased here, but it is correct to call canDisplayObject because
465 // there can be additional check (e.g. editor widget in distance constraint)
466 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
467 (getCurrentOperation());
469 FeaturePtr aFeature = aFOperation->feature();
470 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
474 myClickedPoint.clear();
477 // 1. the current selection is saved in the mouse press method in order to restore it after moving
478 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
479 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
480 // deselected). This flag should be restored in the slot, processed the mouse release signal.
482 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
483 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
484 //aViewer->enableSelection(false);
486 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
487 if (!aCurrentOperation)
489 if (isSketchOperation(aCurrentOperation))
490 return; // No edit operation activated
492 Handle(V3d_View) aView = theWnd->v3dView();
493 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
495 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
496 double dX = aX - myCurrentPoint.myCurX;
497 double dY = aY - myCurrentPoint.myCurY;
499 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
500 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
501 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
502 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
503 // viewer happens by deselect/select the modified objects. The flag should be restored after
504 // the selection processing. The update viewer should be also called.
505 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
507 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
508 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
509 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
510 aLast = myCurrentSelection.end();
511 // 4. the features and attributes modification(move)
512 bool isModified = false;
513 for (; anIt != aLast; anIt++) {
514 FeaturePtr aFeature = anIt.key();
516 std::set<AttributePtr> anAttributes = anIt.value().first;
517 // Process selection by attribute: the priority to the attribute
518 if (!anAttributes.empty()) {
519 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
520 anAttLast = anAttributes.end();
521 for (; anAttIt != anAttLast; anAttIt++) {
522 AttributePtr anAttr = *anAttIt;
523 if (anAttr.get() == NULL)
525 std::string aAttrId = anAttr->id();
526 DataPtr aData = aFeature->data();
527 if (aData->isValid()) {
528 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
529 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
530 if (aPoint.get() != NULL) {
531 bool isImmutable = aPoint->setImmutable(true);
532 aPoint->move(dX, dY);
534 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
535 aPoint->setImmutable(isImmutable);
540 // Process selection by feature
541 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
542 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
543 if (aSketchFeature) {
544 aSketchFeature->move(dX, dY);
546 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
550 // the modified state of the current operation should be updated if there are features, which
553 aCurrentOperation->onValuesChanged();
555 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
556 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
558 // 5. it is necessary to save current selection in order to restore it after the features moving
560 // 6. restore the update viewer flag and call this update
561 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
562 aDisplayer->updateViewer();
565 myCurrentPoint.setValue(aX, aY);
569 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
571 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
572 (getCurrentOperation());
573 if (aFOperation && aFOperation->isEditOperation()) {
574 std::string aId = aFOperation->id().toStdString();
575 if (isDistanceOperation(aFOperation))
577 // Activate dimension value editing on double click
578 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
579 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
580 // Find corresponded widget to activate value editing
581 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
582 if (aWgt->attributeID() == "ConstraintValue") {
583 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
585 anEditor->showPopupEditor();
593 void PartSet_SketcherMgr::onApplicationStarted()
595 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
596 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
597 XGUI_Workshop* aWorkshop = aConnector->workshop();
598 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
600 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
601 if (aPropertyPanel) {
602 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
603 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
605 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
606 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
607 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
608 aReentranceMgr, SLOT(onWidgetActivated()));
611 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
612 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
613 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
615 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
616 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
617 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
620 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
622 if (!myClickedPoint.myIsInitialized)
625 ModuleBase_Operation* aOperation = getCurrentOperation();
626 // the distance constraint feature should not use the clickedd point
627 // this is workaround in order to don't throw down the flyout point value,
628 // set by execute() method of these type of features
629 if (isDistanceOperation(aOperation))
632 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
634 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
638 void PartSet_SketcherMgr::onBeforeContextMenu()
640 myIsPopupMenuActive = true;
643 void PartSet_SketcherMgr::onAfterContextMenu()
645 myIsPopupMenuActive = false;
648 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
651 Handle(V3d_View) aView = theWnd->v3dView();
652 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
654 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
655 thePoint.setValue(aX, anY);
658 void PartSet_SketcherMgr::launchEditing()
660 if (!myCurrentSelection.empty()) {
661 FeaturePtr aFeature = myCurrentSelection.begin().key();
662 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
663 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
665 myModule->editFeature(aSPFeature);
670 bool PartSet_SketcherMgr::sketchSolverError()
672 bool anError = false;
673 CompositeFeaturePtr aSketch = activeSketch();
675 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
676 anError = !aAttributeString->value().empty();
681 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
683 QString anError = "";
684 if (!theFeature.get() || !theFeature->data()->isValid())
687 CompositeFeaturePtr aSketch = activeSketch();
688 if (aSketch.get() && aSketch == theFeature) {
689 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
690 anError = aAttributeString->value().c_str();
693 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
694 if (isCheckGUI && anActiveWidget) {
695 ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState();
696 if (aState != ModuleBase_ModelWidget::Stored) {
697 AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
699 QString anAttributeName = anAttr->id().c_str();
701 case ModuleBase_ModelWidget::ModifiedInPP:
702 anError = "Attribute \"" + anAttributeName +
703 "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
705 case ModuleBase_ModelWidget::ModifiedInViewer:
706 anError = "Attribute \"" + anAttributeName +
707 "\" is locked by modification value in the viewer.";
709 case ModuleBase_ModelWidget::Reset:
710 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
720 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
722 static QStringList aIds;
723 if (aIds.size() == 0) {
724 aIds << SketchPlugin_Line::ID().c_str();
725 aIds << SketchPlugin_Point::ID().c_str();
726 aIds << SketchPlugin_Arc::ID().c_str();
727 aIds << SketchPlugin_Circle::ID().c_str();
728 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
729 aIds.append(constraintsIdList());
734 const QStringList& PartSet_SketcherMgr::constraintsIdList()
736 static QStringList aIds;
737 if (aIds.size() == 0) {
738 aIds << SketchPlugin_ConstraintLength::ID().c_str();
739 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
740 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
741 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
742 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
743 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
744 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
745 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
746 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
747 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
748 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
749 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
750 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
751 aIds << SketchPlugin_MultiRotation::ID().c_str();
752 aIds << SketchPlugin_MultiTranslation::ID().c_str();
757 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
761 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
762 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
763 theModes.append(SketcherPrs_Tools::Sel_Constraint);
764 theModes.append(TopAbs_VERTEX);
765 theModes.append(TopAbs_EDGE);
768 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
770 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
773 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
775 return theOperation &&
776 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
779 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
781 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
783 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
786 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
788 return (theId == SketchPlugin_Line::ID()) ||
789 (theId == SketchPlugin_Point::ID()) ||
790 (theId == SketchPlugin_Arc::ID()) ||
791 (theId == SketchPlugin_Circle::ID());
794 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
796 std::string aId = theOperation ? theOperation->id().toStdString() : "";
798 return (aId == SketchPlugin_ConstraintLength::ID()) ||
799 (aId == SketchPlugin_ConstraintDistance::ID()) ||
800 (aId == SketchPlugin_ConstraintRadius::ID()) ||
801 (aId == SketchPlugin_ConstraintAngle::ID());
804 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
806 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
807 (getCurrentOperation());
811 myModule->onViewTransformed();
813 // Display all sketcher sub-Objects
814 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
815 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
817 // Hide sketcher result
818 std::list<ResultPtr> aResults = myCurrentSketch->results();
819 std::list<ResultPtr>::const_iterator aIt;
820 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
821 (*aIt)->setDisplayed(false);
823 myCurrentSketch->setDisplayed(false);
825 // Display sketcher objects
826 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
827 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
828 std::list<ResultPtr> aResults = aFeature->results();
829 std::list<ResultPtr>::const_iterator aIt;
830 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
831 (*aIt)->setDisplayed(true);
833 aFeature->setDisplayed(true);
836 if (myPlaneFilter.IsNull())
837 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
839 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
841 bool aHasPlane = false;
842 std::shared_ptr<GeomAPI_Pln> aPln;
843 if (aFOperation->isEditOperation()) {
844 // If it is editing of sketch then it means that plane is already defined
845 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
849 myPlaneFilter->setPlane(aPln);
851 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
852 // all sketch objects should be activated in the sketch selection modes by edit operation start
853 // in case of creation operation, there is an active widget, which activates own selection mode
854 if (aFOperation->isEditOperation() && aHasPlane)
855 aConnector->activateModuleSelectionModes();
858 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
860 myIsMouseOverWindow = false;
861 myIsConstraintsShown = true;
863 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
865 DataPtr aData = myCurrentSketch->data();
866 if (!aData->isValid()) {
867 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
868 // The sketch was aborted
869 myCurrentSketch = CompositeFeaturePtr();
870 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
872 // Erase all sketcher objects
873 QStringList aSketchIds = sketchOperationIdList();
874 QObjectPtrList aObjects = aDisplayer->displayedObjects();
875 foreach (ObjectPtr aObj, aObjects) {
876 DataPtr aObjData = aObj->data();
877 if (!aObjData->isValid())
878 aObj->setDisplayed(false);
882 // Hide all sketcher sub-Objects
883 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
884 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
885 std::list<ResultPtr> aResults = aFeature->results();
886 std::list<ResultPtr>::const_iterator aIt;
887 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
888 (*aIt)->setDisplayed(false);
890 aFeature->setDisplayed(false);
892 // Display sketcher result
893 std::list<ResultPtr> aResults = myCurrentSketch->results();
894 std::list<ResultPtr>::const_iterator aIt;
895 Events_Loop* aLoop = Events_Loop::loop();
896 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
898 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
900 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
901 if (!aFOperation->isDisplayedOnStart(*aIt)) {
902 (*aIt)->setDisplayed(true);
903 // this display event is needed because sketch already may have "displayed" state,
904 // but not displayed while it is still active (issue 613, abort of existing sketch)
905 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
908 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
909 myCurrentSketch->setDisplayed(true);
911 myCurrentSketch = CompositeFeaturePtr();
912 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
914 Events_Loop::loop()->flush(aDispEvent);
916 // restore the module selection modes, which were changed on startSketch
917 aConnector->activateModuleSelectionModes();
920 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
922 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
923 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
926 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
928 myIsMouseOverViewProcessed = true;
929 operationMgr()->onValidateOperation();
930 if (isNestedCreateOperation(theOp) || myModule->sketchReentranceMgr()->isInternalEditActive())
931 QApplication::restoreOverrideCursor();
934 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
936 if (isNestedCreateOperation(theOperation)) {
937 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
940 FeaturePtr aFeature = aFOperation->feature();
941 // it is necessary to check the the feature data validity because
942 // some kind of features are removed by an operation commit(the macro state of a feature)
943 if (aFeature.get() && aFeature->data()->isValid()) {
944 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
950 bool PartSet_SketcherMgr::canUndo() const
952 return isNestedCreateOperation(getCurrentOperation());
955 bool PartSet_SketcherMgr::canRedo() const
957 return isNestedCreateOperation(getCurrentOperation());
960 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
962 bool aCanErase = true;
963 // when the sketch operation is active, results of sketch sub-feature can not be hidden
964 if (myCurrentSketch.get()) {
965 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
967 // Display sketcher objects
968 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
970 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
971 std::list<ResultPtr> aResults = aFeature->results();
972 std::list<ResultPtr>::const_iterator anIt;
973 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
974 aCanErase = *anIt != aResult;
982 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
984 bool aCanDisplay = true;
986 bool aHasActiveSketch = activeSketch().get() != NULL;
987 if (aHasActiveSketch) {
988 // 1. the sketch feature should not be displayed during the sketch active operation
989 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
990 // nested features can be visualized
991 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
992 if (aFeature.get() != NULL && aFeature == activeSketch()) {
996 else { // there are no an active sketch
997 // 2. sketch sub-features should not be visualized if the sketch operation is not active
998 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
999 if (aFeature.get() != NULL) {
1000 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1001 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1002 if (aSketchFeature.get()) {
1003 aCanDisplay = false;
1008 // 3. the method should not filter the objects, which are not related to the current operation.
1009 // The object is filtered just if it is a current operation feature or this feature result
1010 bool isObjectFound = false;
1011 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1012 (getCurrentOperation());
1014 FeaturePtr aFeature = aFOperation->feature();
1015 if (aFeature.get()) {
1016 std::list<ResultPtr> aResults = aFeature->results();
1017 if (theObject == aFeature)
1018 isObjectFound = true;
1020 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1021 for (; anIt != aLast && !isObjectFound; anIt++) {
1022 isObjectFound = *anIt == theObject;
1030 // 4. For created nested feature operation do not display the created feature if
1031 // the mouse curstor leaves the OCC window.
1032 // The correction cases, which ignores this condition:
1033 // a. the property panel values modification
1034 // b. the popup menu activated
1035 // c. widget editor control
1036 #ifndef DEBUG_DO_NOT_BY_ENTER
1037 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1038 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1039 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1040 // the active widget editor should not influence here. The presentation should be visible always
1041 // when this widget is active.
1042 if (!anEditorWdg && !myIsPopupMenuActive) {
1043 // during a nested create operation, the feature is redisplayed only if the mouse over view
1044 // of there was a value modified in the property panel after the mouse left the view
1045 aCanDisplay = canDisplayCurrentCreatedFeature();
1052 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1054 bool aCanDisplay = myIsMouseOverWindow;
1056 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1058 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1063 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1065 bool isFoundObject = false;
1067 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1068 if (anObjectFeature.get()) {
1069 int aSize = myCurrentSketch->numberOfSubs();
1070 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1071 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1072 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1075 return isFoundObject;
1078 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1080 if (myPlaneFilter.IsNull())
1081 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1083 myPlaneFilter->setPlane(thePln);
1086 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1087 const FeaturePtr& theSketch,
1088 ModuleBase_IWorkshop* theWorkshop,
1089 FeatureToSelectionMap& theSelection)
1091 if (theFeature.get() == NULL)
1094 std::set<AttributePtr> aSelectedAttributes;
1095 std::set<ResultPtr> aSelectedResults;
1097 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1098 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1099 if (!aContext.IsNull()) {
1100 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1101 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1103 std::list<ResultPtr> aResults = theFeature->results();
1104 std::list<ResultPtr>::const_iterator aIt;
1105 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1107 ResultPtr aResult = *aIt;
1108 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1109 if (aAISObj.get() == NULL)
1111 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1112 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1114 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1115 if (anOwner->Selectable() != anAISIO)
1117 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1118 aSelectedAttributes, aSelectedResults);
1120 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1121 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1122 if (anOwner.IsNull())
1124 if (anOwner->Selectable() != anAISIO)
1126 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1127 aSelectedAttributes, aSelectedResults);
1131 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1134 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1135 const FeaturePtr& theSketch,
1136 ModuleBase_IWorkshop* theWorkshop,
1137 const FeatureToSelectionMap& theSelection,
1138 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1140 if (theFeature.get() == NULL)
1143 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1144 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1145 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1147 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1149 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1150 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1152 // 1. found the feature's owners. Check the AIS objects of the constructions
1153 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1154 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1155 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1157 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1158 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1159 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1160 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1161 if (!anOwner.IsNull())
1162 theOwnersToSelect.Add(anOwner);
1166 // 2. found the feature results's owners
1167 std::list<ResultPtr> aResults = theFeature->results();
1168 std::list<ResultPtr>::const_iterator aIt;
1169 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1171 ResultPtr aResult = *aIt;
1172 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1173 if (aAISObj.get() == NULL)
1175 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1177 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1178 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1179 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1180 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1181 if ( anOwner.IsNull() || !anOwner->HasShape() )
1183 const TopoDS_Shape& aShape = anOwner->Shape();
1184 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1185 if (aShapeType == TopAbs_VERTEX) {
1186 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1187 if (aPntAttr.get() != NULL &&
1188 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1189 theOwnersToSelect.Add(anOwner);
1192 else if (aShapeType == TopAbs_EDGE) {
1193 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1194 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1195 theOwnersToSelect.FindIndex(anOwner) <= 0)
1196 theOwnersToSelect.Add(anOwner);
1202 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1205 connect(theWidget, SIGNAL(beforeValuesChanged()),
1206 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1207 connect(theWidget, SIGNAL(afterValuesChanged()),
1208 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1211 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1212 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1213 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1214 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1218 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1220 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1221 (getCurrentOperation());
1223 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1224 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1225 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1226 FeaturePtr aFeature = aFOperation->feature();
1227 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1232 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1234 return myModule->workshop()->currentOperation();
1237 //**************************************************************
1238 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1240 ModuleBase_ModelWidget* aWidget = 0;
1241 ModuleBase_Operation* anOperation = getCurrentOperation();
1243 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1245 aWidget = aPanel->activeWidget();
1250 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1251 const bool isEditOperation,
1252 const bool isToDisplay,
1253 const bool isFlushRedisplay)
1255 #ifdef DEBUG_DO_NOT_BY_ENTER
1259 if (isEditOperation || !theFeature.get())
1262 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1263 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1265 // 1. change visibility of the object itself, here the presentable object is processed,
1266 // e.g. constraints features
1267 //FeaturePtr aFeature = aFOperation->feature();
1268 std::list<ResultPtr> aResults = theFeature->results();
1270 theFeature->setDisplayed(true);
1272 theFeature->setDisplayed(false);
1274 // change visibility of the object results, e.g. non-constraint features
1275 std::list<ResultPtr>::const_iterator aIt;
1276 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1278 (*aIt)->setDisplayed(true);
1281 (*aIt)->setDisplayed(false);
1284 if (isFlushRedisplay)
1285 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1288 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1290 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1291 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1292 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1294 QList<FeaturePtr> aFeatureList;
1295 if (theHighlightedOnly) {
1296 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1299 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1301 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1302 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1305 // 1. it is necessary to save current selection in order to restore it after the features moving
1306 myCurrentSelection.clear();
1307 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1308 for (; anIt != aLast; anIt++) {
1309 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1311 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1314 void PartSet_SketcherMgr::restoreSelection()
1316 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1317 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1318 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1319 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1320 aSLast = myCurrentSelection.end();
1321 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1322 for (; aSIt != aSLast; aSIt++) {
1323 anOwnersToSelect.Clear();
1324 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1326 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1330 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1332 if (myIsConstraintsShown == theOn)
1334 if (myCurrentSketch.get() == NULL)
1337 myIsConstraintsShown = theOn;
1339 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1340 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1342 const QStringList& aConstrIds = constraintsIdList();
1343 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1344 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1345 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1346 if (myIsConstraintsShown)
1347 aSubFeature->setDisplayed(true);
1349 aSubFeature->setDisplayed(false);
1352 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1355 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1357 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1358 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1359 XGUI_Workshop* aWorkshop = aConnector->workshop();
1361 return aWorkshop->operationMgr();