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"
11 #include "XGUI_OperationMgr.h"
14 #include <AppElements_MainWindow.h>
17 #include <ModelAPI_Feature.h>
18 #include <ModelAPI_Session.h>
19 #include <ModelAPI_AttributeDocRef.h>
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_Result.h>
22 #include <ModelAPI_Object.h>
23 #include <ModelAPI_ResultCompSolid.h>
25 #include <ModuleBase_ViewerPrs.h>
26 #include <ModuleBase_Tools.h>
28 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
31 #include <VInspectorAPI_CallBack.hxx>
34 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
38 mySelection = new XGUI_Selection(myWorkshop);
41 XGUI_SelectionMgr::~XGUI_SelectionMgr()
46 //**************************************************************
47 void XGUI_SelectionMgr::connectViewers()
49 connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
50 SLOT(onObjectBrowserSelection()));
52 //Connect to other viewers
53 connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
56 //**************************************************************
57 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
60 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
61 if (!aContext.IsNull()) {
62 /// previous selection should be cleared, else there will be decomposition of selections:
63 /// as AddOrRemoveSelected inverts current selection
64 aContext->ClearSelected(false);
66 for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) {
67 Handle(SelectMgr_EntityOwner) anOwner = theSelectedOwners(i);
69 aContext->AddOrRemoveSelected(anOwner, isUpdateViewer);
71 if (myWorkshop->displayer()->getCallBack())
72 myWorkshop->displayer()->getCallBack()->AddOrRemoveSelected(anOwner);
78 //**************************************************************
79 void XGUI_SelectionMgr::onObjectBrowserSelection()
81 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
82 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
84 QList<ModuleBase_ViewerPrsPtr> aTmpList = aSelectedPrs;
87 foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) {
88 aObject = aPrs->object();
90 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
92 const std::list<std::shared_ptr<ModelAPI_Result>> aResList = aFeature->results();
94 ResultCompSolidPtr aCompSolid;
95 std::list<ResultPtr>::const_iterator aIt;
96 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
98 aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
99 new ModuleBase_ViewerPrs(aResult, GeomShapePtr(), NULL)));
100 aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
101 if (aCompSolid.get()) {
102 for (int i = 0; i < aCompSolid->numberOfSubs(); i++) {
103 ResultBodyPtr aResult = aCompSolid->subResult(i);
104 aSelectedPrs.append(std::shared_ptr<ModuleBase_ViewerPrs>(
105 new ModuleBase_ViewerPrs(aResult, aResult->shape(), NULL)));
112 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
113 aDisplayer->setSelected(aSelectedPrs);
114 emit selectionChanged();
117 //**************************************************************
118 void XGUI_SelectionMgr::onViewerSelection()
120 SessionPtr aMgr = ModelAPI_Session::get();
121 DocumentPtr anActiveDocument = aMgr->activeDocument();
122 QObjectPtrList aFeatures;
125 bool aHasOperation = (myWorkshop->operationMgr()->currentOperation() != 0);
126 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
127 if (!aContext.IsNull()) {
128 QList<ModuleBase_ViewerPrsPtr> aPresentations =
129 selection()->getSelected(ModuleBase_ISelection::Viewer);
130 foreach(ModuleBase_ViewerPrsPtr aPrs, aPresentations) {
131 if (aPrs->object().get()) {
132 if (!aFeatures.contains(aPrs->object()))
133 aFeatures.append(aPrs->object());
134 if (aPrs->shape().get() && (!aHasOperation)) {
135 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
137 aFeature = anActiveDocument->producedByFeature(aResult, aPrs->shape());
138 if (aFeature.get() && (!aFeatures.contains(aFeature)))
139 aFeatures.append(aFeature);
145 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
146 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
147 myWorkshop->objectBrowser()->blockSignals(aBlocked);
149 emit selectionChanged();
152 //**************************************************************
153 void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace)
155 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
156 myWorkshop->selector()->selection()->getSelected(thePlace);
157 if (thePlace == ModuleBase_ISelection::Browser) {
158 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
159 aDisplayer->setSelected(aSelectedPrs);
163 //**************************************************************
164 void XGUI_SelectionMgr::clearSelection()
166 QObjectPtrList aFeatures;
167 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
168 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
169 myWorkshop->objectBrowser()->blockSignals(aBlocked);
171 QList<ModuleBase_ViewerPrsPtr> aSelectedPrs =
172 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser);
174 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
175 aDisplayer->setSelected(aSelectedPrs);
177 emit selectionChanged();