1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_SketcherMgr.cpp
4 // Created: 19 Dec 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "PartSet_SketcherMgr.h"
8 #include "PartSet_Module.h"
9 #include "PartSet_WidgetPoint2d.h"
10 #include "PartSet_WidgetPoint2dDistance.h"
11 #include "PartSet_Tools.h"
12 #include "PartSet_WidgetSketchLabel.h"
14 #include <XGUI_ModuleConnector.h>
15 #include <XGUI_Displayer.h>
16 #include <XGUI_Workshop.h>
17 #include <XGUI_ContextMenuMgr.h>
18 #include <XGUI_Selection.h>
19 #include <XGUI_SelectionMgr.h>
20 #include <XGUI_ModuleConnector.h>
21 #include <XGUI_PropertyPanel.h>
22 #include <XGUI_ViewerProxy.h>
23 #include <XGUI_OperationMgr.h>
25 #include <ModuleBase_IPropertyPanel.h>
26 #include <ModuleBase_ISelection.h>
27 #include <ModuleBase_IViewer.h>
28 #include <ModuleBase_IWorkshop.h>
29 #include <ModuleBase_IViewWindow.h>
30 #include <ModuleBase_ModelWidget.h>
31 #include <ModuleBase_Operation.h>
32 #include <ModuleBase_OperationFeature.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_WidgetEditor.h>
36 #include <GeomDataAPI_Point2D.h>
38 #include <Events_Loop.h>
40 #include <SketchPlugin_Line.h>
41 #include <SketchPlugin_Sketch.h>
42 #include <SketchPlugin_Point.h>
43 #include <SketchPlugin_Arc.h>
44 #include <SketchPlugin_Circle.h>
45 #include <SketchPlugin_ConstraintLength.h>
46 #include <SketchPlugin_ConstraintDistance.h>
47 #include <SketchPlugin_ConstraintParallel.h>
48 #include <SketchPlugin_ConstraintPerpendicular.h>
49 #include <SketchPlugin_ConstraintRadius.h>
50 #include <SketchPlugin_ConstraintRigid.h>
51 #include <SketchPlugin_ConstraintHorizontal.h>
52 #include <SketchPlugin_ConstraintVertical.h>
53 #include <SketchPlugin_ConstraintEqual.h>
54 #include <SketchPlugin_ConstraintTangent.h>
55 #include <SketchPlugin_ConstraintCoincidence.h>
56 #include <SketchPlugin_ConstraintFillet.h>
57 #include <SketchPlugin_ConstraintMirror.h>
58 #include <SketchPlugin_ConstraintAngle.h>
59 #include <SketchPlugin_MultiRotation.h>
60 #include <SketchPlugin_MultiTranslation.h>
62 #include <SketcherPrs_Tools.h>
64 #include <SelectMgr_IndexedMapOfOwner.hxx>
65 #include <StdSelect_BRepOwner.hxx>
67 //#include <AIS_DimensionSelectionMode.hxx>
68 #include <AIS_Shape.hxx>
70 #include <ModelAPI_Events.h>
71 #include <ModelAPI_Session.h>
72 #include <ModelAPI_AttributeString.h>
74 #include <QMouseEvent>
75 #include <QApplication>
77 //#define DEBUG_DO_NOT_BY_ENTER
79 /// Returns list of unique objects by sum of objects from List1 and List2
80 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
81 const QList<ModuleBase_ViewerPrs>& theList2)
83 QList<ModuleBase_ViewerPrs> aRes;
84 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
85 if (!aRes.contains(aPrs))
88 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
89 if (!aRes.contains(aPrs))
95 // Fills the list of features the list of selected presentations.
96 // \param theList a list of selected presentations
97 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
98 // and find the corresponded attribute
99 // \param theFeatureList an output list of features
100 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
101 const FeaturePtr theSketch,
102 QList<FeaturePtr>& theFeatureList)
104 QList<ModuleBase_ViewerPrs> aRes;
106 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
107 aLast = theList.end();
108 for (; anIt != aLast; anIt++)
110 ModuleBase_ViewerPrs aPrs = *anIt;
111 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
112 if (aFeature.get() && !theFeatureList.contains(aFeature))
113 theFeatureList.append(aFeature);
117 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
118 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
119 /// result as is to the list of results.
120 /// \param theOwner a viewer selected owner
121 /// \param theFeature a feature, where the attribute is searched
122 /// \param theSketch a current sketch
123 /// \param theSelectedAttribute an output list of attributes
124 /// \param theSelectedResults an output list of edge results
125 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
126 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
127 const ResultPtr& theResult,
128 std::set<AttributePtr>& aSelectedAttributes,
129 std::set<ResultPtr>& aSelectedResults)
131 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
132 if (aBRepOwner.IsNull())
134 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
135 aBRepOwner->Selectable());
136 if (aBRepOwner->HasShape()) {
137 const TopoDS_Shape& aShape = aBRepOwner->Shape();
138 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
139 if (aShapeType == TopAbs_VERTEX) {
140 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
142 if (aPntAttr.get() != NULL)
143 aSelectedAttributes.insert(aPntAttr);
145 else if (aShapeType == TopAbs_EDGE &&
146 aSelectedResults.find(theResult) == aSelectedResults.end()) {
147 aSelectedResults.insert(theResult);
152 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
153 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
154 myIsMouseOverWindow(false),
155 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
156 myIsPopupMenuActive(false), myIsConstraintsShown(true)
158 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
159 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
161 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
163 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
164 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
166 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
167 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
169 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
170 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
172 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
173 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
175 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
176 XGUI_Workshop* aWorkshop = aConnector->workshop();
177 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
180 PartSet_SketcherMgr::~PartSet_SketcherMgr()
182 if (!myPlaneFilter.IsNull())
183 myPlaneFilter.Nullify();
186 void PartSet_SketcherMgr::onEnterViewPort()
188 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
189 // created feature because it should be done in onMouseMove(). Some widgets watch
190 // the mouse move and use the cursor position to update own values. If the presentaion is
191 // redisplayed before this update, the feature presentation jumps from reset value to current.
192 myIsMouseOverWindow = true;
194 #ifdef DEBUG_DO_NOT_BY_ENTER
198 if (!isNestedCreateOperation(getCurrentOperation()))
201 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
203 operationMgr()->onValidateOperation();
205 // we need change displayed state of the current operation feature
206 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
207 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
208 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
209 // presentation becomes valid and redisplay happens
210 //ModuleBase_Operation* aOperation = getCurrentOperation();
211 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
212 (getCurrentOperation());
214 FeaturePtr aFeature = aFOperation->feature();
215 if (aFeature.get() && aFeature->data()->isValid()) {
216 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
221 void PartSet_SketcherMgr::onLeaveViewPort()
223 myIsMouseOverViewProcessed = false;
224 myIsMouseOverWindow = false;
225 // it is important to validate operation here only if sketch entity create operation is active
226 // because at this operation we reacts to the mouse leave/enter view port
227 //operationMgr()->onValidateOperation();
229 #ifdef DEBUG_DO_NOT_BY_ENTER
233 if (!isNestedCreateOperation(getCurrentOperation()))
236 QApplication::restoreOverrideCursor();
238 // the method should be performed if the popup menu is called,
239 // the reset of the current widget should not happen
240 if (myIsPopupMenuActive)
243 operationMgr()->onValidateOperation();
245 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
246 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
247 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
248 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
249 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
250 // obtained after reset value
251 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
252 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
254 anActiveWidget->reset();
255 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
257 // hides the presentation of the current operation feature
258 // the feature is to be erased here, but it is correct to call canDisplayObject because
259 // there can be additional check (e.g. editor widget in distance constraint)
260 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
261 (getCurrentOperation());
263 FeaturePtr aFeature = aFOperation->feature();
264 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
268 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
270 if (isNestedCreateOperation(getCurrentOperation()))
272 // it is necessary to save current selection in order to restore it after the values are modifed
275 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
276 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
277 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
278 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
281 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
283 if (isNestedCreateOperation(getCurrentOperation()))
285 // it is necessary to restore current selection in order to restore it after the values are modified
287 myCurrentSelection.clear();
289 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
290 // viewer happens by deselect/select the modified objects. The flag should be restored after
291 // the selection processing. The update viewer should be also called.
292 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
293 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
294 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
295 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
296 aDisplayer->updateViewer();
299 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
301 if (!isNestedCreateOperation(getCurrentOperation()))
304 operationMgr()->onValidateOperation();
305 // the feature is to be erased here, but it is correct to call canDisplayObject because
306 // there can be additional check (e.g. editor widget in distance constraint)
307 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
308 (getCurrentOperation());
310 FeaturePtr aFeature = aFOperation->feature();
311 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
315 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
317 get2dPoint(theWnd, theEvent, myClickedPoint);
319 if (!(theEvent->buttons() & Qt::LeftButton))
322 // Clear dragging mode
323 myIsDragging = false;
325 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
326 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
327 if (!aViewer->canDragByMouse())
330 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
331 (getCurrentOperation());
335 if (aFOperation->isEditOperation()) {
336 // If the current widget is a selector, do nothing, it processes the mouse press
337 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
338 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
343 // Use only for sketch operations
344 if (myCurrentSketch) {
345 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
348 bool isSketcher = isSketchOperation(aFOperation);
349 bool isSketchOpe = isNestedSketchOperation(aFOperation);
351 // Avoid non-sketch operations
352 if ((!isSketchOpe) && (!isSketcher))
355 bool isEditing = aFOperation->isEditOperation();
357 // Ignore creation sketch operation
358 if ((!isSketcher) && (!isEditing))
361 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
362 if (!aContext.IsNull()) {
363 // MoveTo in order to highlight current object
364 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
366 // Remember highlighted objects for editing
367 ModuleBase_ISelection* aSelect = aWorkshop->selection();
369 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
370 storeSelection(!aHasShift);
372 if (myCurrentSelection.empty()) {
373 if (isSketchOpe && (!isSketcher))
374 // commit previous operation
375 if (!aFOperation->commit())
376 aFOperation->abort();
379 // Init flyout point for radius rotation
380 FeaturePtr aFeature = myCurrentSelection.begin().key();
384 get2dPoint(theWnd, theEvent, myCurrentPoint);
386 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
387 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
389 if (aFeature.get() != NULL) {
390 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
391 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
392 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
393 DataPtr aData = aSPFeature->data();
394 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
395 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
396 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
397 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
400 } else if (isSketchOpe && isEditing) {
401 // If selected another object commit current result
402 aFOperation->commit();
405 get2dPoint(theWnd, theEvent, myCurrentPoint);
407 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
408 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
410 // This is necessary in order to finalize previous operation
411 QApplication::processEvents();
417 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
419 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
420 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
421 if (!aViewer->canDragByMouse())
423 ModuleBase_Operation* aOp = getCurrentOperation();
425 if (isNestedSketchOperation(aOp)) {
426 get2dPoint(theWnd, theEvent, myClickedPoint);
428 // Only for sketcher operations
432 myCurrentSelection.clear();
433 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
434 if (!aContext.IsNull()) {
435 // Reselect edited object
436 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
437 if (theEvent->modifiers() & Qt::ShiftModifier)
438 aContext->ShiftSelect();
446 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
447 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
448 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
449 myIsDragging = false;
452 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
454 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
455 myIsMouseOverViewProcessed = true;
456 // 1. perform the widget mouse move functionality and display the presentation
457 // the mouse move should be processed in the widget, if it can in order to visualize correct
458 // presentation. These widgets correct the feature attribute according to the mouse position
459 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
460 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
462 aPoint2DWdg->onMouseMove(theWnd, theEvent);
464 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
467 aDistanceWdg->onMouseMove(theWnd, theEvent);
469 // the feature is to be erased here, but it is correct to call canDisplayObject because
470 // there can be additional check (e.g. editor widget in distance constraint)
471 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
472 (getCurrentOperation());
474 FeaturePtr aFeature = aFOperation->feature();
475 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
479 myClickedPoint.clear();
482 // 1. the current selection is saved in the mouse press method in order to restore it after moving
483 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
484 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
485 // deselected). This flag should be restored in the slot, processed the mouse release signal.
487 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
488 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
489 //aViewer->enableSelection(false);
491 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
492 if (!aCurrentOperation)
494 if (isSketchOperation(aCurrentOperation))
495 return; // No edit operation activated
497 Handle(V3d_View) aView = theWnd->v3dView();
498 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
500 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
501 double dX = aX - myCurrentPoint.myCurX;
502 double dY = aY - myCurrentPoint.myCurY;
504 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
505 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
506 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
507 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
508 // viewer happens by deselect/select the modified objects. The flag should be restored after
509 // the selection processing. The update viewer should be also called.
510 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
512 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
513 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
514 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
515 aLast = myCurrentSelection.end();
516 // 4. the features and attributes modification(move)
517 bool isModified = false;
518 for (; anIt != aLast; anIt++) {
519 FeaturePtr aFeature = anIt.key();
521 std::set<AttributePtr> anAttributes = anIt.value().first;
522 // Process selection by attribute: the priority to the attribute
523 if (!anAttributes.empty()) {
524 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
525 anAttLast = anAttributes.end();
526 for (; anAttIt != anAttLast; anAttIt++) {
527 AttributePtr anAttr = *anAttIt;
528 if (anAttr.get() == NULL)
530 std::string aAttrId = anAttr->id();
531 DataPtr aData = aFeature->data();
532 if (aData->isValid()) {
533 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
534 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
535 if (aPoint.get() != NULL) {
536 bool isImmutable = aPoint->setImmutable(true);
537 aPoint->move(dX, dY);
539 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
540 aPoint->setImmutable(isImmutable);
545 // Process selection by feature
546 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
547 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
548 if (aSketchFeature) {
549 aSketchFeature->move(dX, dY);
551 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
555 // the modified state of the current operation should be updated if there are features, which
558 aCurrentOperation->onValuesChanged();
560 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
561 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
563 // 5. it is necessary to save current selection in order to restore it after the features moving
565 // 6. restore the update viewer flag and call this update
566 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
567 aDisplayer->updateViewer();
570 myCurrentPoint.setValue(aX, aY);
574 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
576 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
577 (getCurrentOperation());
578 if (aFOperation && aFOperation->isEditOperation()) {
579 std::string aId = aFOperation->id().toStdString();
580 if (isDistanceOperation(aFOperation))
582 // Activate dimension value editing on double click
583 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
584 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
585 // Find corresponded widget to activate value editing
586 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
587 if (aWgt->attributeID() == "ConstraintValue") {
596 void PartSet_SketcherMgr::onApplicationStarted()
598 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
599 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
600 XGUI_Workshop* aWorkshop = aConnector->workshop();
601 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
602 if (aPropertyPanel) {
603 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
604 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
607 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
608 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
609 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
611 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
612 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
613 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
616 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
618 if (!myClickedPoint.myIsInitialized)
621 ModuleBase_Operation* aOperation = getCurrentOperation();
622 // the distance constraint feature should not use the clickedd point
623 // this is workaround in order to don't throw down the flyout point value,
624 // set by execute() method of these type of features
625 if (isDistanceOperation(aOperation))
628 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
630 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
634 void PartSet_SketcherMgr::onBeforeContextMenu()
636 myIsPopupMenuActive = true;
639 void PartSet_SketcherMgr::onAfterContextMenu()
641 myIsPopupMenuActive = false;
644 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
647 Handle(V3d_View) aView = theWnd->v3dView();
648 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
650 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
651 thePoint.setValue(aX, anY);
654 void PartSet_SketcherMgr::launchEditing()
656 if (!myCurrentSelection.empty()) {
657 FeaturePtr aFeature = myCurrentSelection.begin().key();
658 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
659 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
661 myModule->editFeature(aSPFeature);
666 bool PartSet_SketcherMgr::sketchSolverError()
668 bool anError = false;
669 CompositeFeaturePtr aSketch = activeSketch();
671 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
672 anError = !aAttributeString->value().empty();
677 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
679 QString anError = "";
680 if (!theFeature.get() || !theFeature->data()->isValid())
683 CompositeFeaturePtr aSketch = activeSketch();
684 if (aSketch.get() && aSketch == theFeature) {
685 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
686 anError = aAttributeString->value().c_str();
689 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
690 if (anActiveWidget) {
691 ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState();
692 if (aState != ModuleBase_ModelWidget::Stored) {
693 AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
695 QString anAttributeName = anAttr->id().c_str();
697 case ModuleBase_ModelWidget::Modified:
698 anError = "Attribute \"" + anAttributeName +
699 "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
701 case ModuleBase_ModelWidget::Reset:
702 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
712 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
714 static QStringList aIds;
715 if (aIds.size() == 0) {
716 aIds << SketchPlugin_Line::ID().c_str();
717 aIds << SketchPlugin_Point::ID().c_str();
718 aIds << SketchPlugin_Arc::ID().c_str();
719 aIds << SketchPlugin_Circle::ID().c_str();
720 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
721 aIds.append(constraintsIdList());
726 const QStringList& PartSet_SketcherMgr::constraintsIdList()
728 static QStringList aIds;
729 if (aIds.size() == 0) {
730 aIds << SketchPlugin_ConstraintLength::ID().c_str();
731 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
732 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
733 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
734 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
735 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
736 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
737 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
738 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
739 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
740 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
741 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
742 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
743 aIds << SketchPlugin_MultiRotation::ID().c_str();
744 aIds << SketchPlugin_MultiTranslation::ID().c_str();
749 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
753 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
754 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
755 theModes.append(SketcherPrs_Tools::Sel_Constraint);
756 theModes.append(TopAbs_VERTEX);
757 theModes.append(TopAbs_EDGE);
760 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
762 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
765 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
767 return theOperation &&
768 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
771 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
773 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
775 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
778 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
780 return (theId == SketchPlugin_Line::ID()) ||
781 (theId == SketchPlugin_Point::ID()) ||
782 (theId == SketchPlugin_Arc::ID()) ||
783 (theId == SketchPlugin_Circle::ID());
786 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
788 std::string aId = theOperation ? theOperation->id().toStdString() : "";
790 return (aId == SketchPlugin_ConstraintLength::ID()) ||
791 (aId == SketchPlugin_ConstraintDistance::ID()) ||
792 (aId == SketchPlugin_ConstraintRadius::ID()) ||
793 (aId == SketchPlugin_ConstraintAngle::ID());
796 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
798 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
799 (getCurrentOperation());
803 myModule->onViewTransformed();
805 // Display all sketcher sub-Objects
806 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
807 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
809 // Hide sketcher result
810 std::list<ResultPtr> aResults = myCurrentSketch->results();
811 std::list<ResultPtr>::const_iterator aIt;
812 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
813 (*aIt)->setDisplayed(false);
815 myCurrentSketch->setDisplayed(false);
817 // Display sketcher objects
818 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
819 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
820 std::list<ResultPtr> aResults = aFeature->results();
821 std::list<ResultPtr>::const_iterator aIt;
822 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
823 (*aIt)->setDisplayed(true);
825 aFeature->setDisplayed(true);
828 if (myPlaneFilter.IsNull())
829 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
831 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
833 bool aHasPlane = false;
834 std::shared_ptr<GeomAPI_Pln> aPln;
835 if (aFOperation->isEditOperation()) {
836 // If it is editing of sketch then it means that plane is already defined
837 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
841 myPlaneFilter->setPlane(aPln);
843 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
844 // all sketch objects should be activated in the sketch selection modes by edit operation start
845 // in case of creation operation, there is an active widget, which activates own selection mode
846 if (aFOperation->isEditOperation() && aHasPlane)
847 aConnector->activateModuleSelectionModes();
850 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
852 myIsMouseOverWindow = false;
853 myIsConstraintsShown = true;
855 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
857 DataPtr aData = myCurrentSketch->data();
858 if (!aData->isValid()) {
859 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
860 // The sketch was aborted
861 myCurrentSketch = CompositeFeaturePtr();
862 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
864 // Erase all sketcher objects
865 QStringList aSketchIds = sketchOperationIdList();
866 QObjectPtrList aObjects = aDisplayer->displayedObjects();
867 foreach (ObjectPtr aObj, aObjects) {
868 DataPtr aObjData = aObj->data();
869 if (!aObjData->isValid())
870 aObj->setDisplayed(false);
874 // Hide all sketcher sub-Objects
875 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
876 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
877 std::list<ResultPtr> aResults = aFeature->results();
878 std::list<ResultPtr>::const_iterator aIt;
879 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
880 (*aIt)->setDisplayed(false);
882 aFeature->setDisplayed(false);
884 // Display sketcher result
885 std::list<ResultPtr> aResults = myCurrentSketch->results();
886 std::list<ResultPtr>::const_iterator aIt;
887 Events_Loop* aLoop = Events_Loop::loop();
888 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
890 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
892 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
893 if (!aFOperation->isDisplayedOnStart(*aIt)) {
894 (*aIt)->setDisplayed(true);
895 // this display event is needed because sketch already may have "displayed" state,
896 // but not displayed while it is still active (issue 613, abort of existing sketch)
897 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
900 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
901 myCurrentSketch->setDisplayed(true);
903 myCurrentSketch = CompositeFeaturePtr();
904 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
906 Events_Loop::loop()->flush(aDispEvent);
908 // restore the module selection modes, which were changed on startSketch
909 aConnector->activateModuleSelectionModes();
912 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
914 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
915 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
918 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
920 myIsMouseOverViewProcessed = true;
921 operationMgr()->onValidateOperation();
922 if (isNestedCreateOperation(theOp))
923 QApplication::restoreOverrideCursor();
926 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
928 if (isNestedCreateOperation(theOperation)) {
929 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
932 FeaturePtr aFeature = aFOperation->feature();
933 // it is necessary to check the the feature data validity because
934 // some kind of features are removed by an operation commit(the macro state of a feature)
935 if (aFeature.get() && aFeature->data()->isValid()) {
936 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
942 bool PartSet_SketcherMgr::canUndo() const
944 return isNestedCreateOperation(getCurrentOperation());
947 bool PartSet_SketcherMgr::canRedo() const
949 return isNestedCreateOperation(getCurrentOperation());
952 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
954 bool aCanErase = true;
955 // when the sketch operation is active, results of sketch sub-feature can not be hidden
956 if (myCurrentSketch.get()) {
957 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
959 // Display sketcher objects
960 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
962 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
963 std::list<ResultPtr> aResults = aFeature->results();
964 std::list<ResultPtr>::const_iterator anIt;
965 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
966 aCanErase = *anIt != aResult;
974 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
976 bool aCanDisplay = true;
978 bool aHasActiveSketch = activeSketch().get() != NULL;
979 if (aHasActiveSketch) {
980 // 1. the sketch feature should not be displayed during the sketch active operation
981 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
982 // nested features can be visualized
983 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
984 if (aFeature.get() != NULL && aFeature == activeSketch()) {
988 else { // there are no an active sketch
989 // 2. sketch sub-features should not be visualized if the sketch operation is not active
990 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
991 if (aFeature.get() != NULL) {
992 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
993 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
994 if (aSketchFeature.get()) {
1000 // 3. the method should not filter the objects, which are not related to the current operation.
1001 // The object is filtered just if it is a current operation feature or this feature result
1002 bool isObjectFound = false;
1003 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1004 (getCurrentOperation());
1006 FeaturePtr aFeature = aFOperation->feature();
1007 if (aFeature.get()) {
1008 std::list<ResultPtr> aResults = aFeature->results();
1009 if (theObject == aFeature)
1010 isObjectFound = true;
1012 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1013 for (; anIt != aLast && !isObjectFound; anIt++) {
1014 isObjectFound = *anIt == theObject;
1022 // 4. For created nested feature operation do not display the created feature if
1023 // the mouse curstor leaves the OCC window.
1024 // The correction cases, which ignores this condition:
1025 // a. the property panel values modification
1026 // b. the popup menu activated
1027 // c. widget editor control
1028 #ifndef DEBUG_DO_NOT_BY_ENTER
1029 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1030 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1031 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1032 // the active widget editor should not influence here. The presentation should be visible always
1033 // when this widget is active.
1034 if (!anEditorWdg && !myIsPopupMenuActive) {
1035 // during a nested create operation, the feature is redisplayed only if the mouse over view
1036 // of there was a value modified in the property panel after the mouse left the view
1037 aCanDisplay = canDisplayCurrentCreatedFeature();
1044 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1046 bool aCanDisplay = myIsMouseOverWindow;
1048 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1050 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1055 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1057 bool isFoundObject = false;
1059 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1060 if (anObjectFeature.get()) {
1061 int aSize = myCurrentSketch->numberOfSubs();
1062 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1063 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1064 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1067 return isFoundObject;
1070 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1072 if (myPlaneFilter.IsNull())
1073 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1075 myPlaneFilter->setPlane(thePln);
1078 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1079 const FeaturePtr& theSketch,
1080 ModuleBase_IWorkshop* theWorkshop,
1081 FeatureToSelectionMap& theSelection)
1083 if (theFeature.get() == NULL)
1086 std::set<AttributePtr> aSelectedAttributes;
1087 std::set<ResultPtr> aSelectedResults;
1089 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1090 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1091 if (!aContext.IsNull()) {
1092 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1093 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1095 std::list<ResultPtr> aResults = theFeature->results();
1096 std::list<ResultPtr>::const_iterator aIt;
1097 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1099 ResultPtr aResult = *aIt;
1100 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1101 if (aAISObj.get() == NULL)
1103 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1104 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1106 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1107 if (anOwner->Selectable() != anAISIO)
1109 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1110 aSelectedAttributes, aSelectedResults);
1112 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1113 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1114 if (anOwner.IsNull())
1116 if (anOwner->Selectable() != anAISIO)
1118 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1119 aSelectedAttributes, aSelectedResults);
1123 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1126 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1127 const FeaturePtr& theSketch,
1128 ModuleBase_IWorkshop* theWorkshop,
1129 const FeatureToSelectionMap& theSelection,
1130 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1132 if (theFeature.get() == NULL)
1135 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1136 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1137 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1139 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1141 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1142 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1144 // 1. found the feature's owners. Check the AIS objects of the constructions
1145 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1146 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1147 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1149 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1150 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1151 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1152 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1153 if (!anOwner.IsNull())
1154 theOwnersToSelect.Add(anOwner);
1158 // 2. found the feature results's owners
1159 std::list<ResultPtr> aResults = theFeature->results();
1160 std::list<ResultPtr>::const_iterator aIt;
1161 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1163 ResultPtr aResult = *aIt;
1164 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1165 if (aAISObj.get() == NULL)
1167 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1169 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1170 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1171 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1172 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1173 if ( anOwner.IsNull() || !anOwner->HasShape() )
1175 const TopoDS_Shape& aShape = anOwner->Shape();
1176 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1177 if (aShapeType == TopAbs_VERTEX) {
1178 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1179 if (aPntAttr.get() != NULL &&
1180 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1181 theOwnersToSelect.Add(anOwner);
1184 else if (aShapeType == TopAbs_EDGE) {
1185 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1186 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1187 theOwnersToSelect.FindIndex(anOwner) <= 0)
1188 theOwnersToSelect.Add(anOwner);
1194 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1197 connect(theWidget, SIGNAL(beforeValuesChanged()),
1198 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1199 connect(theWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1200 connect(theWidget, SIGNAL(afterValuesChanged()),
1201 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1204 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1205 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1206 disconnect(theWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1207 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1208 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1212 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1214 return myModule->workshop()->currentOperation();
1217 //**************************************************************
1218 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1220 ModuleBase_ModelWidget* aWidget = 0;
1221 ModuleBase_Operation* anOperation = getCurrentOperation();
1223 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1225 aWidget = aPanel->activeWidget();
1230 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1231 const bool isEditOperation,
1232 const bool isToDisplay,
1233 const bool isFlushRedisplay)
1235 #ifdef DEBUG_DO_NOT_BY_ENTER
1239 if (isEditOperation || !theFeature.get())
1242 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1243 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1245 // 1. change visibility of the object itself, here the presentable object is processed,
1246 // e.g. constraints features
1247 //FeaturePtr aFeature = aFOperation->feature();
1248 std::list<ResultPtr> aResults = theFeature->results();
1250 theFeature->setDisplayed(true);
1252 theFeature->setDisplayed(false);
1254 // change visibility of the object results, e.g. non-constraint features
1255 std::list<ResultPtr>::const_iterator aIt;
1256 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1258 (*aIt)->setDisplayed(true);
1261 (*aIt)->setDisplayed(false);
1264 if (isFlushRedisplay)
1265 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1268 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1270 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1271 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1272 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1274 QList<FeaturePtr> aFeatureList;
1275 if (theHighlightedOnly) {
1276 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1279 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1281 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1282 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1285 // 1. it is necessary to save current selection in order to restore it after the features moving
1286 myCurrentSelection.clear();
1287 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1288 for (; anIt != aLast; anIt++) {
1289 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1291 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1294 void PartSet_SketcherMgr::restoreSelection()
1296 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1297 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1298 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1299 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1300 aSLast = myCurrentSelection.end();
1301 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1302 for (; aSIt != aSLast; aSIt++) {
1303 anOwnersToSelect.Clear();
1304 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1306 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1310 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1312 if (myIsConstraintsShown == theOn)
1314 if (myCurrentSketch.get() == NULL)
1317 myIsConstraintsShown = theOn;
1319 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1320 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1322 const QStringList& aConstrIds = constraintsIdList();
1323 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1324 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1325 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1326 if (myIsConstraintsShown)
1327 aSubFeature->setDisplayed(true);
1329 aSubFeature->setDisplayed(false);
1332 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1335 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1337 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1338 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1339 XGUI_Workshop* aWorkshop = aConnector->workshop();
1341 return aWorkshop->operationMgr();