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
78 //#define DEBUG_MOUSE_OVER_WINDOW_FLAGS
80 /// Returns list of unique objects by sum of objects from List1 and List2
81 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
82 const QList<ModuleBase_ViewerPrs>& theList2)
84 QList<ModuleBase_ViewerPrs> aRes;
85 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
86 if (!aRes.contains(aPrs))
89 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
90 if (!aRes.contains(aPrs))
96 // Fills the list of features the list of selected presentations.
97 // \param theList a list of selected presentations
98 // \param theSketch a sketch to project a vertex shape of a presentation to the plane
99 // and find the corresponded attribute
100 // \param theFeatureList an output list of features
101 void fillFeatureList(const QList<ModuleBase_ViewerPrs>& theList,
102 const FeaturePtr theSketch,
103 QList<FeaturePtr>& theFeatureList)
105 QList<ModuleBase_ViewerPrs> aRes;
107 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
108 aLast = theList.end();
109 for (; anIt != aLast; anIt++)
111 ModuleBase_ViewerPrs aPrs = *anIt;
112 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
113 if (aFeature.get() && !theFeatureList.contains(aFeature))
114 theFeatureList.append(aFeature);
118 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
119 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge, put the function
120 /// result as is to the list of results.
121 /// \param theOwner a viewer selected owner
122 /// \param theFeature a feature, where the attribute is searched
123 /// \param theSketch a current sketch
124 /// \param theSelectedAttribute an output list of attributes
125 /// \param theSelectedResults an output list of edge results
126 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
127 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
128 const ResultPtr& theResult,
129 std::set<AttributePtr>& aSelectedAttributes,
130 std::set<ResultPtr>& aSelectedResults)
132 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
133 if (aBRepOwner.IsNull())
135 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
136 aBRepOwner->Selectable());
137 if (aBRepOwner->HasShape()) {
138 const TopoDS_Shape& aShape = aBRepOwner->Shape();
139 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
140 if (aShapeType == TopAbs_VERTEX) {
141 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
143 if (aPntAttr.get() != NULL)
144 aSelectedAttributes.insert(aPntAttr);
146 else if (aShapeType == TopAbs_EDGE &&
147 aSelectedResults.find(theResult) == aSelectedResults.end()) {
148 aSelectedResults.insert(theResult);
153 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
154 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
155 myIsResetCurrentValue(false), myIsMouseOverWindow(false),
156 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
157 myIsPopupMenuActive(false), myIsConstraintsShown(true)
159 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
160 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
162 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
164 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
165 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
167 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
168 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
170 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
171 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
173 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
174 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
176 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
177 XGUI_Workshop* aWorkshop = aConnector->workshop();
178 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
181 PartSet_SketcherMgr::~PartSet_SketcherMgr()
183 if (!myPlaneFilter.IsNull())
184 myPlaneFilter.Nullify();
187 void PartSet_SketcherMgr::onEnterViewPort()
189 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
190 // created feature because it should be done in onMouseMove(). Some widgets watch
191 // the mouse move and use the cursor position to update own values. If the presentaion is
192 // redisplayed before this update, the feature presentation jumps from reset value to current.
193 myIsMouseOverWindow = true;
194 myIsResetCurrentValue = false;
195 //myIsCurrentValueUnderModification = false;
196 // it is important to validate operation here only if sketch entity create operation is active
197 // because at this operation we reacts to the mouse leave/enter view port
198 //operationMgr()->onValidateOperation();
199 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
200 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
203 #ifdef DEBUG_DO_NOT_BY_ENTER
207 if (!isNestedCreateOperation(getCurrentOperation()))
210 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
212 operationMgr()->onValidateOperation();
214 // we need change displayed state of the current operation feature
215 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
216 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
217 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
218 // presentation becomes valid and redisplay happens
219 //ModuleBase_Operation* aOperation = getCurrentOperation();
220 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
221 (getCurrentOperation());
223 FeaturePtr aFeature = aFOperation->feature();
224 if (aFeature.get() && aFeature->data()->isValid()) {
225 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
230 void PartSet_SketcherMgr::onLeaveViewPort()
232 myIsMouseOverViewProcessed = false;
233 myIsMouseOverWindow = false;
234 // it is important to validate operation here only if sketch entity create operation is active
235 // because at this operation we reacts to the mouse leave/enter view port
236 //operationMgr()->onValidateOperation();
237 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
238 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
241 #ifdef DEBUG_DO_NOT_BY_ENTER
245 if (!isNestedCreateOperation(getCurrentOperation()))
248 QApplication::restoreOverrideCursor();
250 // the method should be performed if the popup menu is called,
251 // the reset of the current widget should not happen
252 if (myIsPopupMenuActive)
255 operationMgr()->onValidateOperation();
257 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
258 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
259 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
260 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
261 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
262 // obtained after reset value
263 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
264 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
265 if (anActiveWidget && anActiveWidget->reset()) {
266 myIsResetCurrentValue = true;
268 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
270 // hides the presentation of the current operation feature
271 // the feature is to be erased here, but it is correct to call canDisplayObject because
272 // there can be additional check (e.g. editor widget in distance constraint)
273 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
274 (getCurrentOperation());
276 FeaturePtr aFeature = aFOperation->feature();
277 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
281 void PartSet_SketcherMgr::onValueStateChanged()
283 ///myIsCurrentValueUnderModification = true;
284 // update Apply enable state
285 //myIsResetCurrentValue = false;
286 //if (!isNestedCreateOperation(getCurrentOperation()))
289 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
290 if (anActiveWidget && anActiveWidget->getValueState() != ModuleBase_ModelWidget::Stored)
291 operationMgr()->onValidateOperation();
294 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
296 myIsResetCurrentValue = false;
297 //myIsCurrentValueUnderModification = false;
299 if (isNestedCreateOperation(getCurrentOperation()))
301 // it is necessary to save current selection in order to restore it after the values are modifed
304 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
305 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
306 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
307 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
310 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
312 if (isNestedCreateOperation(getCurrentOperation()))
314 // it is necessary to restore current selection in order to restore it after the values are modified
316 myCurrentSelection.clear();
318 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
319 // viewer happens by deselect/select the modified objects. The flag should be restored after
320 // the selection processing. The update viewer should be also called.
321 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
322 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
323 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
324 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
325 aDisplayer->updateViewer();
328 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
330 if (!isNestedCreateOperation(getCurrentOperation()))
333 // visualize the current operation feature
334 //myIsResetCurrentValue = false;
335 operationMgr()->onValidateOperation();
336 // the feature is to be erased here, but it is correct to call canDisplayObject because
337 // there can be additional check (e.g. editor widget in distance constraint)
338 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
339 (getCurrentOperation());
341 FeaturePtr aFeature = aFOperation->feature();
342 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
346 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
348 get2dPoint(theWnd, theEvent, myClickedPoint);
350 if (!(theEvent->buttons() & Qt::LeftButton))
353 // Clear dragging mode
354 myIsDragging = false;
356 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
357 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
358 if (!aViewer->canDragByMouse())
361 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
362 (getCurrentOperation());
366 if (aFOperation->isEditOperation()) {
367 // If the current widget is a selector, do nothing, it processes the mouse press
368 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
369 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
374 // Use only for sketch operations
375 if (myCurrentSketch) {
376 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
379 bool isSketcher = isSketchOperation(aFOperation);
380 bool isSketchOpe = isNestedSketchOperation(aFOperation);
382 // Avoid non-sketch operations
383 if ((!isSketchOpe) && (!isSketcher))
386 bool isEditing = aFOperation->isEditOperation();
388 // Ignore creation sketch operation
389 if ((!isSketcher) && (!isEditing))
392 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
393 if (!aContext.IsNull()) {
394 // MoveTo in order to highlight current object
395 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
397 // Remember highlighted objects for editing
398 ModuleBase_ISelection* aSelect = aWorkshop->selection();
400 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
401 storeSelection(!aHasShift);
403 if (myCurrentSelection.empty()) {
404 if (isSketchOpe && (!isSketcher))
405 // commit previous operation
406 if (!aFOperation->commit())
407 aFOperation->abort();
410 // Init flyout point for radius rotation
411 FeaturePtr aFeature = myCurrentSelection.begin().key();
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 if (aFeature.get() != NULL) {
421 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
422 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
423 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
424 DataPtr aData = aSPFeature->data();
425 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
426 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
427 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
428 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
431 } else if (isSketchOpe && isEditing) {
432 // If selected another object commit current result
433 aFOperation->commit();
436 get2dPoint(theWnd, theEvent, myCurrentPoint);
438 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
439 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
441 // This is necessary in order to finalize previous operation
442 QApplication::processEvents();
448 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
450 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
451 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
452 if (!aViewer->canDragByMouse())
454 ModuleBase_Operation* aOp = getCurrentOperation();
456 if (isNestedSketchOperation(aOp)) {
457 get2dPoint(theWnd, theEvent, myClickedPoint);
459 // Only for sketcher operations
463 myCurrentSelection.clear();
464 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
465 if (!aContext.IsNull()) {
466 // Reselect edited object
467 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
468 if (theEvent->modifiers() & Qt::ShiftModifier)
469 aContext->ShiftSelect();
477 // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
478 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
479 //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
480 myIsDragging = false;
483 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
485 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
486 myIsMouseOverViewProcessed = true;
487 // 1. perform the widget mouse move functionality and display the presentation
488 // the mouse move should be processed in the widget, if it can in order to visualize correct
489 // presentation. These widgets correct the feature attribute according to the mouse position
490 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
491 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
493 aPoint2DWdg->onMouseMove(theWnd, theEvent);
495 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
498 aDistanceWdg->onMouseMove(theWnd, theEvent);
500 // the feature is to be erased here, but it is correct to call canDisplayObject because
501 // there can be additional check (e.g. editor widget in distance constraint)
502 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
503 (getCurrentOperation());
505 FeaturePtr aFeature = aFOperation->feature();
506 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
510 myClickedPoint.clear();
513 // 1. the current selection is saved in the mouse press method in order to restore it after moving
514 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
515 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
516 // deselected). This flag should be restored in the slot, processed the mouse release signal.
518 // TODO: Has to be commented out when SALOME patch on draw mode become avialable
519 //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
520 //aViewer->enableSelection(false);
522 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
523 if (!aCurrentOperation)
525 if (isSketchOperation(aCurrentOperation))
526 return; // No edit operation activated
528 Handle(V3d_View) aView = theWnd->v3dView();
529 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
531 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
532 double dX = aX - myCurrentPoint.myCurX;
533 double dY = aY - myCurrentPoint.myCurY;
535 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
536 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
537 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
538 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
539 // viewer happens by deselect/select the modified objects. The flag should be restored after
540 // the selection processing. The update viewer should be also called.
541 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
543 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
544 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
545 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
546 aLast = myCurrentSelection.end();
547 // 4. the features and attributes modification(move)
548 bool isModified = false;
549 for (; anIt != aLast; anIt++) {
550 FeaturePtr aFeature = anIt.key();
552 std::set<AttributePtr> anAttributes = anIt.value().first;
553 // Process selection by attribute: the priority to the attribute
554 if (!anAttributes.empty()) {
555 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
556 anAttLast = anAttributes.end();
557 for (; anAttIt != anAttLast; anAttIt++) {
558 AttributePtr anAttr = *anAttIt;
559 if (anAttr.get() == NULL)
561 std::string aAttrId = anAttr->id();
562 DataPtr aData = aFeature->data();
563 if (aData->isValid()) {
564 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
565 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
566 if (aPoint.get() != NULL) {
567 bool isImmutable = aPoint->setImmutable(true);
568 aPoint->move(dX, dY);
570 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
571 aPoint->setImmutable(isImmutable);
576 // Process selection by feature
577 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
578 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
579 if (aSketchFeature) {
580 aSketchFeature->move(dX, dY);
582 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
586 // the modified state of the current operation should be updated if there are features, which
589 aCurrentOperation->onValuesChanged();
591 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
592 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
594 // 5. it is necessary to save current selection in order to restore it after the features moving
596 // 6. restore the update viewer flag and call this update
597 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
598 aDisplayer->updateViewer();
601 myCurrentPoint.setValue(aX, aY);
605 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
607 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
608 (getCurrentOperation());
609 if (aFOperation && aFOperation->isEditOperation()) {
610 std::string aId = aFOperation->id().toStdString();
611 if (isDistanceOperation(aFOperation))
613 // Activate dimension value editing on double click
614 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
615 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
616 // Find corresponded widget to activate value editing
617 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
618 if (aWgt->attributeID() == "ConstraintValue") {
627 void PartSet_SketcherMgr::onApplicationStarted()
629 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
630 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
631 XGUI_Workshop* aWorkshop = aConnector->workshop();
632 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
633 if (aPropertyPanel) {
634 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
635 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
638 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
639 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
640 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
642 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
643 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
644 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
647 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
649 if (!myClickedPoint.myIsInitialized)
652 ModuleBase_Operation* aOperation = getCurrentOperation();
653 // the distance constraint feature should not use the clickedd point
654 // this is workaround in order to don't throw down the flyout point value,
655 // set by execute() method of these type of features
656 if (isDistanceOperation(aOperation))
659 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
661 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
665 void PartSet_SketcherMgr::onBeforeContextMenu()
667 myIsPopupMenuActive = true;
670 void PartSet_SketcherMgr::onAfterContextMenu()
672 myIsPopupMenuActive = false;
675 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
678 Handle(V3d_View) aView = theWnd->v3dView();
679 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
681 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
682 thePoint.setValue(aX, anY);
685 void PartSet_SketcherMgr::launchEditing()
687 if (!myCurrentSelection.empty()) {
688 FeaturePtr aFeature = myCurrentSelection.begin().key();
689 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
690 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
692 myModule->editFeature(aSPFeature);
697 bool PartSet_SketcherMgr::sketchSolverError()
699 bool anError = false;
700 CompositeFeaturePtr aSketch = activeSketch();
702 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
703 anError = !aAttributeString->value().empty();
708 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
710 QString anError = "";
711 if (!theFeature.get() || !theFeature->data()->isValid())
714 CompositeFeaturePtr aSketch = activeSketch();
715 if (aSketch.get() && aSketch == theFeature) {
716 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
717 anError = aAttributeString->value().c_str();
719 else if (myIsResetCurrentValue /*|| myIsCurrentValueUnderModification*/) {
720 // this flags do not allow commit of the current operation
721 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
722 (getCurrentOperation());
724 FeaturePtr aFeature = aFOperation->feature();
725 if (aFeature.get() && aFeature == theFeature && isNestedCreateOperation(aFOperation)) {
726 QString anAttributeName = "";
727 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
728 if (anActiveWidget) {
729 AttributePtr anAttr = aFeature->attribute(anActiveWidget->attributeID());
731 anAttributeName = anAttr->id().c_str();
733 if (myIsResetCurrentValue)
734 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
735 //else if (myIsCurrentValueUnderModification) {
736 // anError = "Attribute \"" + anAttributeName + "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
742 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
743 if (anActiveWidget && anActiveWidget->getValueState() != ModuleBase_ModelWidget::Stored) {
744 AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
746 QString anAttributeName = anAttr->id().c_str();
747 anError = "Attribute \"" + anAttributeName + "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
754 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
756 static QStringList aIds;
757 if (aIds.size() == 0) {
758 aIds << SketchPlugin_Line::ID().c_str();
759 aIds << SketchPlugin_Point::ID().c_str();
760 aIds << SketchPlugin_Arc::ID().c_str();
761 aIds << SketchPlugin_Circle::ID().c_str();
762 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
763 aIds.append(constraintsIdList());
768 const QStringList& PartSet_SketcherMgr::constraintsIdList()
770 static QStringList aIds;
771 if (aIds.size() == 0) {
772 aIds << SketchPlugin_ConstraintLength::ID().c_str();
773 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
774 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
775 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
776 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
777 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
778 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
779 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
780 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
781 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
782 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
783 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
784 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
785 aIds << SketchPlugin_MultiRotation::ID().c_str();
786 aIds << SketchPlugin_MultiTranslation::ID().c_str();
791 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
795 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
796 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
797 theModes.append(SketcherPrs_Tools::Sel_Constraint);
798 theModes.append(TopAbs_VERTEX);
799 theModes.append(TopAbs_EDGE);
802 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
804 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
807 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
809 return theOperation &&
810 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
813 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
815 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
817 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
820 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
822 return (theId == SketchPlugin_Line::ID()) ||
823 (theId == SketchPlugin_Point::ID()) ||
824 (theId == SketchPlugin_Arc::ID()) ||
825 (theId == SketchPlugin_Circle::ID());
828 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
830 std::string aId = theOperation ? theOperation->id().toStdString() : "";
832 return (aId == SketchPlugin_ConstraintLength::ID()) ||
833 (aId == SketchPlugin_ConstraintDistance::ID()) ||
834 (aId == SketchPlugin_ConstraintRadius::ID()) ||
835 (aId == SketchPlugin_ConstraintAngle::ID());
838 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
840 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
841 (getCurrentOperation());
845 myModule->onViewTransformed();
847 // Display all sketcher sub-Objects
848 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
849 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
851 // Hide sketcher result
852 std::list<ResultPtr> aResults = myCurrentSketch->results();
853 std::list<ResultPtr>::const_iterator aIt;
854 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
855 (*aIt)->setDisplayed(false);
857 myCurrentSketch->setDisplayed(false);
859 // Display sketcher objects
860 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
861 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
862 std::list<ResultPtr> aResults = aFeature->results();
863 std::list<ResultPtr>::const_iterator aIt;
864 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
865 (*aIt)->setDisplayed(true);
867 aFeature->setDisplayed(true);
870 if (myPlaneFilter.IsNull())
871 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
873 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
875 bool aHasPlane = false;
876 std::shared_ptr<GeomAPI_Pln> aPln;
877 if (aFOperation->isEditOperation()) {
878 // If it is editing of sketch then it means that plane is already defined
879 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
883 myPlaneFilter->setPlane(aPln);
885 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
886 // all sketch objects should be activated in the sketch selection modes by edit operation start
887 // in case of creation operation, there is an active widget, which activates own selection mode
888 if (aFOperation->isEditOperation() && aHasPlane)
889 aConnector->activateModuleSelectionModes();
892 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
894 myIsMouseOverWindow = false;
895 myIsConstraintsShown = true;
896 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
897 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
899 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
901 DataPtr aData = myCurrentSketch->data();
902 if (!aData->isValid()) {
903 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
904 // The sketch was aborted
905 myCurrentSketch = CompositeFeaturePtr();
906 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
908 // Erase all sketcher objects
909 QStringList aSketchIds = sketchOperationIdList();
910 QObjectPtrList aObjects = aDisplayer->displayedObjects();
911 foreach (ObjectPtr aObj, aObjects) {
912 DataPtr aObjData = aObj->data();
913 if (!aObjData->isValid())
914 aObj->setDisplayed(false);
918 // Hide all sketcher sub-Objects
919 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
920 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
921 std::list<ResultPtr> aResults = aFeature->results();
922 std::list<ResultPtr>::const_iterator aIt;
923 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
924 (*aIt)->setDisplayed(false);
926 aFeature->setDisplayed(false);
928 // Display sketcher result
929 std::list<ResultPtr> aResults = myCurrentSketch->results();
930 std::list<ResultPtr>::const_iterator aIt;
931 Events_Loop* aLoop = Events_Loop::loop();
932 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
934 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
936 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
937 if (!aFOperation->isDisplayedOnStart(*aIt)) {
938 (*aIt)->setDisplayed(true);
939 // this display event is needed because sketch already may have "displayed" state,
940 // but not displayed while it is still active (issue 613, abort of existing sketch)
941 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
944 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
945 myCurrentSketch->setDisplayed(true);
947 myCurrentSketch = CompositeFeaturePtr();
948 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
950 Events_Loop::loop()->flush(aDispEvent);
952 // restore the module selection modes, which were changed on startSketch
953 aConnector->activateModuleSelectionModes();
956 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
958 connectToPropertyPanel(true);
959 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
960 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
963 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
965 connectToPropertyPanel(false);
966 myIsResetCurrentValue = false;
967 //myIsCurrentValueUnderModification = false;
968 myIsMouseOverViewProcessed = true;
969 operationMgr()->onValidateOperation();
970 if (isNestedCreateOperation(theOp))
971 QApplication::restoreOverrideCursor();
974 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
976 if (isNestedCreateOperation(theOperation)) {
977 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
980 FeaturePtr aFeature = aFOperation->feature();
981 // it is necessary to check the the feature data validity because
982 // some kind of features are removed by an operation commit(the macro state of a feature)
983 if (aFeature.get() && aFeature->data()->isValid()) {
984 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
990 bool PartSet_SketcherMgr::canUndo() const
992 return isNestedCreateOperation(getCurrentOperation());
995 bool PartSet_SketcherMgr::canRedo() const
997 return isNestedCreateOperation(getCurrentOperation());
1000 /*bool PartSet_SketcherMgr::canCommitOperation() const
1002 bool aCanCommit = true;
1004 if (isNestedCreateOperation(getCurrentOperation()) &&
1005 (myIsResetCurrentValue || myIsCurrentValueUnderModification))
1011 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1013 bool aCanErase = true;
1014 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1015 if (myCurrentSketch.get()) {
1016 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1017 if (aResult.get()) {
1018 // Display sketcher objects
1019 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1021 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1022 std::list<ResultPtr> aResults = aFeature->results();
1023 std::list<ResultPtr>::const_iterator anIt;
1024 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1025 aCanErase = *anIt != aResult;
1033 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1035 bool aCanDisplay = true;
1037 bool aHasActiveSketch = activeSketch().get() != NULL;
1038 if (aHasActiveSketch) {
1039 // 1. the sketch feature should not be displayed during the sketch active operation
1040 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1041 // nested features can be visualized
1042 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1043 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1044 aCanDisplay = false;
1047 else { // there are no an active sketch
1048 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1049 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1050 if (aFeature.get() != NULL) {
1051 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1052 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1053 if (aSketchFeature.get()) {
1054 aCanDisplay = false;
1059 // 3. the method should not filter the objects, which are not related to the current operation.
1060 // The object is filtered just if it is a current operation feature or this feature result
1061 bool isObjectFound = false;
1062 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1063 (getCurrentOperation());
1065 FeaturePtr aFeature = aFOperation->feature();
1066 if (aFeature.get()) {
1067 std::list<ResultPtr> aResults = aFeature->results();
1068 if (theObject == aFeature)
1069 isObjectFound = true;
1071 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1072 for (; anIt != aLast && !isObjectFound; anIt++) {
1073 isObjectFound = *anIt == theObject;
1081 // 4. For created nested feature operation do not display the created feature if
1082 // the mouse curstor leaves the OCC window.
1083 // The correction cases, which ignores this condition:
1084 // a. the property panel values modification
1085 // b. the popup menu activated
1086 // c. widget editor control
1087 #ifndef DEBUG_DO_NOT_BY_ENTER
1088 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1089 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1090 ModuleBase_WidgetEditor* anEditorWdg = anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1091 // the active widget editor should not influence here. The presentation should be visible always
1092 // when this widget is active.
1093 if (!anEditorWdg && !myIsPopupMenuActive) {
1094 // during a nested create operation, the feature is redisplayed only if the mouse over view
1095 // of there was a value modified in the property panel after the mouse left the view
1096 aCanDisplay = canDisplayCurrentCreatedFeature();
1103 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1105 bool aCanDisplay = myIsMouseOverWindow;
1107 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1108 bool isValueStored = anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1109 aCanDisplay = !myIsResetCurrentValue && isValueStored;
1112 //return myIsMouseOverWindow || (!myIsResetCurrentValue && !myIsCurrentValueUnderModification);
1113 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1114 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1118 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1120 bool isFoundObject = false;
1122 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1123 if (anObjectFeature.get()) {
1124 int aSize = myCurrentSketch->numberOfSubs();
1125 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1126 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1127 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1130 return isFoundObject;
1133 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1135 if (myPlaneFilter.IsNull())
1136 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1138 myPlaneFilter->setPlane(thePln);
1141 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1142 const FeaturePtr& theSketch,
1143 ModuleBase_IWorkshop* theWorkshop,
1144 FeatureToSelectionMap& theSelection)
1146 if (theFeature.get() == NULL)
1149 std::set<AttributePtr> aSelectedAttributes;
1150 std::set<ResultPtr> aSelectedResults;
1152 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1153 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1154 if (!aContext.IsNull()) {
1155 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1156 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1158 std::list<ResultPtr> aResults = theFeature->results();
1159 std::list<ResultPtr>::const_iterator aIt;
1160 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1162 ResultPtr aResult = *aIt;
1163 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1164 if (aAISObj.get() == NULL)
1166 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1167 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1169 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1170 if (anOwner->Selectable() != anAISIO)
1172 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1173 aSelectedAttributes, aSelectedResults);
1175 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1176 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1177 if (anOwner.IsNull())
1179 if (anOwner->Selectable() != anAISIO)
1181 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1182 aSelectedAttributes, aSelectedResults);
1186 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1189 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1190 const FeaturePtr& theSketch,
1191 ModuleBase_IWorkshop* theWorkshop,
1192 const FeatureToSelectionMap& theSelection,
1193 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1195 if (theFeature.get() == NULL)
1198 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1199 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1200 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1202 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1204 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1205 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1207 // 1. found the feature's owners. Check the AIS objects of the constructions
1208 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1209 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1210 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1212 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1213 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1214 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1215 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1216 if (!anOwner.IsNull())
1217 theOwnersToSelect.Add(anOwner);
1221 // 2. found the feature results's owners
1222 std::list<ResultPtr> aResults = theFeature->results();
1223 std::list<ResultPtr>::const_iterator aIt;
1224 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1226 ResultPtr aResult = *aIt;
1227 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1228 if (aAISObj.get() == NULL)
1230 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1232 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1233 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1234 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1235 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1236 if ( anOwner.IsNull() || !anOwner->HasShape() )
1238 const TopoDS_Shape& aShape = anOwner->Shape();
1239 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1240 if (aShapeType == TopAbs_VERTEX) {
1241 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1242 if (aPntAttr.get() != NULL &&
1243 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1244 theOwnersToSelect.Add(anOwner);
1247 else if (aShapeType == TopAbs_EDGE) {
1248 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1249 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1250 theOwnersToSelect.FindIndex(anOwner) <= 0)
1251 theOwnersToSelect.Add(anOwner);
1257 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1259 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1260 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1261 XGUI_Workshop* aWorkshop = aConnector->workshop();
1262 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1263 if (aPropertyPanel) {
1264 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1265 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1267 connect(aWidget, SIGNAL(beforeValuesChanged()),
1268 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1269 connect(aWidget, SIGNAL(valueStateChanged()),
1270 this, SLOT(onValueStateChanged()));
1271 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1272 connect(aWidget, SIGNAL(afterValuesChanged()),
1273 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1276 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1277 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1278 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1279 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1280 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1286 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1288 return myModule->workshop()->currentOperation();
1291 //**************************************************************
1292 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1294 ModuleBase_ModelWidget* aWidget = 0;
1295 ModuleBase_Operation* anOperation = getCurrentOperation();
1297 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1299 aWidget = aPanel->activeWidget();
1304 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1305 const bool isEditOperation,
1306 const bool isToDisplay,
1307 const bool isFlushRedisplay)
1309 #ifdef DEBUG_DO_NOT_BY_ENTER
1313 if (isEditOperation || !theFeature.get())
1316 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1317 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1319 // 1. change visibility of the object itself, here the presentable object is processed,
1320 // e.g. constraints features
1321 //FeaturePtr aFeature = aFOperation->feature();
1322 std::list<ResultPtr> aResults = theFeature->results();
1324 theFeature->setDisplayed(true);
1326 theFeature->setDisplayed(false);
1328 // change visibility of the object results, e.g. non-constraint features
1329 std::list<ResultPtr>::const_iterator aIt;
1330 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1332 (*aIt)->setDisplayed(true);
1335 (*aIt)->setDisplayed(false);
1338 if (isFlushRedisplay)
1339 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1342 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1344 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1345 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1346 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1348 QList<FeaturePtr> aFeatureList;
1349 if (theHighlightedOnly) {
1350 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1353 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1355 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1356 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1359 // 1. it is necessary to save current selection in order to restore it after the features moving
1360 myCurrentSelection.clear();
1361 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1362 for (; anIt != aLast; anIt++) {
1363 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1365 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1368 void PartSet_SketcherMgr::restoreSelection()
1370 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1371 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1372 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1373 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1374 aSLast = myCurrentSelection.end();
1375 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1376 for (; aSIt != aSLast; aSIt++) {
1377 anOwnersToSelect.Clear();
1378 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1380 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1384 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1386 if (myIsConstraintsShown == theOn)
1388 if (myCurrentSketch.get() == NULL)
1391 myIsConstraintsShown = theOn;
1393 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1394 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1396 const QStringList& aConstrIds = constraintsIdList();
1397 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1398 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1399 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1400 if (myIsConstraintsShown)
1401 aSubFeature->setDisplayed(true);
1403 aSubFeature->setDisplayed(false);
1406 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1409 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1411 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1412 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1415 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1417 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1418 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1419 XGUI_Workshop* aWorkshop = aConnector->workshop();
1421 return aWorkshop->operationMgr();