]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_SelectionMgr.cpp
Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[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 #include "XGUI_Selection.h"
10
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_AttributeDocRef.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Result.h>
16 #include <ModelAPI_Object.h>
17
18 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
19     : QObject(theParent),
20       myWorkshop(theParent)
21 {
22   mySelection = new XGUI_Selection(myWorkshop);
23 }
24
25 XGUI_SelectionMgr::~XGUI_SelectionMgr()
26 {
27   delete mySelection;
28 }
29
30 //**************************************************************
31 void XGUI_SelectionMgr::connectViewers()
32 {
33   connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), this,
34           SLOT(onObjectBrowserSelection()));
35
36   //Connect to other viewers
37   connect(myWorkshop->viewer(), SIGNAL(selectionChanged()), this, SLOT(onViewerSelection()));
38 }
39
40 //**************************************************************
41 void XGUI_SelectionMgr::onObjectBrowserSelection()
42 {
43   QList<ObjectPtr> aObjects = myWorkshop->objectBrowser()->selectedObjects();
44   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
45   aDisplayer->setSelected(aObjects);
46   emit selectionChanged();
47 }
48
49 //**************************************************************
50 void XGUI_SelectionMgr::onViewerSelection()
51 {
52   QList<ObjectPtr> aFeatures;
53   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
54   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
55     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
56     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
57     if (aResult)
58       aFeatures.append(aResult);
59   }
60   bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true);
61   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
62   myWorkshop->objectBrowser()->blockSignals(aBlocked);
63
64   emit selectionChanged();
65 }
66
67 //**************************************************************
68 /*QFeatureList XGUI_SelectionMgr::selectedFeatures() const 
69  { 
70  return myWorkshop->objectBrowser()->selectedFeatures(); 
71  }
72
73  //**************************************************************
74  QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
75  { 
76  return myWorkshop->objectBrowser()->selectedIndexes();
77  }
78
79  //**************************************************************
80  void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
81  {
82  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
83  theList.Clear();
84  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
85  theList.Append(aContext->SelectedInteractive());
86  }
87
88  //**************************************************************
89  void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
90  {
91  theList.Clear();
92  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
93  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
94  TopoDS_Shape aShape = aContext->SelectedShape();
95  if (!aShape.IsNull())
96  theList.Append(aShape);
97  }
98  }*/