Salome HOME
Using of SelectionMgr instead of using Viewer directly in Sketcher starting operation
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.cpp
1 #include "XGUI_SelectionMgr.h"
2 #include "XGUI_Workshop.h"
3 #include "XGUI_MainWindow.h"
4 #include "XGUI_ObjectsBrowser.h"
5 #include "XGUI_Viewer.h"
6 #include "XGUI_SalomeConnector.h"
7
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_PluginManager.h>
10 #include <ModelAPI_AttributeDocRef.h>
11 #include <ModelAPI_Data.h>
12
13
14
15 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
16   QObject(theParent), myWorkshop(theParent)
17 {
18 }
19
20 XGUI_SelectionMgr::~XGUI_SelectionMgr()
21 {
22 }
23
24 //**************************************************************
25 void XGUI_SelectionMgr::connectViewers()
26 {
27   connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), 
28     this, SLOT(onObjectBrowserSelection()));
29
30   //Connect to other viewers
31   if (myWorkshop->isSalomeMode()) {
32     connect(myWorkshop, SIGNAL(salomeViewerSelection()),
33       this, SLOT(onViewerSelection()));
34   } else {
35     connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
36       this, SLOT(onViewerSelection()));
37   }
38 }
39
40 //**************************************************************
41 void XGUI_SelectionMgr::onObjectBrowserSelection()
42 {
43
44   // TODO: Highliht selected objects in Viewer 3d
45
46   emit selectionChanged();
47 }
48
49 //**************************************************************
50 void XGUI_SelectionMgr::onViewerSelection()
51 {
52   emit selectionChanged();
53 }
54
55 //**************************************************************
56 QFeatureList XGUI_SelectionMgr::selectedFeatures() const 
57
58   return myWorkshop->objectBrowser()->selectedFeatures(); 
59 }
60
61 //**************************************************************
62 QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
63
64   return myWorkshop->objectBrowser()->selectionModel()->selectedIndexes();
65 }
66
67 //**************************************************************
68 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
69 {
70   if (myWorkshop->isSalomeMode()) {
71     Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext();
72     theList.Clear();
73     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
74       theList.Append(aContext->SelectedInteractive());
75   } else {
76     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
77     aViewer->getSelectedObjects(theList);
78   }
79 }
80
81 //**************************************************************
82 void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
83 {
84   if (myWorkshop->isSalomeMode()) {
85     theList.Clear();
86     Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext();
87     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
88       TopoDS_Shape aShape = aContext->SelectedShape();
89       if (!aShape.IsNull())
90         theList.Append(aShape);
91     }
92   } else {
93     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
94     aViewer->getSelectedShapes(theList);
95   }
96 }