Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.cpp
1 #include "XGUI_SelectionMgr.h"
2
3 #include "XGUI_Workshop.h"
4 #include "XGUI_MainWindow.h"
5 #include "XGUI_ObjectsBrowser.h"
6 #include "XGUI_SalomeConnector.h"
7 #include "XGUI_ViewerProxy.h"
8 #include "XGUI_Displayer.h"
9
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_PluginManager.h>
12 #include <ModelAPI_AttributeDocRef.h>
13 #include <ModelAPI_Data.h>
14
15
16
17 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
18   QObject(theParent), myWorkshop(theParent)
19 {
20 }
21
22 XGUI_SelectionMgr::~XGUI_SelectionMgr()
23 {
24 }
25
26 //**************************************************************
27 void XGUI_SelectionMgr::connectViewers()
28 {
29   connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), 
30     this, SLOT(onObjectBrowserSelection()));
31
32   //Connect to other viewers
33   connect(myWorkshop->viewer(), SIGNAL(selectionChanged()),
34     this, SLOT(onViewerSelection()));
35 }
36
37 //**************************************************************
38 void XGUI_SelectionMgr::onObjectBrowserSelection()
39 {
40   QFeatureList aFeatures = selectedFeatures();
41   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
42   aDisplayer->setSelected(aFeatures);
43
44   emit selectionChanged();
45 }
46
47 //**************************************************************
48 void XGUI_SelectionMgr::onViewerSelection()
49 {
50   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
51   QFeatureList aFeatures = aDisplayer->selectedFeatures();
52   myWorkshop->objectBrowser()->setFeaturesSelected(aFeatures);
53   emit selectionChanged();
54 }
55
56 //**************************************************************
57 QFeatureList XGUI_SelectionMgr::selectedFeatures() const 
58
59   return myWorkshop->objectBrowser()->selectedFeatures(); 
60 }
61
62 //**************************************************************
63 QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
64
65   return myWorkshop->objectBrowser()->selectedIndexes();
66 }
67
68 //**************************************************************
69 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
70 {
71   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
72   theList.Clear();
73   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
74     theList.Append(aContext->SelectedInteractive());
75 }
76
77 //**************************************************************
78 void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
79 {
80   theList.Clear();
81   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
82   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
83     TopoDS_Shape aShape = aContext->SelectedShape();
84     if (!aShape.IsNull())
85       theList.Append(aShape);
86   }
87 }