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_ViewerPrsPtr> aSelectedPrs =
97 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
99 QList<ModuleBase_ViewerPrsPtr> aTmpList = aSelectedPrs;
102 foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) {
103 aObject = aPrs->object();
105 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
106 if (aFeature.get()) {
107 const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
108 std::list<ResultPtr>::const_iterator aIt;
109 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
110 aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
111 new ModuleBase_ViewerPrs((*aIt), GeomShapePtr(), NULL)));
116 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
117 aDisplayer->setSelected(aSelectedPrs);
118 emit selectionChanged();
121 //**************************************************************
122 void XGUI_SelectionMgr::onViewerSelection()
124 SessionPtr aMgr = ModelAPI_Session::get();
125 DocumentPtr anActiveDocument = aMgr->activeDocument();
126 QObjectPtrList aFeatures;
129 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
130 if (!aContext.IsNull()) {
131 QList<ModuleBase_ViewerPrsPtr> aPresentations = selection()->getSelected(ModuleBase_ISelection::Viewer);
132 foreach(ModuleBase_ViewerPrsPtr aPrs, aPresentations) {
133 if (aPrs->object().get()) {
134 aFeatures.append(aPrs->object());
135 if (aPrs->shape().get()) {
136 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
138 aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape());
139 if (aFeature.get() && (!aFeatures.contains(aFeature)))
140 aFeatures.append(aFeature);
146 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
147 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
148 myWorkshop->objectBrowser()->blockSignals(aBlocked);
150 emit selectionChanged();
153 //**************************************************************
154 void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace)
156 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
157 myWorkshop->selector()->selection()->getSelected(thePlace);
158 if (thePlace == ModuleBase_ISelection::Browser) {
159 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
160 aDisplayer->setSelected(aSelectedPrs);
164 //**************************************************************
165 void XGUI_SelectionMgr::clearSelection()
167 QObjectPtrList aFeatures;
168 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
169 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
170 myWorkshop->objectBrowser()->blockSignals(aBlocked);
172 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
173 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
175 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
176 aDisplayer->setSelected(aSelectedPrs);
178 emit selectionChanged();