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 <ModuleBase_ViewerPrs.h>
25 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
27 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
31 mySelection = new XGUI_Selection(myWorkshop);
34 XGUI_SelectionMgr::~XGUI_SelectionMgr()
39 //**************************************************************
40 void XGUI_SelectionMgr::connectViewers()
42 connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
43 SLOT(onObjectBrowserSelection()));
45 //Connect to other viewers
46 connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
49 //**************************************************************
50 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
53 SelectMgr_IndexedMapOfOwner aSelectedOwners;
54 selection()->selectedOwners(aSelectedOwners);
56 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
57 if (!aContext.IsNull()) {
58 for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) {
59 Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
60 if (aSelectedOwners.FindIndex(anOwner) > 0)
63 aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
68 //**************************************************************
69 void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
71 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
72 if (aContext.IsNull())
75 const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
77 SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
79 SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
80 for (; anIt.More(); anIt.Next()) {
81 Handle(SelectMgr_Filter) aFilter = anIt.Value();
82 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
83 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
84 if (!aFilter->IsOk(anOwner))
85 anOwnersToDeselect.Add(aContext->SelectedOwner());
89 setSelectedOwners(anOwnersToDeselect, false);
92 aContext->UpdateCurrentViewer();
95 //**************************************************************
96 void XGUI_SelectionMgr::onObjectBrowserSelection()
98 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
99 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
101 QList<ModuleBase_ViewerPrsPtr> aTmpList = aSelectedPrs;
104 foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) {
105 aObject = aPrs->object();
107 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
108 if (aFeature.get()) {
109 const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
110 std::list<ResultPtr>::const_iterator aIt;
111 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
112 aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
113 new ModuleBase_ViewerPrs((*aIt), GeomShapePtr(), NULL)));
118 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
119 aDisplayer->setSelected(aSelectedPrs);
120 emit selectionChanged();
123 //**************************************************************
124 void XGUI_SelectionMgr::onViewerSelection()
126 SessionPtr aMgr = ModelAPI_Session::get();
127 DocumentPtr anActiveDocument = aMgr->activeDocument();
128 QObjectPtrList aFeatures;
131 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
132 if (!aContext.IsNull()) {
133 QList<ModuleBase_ViewerPrsPtr> aPresentations = selection()->getSelected(ModuleBase_ISelection::Viewer);
134 foreach(ModuleBase_ViewerPrsPtr aPrs, aPresentations) {
135 if (aPrs->object().get()) {
136 aFeatures.append(aPrs->object());
137 if (aPrs->shape().get()) {
138 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
140 aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape());
141 if (aFeature.get() && (!aFeatures.contains(aFeature)))
142 aFeatures.append(aFeature);
148 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
149 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
150 myWorkshop->objectBrowser()->blockSignals(aBlocked);
152 emit selectionChanged();
155 //**************************************************************
156 void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace)
158 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
159 myWorkshop->selector()->selection()->getSelected(thePlace);
160 if (thePlace == ModuleBase_ISelection::Browser) {
161 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
162 aDisplayer->setSelected(aSelectedPrs);
166 //**************************************************************
167 void XGUI_SelectionMgr::clearSelection()
169 QObjectPtrList aFeatures;
170 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
171 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
172 myWorkshop->objectBrowser()->blockSignals(aBlocked);
174 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
175 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
177 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
178 aDisplayer->setSelected(aSelectedPrs);
180 emit selectionChanged();