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>
71 #include <AIS_Dimension.hxx>
73 #include <ModelAPI_Events.h>
74 #include <ModelAPI_Session.h>
75 #include <ModelAPI_AttributeString.h>
77 #include <QMouseEvent>
78 #include <QApplication>
81 //#define DEBUG_DO_NOT_BY_ENTER
83 //#define DEBUG_CURSOR
85 /// Returns list of unique objects by sum of objects from List1 and List2
86 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
87 const QList<ModuleBase_ViewerPrs>& theList2)
89 QList<ModuleBase_ViewerPrs> aRes;
90 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
91 if (!aRes.contains(aPrs))
94 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
95 if (!aRes.contains(aPrs))
101 // Fills the list of features the list of selected presentations.
102 // \param theList a list of selected presentations
103 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
104 // and find the corresponded attribute
105 // \param theFeatureList an output list of features
106 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
107 const FeaturePtr theSketch,
108 QList<FeaturePtr>& theFeatureList)
110 QList<ModuleBase_ViewerPrs> aRes;
112 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
113 aLast = theList.end();
114 for (; anIt != aLast; anIt++)
116 ModuleBase_ViewerPrs aPrs = *anIt;
117 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
118 if (aFeature.get() && !theFeatureList.contains(aFeature))
119 theFeatureList.append(aFeature);
123 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
124 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
125 /// result as is to the list of results.
126 /// \param theOwner a viewer selected owner
127 /// \param theFeature a feature, where the attribute is searched
128 /// \param theSketch a current sketch
129 /// \param theSelectedAttribute an output list of attributes
130 /// \param theSelectedResults an output list of edge results
131 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
132 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
133 const ResultPtr& theResult,
134 std::set<AttributePtr>& aSelectedAttributes,
135 std::set<ResultPtr>& aSelectedResults)
137 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
138 if (aBRepOwner.IsNull())
140 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
141 aBRepOwner->Selectable());
142 if (aBRepOwner->HasShape()) {
143 const TopoDS_Shape& aShape = aBRepOwner->Shape();
144 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
145 if (aShapeType == TopAbs_VERTEX) {
146 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
148 if (aPntAttr.get() != NULL)
149 aSelectedAttributes.insert(aPntAttr);
151 else if (aShapeType == TopAbs_EDGE &&
152 aSelectedResults.find(theResult) == aSelectedResults.end()) {
153 aSelectedResults.insert(theResult);
158 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
159 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
160 myIsMouseOverWindow(false),
161 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
162 myIsPopupMenuActive(false), myIsConstraintsShown(true)
164 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
165 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
167 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
169 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
170 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
172 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
173 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
175 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
176 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
178 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
179 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
181 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
182 XGUI_Workshop* aWorkshop = aConnector->workshop();
183 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
186 PartSet_SketcherMgr::~PartSet_SketcherMgr()
188 if (!myPlaneFilter.IsNull())
189 myPlaneFilter.Nullify();
192 void PartSet_SketcherMgr::onEnterViewPort()
194 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
195 // created feature because it should be done in onMouseMove(). Some widgets watch
196 // the mouse move and use the cursor position to update own values. If the presentaion is
197 // redisplayed before this update, the feature presentation jumps from reset value to current.
198 myIsMouseOverWindow = true;
200 #ifdef DEBUG_DO_NOT_BY_ENTER
204 if (canChangeCursor(getCurrentOperation())) {
205 QCursor* aCurrentCursor = QApplication::overrideCursor();
206 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
207 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
209 qDebug("onEnterViewPort() : Qt::CrossCursor");
214 if (!isNestedCreateOperation(getCurrentOperation()))
217 operationMgr()->onValidateOperation();
219 // we need change displayed state of the current operation feature
220 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
221 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
222 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
223 // presentation becomes valid and redisplay happens
224 //ModuleBase_Operation* aOperation = getCurrentOperation();
225 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
226 (getCurrentOperation());
228 FeaturePtr aFeature = aFOperation->feature();
229 if (aFeature.get() && aFeature->data()->isValid()) {
230 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
235 void PartSet_SketcherMgr::onLeaveViewPort()
237 myIsMouseOverViewProcessed = false;
238 myIsMouseOverWindow = false;
239 // it is important to validate operation here only if sketch entity create operation is active
240 // because at this operation we reacts to the mouse leave/enter view port
241 //operationMgr()->onValidateOperation();
243 #ifdef DEBUG_DO_NOT_BY_ENTER
247 if (canChangeCursor(getCurrentOperation())) {
248 QApplication::restoreOverrideCursor();
250 qDebug("onLeaveViewPort() : None");
254 if (!isNestedCreateOperation(getCurrentOperation()))
257 // the method should be performed if the popup menu is called,
258 // the reset of the current widget should not happen
259 if (myIsPopupMenuActive)
262 operationMgr()->onValidateOperation();
264 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
265 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
266 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
267 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
268 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
269 // obtained after reset value
270 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
271 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
273 anActiveWidget->reset();
275 // hides the presentation of the current operation feature
276 // the feature is to be erased here, but it is correct to call canDisplayObject because
277 // there can be additional check (e.g. editor widget in distance constraint)
278 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
279 (getCurrentOperation());
281 FeaturePtr aFeature = aFOperation->feature();
282 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
284 // we should update viewer after the presentation are hidden in the viewer
285 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
286 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
289 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
291 if (!isNestedEditOperation(getCurrentOperation()) ||
292 myModule->sketchReentranceMgr()->isInternalEditActive())
294 // it is necessary to save current selection in order to restore it after the values are modifed
297 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
298 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
299 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
300 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
303 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
305 if (!isNestedEditOperation(getCurrentOperation()) ||
306 myModule->sketchReentranceMgr()->isInternalEditActive())
308 // it is necessary to restore current selection in order to restore it after the values are modified
310 myCurrentSelection.clear();
312 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
313 // viewer happens by deselect/select the modified objects. The flag should be restored after
314 // the selection processing. The update viewer should be also called.
315 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
316 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
317 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
318 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
319 aDisplayer->updateViewer();
322 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
324 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
327 //get2dPoint(theWnd, theEvent, myClickedPoint);
329 if (!(theEvent->buttons() & Qt::LeftButton))
332 // Clear dragging mode
333 myIsDragging = false;
335 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
336 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
337 if (!aViewer->canDragByMouse())
340 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
341 (getCurrentOperation());
345 if (aFOperation->isEditOperation()) {
346 // If the current widget is a selector, do nothing, it processes the mouse press
347 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
348 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
353 // Use only for sketch operations
354 if (myCurrentSketch) {
355 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
358 bool isSketcher = isSketchOperation(aFOperation);
359 bool isSketchOpe = isNestedSketchOperation(aFOperation);
361 // Avoid non-sketch operations
362 if ((!isSketchOpe) && (!isSketcher))
365 bool isEditing = aFOperation->isEditOperation();
367 // Ignore creation sketch operation
368 if ((!isSketcher) && (!isEditing))
371 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
372 if (!aContext.IsNull()) {
373 // MoveTo in order to highlight current object
374 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
376 // Remember highlighted objects for editing
377 ModuleBase_ISelection* aSelect = aWorkshop->selection();
379 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
380 storeSelection(!aHasShift);
382 if (myCurrentSelection.empty()) {
383 if (isSketchOpe && (!isSketcher))
384 // commit previous operation
385 if (!aFOperation->commit())
386 aFOperation->abort();
389 // Init flyout point for radius rotation
390 FeaturePtr aFeature = myCurrentSelection.begin().key();
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 if (aFeature.get() != NULL) {
400 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
401 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
402 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
403 DataPtr aData = aSPFeature->data();
404 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
405 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
406 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
407 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
410 } else if (isSketchOpe && isEditing) {
411 // If selected another object commit current result
412 aFOperation->commit();
415 get2dPoint(theWnd, theEvent, myCurrentPoint);
417 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
418 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
420 // this is temporary commented in order to avoid the following wrong case:
421 // Distance constraint is under edition, double click on the digit -> nothing happens
422 // because QApplication::processEvents() calls onMouseDoubleClick, which try to show editor
423 // but as the prev edit is commited an new one is not started, editor is not shown.
424 // This is necessary in order to finalize previous operation
425 //QApplication::processEvents();
431 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
433 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
436 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
437 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
438 if (!aViewer->canDragByMouse())
440 ModuleBase_Operation* aOp = getCurrentOperation();
442 if (isNestedSketchOperation(aOp)) {
443 //get2dPoint(theWnd, theEvent, myClickedPoint);
445 // Only for sketcher operations
449 myCurrentSelection.clear();
450 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
451 if (!aContext.IsNull()) {
452 // Reselect edited object
453 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
454 if (theEvent->modifiers() & Qt::ShiftModifier)
455 aContext->ShiftSelect();
463 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
464 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
465 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
466 myIsDragging = false;
469 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
471 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
474 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
475 myIsMouseOverViewProcessed = true;
476 // 1. perform the widget mouse move functionality and display the presentation
477 // the mouse move should be processed in the widget, if it can in order to visualize correct
478 // presentation. These widgets correct the feature attribute according to the mouse position
479 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
480 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
482 aPoint2DWdg->onMouseMove(theWnd, theEvent);
484 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
487 aDistanceWdg->onMouseMove(theWnd, theEvent);
489 // the feature is to be erased here, but it is correct to call canDisplayObject because
490 // there can be additional check (e.g. editor widget in distance constraint)
491 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
492 (getCurrentOperation());
494 FeaturePtr aFeature = aFOperation->feature();
495 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
499 //myClickedPoint.clear();
502 // 1. the current selection is saved in the mouse press method in order to restore it after moving
503 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
504 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
505 // deselected). This flag should be restored in the slot, processed the mouse release signal.
507 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
508 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
509 //aViewer->enableSelection(false);
511 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
512 if (!aCurrentOperation)
514 if (isSketchOperation(aCurrentOperation))
515 return; // No edit operation activated
517 Handle(V3d_View) aView = theWnd->v3dView();
518 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
520 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
521 double dX = aX - myCurrentPoint.myCurX;
522 double dY = aY - myCurrentPoint.myCurY;
524 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
525 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
526 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
527 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
528 // viewer happens by deselect/select the modified objects. The flag should be restored after
529 // the selection processing. The update viewer should be also called.
530 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
532 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
533 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
534 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
535 aLast = myCurrentSelection.end();
536 // 4. the features and attributes modification(move)
537 bool isModified = false;
538 for (; anIt != aLast; anIt++) {
539 FeaturePtr aFeature = anIt.key();
541 std::set<AttributePtr> anAttributes = anIt.value().first;
542 // Process selection by attribute: the priority to the attribute
543 if (!anAttributes.empty()) {
544 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
545 anAttLast = anAttributes.end();
546 for (; anAttIt != anAttLast; anAttIt++) {
547 AttributePtr anAttr = *anAttIt;
548 if (anAttr.get() == NULL)
550 std::string aAttrId = anAttr->id();
551 DataPtr aData = aFeature->data();
552 if (aData->isValid()) {
553 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
554 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
555 if (aPoint.get() != NULL) {
556 bool isImmutable = aPoint->setImmutable(true);
557 aPoint->move(dX, dY);
559 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
560 aPoint->setImmutable(isImmutable);
565 // Process selection by feature
566 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
567 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
568 if (aSketchFeature) {
569 aSketchFeature->move(dX, dY);
571 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
575 // the modified state of the current operation should be updated if there are features, which
578 aCurrentOperation->onValuesChanged();
580 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
581 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
583 // 5. it is necessary to save current selection in order to restore it after the features moving
585 // 6. restore the update viewer flag and call this update
586 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
587 aDisplayer->updateViewer();
590 myCurrentPoint.setValue(aX, aY);
594 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
596 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
597 (getCurrentOperation());
598 if (aFOperation && aFOperation->isEditOperation()) {
599 std::string aId = aFOperation->id().toStdString();
600 if (isDistanceOperation(aFOperation))
602 // Activate dimension value editing on double click
603 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
604 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
605 // Find corresponded widget to activate value editing
606 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
607 if (aWgt->attributeID() == "ConstraintValue") {
608 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
610 anEditor->showPopupEditor();
618 void PartSet_SketcherMgr::onApplicationStarted()
620 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
621 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
622 XGUI_Workshop* aWorkshop = aConnector->workshop();
623 PartSet_SketcherReetntrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
625 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
626 if (aPropertyPanel) {
627 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
628 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
630 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
631 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
632 connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
633 aReentranceMgr, SLOT(onWidgetActivated()));
636 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
637 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
638 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
640 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
641 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
642 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
645 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
647 //if (!myClickedPoint.myIsInitialized)
650 //ModuleBase_Operation* aOperation = getCurrentOperation();
651 // the distance constraint feature should not use the clickedd point
652 // this is workaround in order to don't throw down the flyout point value,
653 // set by execute() method of these type of features
654 //if (isDistanceOperation(aOperation))
657 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
659 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
663 void PartSet_SketcherMgr::onBeforeContextMenu()
665 myIsPopupMenuActive = true;
668 void PartSet_SketcherMgr::onAfterContextMenu()
670 myIsPopupMenuActive = false;
673 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
676 Handle(V3d_View) aView = theWnd->v3dView();
677 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
679 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
680 thePoint.setValue(aX, anY);
683 void PartSet_SketcherMgr::launchEditing()
685 if (!myCurrentSelection.empty()) {
686 FeaturePtr aFeature = myCurrentSelection.begin().key();
687 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
688 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
690 myModule->editFeature(aSPFeature);
695 bool PartSet_SketcherMgr::sketchSolverError()
697 bool anError = false;
698 CompositeFeaturePtr aSketch = activeSketch();
700 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
701 anError = !aAttributeString->value().empty();
706 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
708 QString anError = "";
709 if (!theFeature.get() || !theFeature->data()->isValid())
712 CompositeFeaturePtr aSketch = activeSketch();
713 if (aSketch.get() && aSketch == theFeature) {
714 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
715 anError = aAttributeString->value().c_str();
720 void PartSet_SketcherMgr::clearClickedFlags()
722 //myClickedPoint.clear();
723 myCurrentPoint.clear();
726 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
728 static QStringList aIds;
729 if (aIds.size() == 0) {
730 aIds << SketchPlugin_Line::ID().c_str();
731 aIds << SketchPlugin_Point::ID().c_str();
732 aIds << SketchPlugin_Arc::ID().c_str();
733 aIds << SketchPlugin_Circle::ID().c_str();
734 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
735 aIds.append(constraintsIdList());
740 const QStringList& PartSet_SketcherMgr::constraintsIdList()
742 static QStringList aIds;
743 if (aIds.size() == 0) {
744 aIds << SketchPlugin_ConstraintLength::ID().c_str();
745 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
746 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
747 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
748 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
749 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
750 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
751 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
752 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
753 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
754 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
755 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
756 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
757 aIds << SketchPlugin_MultiRotation::ID().c_str();
758 aIds << SketchPlugin_MultiTranslation::ID().c_str();
763 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
767 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
768 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
769 theModes.append(SketcherPrs_Tools::Sel_Constraint);
770 theModes.append(TopAbs_VERTEX);
771 theModes.append(TopAbs_EDGE);
774 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
776 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
779 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
781 return theOperation &&
782 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
785 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
787 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
789 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
792 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
794 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
796 return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
799 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
801 return (theId == SketchPlugin_Line::ID()) ||
802 (theId == SketchPlugin_Point::ID()) ||
803 (theId == SketchPlugin_Arc::ID()) ||
804 (theId == SketchPlugin_Circle::ID());
807 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
809 std::string aId = theOperation ? theOperation->id().toStdString() : "";
811 return (aId == SketchPlugin_ConstraintLength::ID()) ||
812 (aId == SketchPlugin_ConstraintDistance::ID()) ||
813 (aId == SketchPlugin_ConstraintRadius::ID()) ||
814 (aId == SketchPlugin_ConstraintAngle::ID());
817 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
819 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
820 (getCurrentOperation());
824 myModule->onViewTransformed();
826 // Display all sketcher sub-Objects
827 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
828 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
829 aConnector->workshop()->displayer()->activateTrihedron(true);
831 // Hide sketcher result
832 std::list<ResultPtr> aResults = myCurrentSketch->results();
833 std::list<ResultPtr>::const_iterator aIt;
834 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
835 (*aIt)->setDisplayed(false);
837 myCurrentSketch->setDisplayed(false);
839 // Display sketcher objects
840 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
841 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
842 std::list<ResultPtr> aResults = aFeature->results();
843 std::list<ResultPtr>::const_iterator aIt;
844 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
845 (*aIt)->setDisplayed(true);
847 aFeature->setDisplayed(true);
850 if (myPlaneFilter.IsNull())
851 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
853 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
855 bool aHasPlane = false;
856 std::shared_ptr<GeomAPI_Pln> aPln;
857 if (aFOperation->isEditOperation()) {
858 // If it is editing of sketch then it means that plane is already defined
859 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
863 myPlaneFilter->setPlane(aPln);
865 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
866 // all sketch objects should be activated in the sketch selection modes by edit operation start
867 // in case of creation operation, there is an active widget, which activates own selection mode
868 if (aFOperation->isEditOperation() && aHasPlane)
869 aConnector->activateModuleSelectionModes();
872 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
874 myIsMouseOverWindow = false;
875 myIsConstraintsShown = true;
877 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
879 DataPtr aData = myCurrentSketch->data();
880 if (!aData->isValid()) {
881 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
882 // The sketch was aborted
883 myCurrentSketch = CompositeFeaturePtr();
884 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
886 // Erase all sketcher objects
887 QStringList aSketchIds = sketchOperationIdList();
888 QObjectPtrList aObjects = aDisplayer->displayedObjects();
889 foreach (ObjectPtr aObj, aObjects) {
890 DataPtr aObjData = aObj->data();
891 if (!aObjData->isValid())
892 aObj->setDisplayed(false);
896 // Hide all sketcher sub-Objects
897 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
898 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
899 std::list<ResultPtr> aResults = aFeature->results();
900 std::list<ResultPtr>::const_iterator aIt;
901 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
902 (*aIt)->setDisplayed(false);
904 aFeature->setDisplayed(false);
906 // Display sketcher result
907 std::list<ResultPtr> aResults = myCurrentSketch->results();
908 std::list<ResultPtr>::const_iterator aIt;
909 Events_Loop* aLoop = Events_Loop::loop();
910 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
912 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
914 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
915 if (!aFOperation->isDisplayedOnStart(*aIt)) {
916 (*aIt)->setDisplayed(true);
917 // this display event is needed because sketch already may have "displayed" state,
918 // but not displayed while it is still active (issue 613, abort of existing sketch)
919 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
922 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
923 myCurrentSketch->setDisplayed(true);
925 myCurrentSketch = CompositeFeaturePtr();
926 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
928 Events_Loop::loop()->flush(aDispEvent);
930 // restore the module selection modes, which were changed on startSketch
931 aConnector->activateModuleSelectionModes();
932 aConnector->workshop()->displayer()->activateTrihedron(false);
935 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
937 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
938 QCursor* aCurrentCursor = QApplication::overrideCursor();
939 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
940 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
942 qDebug("startNestedSketch() : Qt::CrossCursor");
948 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
950 myIsMouseOverViewProcessed = true;
951 operationMgr()->onValidateOperation();
952 if (canChangeCursor(theOperation)) {
953 QApplication::restoreOverrideCursor();
955 qDebug("stopNestedSketch() : None");
960 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
962 if (isNestedCreateOperation(theOperation)) {
963 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
966 FeaturePtr aFeature = aFOperation->feature();
967 // it is necessary to check the the feature data validity because
968 // some kind of features are removed by an operation commit(the macro state of a feature)
969 if (aFeature.get() && aFeature->data()->isValid()) {
970 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
976 void PartSet_SketcherMgr::operationActivatedByPreselection()
978 ModuleBase_Operation* anOperation = getCurrentOperation();
979 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
980 // Set final definitions if they are necessary
981 //propertyPanelDefined(aOperation);
982 /// Commit sketcher operations automatically
983 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
986 if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
987 FeaturePtr aFeature = aFOperation->feature();
988 // editor is shown only if all attribute references are filled by preseletion
989 bool anAllRefAttrInitialized = true;
991 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
992 ModelAPI_AttributeRefAttr::typeId());
993 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
994 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
995 anAllRefAttrInitialized = (*anIt)->isInitialized();
997 if (anAllRefAttrInitialized) {
998 // Activate dimension value editing on double click
999 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1000 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1001 // Find corresponded widget to activate value editing
1002 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1003 if (aWgt->attributeID() == "ConstraintValue") {
1004 // the featue should be displayed in order to find the AIS text position,
1005 // the place where the editor will be shown
1006 aFeature->setDisplayed(true);
1007 /// the execute is necessary to perform in the feature compute for flyout position
1008 aFeature->execute();
1010 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1011 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1013 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1015 int aX = 0, anY = 0;
1017 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1018 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1019 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1020 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1021 Handle(AIS_InteractiveObject) anAISIO;
1022 if (anAIS.get() != NULL) {
1023 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1025 if (anAIS.get() != NULL) {
1026 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1028 if (!anAISIO.IsNull()) {
1029 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1030 if (!aDim.IsNull()) {
1031 gp_Pnt aPosition = aDim->GetTextPosition();
1033 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1034 Handle(V3d_View) aView = aViewer->activeView();
1036 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1038 QWidget* aViewPort = aViewer->activeViewPort();
1039 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1044 anEditor->setCursorPosition(aX, anY);
1045 anEditor->showPopupEditor(false);
1053 anOperation->commit();
1057 bool PartSet_SketcherMgr::canUndo() const
1059 return isNestedCreateOperation(getCurrentOperation());
1062 bool PartSet_SketcherMgr::canRedo() const
1064 return isNestedCreateOperation(getCurrentOperation());
1067 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1069 bool aCanErase = true;
1070 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1071 if (myCurrentSketch.get()) {
1072 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1073 if (aResult.get()) {
1074 // Display sketcher objects
1075 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1077 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1078 std::list<ResultPtr> aResults = aFeature->results();
1079 std::list<ResultPtr>::const_iterator anIt;
1080 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1081 aCanErase = *anIt != aResult;
1089 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1091 bool aCanDisplay = true;
1093 bool aHasActiveSketch = activeSketch().get() != NULL;
1094 if (aHasActiveSketch) {
1095 // 1. the sketch feature should not be displayed during the sketch active operation
1096 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1097 // nested features can be visualized
1098 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1099 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1100 aCanDisplay = false;
1103 else { // there are no an active sketch
1104 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1105 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1106 if (aFeature.get() != NULL) {
1107 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1108 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1109 if (aSketchFeature.get()) {
1110 aCanDisplay = false;
1115 // 3. the method should not filter the objects, which are not related to the current operation.
1116 // The object is filtered just if it is a current operation feature or this feature result
1117 bool isObjectFound = false;
1118 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1119 (getCurrentOperation());
1121 FeaturePtr aFeature = aFOperation->feature();
1122 if (aFeature.get()) {
1123 std::list<ResultPtr> aResults = aFeature->results();
1124 if (theObject == aFeature)
1125 isObjectFound = true;
1127 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1128 for (; anIt != aLast && !isObjectFound; anIt++) {
1129 isObjectFound = *anIt == theObject;
1137 // 4. For created nested feature operation do not display the created feature if
1138 // the mouse curstor leaves the OCC window.
1139 // The correction cases, which ignores this condition:
1140 // a. the property panel values modification
1141 // b. the popup menu activated
1142 // c. widget editor control
1143 #ifndef DEBUG_DO_NOT_BY_ENTER
1144 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1145 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1146 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1147 // the active widget editor should not influence here. The presentation should be visible always
1148 // when this widget is active.
1149 if (!anEditorWdg && !myIsPopupMenuActive) {
1150 // during a nested create operation, the feature is redisplayed only if the mouse over view
1151 // of there was a value modified in the property panel after the mouse left the view
1152 aCanDisplay = canDisplayCurrentCreatedFeature();
1159 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1161 bool aCanDisplay = myIsMouseOverWindow;
1163 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1165 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1170 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1172 return isNestedCreateOperation(theOperation) ||
1173 myModule->sketchReentranceMgr()->isInternalEditActive();
1176 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1178 bool isFoundObject = false;
1180 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1181 if (anObjectFeature.get()) {
1182 int aSize = myCurrentSketch->numberOfSubs();
1183 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1184 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1185 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1188 return isFoundObject;
1191 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1193 if (myPlaneFilter.IsNull())
1194 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1196 myPlaneFilter->setPlane(thePln);
1199 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1200 const FeaturePtr& theSketch,
1201 ModuleBase_IWorkshop* theWorkshop,
1202 FeatureToSelectionMap& theSelection)
1204 if (theFeature.get() == NULL)
1207 std::set<AttributePtr> aSelectedAttributes;
1208 std::set<ResultPtr> aSelectedResults;
1210 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1211 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1212 if (!aContext.IsNull()) {
1213 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1214 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1216 std::list<ResultPtr> aResults = theFeature->results();
1217 std::list<ResultPtr>::const_iterator aIt;
1218 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1220 ResultPtr aResult = *aIt;
1221 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1222 if (aAISObj.get() == NULL)
1224 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1225 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1227 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1228 if (anOwner->Selectable() != anAISIO)
1230 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1231 aSelectedAttributes, aSelectedResults);
1233 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1234 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1235 if (anOwner.IsNull())
1237 if (anOwner->Selectable() != anAISIO)
1239 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1240 aSelectedAttributes, aSelectedResults);
1244 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1247 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1248 const FeaturePtr& theSketch,
1249 ModuleBase_IWorkshop* theWorkshop,
1250 const FeatureToSelectionMap& theSelection,
1251 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1253 if (theFeature.get() == NULL)
1256 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1257 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1258 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1260 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1262 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1263 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1265 // 1. found the feature's owners. Check the AIS objects of the constructions
1266 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1267 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1268 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1270 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1271 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1272 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1273 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1274 if (!anOwner.IsNull())
1275 theOwnersToSelect.Add(anOwner);
1279 // 2. found the feature results's owners
1280 std::list<ResultPtr> aResults = theFeature->results();
1281 std::list<ResultPtr>::const_iterator aIt;
1282 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1284 ResultPtr aResult = *aIt;
1285 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1286 if (aAISObj.get() == NULL)
1288 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1290 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1291 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1292 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1293 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1294 if ( anOwner.IsNull() || !anOwner->HasShape() )
1296 const TopoDS_Shape& aShape = anOwner->Shape();
1297 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1298 if (aShapeType == TopAbs_VERTEX) {
1299 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1300 if (aPntAttr.get() != NULL &&
1301 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1302 theOwnersToSelect.Add(anOwner);
1305 else if (aShapeType == TopAbs_EDGE) {
1306 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1307 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1308 theOwnersToSelect.FindIndex(anOwner) <= 0)
1309 theOwnersToSelect.Add(anOwner);
1315 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
1318 connect(theWidget, SIGNAL(beforeValuesChanged()),
1319 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1320 connect(theWidget, SIGNAL(afterValuesChanged()),
1321 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1324 disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1325 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1326 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1327 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1331 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1333 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1334 (getCurrentOperation());
1336 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1337 PartSet_SketcherMgr::isNestedSketchOperation(aFOperation) &&
1338 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1339 FeaturePtr aFeature = aFOperation->feature();
1340 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1345 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1347 return myModule->workshop()->currentOperation();
1350 //**************************************************************
1351 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1353 ModuleBase_ModelWidget* aWidget = 0;
1354 ModuleBase_Operation* anOperation = getCurrentOperation();
1356 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1358 aWidget = aPanel->activeWidget();
1363 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1364 const bool isEditOperation,
1365 const bool isToDisplay,
1366 const bool isFlushRedisplay)
1368 #ifdef DEBUG_DO_NOT_BY_ENTER
1372 if (isEditOperation || !theFeature.get())
1375 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1376 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1378 // 1. change visibility of the object itself, here the presentable object is processed,
1379 // e.g. constraints features
1380 //FeaturePtr aFeature = aFOperation->feature();
1381 std::list<ResultPtr> aResults = theFeature->results();
1383 theFeature->setDisplayed(true);
1385 theFeature->setDisplayed(false);
1387 // change visibility of the object results, e.g. non-constraint features
1388 std::list<ResultPtr>::const_iterator aIt;
1389 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1391 (*aIt)->setDisplayed(true);
1394 (*aIt)->setDisplayed(false);
1397 if (isFlushRedisplay)
1398 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1401 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1403 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1404 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1405 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1407 QList<FeaturePtr> aFeatureList;
1408 if (theHighlightedOnly) {
1409 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1412 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1414 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1415 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1418 // 1. it is necessary to save current selection in order to restore it after the features moving
1419 myCurrentSelection.clear();
1420 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1421 for (; anIt != aLast; anIt++) {
1422 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1424 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1427 void PartSet_SketcherMgr::restoreSelection()
1429 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1430 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1431 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1432 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1433 aSLast = myCurrentSelection.end();
1434 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1435 for (; aSIt != aSLast; aSIt++) {
1436 anOwnersToSelect.Clear();
1437 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1439 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1443 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1445 if (myIsConstraintsShown == theOn)
1447 if (myCurrentSketch.get() == NULL)
1450 myIsConstraintsShown = theOn;
1452 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1453 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1455 const QStringList& aConstrIds = constraintsIdList();
1456 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1457 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1458 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1459 if (myIsConstraintsShown)
1460 aSubFeature->setDisplayed(true);
1462 aSubFeature->setDisplayed(false);
1465 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1468 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1470 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1471 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1472 XGUI_Workshop* aWorkshop = aConnector->workshop();
1474 return aWorkshop->operationMgr();