1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #include "XGUI_SelectionMgr.h"
5 #include "XGUI_Workshop.h"
6 #include "XGUI_ObjectsBrowser.h"
7 #include "XGUI_SalomeConnector.h"
8 #include "XGUI_ViewerProxy.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_Selection.h"
12 #include <AppElements_MainWindow.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Session.h>
16 #include <ModelAPI_AttributeDocRef.h>
17 #include <ModelAPI_Data.h>
18 #include <ModelAPI_Result.h>
19 #include <ModelAPI_Object.h>
21 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
23 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
27 mySelection = new XGUI_Selection(myWorkshop);
30 XGUI_SelectionMgr::~XGUI_SelectionMgr()
35 //**************************************************************
36 void XGUI_SelectionMgr::connectViewers()
38 connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
39 SLOT(onObjectBrowserSelection()));
41 //Connect to other viewers
42 connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
45 //**************************************************************
46 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
49 SelectMgr_IndexedMapOfOwner aSelectedOwners;
50 selection()->selectedOwners(aSelectedOwners);
52 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
53 for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) {
54 Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
55 if (aSelectedOwners.FindIndex(anOwner) > 0)
58 aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
62 //**************************************************************
63 void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
65 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
66 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
68 SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
70 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
71 for (; anIt.More(); anIt.Next()) {
72 Handle(SelectMgr_Filter) aFilter = anIt.Value();
73 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
74 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
75 if (!aFilter->IsOk(anOwner))
76 anOwnersToDeselect.Add(aContext->SelectedOwner());
80 setSelectedOwners(anOwnersToDeselect, false);
83 aContext->UpdateCurrentViewer();
86 //**************************************************************
87 void XGUI_SelectionMgr::onObjectBrowserSelection()
89 QObjectPtrList aObjects = myWorkshop->objectBrowser()->selectedObjects();
90 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
91 aDisplayer->setSelected(aObjects);
92 emit selectionChanged();
95 //**************************************************************
96 void XGUI_SelectionMgr::onViewerSelection()
98 QObjectPtrList aFeatures;
99 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
100 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
101 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
102 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
104 aFeatures.append(aResult);
106 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
107 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
108 myWorkshop->objectBrowser()->blockSignals(aBlocked);
110 emit selectionChanged();
113 //**************************************************************
114 void XGUI_SelectionMgr::clearSelection()
116 QObjectPtrList aFeatures;
117 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
118 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
119 myWorkshop->objectBrowser()->blockSignals(aBlocked);
121 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
122 aDisplayer->setSelected(aFeatures);
124 emit selectionChanged();