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