Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.cpp
index 6421d278b62bcd816a9999d6ae99cc485ea1196c..f949c782a5a4b4a7ca17f5440ef2a7513a1cc441 100644 (file)
@@ -2,6 +2,9 @@
 #include "XGUI_Workshop.h"
 #include "XGUI_MainWindow.h"
 #include "XGUI_ObjectsBrowser.h"
+#include "XGUI_Viewer.h"
+#include "XGUI_SalomeConnector.h"
+#include "XGUI_ViewerProxy.h"
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_PluginManager.h>
@@ -15,30 +18,71 @@ XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) :
 {
 }
 
-void XGUI_SelectionMgr::connectObjectBrowser(XGUI_ObjectsBrowser* theOB)
+XGUI_SelectionMgr::~XGUI_SelectionMgr()
 {
-  myObjectBrowser = theOB;
-  connect(myObjectBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
 }
 
-XGUI_SelectionMgr::~XGUI_SelectionMgr()
+//**************************************************************
+void XGUI_SelectionMgr::connectViewers()
 {
+  connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), 
+    this, SLOT(onObjectBrowserSelection()));
+
+  //Connect to other viewers
+  if (myWorkshop->isSalomeMode()) {
+    connect(myWorkshop, SIGNAL(salomeViewerSelection()),
+      this, SLOT(onViewerSelection()));
+  } else {
+    connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+      this, SLOT(onViewerSelection()));
+  }
 }
 
-void XGUI_SelectionMgr::onSelectionChanged()
+//**************************************************************
+void XGUI_SelectionMgr::onObjectBrowserSelection()
 {
-  XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->mainWindow()->objectBrowser();
-  mySelectedData = aObjBrowser->selectedData();
-  
-  // Set current document
-  if (mySelectedData.size() > 0) {
-    FeaturePtr aFeature = mySelectedData.first();
-
-    boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
-    boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
-    if (aDocRef)
-      aMgr->setCurrentDocument(aDocRef->value());
-  }
+
+  // TODO: Highliht selected objects in Viewer 3d
 
   emit selectionChanged();
-}
\ No newline at end of file
+}
+
+//**************************************************************
+void XGUI_SelectionMgr::onViewerSelection()
+{
+  // TODO: Highliht selected objects in Object Browser
+  emit selectionChanged();
+}
+
+//**************************************************************
+QFeatureList XGUI_SelectionMgr::selectedFeatures() const 
+{ 
+  return myWorkshop->objectBrowser()->selectedFeatures(); 
+}
+
+//**************************************************************
+QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
+{ 
+  return myWorkshop->objectBrowser()->selectedIndexes();
+}
+
+//**************************************************************
+void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const
+{
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  theList.Clear();
+  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
+    theList.Append(aContext->SelectedInteractive());
+}
+
+//**************************************************************
+void XGUI_SelectionMgr::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
+{
+  theList.Clear();
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+    TopoDS_Shape aShape = aContext->SelectedShape();
+    if (!aShape.IsNull())
+      theList.Append(aShape);
+  }
+}