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"
13 #include <AppElements_MainWindow.h>
16 #include <ModelAPI_Feature.h>
17 #include <ModelAPI_Session.h>
18 #include <ModelAPI_AttributeDocRef.h>
19 #include <ModelAPI_Data.h>
20 #include <ModelAPI_Result.h>
21 #include <ModelAPI_Object.h>
23 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
25 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
29 mySelection = new XGUI_Selection(myWorkshop);
32 XGUI_SelectionMgr::~XGUI_SelectionMgr()
37 //**************************************************************
38 void XGUI_SelectionMgr::connectViewers()
40 connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
41 SLOT(onObjectBrowserSelection()));
43 //Connect to other viewers
44 connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
47 //**************************************************************
48 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
51 SelectMgr_IndexedMapOfOwner aSelectedOwners;
52 selection()->selectedOwners(aSelectedOwners);
54 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
55 if (!aContext.IsNull()) {
56 for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) {
57 Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
58 if (aSelectedOwners.FindIndex(anOwner) > 0)
61 aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
66 //**************************************************************
67 void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
69 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
70 if (aContext.IsNull())
73 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
75 SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
77 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
78 for (; anIt.More(); anIt.Next()) {
79 Handle(SelectMgr_Filter) aFilter = anIt.Value();
80 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
81 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
82 if (!aFilter->IsOk(anOwner))
83 anOwnersToDeselect.Add(aContext->SelectedOwner());
87 setSelectedOwners(anOwnersToDeselect, false);
90 aContext->UpdateCurrentViewer();
93 //**************************************************************
94 void XGUI_SelectionMgr::onObjectBrowserSelection()
96 QList<ModuleBase_ViewerPrs> aSelectedPrs =
97 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
99 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
100 aDisplayer->setSelected(aSelectedPrs);
101 emit selectionChanged();
104 //**************************************************************
105 void XGUI_SelectionMgr::onViewerSelection()
107 QObjectPtrList aFeatures;
108 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
109 if (!aContext.IsNull()) {
110 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
111 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
112 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
114 aFeatures.append(aResult);
117 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
118 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
119 myWorkshop->objectBrowser()->blockSignals(aBlocked);
121 emit selectionChanged();
124 //**************************************************************
125 void XGUI_SelectionMgr::clearSelection()
127 QObjectPtrList aFeatures;
128 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
129 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
130 myWorkshop->objectBrowser()->blockSignals(aBlocked);
132 QList<ModuleBase_ViewerPrs> aSelectedPrs =
133 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
135 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
136 aDisplayer->setSelected(aSelectedPrs);
138 emit selectionChanged();