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 myPreviousSelectionEnabled = 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 // it is important to validate operation here only if sketch entity create operation is active
196 // because at this operation we reacts to the mouse leave/enter view port
197 //operationMgr()->onValidateOperation();
198 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
199 qDebug(QString("onEnterViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
202 #ifdef DEBUG_DO_NOT_BY_ENTER
206 if (!isNestedCreateOperation(getCurrentOperation()))
209 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
210 operationMgr()->onValidateOperation();
212 // we need change displayed state of the current operation feature
213 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
214 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
215 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
216 // presentation becomes valid and redisplay happens
217 //ModuleBase_Operation* aOperation = getCurrentOperation();
218 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
219 (getCurrentOperation());
221 FeaturePtr aFeature = aFOperation->feature();
222 if (aFeature.get() && aFeature->data()->isValid()) {
223 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
228 void PartSet_SketcherMgr::onLeaveViewPort()
230 myIsMouseOverViewProcessed = false;
231 myIsMouseOverWindow = false;
232 // it is important to validate operation here only if sketch entity create operation is active
233 // because at this operation we reacts to the mouse leave/enter view port
234 //operationMgr()->onValidateOperation();
235 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
236 qDebug(QString("onLeaveViewPort: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
239 #ifdef DEBUG_DO_NOT_BY_ENTER
243 if (!isNestedCreateOperation(getCurrentOperation()))
246 QApplication::restoreOverrideCursor();
248 // the method should be performed if the popup menu is called,
249 // the reset of the current widget should not happen
250 if (myIsPopupMenuActive)
253 operationMgr()->onValidateOperation();
255 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
256 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
257 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
258 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
259 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
260 // obtained after reset value
261 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
262 ModuleBase_Operation* aOperation = getCurrentOperation();
263 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
264 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
265 if (aActiveWgt && aActiveWgt->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::onBeforeValuesChangedInPropertyPanel()
283 myIsResetCurrentValue = false;
285 if (isNestedCreateOperation(getCurrentOperation()))
287 // it is necessary to save current selection in order to restore it after the values are modifed
290 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
291 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
292 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
293 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
296 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
298 if (isNestedCreateOperation(getCurrentOperation()))
300 // it is necessary to restore current selection in order to restore it after the values are modified
302 myCurrentSelection.clear();
304 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
305 // viewer happens by deselect/select the modified objects. The flag should be restored after
306 // the selection processing. The update viewer should be also called.
307 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
308 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
309 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
310 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
311 aDisplayer->updateViewer();
314 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
316 if (!isNestedCreateOperation(getCurrentOperation()))
319 // visualize the current operation feature
320 //myIsResetCurrentValue = false;
321 operationMgr()->onValidateOperation();
322 // the feature is to be erased here, but it is correct to call canDisplayObject because
323 // there can be additional check (e.g. editor widget in distance constraint)
324 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
325 (getCurrentOperation());
327 FeaturePtr aFeature = aFOperation->feature();
328 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
332 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
334 get2dPoint(theWnd, theEvent, myClickedPoint);
336 if (!(theEvent->buttons() & Qt::LeftButton))
339 // Clear dragging mode
340 myIsDragging = false;
342 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
343 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
344 myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
345 if (!aViewer->canDragByMouse())
348 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
349 (getCurrentOperation());
353 if (aFOperation->isEditOperation()) {
354 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
355 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
356 // If the current widget is a selector, do nothing, it processes the mouse press
357 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
362 // Use only for sketch operations
363 if (myCurrentSketch) {
364 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
367 bool isSketcher = isSketchOperation(aFOperation);
368 bool isSketchOpe = isNestedSketchOperation(aFOperation);
370 // Avoid non-sketch operations
371 if ((!isSketchOpe) && (!isSketcher))
374 bool isEditing = aFOperation->isEditOperation();
376 // Ignore creation sketch operation
377 if ((!isSketcher) && (!isEditing))
380 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
381 if (!aContext.IsNull()) {
382 // MoveTo in order to highlight current object
383 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
385 // Remember highlighted objects for editing
386 ModuleBase_ISelection* aSelect = aWorkshop->selection();
388 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
389 storeSelection(!aHasShift);
391 if (myCurrentSelection.empty()) {
392 if (isSketchOpe && (!isSketcher))
393 // commit previous operation
394 if (!aFOperation->commit())
395 aFOperation->abort();
398 // Init flyout point for radius rotation
399 FeaturePtr aFeature = myCurrentSelection.begin().key();
403 get2dPoint(theWnd, theEvent, myCurrentPoint);
406 if (aFeature.get() != NULL) {
407 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
408 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
409 if (aSPFeature.get() && aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID()) {
410 DataPtr aData = aSPFeature->data();
411 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
412 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
413 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
414 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
417 } else if (isSketchOpe && isEditing) {
418 // If selected another object commit current result
419 aFOperation->commit();
422 get2dPoint(theWnd, theEvent, myCurrentPoint);
425 // This is necessary in order to finalize previous operation
426 QApplication::processEvents();
432 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
434 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
435 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
436 if (!aViewer->canDragByMouse())
438 ModuleBase_Operation* aOp = getCurrentOperation();
440 if (isNestedSketchOperation(aOp)) {
441 get2dPoint(theWnd, theEvent, myClickedPoint);
443 // Only for sketcher operations
447 myCurrentSelection.clear();
448 /*Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
449 if (!aContext.IsNull()) {
450 // Reselect edited object
451 aContext->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
452 if (theEvent->modifiers() & Qt::ShiftModifier)
453 aContext->ShiftSelect();
461 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
462 myIsDragging = false;
465 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
467 if (isNestedCreateOperation(getCurrentOperation()) && !myIsMouseOverViewProcessed) {
468 myIsMouseOverViewProcessed = true;
469 // 1. perform the widget mouse move functionality and display the presentation
470 ModuleBase_Operation* aOperation = getCurrentOperation();
471 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
472 ModuleBase_ModelWidget* anActiveWdg = aPanel->activeWidget();
473 // the mouse move should be processed in the widget, if it can in order to visualize correct
474 // presentation. These widgets correct the feature attribute according to the mouse position
475 PartSet_WidgetPoint2D* aPoint2DWdg = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWdg);
477 aPoint2DWdg->onMouseMove(theWnd, theEvent);
479 PartSet_WidgetPoint2dDistance* aDistanceWdg = dynamic_cast<PartSet_WidgetPoint2dDistance*>
482 aDistanceWdg->onMouseMove(theWnd, theEvent);
484 // the feature is to be erased here, but it is correct to call canDisplayObject because
485 // there can be additional check (e.g. editor widget in distance constraint)
486 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
487 (getCurrentOperation());
489 FeaturePtr aFeature = aFOperation->feature();
490 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
494 myClickedPoint.clear();
497 // 1. the current selection is saved in the mouse press method in order to restore it after moving
498 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
499 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
500 // deselected). This flag should be restored in the slot, processed the mouse release signal.
501 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
502 aViewer->enableSelection(false);
504 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
505 if (!aCurrentOperation)
507 if (isSketchOperation(aCurrentOperation))
508 return; // No edit operation activated
510 Handle(V3d_View) aView = theWnd->v3dView();
511 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
513 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
514 double dX = aX - myCurrentPoint.myCurX;
515 double dY = aY - myCurrentPoint.myCurY;
517 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
518 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
519 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
520 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
521 // viewer happens by deselect/select the modified objects. The flag should be restored after
522 // the selection processing. The update viewer should be also called.
523 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
525 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
526 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
527 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
528 aLast = myCurrentSelection.end();
529 // 4. the features and attributes modification(move)
530 bool isModified = false;
531 for (; anIt != aLast; anIt++) {
532 FeaturePtr aFeature = anIt.key();
534 std::set<AttributePtr> anAttributes = anIt.value().first;
535 // Process selection by attribute: the priority to the attribute
536 if (!anAttributes.empty()) {
537 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
538 anAttLast = anAttributes.end();
539 for (; anAttIt != anAttLast; anAttIt++) {
540 AttributePtr anAttr = *anAttIt;
541 if (anAttr.get() == NULL)
543 std::string aAttrId = anAttr->id();
544 DataPtr aData = aFeature->data();
545 if (aData->isValid()) {
546 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
547 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
548 if (aPoint.get() != NULL) {
549 bool isImmutable = aPoint->setImmutable(true);
550 aPoint->move(dX, dY);
552 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
553 aPoint->setImmutable(isImmutable);
558 // Process selection by feature
559 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
560 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
561 if (aSketchFeature) {
562 aSketchFeature->move(dX, dY);
564 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
568 // the modified state of the current operation should be updated if there are features, which
571 aCurrentOperation->onValuesChanged();
573 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
574 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
576 // 5. it is necessary to save current selection in order to restore it after the features moving
578 // 6. restore the update viewer flag and call this update
579 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
580 aDisplayer->updateViewer();
583 myCurrentPoint.setValue(aX, aY);
587 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
589 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
590 (getCurrentOperation());
591 if (aFOperation && aFOperation->isEditOperation()) {
592 std::string aId = aFOperation->id().toStdString();
593 if (isDistanceOperation(aFOperation))
595 // Activate dimension value editing on double click
596 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
597 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
598 // Find corresponded widget to activate value editing
599 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
600 if (aWgt->attributeID() == "ConstraintValue") {
609 void PartSet_SketcherMgr::onApplicationStarted()
611 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
612 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
613 XGUI_Workshop* aWorkshop = aConnector->workshop();
614 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
615 if (aPropertyPanel) {
616 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
617 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
620 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
621 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
622 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
624 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
625 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
626 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
629 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
631 if (!myClickedPoint.myIsInitialized)
634 ModuleBase_Operation* aOperation = getCurrentOperation();
635 // the distance constraint feature should not use the clickedd point
636 // this is workaround in order to don't throw down the flyout point value,
637 // set by execute() method of these type of features
638 if (isDistanceOperation(aOperation))
641 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
643 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
647 void PartSet_SketcherMgr::onBeforeContextMenu()
649 myIsPopupMenuActive = true;
652 void PartSet_SketcherMgr::onAfterContextMenu()
654 myIsPopupMenuActive = false;
657 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
660 Handle(V3d_View) aView = theWnd->v3dView();
661 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
663 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
664 thePoint.setValue(aX, anY);
667 void PartSet_SketcherMgr::launchEditing()
669 if (!myCurrentSelection.empty()) {
670 FeaturePtr aFeature = myCurrentSelection.begin().key();
671 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
672 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
674 myModule->editFeature(aSPFeature);
679 bool PartSet_SketcherMgr::sketchSolverError()
681 bool anError = false;
682 CompositeFeaturePtr aSketch = activeSketch();
684 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
685 anError = !aAttributeString->value().empty();
690 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
692 QString anError = "";
693 if (!theFeature.get() || !theFeature->data()->isValid())
696 CompositeFeaturePtr aSketch = activeSketch();
697 if (aSketch.get() && aSketch == theFeature) {
698 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
699 anError = aAttributeString->value().c_str();
701 else if (myIsResetCurrentValue) { // this flag do not allow commit of the current operation
702 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
703 (getCurrentOperation());
705 FeaturePtr aFeature = aFOperation->feature();
706 if (aFeature.get() && aFeature == theFeature && isNestedCreateOperation(aFOperation)) {
707 QString anAttributeName = "";
708 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
709 ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
711 AttributePtr anAttr = aFeature->attribute(anActiveWgt->attributeID());
713 anAttributeName = anAttr->id().c_str();
715 anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
722 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
724 static QStringList aIds;
725 if (aIds.size() == 0) {
726 aIds << SketchPlugin_Line::ID().c_str();
727 aIds << SketchPlugin_Point::ID().c_str();
728 aIds << SketchPlugin_Arc::ID().c_str();
729 aIds << SketchPlugin_Circle::ID().c_str();
730 aIds << SketchPlugin_ConstraintFillet::ID().c_str();
731 aIds.append(constraintsIdList());
736 const QStringList& PartSet_SketcherMgr::constraintsIdList()
738 static QStringList aIds;
739 if (aIds.size() == 0) {
740 aIds << SketchPlugin_ConstraintLength::ID().c_str();
741 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
742 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
743 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
744 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
745 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
746 aIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
747 aIds << SketchPlugin_ConstraintVertical::ID().c_str();
748 aIds << SketchPlugin_ConstraintEqual::ID().c_str();
749 aIds << SketchPlugin_ConstraintTangent::ID().c_str();
750 aIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
751 aIds << SketchPlugin_ConstraintMirror::ID().c_str();
752 aIds << SketchPlugin_ConstraintAngle::ID().c_str();
753 aIds << SketchPlugin_MultiRotation::ID().c_str();
754 aIds << SketchPlugin_MultiTranslation::ID().c_str();
759 void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes)
763 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
764 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
765 theModes.append(SketcherPrs_Tools::Sel_Constraint);
766 theModes.append(TopAbs_VERTEX);
767 theModes.append(TopAbs_EDGE);
770 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
772 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
775 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
777 return theOperation &&
778 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
781 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
783 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
785 return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
788 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
790 return (theId == SketchPlugin_Line::ID()) ||
791 (theId == SketchPlugin_Point::ID()) ||
792 (theId == SketchPlugin_Arc::ID()) ||
793 (theId == SketchPlugin_Circle::ID());
796 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
798 std::string aId = theOperation ? theOperation->id().toStdString() : "";
800 return (aId == SketchPlugin_ConstraintLength::ID()) ||
801 (aId == SketchPlugin_ConstraintDistance::ID()) ||
802 (aId == SketchPlugin_ConstraintRadius::ID()) ||
803 (aId == SketchPlugin_ConstraintAngle::ID());
806 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
808 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
809 (getCurrentOperation());
813 myModule->onViewTransformed();
815 // Display all sketcher sub-Objects
816 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
817 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
819 // Hide sketcher result
820 std::list<ResultPtr> aResults = myCurrentSketch->results();
821 std::list<ResultPtr>::const_iterator aIt;
822 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
823 (*aIt)->setDisplayed(false);
825 myCurrentSketch->setDisplayed(false);
827 // Display sketcher objects
828 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
829 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
830 std::list<ResultPtr> aResults = aFeature->results();
831 std::list<ResultPtr>::const_iterator aIt;
832 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
833 (*aIt)->setDisplayed(true);
835 aFeature->setDisplayed(true);
838 if (myPlaneFilter.IsNull())
839 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
841 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
843 bool aHasPlane = false;
844 std::shared_ptr<GeomAPI_Pln> aPln;
845 if (aFOperation->isEditOperation()) {
846 // If it is editing of sketch then it means that plane is already defined
847 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
851 myPlaneFilter->setPlane(aPln);
853 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
854 // all sketch objects should be activated in the sketch selection modes by edit operation start
855 // in case of creation operation, there is an active widget, which activates own selection mode
856 if (aFOperation->isEditOperation() && aHasPlane)
857 aConnector->activateModuleSelectionModes();
860 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
862 myIsMouseOverWindow = false;
863 myIsConstraintsShown = true;
864 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
865 qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
867 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
869 DataPtr aData = myCurrentSketch->data();
870 if (!aData->isValid()) {
871 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
872 // The sketch was aborted
873 myCurrentSketch = CompositeFeaturePtr();
874 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
876 // Erase all sketcher objects
877 QStringList aSketchIds = sketchOperationIdList();
878 QObjectPtrList aObjects = aDisplayer->displayedObjects();
879 foreach (ObjectPtr aObj, aObjects) {
880 DataPtr aObjData = aObj->data();
881 if (!aObjData->isValid())
882 aObj->setDisplayed(false);
886 // Hide all sketcher sub-Objects
887 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
888 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
889 std::list<ResultPtr> aResults = aFeature->results();
890 std::list<ResultPtr>::const_iterator aIt;
891 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
892 (*aIt)->setDisplayed(false);
894 aFeature->setDisplayed(false);
896 // Display sketcher result
897 std::list<ResultPtr> aResults = myCurrentSketch->results();
898 std::list<ResultPtr>::const_iterator aIt;
899 Events_Loop* aLoop = Events_Loop::loop();
900 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
902 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
904 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
905 if (!aFOperation->isDisplayedOnStart(*aIt)) {
906 (*aIt)->setDisplayed(true);
907 // this display event is needed because sketch already may have "displayed" state,
908 // but not displayed while it is still active (issue 613, abort of existing sketch)
909 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
912 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
913 myCurrentSketch->setDisplayed(true);
915 myCurrentSketch = CompositeFeaturePtr();
916 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
918 Events_Loop::loop()->flush(aDispEvent);
920 // restore the module selection modes, which were changed on startSketch
921 aConnector->activateModuleSelectionModes();
924 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
926 connectToPropertyPanel(true);
927 if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
928 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
931 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
933 connectToPropertyPanel(false);
934 myIsResetCurrentValue = false;
935 myIsMouseOverViewProcessed = true;
936 operationMgr()->onValidateOperation();
937 if (isNestedCreateOperation(theOp))
938 QApplication::restoreOverrideCursor();
941 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
943 if (isNestedCreateOperation(theOperation)) {
944 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
947 FeaturePtr aFeature = aFOperation->feature();
948 // it is necessary to check the the feature data validity because
949 // some kind of features are removed by an operation commit(the macro state of a feature)
950 if (aFeature.get() && aFeature->data()->isValid()) {
951 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
957 bool PartSet_SketcherMgr::canUndo() const
959 return isNestedCreateOperation(getCurrentOperation());
962 bool PartSet_SketcherMgr::canRedo() const
964 return isNestedCreateOperation(getCurrentOperation());
967 bool PartSet_SketcherMgr::canCommitOperation() const
969 bool aCanCommit = true;
971 if (isNestedCreateOperation(getCurrentOperation()) && myIsResetCurrentValue)
977 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
979 bool aCanErase = true;
980 // when the sketch operation is active, results of sketch sub-feature can not be hidden
981 if (myCurrentSketch.get()) {
982 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
984 // Display sketcher objects
985 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
987 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
988 std::list<ResultPtr> aResults = aFeature->results();
989 std::list<ResultPtr>::const_iterator anIt;
990 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
991 aCanErase = *anIt != aResult;
999 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1001 bool aCanDisplay = true;
1003 bool aHasActiveSketch = activeSketch().get() != NULL;
1004 if (aHasActiveSketch) {
1005 // 1. the sketch feature should not be displayed during the sketch active operation
1006 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1007 // nested features can be visualized
1008 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1009 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1010 aCanDisplay = false;
1013 else { // there are no an active sketch
1014 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1015 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1016 if (aFeature.get() != NULL) {
1017 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1018 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1019 if (aSketchFeature.get()) {
1020 aCanDisplay = false;
1025 // 3. the method should not filter the objects, which are not related to the current operation.
1026 // The object is filtered just if it is a current operation feature or this feature result
1027 bool isObjectFound = false;
1028 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1029 (getCurrentOperation());
1031 FeaturePtr aFeature = aFOperation->feature();
1032 if (aFeature.get()) {
1033 std::list<ResultPtr> aResults = aFeature->results();
1034 if (theObject == aFeature)
1035 isObjectFound = true;
1037 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1038 for (; anIt != aLast && !isObjectFound; anIt++) {
1039 isObjectFound = *anIt == theObject;
1047 // 4. For created nested feature operation do not display the created feature if
1048 // the mouse curstor leaves the OCC window.
1049 // The correction cases, which ignores this condition:
1050 // a. the property panel values modification
1051 // b. the popup menu activated
1052 // c. widget editor control
1053 #ifndef DEBUG_DO_NOT_BY_ENTER
1054 if (aCanDisplay && isNestedCreateOperation(getCurrentOperation())) {
1055 ModuleBase_Operation* aOperation = getCurrentOperation();
1056 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1057 ModuleBase_ModelWidget* anActiveWdg = aPanel ? aPanel->activeWidget() : 0;
1058 ModuleBase_WidgetEditor* anEditorWdg = anActiveWdg ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWdg) : 0;
1059 // the active widget editor should not influence here. The presentation should be visible always
1060 // when this widget is active.
1061 if (!anEditorWdg && !myIsPopupMenuActive) {
1062 // during a nested create operation, the feature is redisplayed only if the mouse over view
1063 // of there was a value modified in the property panel after the mouse left the view
1064 aCanDisplay = canDisplayCurrentCreatedFeature();
1071 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1073 return myIsMouseOverWindow || !myIsResetCurrentValue;
1074 #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS
1075 qDebug(QString("canDisplayCurrentCreatedFeature: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str());
1079 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1081 bool isFoundObject = false;
1083 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1084 if (anObjectFeature.get()) {
1085 int aSize = myCurrentSketch->numberOfSubs();
1086 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1087 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1088 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1091 return isFoundObject;
1094 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
1096 if (myPlaneFilter.IsNull())
1097 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
1099 myPlaneFilter->setPlane(thePln);
1102 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
1103 const FeaturePtr& theSketch,
1104 ModuleBase_IWorkshop* theWorkshop,
1105 FeatureToSelectionMap& theSelection)
1107 if (theFeature.get() == NULL)
1110 std::set<AttributePtr> aSelectedAttributes;
1111 std::set<ResultPtr> aSelectedResults;
1113 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1114 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1115 if (!aContext.IsNull()) {
1116 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1117 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1119 std::list<ResultPtr> aResults = theFeature->results();
1120 std::list<ResultPtr>::const_iterator aIt;
1121 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1123 ResultPtr aResult = *aIt;
1124 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1125 if (aAISObj.get() == NULL)
1127 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1128 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
1130 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
1131 if (anOwner->Selectable() != anAISIO)
1133 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1134 aSelectedAttributes, aSelectedResults);
1136 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
1137 Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner();
1138 if (anOwner.IsNull())
1140 if (anOwner->Selectable() != anAISIO)
1142 getAttributesOrResults(anOwner, theFeature, theSketch, aResult,
1143 aSelectedAttributes, aSelectedResults);
1147 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
1150 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1151 const FeaturePtr& theSketch,
1152 ModuleBase_IWorkshop* theWorkshop,
1153 const FeatureToSelectionMap& theSelection,
1154 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1156 if (theFeature.get() == NULL)
1159 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1160 std::set<AttributePtr> aSelectedAttributes = anIt.value().first;
1161 std::set<ResultPtr> aSelectedResults = anIt.value().second;
1163 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1165 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1166 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1168 // 1. found the feature's owners. Check the AIS objects of the constructions
1169 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1170 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1171 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1173 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1174 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1175 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1176 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1177 if (!anOwner.IsNull())
1178 theOwnersToSelect.Add(anOwner);
1182 // 2. found the feature results's owners
1183 std::list<ResultPtr> aResults = theFeature->results();
1184 std::list<ResultPtr>::const_iterator aIt;
1185 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
1187 ResultPtr aResult = *aIt;
1188 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1189 if (aAISObj.get() == NULL)
1191 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1193 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1194 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1195 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1196 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1197 if ( anOwner.IsNull() || !anOwner->HasShape() )
1199 const TopoDS_Shape& aShape = anOwner->Shape();
1200 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1201 if (aShapeType == TopAbs_VERTEX) {
1202 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1203 if (aPntAttr.get() != NULL &&
1204 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
1205 theOwnersToSelect.Add(anOwner);
1208 else if (aShapeType == TopAbs_EDGE) {
1209 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
1210 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
1211 theOwnersToSelect.FindIndex(anOwner) <= 0)
1212 theOwnersToSelect.Add(anOwner);
1218 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
1220 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1221 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1222 XGUI_Workshop* aWorkshop = aConnector->workshop();
1223 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
1224 if (aPropertyPanel) {
1225 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
1226 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
1228 connect(aWidget, SIGNAL(beforeValuesChanged()),
1229 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1230 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1231 connect(aWidget, SIGNAL(afterValuesChanged()),
1232 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1235 disconnect(aWidget, SIGNAL(beforeValuesChanged()),
1236 this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1237 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
1238 disconnect(aWidget, SIGNAL(afterValuesChanged()),
1239 this, SLOT(onAfterValuesChangedInPropertyPanel()));
1245 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1247 return myModule->workshop()->currentOperation();
1250 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1251 const bool isEditOperation,
1252 const bool isToDisplay,
1253 const bool isFlushRedisplay)
1255 #ifdef DEBUG_DO_NOT_BY_ENTER
1259 if (isEditOperation || !theFeature.get())
1262 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1263 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1265 // 1. change visibility of the object itself, here the presentable object is processed,
1266 // e.g. constraints features
1267 //FeaturePtr aFeature = aFOperation->feature();
1268 std::list<ResultPtr> aResults = theFeature->results();
1270 theFeature->setDisplayed(true);
1272 theFeature->setDisplayed(false);
1274 // change visibility of the object results, e.g. non-constraint features
1275 std::list<ResultPtr>::const_iterator aIt;
1276 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1278 (*aIt)->setDisplayed(true);
1281 (*aIt)->setDisplayed(false);
1284 if (isFlushRedisplay)
1285 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1288 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
1290 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1291 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1292 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
1294 QList<FeaturePtr> aFeatureList;
1295 if (theHighlightedOnly) {
1296 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1299 fillFeatureList(aHighlighted, myCurrentSketch, aFeatureList);
1301 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected(ModuleBase_ISelection::AllControls);
1302 fillFeatureList(aSelected, myCurrentSketch, aFeatureList);
1305 // 1. it is necessary to save current selection in order to restore it after the features moving
1306 myCurrentSelection.clear();
1307 QList<FeaturePtr>::const_iterator anIt = aFeatureList.begin(), aLast = aFeatureList.end();
1308 for (; anIt != aLast; anIt++) {
1309 getCurrentSelection(*anIt, myCurrentSketch, aWorkshop, myCurrentSelection);
1311 //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1314 void PartSet_SketcherMgr::restoreSelection()
1316 //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
1317 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1318 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1319 FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
1320 aSLast = myCurrentSelection.end();
1321 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1322 for (; aSIt != aSLast; aSIt++) {
1323 anOwnersToSelect.Clear();
1324 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, myCurrentSelection,
1326 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1330 void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
1332 if (myIsConstraintsShown == theOn)
1334 if (myCurrentSketch.get() == NULL)
1337 myIsConstraintsShown = theOn;
1339 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1340 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1342 const QStringList& aConstrIds = constraintsIdList();
1343 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1344 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1345 if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
1346 if (myIsConstraintsShown)
1347 aSubFeature->setDisplayed(true);
1349 aSubFeature->setDisplayed(false);
1352 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1355 QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const
1357 return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2")
1358 .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow);
1361 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1363 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1364 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1365 XGUI_Workshop* aWorkshop = aConnector->workshop();
1367 return aWorkshop->operationMgr();