Salome HOME
GeomAPI_IPresentation in terface created
[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_PluginManager.h>
13 #include <ModelAPI_AttributeDocRef.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Result.h>
16 #include <ModelAPI_Object.h>
17
18
19
20 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
21   QObject(theParent), 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()), 
35     this, SLOT(onObjectBrowserSelection()));
36
37   //Connect to other viewers
38   connect(myWorkshop->viewer(), SIGNAL(selectionChanged()),
39     this, SLOT(onViewerSelection()));
40 }
41
42 //**************************************************************
43 void XGUI_SelectionMgr::onObjectBrowserSelection()
44 {
45   QList<ObjectPtr> aObjects = myWorkshop->objectBrowser()->selectedObjects();
46   QResultList aResults;
47   foreach(ObjectPtr aObject, aObjects) {
48     ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
49     if (aRes)
50       aResults.append(aRes);
51   }
52   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
53   aDisplayer->setSelected(aResults);
54   emit selectionChanged();
55 }
56
57 //**************************************************************
58 void XGUI_SelectionMgr::onViewerSelection()
59 {
60   QList<ObjectPtr> aFeatures;
61   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
62   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
63     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
64     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
65     if (aResult)
66       aFeatures.append(aResult);
67   }
68   myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
69   emit selectionChanged();
70 }
71
72 //**************************************************************
73 /*QFeatureList XGUI_SelectionMgr::selectedFeatures() const 
74
75   return myWorkshop->objectBrowser()->selectedFeatures(); 
76 }
77
78 //**************************************************************
79 QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
80
81   return myWorkshop->objectBrowser()->selectedIndexes();
82 }
83
84 //**************************************************************
85 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
86 {
87   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
88   theList.Clear();
89   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
90     theList.Append(aContext->SelectedInteractive());
91 }
92
93 //**************************************************************
94 void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
95 {
96   theList.Clear();
97   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
98   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
99     TopoDS_Shape aShape = aContext->SelectedShape();
100     if (!aShape.IsNull())
101       theList.Append(aShape);
102   }
103 }*/