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_Tools.h"
12 #include <XGUI_ModuleConnector.h>
13 #include <XGUI_Displayer.h>
14 #include <XGUI_Workshop.h>
15 #include <XGUI_Selection.h>
16 #include <XGUI_SelectionMgr.h>
17 #include <ModuleBase_ModelWidget.h>
18 #include <XGUI_ModuleConnector.h>
19 #include <XGUI_PropertyPanel.h>
21 #include <AppElements_MainWindow.h>
23 #include <ModuleBase_IViewer.h>
24 #include <ModuleBase_IWorkshop.h>
25 #include <ModuleBase_IViewWindow.h>
26 #include <ModuleBase_Operation.h>
27 #include <ModuleBase_ISelection.h>
28 #include <ModuleBase_IPropertyPanel.h>
29 #include <ModuleBase_Operation.h>
31 #include <GeomDataAPI_Point2D.h>
33 #include <Events_Loop.h>
35 #include <SketchPlugin_Line.h>
36 #include <SketchPlugin_Sketch.h>
37 #include <SketchPlugin_Point.h>
38 #include <SketchPlugin_Arc.h>
39 #include <SketchPlugin_Circle.h>
40 #include <SketchPlugin_ConstraintLength.h>
41 #include <SketchPlugin_ConstraintDistance.h>
42 #include <SketchPlugin_ConstraintParallel.h>
43 #include <SketchPlugin_ConstraintPerpendicular.h>
44 #include <SketchPlugin_ConstraintRadius.h>
45 #include <SketchPlugin_ConstraintRigid.h>
47 #include <SelectMgr_IndexedMapOfOwner.hxx>
48 #include <StdSelect_BRepOwner.hxx>
50 //#include <AIS_DimensionSelectionMode.hxx>
51 //#include <AIS_Shape.hxx>
53 #include <ModelAPI_Events.h>
55 #include <QMouseEvent>
56 #include <QApplication>
59 /// Returns list of unique objects by sum of objects from List1 and List2
60 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
61 const QList<ModuleBase_ViewerPrs>& theList2)
63 QList<ModuleBase_ViewerPrs> aRes;
64 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
65 if (!aRes.contains(aPrs))
68 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
69 if (!aRes.contains(aPrs))
75 void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
76 QMap<FeaturePtr, QList<AttributePtr> >& theFeature2AttributeMap,
77 const FeaturePtr theSketch)
79 QList<ModuleBase_ViewerPrs> aRes;
81 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theList.begin(),
82 aLast = theList.end();
83 for (; anIt != aLast; anIt++)
85 ModuleBase_ViewerPrs aPrs = *anIt;
86 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
87 if (aFeature.get() == NULL)
90 QList<AttributePtr> anAttributes;
91 if (theFeature2AttributeMap.contains(aFeature)) {
92 anAttributes = theFeature2AttributeMap[aFeature];
95 TopoDS_Shape aShape = aPrs.shape();
96 if (!aShape.IsNull()) {
97 if (aShape.ShapeType() == TopAbs_VERTEX) {
98 anAttr = PartSet_Tools::findAttributeBy2dPoint(aFeature, aShape, theSketch);
99 if (anAttr.get() != NULL && !anAttributes.contains(anAttr))
100 anAttributes.push_back(anAttr);
103 theFeature2AttributeMap[aFeature] = anAttributes;
110 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
111 : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
112 myIsMouseOverWindow(false), myIsPropertyPanelValueChanged(false)
114 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
115 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
117 myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
119 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
120 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
122 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
123 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
125 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
126 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
128 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
129 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
131 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
132 XGUI_Workshop* aWorkshop = aConnector->workshop();
133 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
136 PartSet_SketcherMgr::~PartSet_SketcherMgr()
138 if (!myPlaneFilter.IsNull())
139 myPlaneFilter.Nullify();
142 void PartSet_SketcherMgr::onMouseMoveOverWindow(bool theOverWindow)
144 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
145 if (!aOperation || aOperation->isEditOperation())
148 myIsMouseOverWindow = theOverWindow;
150 myIsPropertyPanelValueChanged = false;
152 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
153 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
158 updateVisibilityOfCreatedFeature();
161 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
163 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
164 if (!aOperation || aOperation->isEditOperation())
167 myIsPropertyPanelValueChanged = true;
169 updateVisibilityOfCreatedFeature();
172 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
174 get2dPoint(theWnd, theEvent, myClickedPoint);
176 if (!(theEvent->buttons() & Qt::LeftButton))
179 // Clear dragging mode
180 myIsDragging = false;
182 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
183 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
184 if (!aViewer->canDragByMouse())
187 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
188 if (aOperation && aOperation->isEditOperation()) {
189 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
190 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
191 // If the current widget is a selector, do do nothing, it processes the mouse press
192 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
197 // Use only for sketch operations
198 if (aOperation && myCurrentSketch) {
199 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
202 bool isSketcher = isSketchOperation(aOperation);
203 bool isSketchOpe = isNestedSketchOperation(aOperation);
205 // Avoid non-sketch operations
206 if ((!isSketchOpe) && (!isSketcher))
209 bool isEditing = aOperation->isEditOperation();
211 // Ignore creation sketch operation
212 if ((!isSketcher) && (!isEditing))
215 // MoveTo in order to highlight current object
216 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
218 // Remember highlighted objects for editing
219 ModuleBase_ISelection* aSelect = aWorkshop->selection();
220 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
221 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
222 myFeature2AttributeMap.clear();
224 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
226 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
227 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
230 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
233 if (myFeature2AttributeMap.empty()) {
234 if (isSketchOpe && (!isSketcher))
235 // commit previous operation
236 if (!aOperation->commit())
243 get2dPoint(theWnd, theEvent, myCurrentPoint);
247 } else if (isSketchOpe && isEditing) {
248 // If selected another object commit current result
249 aOperation->commit();
252 get2dPoint(theWnd, theEvent, myCurrentPoint);
255 // This is necessary in order to finalize previous operation
256 QApplication::processEvents();
262 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
264 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
265 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
266 if (!aViewer->canDragByMouse())
268 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
270 if (isNestedSketchOperation(aOp)) {
271 get2dPoint(theWnd, theEvent, myClickedPoint);
273 // Only for sketcher operations
277 myFeature2AttributeMap.clear();
279 // Reselect edited object
280 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
281 if (theEvent->modifiers() & Qt::ShiftModifier)
282 aViewer->AISContext()->ShiftSelect();
284 aViewer->AISContext()->Select();
290 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
291 myIsDragging = false;
294 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
296 myClickedPoint.clear();
299 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
300 // 1. it is necessary to save current selection in order to restore it after the features moving
301 FeatureToSelectionMap aCurrentSelection;
302 getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, aCurrentSelection);
304 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
305 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
306 // deselected). This flag should be restored in the slot, processed the mouse release signal.
307 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
308 aViewer->enableSelection(false);
310 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
313 if (isSketchOperation(aOperation))
314 return; // No edit operation activated
316 Handle(V3d_View) aView = theWnd->v3dView();
317 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
319 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
320 double dX = aX - myCurrentPoint.myCurX;
321 double dY = aY - myCurrentPoint.myCurY;
323 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
324 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
325 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
326 // viewer happens by deselect/select the modified objects. The flag should be restored after
327 // the selection processing. The update viewer should be also called.
328 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
330 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
331 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
333 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
334 aLast = myFeature2AttributeMap.end();
335 // 4. the features and attributes modification(move)
336 for (; anIt != aLast; anIt++) {
337 FeaturePtr aFeature = anIt.key();
339 AttributeList anAttributes = anIt.value();
340 // Process selection by attribute: the priority to the attribute
341 if (!anAttributes.empty()) {
342 AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
343 for (; anAttIt != anAttLast; anAttIt++) {
344 AttributePtr anAttr = *anAttIt;
345 if (anAttr.get() == NULL)
347 std::string aAttrId = anAttr->id();
348 DataPtr aData = aFeature->data();
349 if (aData.get() != NULL) {
350 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
351 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
352 if (aPoint.get() != NULL) {
353 bool isImmutable = aPoint->setImmutable(true);
354 aPoint->move(dX, dY);
355 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
356 aPoint->setImmutable(isImmutable);
361 // Process selection by feature
362 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
363 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
364 if (aSketchFeature) {
365 aSketchFeature->move(dX, dY);
366 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
370 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
371 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
373 // 5. it is necessary to save current selection in order to restore it after the features moving
374 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
375 aSLast = aCurrentSelection.end();
376 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
377 for (; aSIt != aSLast; aSIt++) {
378 anOwnersToSelect.Clear();
379 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
381 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
384 // 6. restore the update viewer flag and call this update
385 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
386 aDisplayer->updateViewer();
388 myCurrentPoint.setValue(aX, aY);
392 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
394 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
395 if (aOperation && aOperation->isEditOperation()) {
396 std::string aId = aOperation->id().toStdString();
397 if (isDistanceOperation(aOperation))
399 // Activate dimension value editing on double click
400 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
401 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
402 // Find corresponded widget to activate value editing
403 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
404 if (aWgt->attributeID() == "ConstraintValue") {
413 void PartSet_SketcherMgr::onApplicationStarted()
415 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
416 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
417 XGUI_Workshop* aWorkshop = aConnector->workshop();
418 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
419 if (aPropertyPanel) {
420 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
421 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
424 AppElements_MainWindow* aMainWindow = aWorkshop->mainWindow();
425 connect(aMainWindow, SIGNAL(mouseMoveOverWindow(bool)), this, SLOT(onMouseMoveOverWindow(bool)));
428 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
430 if (!myClickedPoint.myIsInitialized)
433 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
434 // the distance constraint feature should not use the clickedd point
435 // this is workaround in order to don't throw down the flyout point value,
436 // set by execute() method of these type of features
437 if (isDistanceOperation(aOperation))
440 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
442 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
446 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
449 Handle(V3d_View) aView = theWnd->v3dView();
450 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
452 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
453 thePoint.setValue(aX, anY);
456 void PartSet_SketcherMgr::launchEditing()
458 // there should be activate the vertex selection mode because the edit can happens by the selected
461 aModes << TopAbs_VERTEX << TopAbs_EDGE;
462 // TODO: #391 - to be uncommented
463 /*aModes.append(AIS_DSM_Text);
464 aModes.append(AIS_DSM_Line);
465 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
466 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/
468 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
469 aConnector->activateSubShapesSelection(aModes);
471 if (!myFeature2AttributeMap.empty()) {
472 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
473 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
474 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
476 myModule->editFeature(aSPFeature);
483 QStringList PartSet_SketcherMgr::sketchOperationIdList()
485 static QStringList aIds;
486 if (aIds.size() == 0) {
487 aIds << SketchPlugin_Line::ID().c_str();
488 aIds << SketchPlugin_Point::ID().c_str();
489 aIds << SketchPlugin_Arc::ID().c_str();
490 aIds << SketchPlugin_Circle::ID().c_str();
491 aIds << SketchPlugin_ConstraintLength::ID().c_str();
492 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
493 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
494 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
495 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
496 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
501 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
503 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
506 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
508 return theOperation &&
509 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
512 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
514 std::string aId = theOperation ? theOperation->id().toStdString() : "";
516 return (aId == SketchPlugin_ConstraintLength::ID()) ||
517 (aId == SketchPlugin_ConstraintDistance::ID()) ||
518 (aId == SketchPlugin_ConstraintRadius::ID());
521 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
523 // Display all sketcher sub-Objects
524 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
525 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
526 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
528 // Hide sketcher result
529 std::list<ResultPtr> aResults = myCurrentSketch->results();
530 std::list<ResultPtr>::const_iterator aIt;
531 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
532 aDisplayer->erase((*aIt), false);
534 aDisplayer->erase(myCurrentSketch, false);
536 // Display sketcher objects
537 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
538 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
539 std::list<ResultPtr> aResults = aFeature->results();
540 std::list<ResultPtr>::const_iterator aIt;
541 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
542 aDisplayer->display((*aIt), false);
544 aDisplayer->display(aFeature, false);
547 if (myPlaneFilter.IsNull())
548 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
550 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
551 if (theOperation->isEditOperation()) {
552 // If it is editing of sketch then it means that plane is already defined
553 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
554 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
556 aDisplayer->updateViewer();
559 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
561 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
562 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
564 DataPtr aData = myCurrentSketch->data();
565 if ((!aData) || (!aData->isValid())) {
566 // The sketch was aborted
567 myCurrentSketch = CompositeFeaturePtr();
568 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
570 // Erase all sketcher objects
571 QStringList aSketchIds = sketchOperationIdList();
572 QObjectPtrList aObjects = aDisplayer->displayedObjects();
573 foreach (ObjectPtr aObj, aObjects) {
574 DataPtr aObjData = aObj->data();
575 if ((!aObjData) || (!aObjData->isValid()))
576 aDisplayer->erase(aObj);
580 // Hide all sketcher sub-Objects
581 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
582 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
583 std::list<ResultPtr> aResults = aFeature->results();
584 std::list<ResultPtr>::const_iterator aIt;
585 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
586 aDisplayer->erase((*aIt), false);
588 aDisplayer->erase(aFeature, false);
590 // Display sketcher result
591 std::list<ResultPtr> aResults = myCurrentSketch->results();
592 std::list<ResultPtr>::const_iterator aIt;
593 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
594 aDisplayer->display((*aIt), false);
596 aDisplayer->display(myCurrentSketch);
598 myCurrentSketch = CompositeFeaturePtr();
599 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
600 aDisplayer->updateViewer();
603 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* )
605 connectToPropertyPanel(true);
608 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* )
610 connectToPropertyPanel(false);
613 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
615 return myIsMouseOverWindow || myIsPropertyPanelValueChanged;
618 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
620 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
623 void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
624 const FeaturePtr& theSketch,
625 ModuleBase_IWorkshop* theWorkshop,
626 FeatureToSelectionMap& theSelection)
628 FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
629 aLast = theFeatureToAttributes.end();
630 for (; anIt != aLast; anIt++) {
631 FeaturePtr aFeature = anIt.key();
632 getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
636 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
637 const FeaturePtr& theSketch,
638 ModuleBase_IWorkshop* theWorkshop,
639 FeatureToSelectionMap& theSelection)
641 if (theFeature.get() == NULL)
644 std::set<AttributePtr> aSelectedAttributes;
645 std::set<ResultPtr> aSelectedResults;
647 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
648 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
649 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
650 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
652 std::list<ResultPtr> aResults = theFeature->results();
653 std::list<ResultPtr>::const_iterator aIt;
654 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
656 ResultPtr aResult = *aIt;
657 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
658 if (aAISObj.get() == NULL)
660 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
661 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
663 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
664 aContext->SelectedOwner());
665 if (aBRepOwner.IsNull())
667 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
668 aBRepOwner->Selectable());
672 if (aBRepOwner->HasShape()) {
673 const TopoDS_Shape& aShape = aBRepOwner->Shape();
674 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
675 if (aShapeType == TopAbs_VERTEX) {
676 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
678 if (aPntAttr.get() != NULL)
679 aSelectedAttributes.insert(aPntAttr);
681 else if (aShapeType == TopAbs_EDGE &&
682 aSelectedResults.find(aResult) == aSelectedResults.end()) {
683 aSelectedResults.insert(aResult);
688 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
691 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
692 const FeaturePtr& theSketch,
693 ModuleBase_IWorkshop* theWorkshop,
694 const FeatureToSelectionMap& theSelection,
695 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
697 if (theFeature.get() == NULL)
700 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
701 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
702 std::set<ResultPtr> aSelectedResults = anIt->second.second;
704 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
705 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
706 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
707 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
709 std::list<ResultPtr> aResults = theFeature->results();
710 std::list<ResultPtr>::const_iterator aIt;
711 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
713 ResultPtr aResult = *aIt;
714 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
715 if (aAISObj.get() == NULL)
717 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
719 SelectMgr_IndexedMapOfOwner aSelectedOwners;
720 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
721 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
722 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
723 if ( anOwner.IsNull() || !anOwner->HasShape() )
725 const TopoDS_Shape& aShape = anOwner->Shape();
726 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
727 if (aShapeType == TopAbs_VERTEX) {
728 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
729 if (aPntAttr.get() != NULL &&
730 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
731 anOwnersToSelect.Add(anOwner);
734 else if (aShapeType == TopAbs_EDGE) {
735 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
736 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
737 anOwnersToSelect.FindIndex(anOwner) <= 0)
738 anOwnersToSelect.Add(anOwner);
744 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
746 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
747 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
748 XGUI_Workshop* aWorkshop = aConnector->workshop();
749 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
750 if (aPropertyPanel) {
751 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
752 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
754 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
756 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
761 void PartSet_SketcherMgr::updateVisibilityOfCreatedFeature()
763 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
764 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
765 if (!aOperation || aOperation->isEditOperation())
767 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
768 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
770 FeaturePtr aFeature = aOperation->feature();
771 std::list<ResultPtr> aResults = aFeature->results();
772 std::list<ResultPtr>::const_iterator aIt;
773 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
774 if (canDisplayObject(aFeature)) {
775 aDisplayer->display(*aIt, false);
778 aDisplayer->erase(*aIt, false);
781 aDisplayer->updateViewer();