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 myIsMouseOverWindow = theOverWindow;
146 myIsPropertyPanelValueChanged = false;
148 updateVisibilityOfCreatedFeature();
151 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
153 myIsPropertyPanelValueChanged = true;
155 updateVisibilityOfCreatedFeature();
158 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
160 get2dPoint(theWnd, theEvent, myClickedPoint);
162 if (!(theEvent->buttons() & Qt::LeftButton))
165 // Clear dragging mode
166 myIsDragging = false;
168 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
169 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
170 if (!aViewer->canDragByMouse())
173 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
174 if (aOperation && aOperation->isEditOperation()) {
175 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
176 ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
177 // If the current widget is a selector, do do nothing, it processes the mouse press
178 if(aActiveWgt && aActiveWgt->isViewerSelector()) {
183 // Use only for sketch operations
184 if (aOperation && myCurrentSketch) {
185 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
188 bool isSketcher = isSketchOperation(aOperation);
189 bool isSketchOpe = isNestedSketchOperation(aOperation);
191 // Avoid non-sketch operations
192 if ((!isSketchOpe) && (!isSketcher))
195 bool isEditing = aOperation->isEditOperation();
197 // Ignore creation sketch operation
198 if ((!isSketcher) && (!isEditing))
201 // MoveTo in order to highlight current object
202 aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
204 // Remember highlighted objects for editing
205 ModuleBase_ISelection* aSelect = aWorkshop->selection();
206 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
207 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
208 myFeature2AttributeMap.clear();
210 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
212 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
213 fillFeature2Attribute(aSelected, myFeature2AttributeMap, myCurrentSketch);
216 fillFeature2Attribute(aHighlighted, myFeature2AttributeMap, myCurrentSketch);
219 if (myFeature2AttributeMap.empty()) {
220 if (isSketchOpe && (!isSketcher))
221 // commit previous operation
222 if (!aOperation->commit())
229 get2dPoint(theWnd, theEvent, myCurrentPoint);
233 } else if (isSketchOpe && isEditing) {
234 // If selected another object commit current result
235 aOperation->commit();
238 get2dPoint(theWnd, theEvent, myCurrentPoint);
241 // This is necessary in order to finalize previous operation
242 QApplication::processEvents();
248 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
250 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
251 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
252 if (!aViewer->canDragByMouse())
254 ModuleBase_Operation* aOp = aWorkshop->currentOperation();
256 if (isNestedSketchOperation(aOp)) {
257 get2dPoint(theWnd, theEvent, myClickedPoint);
259 // Only for sketcher operations
263 myFeature2AttributeMap.clear();
265 // Reselect edited object
266 /*aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
267 if (theEvent->modifiers() & Qt::ShiftModifier)
268 aViewer->AISContext()->ShiftSelect();
270 aViewer->AISContext()->Select();
276 aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
277 myIsDragging = false;
280 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
282 myClickedPoint.clear();
285 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
286 // 1. it is necessary to save current selection in order to restore it after the features moving
287 FeatureToSelectionMap aCurrentSelection;
288 getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, aCurrentSelection);
290 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
291 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
292 // deselected). This flag should be restored in the slot, processed the mouse release signal.
293 ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
294 aViewer->enableSelection(false);
296 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
299 if (isSketchOperation(aOperation))
300 return; // No edit operation activated
302 Handle(V3d_View) aView = theWnd->v3dView();
303 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
305 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
306 double dX = aX - myCurrentPoint.myCurX;
307 double dY = aY - myCurrentPoint.myCurY;
309 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
310 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
311 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
312 // viewer happens by deselect/select the modified objects. The flag should be restored after
313 // the selection processing. The update viewer should be also called.
314 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
316 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
317 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
319 FeatureToAttributesMap::const_iterator anIt = myFeature2AttributeMap.begin(),
320 aLast = myFeature2AttributeMap.end();
321 // 4. the features and attributes modification(move)
322 for (; anIt != aLast; anIt++) {
323 FeaturePtr aFeature = anIt.key();
325 AttributeList anAttributes = anIt.value();
326 // Process selection by attribute: the priority to the attribute
327 if (!anAttributes.empty()) {
328 AttributeList::const_iterator anAttIt = anAttributes.begin(), anAttLast = anAttributes.end();
329 for (; anAttIt != anAttLast; anAttIt++) {
330 AttributePtr anAttr = *anAttIt;
331 if (anAttr.get() == NULL)
333 std::string aAttrId = anAttr->id();
334 DataPtr aData = aFeature->data();
335 if (aData.get() != NULL) {
336 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
337 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
338 if (aPoint.get() != NULL) {
339 bool isImmutable = aPoint->setImmutable(true);
340 aPoint->move(dX, dY);
341 ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
342 aPoint->setImmutable(isImmutable);
347 // Process selection by feature
348 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
349 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
350 if (aSketchFeature) {
351 aSketchFeature->move(dX, dY);
352 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
356 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
357 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
359 // 5. it is necessary to save current selection in order to restore it after the features moving
360 FeatureToSelectionMap::const_iterator aSIt = aCurrentSelection.begin(),
361 aSLast = aCurrentSelection.end();
362 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
363 for (; aSIt != aSLast; aSIt++) {
364 anOwnersToSelect.Clear();
365 getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, aCurrentSelection,
367 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
370 // 6. restore the update viewer flag and call this update
371 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
372 aDisplayer->updateViewer();
374 myCurrentPoint.setValue(aX, aY);
378 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
380 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
381 if (aOperation && aOperation->isEditOperation()) {
382 std::string aId = aOperation->id().toStdString();
383 if (isDistanceOperation(aOperation))
385 // Activate dimension value editing on double click
386 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
387 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
388 // Find corresponded widget to activate value editing
389 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
390 if (aWgt->attributeID() == "ConstraintValue") {
399 void PartSet_SketcherMgr::onApplicationStarted()
401 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
402 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
403 XGUI_Workshop* aWorkshop = aConnector->workshop();
404 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
405 if (aPropertyPanel) {
406 connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
407 this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
410 AppElements_MainWindow* aMainWindow = aWorkshop->mainWindow();
411 connect(aMainWindow, SIGNAL(mouseMoveOverWindow(bool)), this, SLOT(onMouseMoveOverWindow(bool)));
414 void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
416 if (!myClickedPoint.myIsInitialized)
419 ModuleBase_Operation* aOperation = myModule->workshop()->currentOperation();
420 // the distance constraint feature should not use the clickedd point
421 // this is workaround in order to don't throw down the flyout point value,
422 // set by execute() method of these type of features
423 if (isDistanceOperation(aOperation))
426 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
428 aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
432 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
435 Handle(V3d_View) aView = theWnd->v3dView();
436 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
438 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
439 thePoint.setValue(aX, anY);
442 void PartSet_SketcherMgr::launchEditing()
444 // there should be activate the vertex selection mode because the edit can happens by the selected
447 aModes << TopAbs_VERTEX << TopAbs_EDGE;
448 // TODO: #391 - to be uncommented
449 /*aModes.append(AIS_DSM_Text);
450 aModes.append(AIS_DSM_Line);
451 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
452 aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/
454 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
455 aConnector->activateSubShapesSelection(aModes);
457 if (!myFeature2AttributeMap.empty()) {
458 FeaturePtr aFeature = myFeature2AttributeMap.begin().key();
459 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
460 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
462 myModule->editFeature(aSPFeature);
469 QStringList PartSet_SketcherMgr::sketchOperationIdList()
471 static QStringList aIds;
472 if (aIds.size() == 0) {
473 aIds << SketchPlugin_Line::ID().c_str();
474 aIds << SketchPlugin_Point::ID().c_str();
475 aIds << SketchPlugin_Arc::ID().c_str();
476 aIds << SketchPlugin_Circle::ID().c_str();
477 aIds << SketchPlugin_ConstraintLength::ID().c_str();
478 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
479 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
480 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
481 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
482 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
487 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
489 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
492 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation)
494 return theOperation &&
495 PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
498 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
500 std::string aId = theOperation ? theOperation->id().toStdString() : "";
502 return (aId == SketchPlugin_ConstraintLength::ID()) ||
503 (aId == SketchPlugin_ConstraintDistance::ID()) ||
504 (aId == SketchPlugin_ConstraintRadius::ID());
507 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
509 // Display all sketcher sub-Objects
510 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
511 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
512 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
514 // Hide sketcher result
515 std::list<ResultPtr> aResults = myCurrentSketch->results();
516 std::list<ResultPtr>::const_iterator aIt;
517 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
518 aDisplayer->erase((*aIt), false);
520 aDisplayer->erase(myCurrentSketch, false);
522 // Display sketcher objects
523 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
524 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
525 std::list<ResultPtr> aResults = aFeature->results();
526 std::list<ResultPtr>::const_iterator aIt;
527 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
528 aDisplayer->display((*aIt), false);
530 aDisplayer->display(aFeature, false);
533 if (myPlaneFilter.IsNull())
534 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
536 myModule->workshop()->viewer()->addSelectionFilter(myPlaneFilter);
537 if (theOperation->isEditOperation()) {
538 // If it is editing of sketch then it means that plane is already defined
539 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
540 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
542 aDisplayer->updateViewer();
545 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
547 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
548 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
550 DataPtr aData = myCurrentSketch->data();
551 if ((!aData) || (!aData->isValid())) {
552 // The sketch was aborted
553 myCurrentSketch = CompositeFeaturePtr();
554 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
556 // Erase all sketcher objects
557 QStringList aSketchIds = sketchOperationIdList();
558 QObjectPtrList aObjects = aDisplayer->displayedObjects();
559 foreach (ObjectPtr aObj, aObjects) {
560 DataPtr aObjData = aObj->data();
561 if ((!aObjData) || (!aObjData->isValid()))
562 aDisplayer->erase(aObj);
566 // Hide all sketcher sub-Objects
567 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
568 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
569 std::list<ResultPtr> aResults = aFeature->results();
570 std::list<ResultPtr>::const_iterator aIt;
571 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
572 aDisplayer->erase((*aIt), false);
574 aDisplayer->erase(aFeature, false);
576 // Display sketcher result
577 std::list<ResultPtr> aResults = myCurrentSketch->results();
578 std::list<ResultPtr>::const_iterator aIt;
579 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
580 aDisplayer->display((*aIt), false);
582 aDisplayer->display(myCurrentSketch);
584 myCurrentSketch = CompositeFeaturePtr();
585 myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
586 aDisplayer->updateViewer();
589 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* )
591 connectToPropertyPanel(true);
594 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* )
596 connectToPropertyPanel(false);
599 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
601 return myIsMouseOverWindow || myIsPropertyPanelValueChanged;
604 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
606 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
609 void PartSet_SketcherMgr::getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
610 const FeaturePtr& theSketch,
611 ModuleBase_IWorkshop* theWorkshop,
612 FeatureToSelectionMap& theSelection)
614 FeatureToAttributesMap::const_iterator anIt = theFeatureToAttributes.begin(),
615 aLast = theFeatureToAttributes.end();
616 for (; anIt != aLast; anIt++) {
617 FeaturePtr aFeature = anIt.key();
618 getCurrentSelection(aFeature, theSketch, theWorkshop, theSelection);
622 void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature,
623 const FeaturePtr& theSketch,
624 ModuleBase_IWorkshop* theWorkshop,
625 FeatureToSelectionMap& theSelection)
627 if (theFeature.get() == NULL)
630 std::set<AttributePtr> aSelectedAttributes;
631 std::set<ResultPtr> aSelectedResults;
633 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
634 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
635 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
636 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
638 std::list<ResultPtr> aResults = theFeature->results();
639 std::list<ResultPtr>::const_iterator aIt;
640 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
642 ResultPtr aResult = *aIt;
643 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
644 if (aAISObj.get() == NULL)
646 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
647 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
649 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(
650 aContext->SelectedOwner());
651 if (aBRepOwner.IsNull())
653 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
654 aBRepOwner->Selectable());
658 if (aBRepOwner->HasShape()) {
659 const TopoDS_Shape& aShape = aBRepOwner->Shape();
660 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
661 if (aShapeType == TopAbs_VERTEX) {
662 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
664 if (aPntAttr.get() != NULL)
665 aSelectedAttributes.insert(aPntAttr);
667 else if (aShapeType == TopAbs_EDGE &&
668 aSelectedResults.find(aResult) == aSelectedResults.end()) {
669 aSelectedResults.insert(aResult);
674 theSelection[theFeature] = std::make_pair(aSelectedAttributes, aSelectedResults);
677 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
678 const FeaturePtr& theSketch,
679 ModuleBase_IWorkshop* theWorkshop,
680 const FeatureToSelectionMap& theSelection,
681 SelectMgr_IndexedMapOfOwner& anOwnersToSelect)
683 if (theFeature.get() == NULL)
686 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
687 std::set<AttributePtr> aSelectedAttributes = anIt->second.first;
688 std::set<ResultPtr> aSelectedResults = anIt->second.second;
690 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
691 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
692 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
693 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
695 std::list<ResultPtr> aResults = theFeature->results();
696 std::list<ResultPtr>::const_iterator aIt;
697 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
699 ResultPtr aResult = *aIt;
700 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
701 if (aAISObj.get() == NULL)
703 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
705 SelectMgr_IndexedMapOfOwner aSelectedOwners;
706 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
707 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
708 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
709 if ( anOwner.IsNull() || !anOwner->HasShape() )
711 const TopoDS_Shape& aShape = anOwner->Shape();
712 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
713 if (aShapeType == TopAbs_VERTEX) {
714 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
715 if (aPntAttr.get() != NULL &&
716 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end()) {
717 anOwnersToSelect.Add(anOwner);
720 else if (aShapeType == TopAbs_EDGE) {
721 bool aFound = aSelectedResults.find(aResult) != aSelectedResults.end();
722 if (aSelectedResults.find(aResult) != aSelectedResults.end() &&
723 anOwnersToSelect.FindIndex(anOwner) <= 0)
724 anOwnersToSelect.Add(anOwner);
730 void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
732 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
733 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
734 XGUI_Workshop* aWorkshop = aConnector->workshop();
735 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
736 if (aPropertyPanel) {
737 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
738 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
740 connect(aWidget, SIGNAL(controlValuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
742 disconnect(aWidget, SIGNAL(controlValuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
747 void PartSet_SketcherMgr::updateVisibilityOfCreatedFeature()
749 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
750 ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
751 if (!aOperation || aOperation->isEditOperation())
753 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
754 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
756 FeaturePtr aFeature = aOperation->feature();
757 std::list<ResultPtr> aResults = aFeature->results();
758 std::list<ResultPtr>::const_iterator aIt;
759 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
760 if (canDisplayObject(aFeature)) {
761 aDisplayer->display(*aIt, false);
764 aDisplayer->erase(*aIt, false);
767 aDisplayer->updateViewer();