1 #include "XGUI_SelectionMgr.h"
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"
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>
20 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
21 QObject(theParent), myWorkshop(theParent)
23 mySelection = new XGUI_Selection(myWorkshop);
26 XGUI_SelectionMgr::~XGUI_SelectionMgr()
31 //**************************************************************
32 void XGUI_SelectionMgr::connectViewers()
34 connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()),
35 this, SLOT(onObjectBrowserSelection()));
37 //Connect to other viewers
38 connect(myWorkshop->viewer(), SIGNAL(selectionChanged()),
39 this, SLOT(onViewerSelection()));
42 //**************************************************************
43 void XGUI_SelectionMgr::onObjectBrowserSelection()
45 QList<ObjectPtr> aObjects = myWorkshop->objectBrowser()->selectedObjects();
47 foreach(ObjectPtr aObject, aObjects) {
48 ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
50 aResults.append(aRes);
52 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
53 aDisplayer->setSelected(aResults);
54 emit selectionChanged();
57 //**************************************************************
58 void XGUI_SelectionMgr::onViewerSelection()
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);
66 aFeatures.append(aResult);
68 myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
69 emit selectionChanged();
72 //**************************************************************
73 /*QFeatureList XGUI_SelectionMgr::selectedFeatures() const
75 return myWorkshop->objectBrowser()->selectedFeatures();
78 //**************************************************************
79 QModelIndexList XGUI_SelectionMgr::selectedIndexes() const
81 return myWorkshop->objectBrowser()->selectedIndexes();
84 //**************************************************************
85 void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
87 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
89 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
90 theList.Append(aContext->SelectedInteractive());
93 //**************************************************************
94 void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
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);