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 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
25 mySelection = new XGUI_Selection(myWorkshop);
28 XGUI_SelectionMgr::~XGUI_SelectionMgr()
33 //**************************************************************
34 void XGUI_SelectionMgr::connectViewers()
36 connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
37 SLOT(onObjectBrowserSelection()));
39 //Connect to other viewers
40 connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
43 //**************************************************************
44 void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
47 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
48 for (Standard_Integer i = 1, n = theSelectedOwners.Extent(); i <= n; i++) {
49 aContext->AddOrRemoveSelected(theSelectedOwners(i), isUpdateViewer);
53 //**************************************************************
54 void XGUI_SelectionMgr::onObjectBrowserSelection()
56 QObjectPtrList aObjects = myWorkshop->objectBrowser()->selectedObjects();
57 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
58 aDisplayer->setSelected(aObjects);
59 emit selectionChanged();
62 //**************************************************************
63 void XGUI_SelectionMgr::onViewerSelection()
65 QObjectPtrList aFeatures;
66 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
67 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
68 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
69 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
71 aFeatures.append(aResult);
73 bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
74 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
75 myWorkshop->objectBrowser()->blockSignals(aBlocked);
77 emit selectionChanged();
80 //**************************************************************
81 /*QFeatureList XGUI_SelectionMgr::selectedFeatures() const
83 return myWorkshop->objectBrowser()->selectedFeatures();
86 //**************************************************************
87 QModelIndexList XGUI_SelectionMgr::selectedIndexes() const
89 return myWorkshop->objectBrowser()->selectedIndexes();
92 //**************************************************************
93 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
95 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
97 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
98 theList.Append(aContext->SelectedInteractive());
101 //**************************************************************
102 void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
105 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
106 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
107 TopoDS_Shape aShape = aContext->SelectedShape();
108 if (!aShape.IsNull())
109 theList.Append(aShape);