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