From e29a3ba22d80d05a6b2a7149f599e62e9f5cac78 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Wed, 25 Mar 2015 16:44:47 +0100
Subject: [PATCH] Add GraphicalInterface::getWindowID.

---
 idl/gepetto/viewer/graphical-interface.idl |  1 +
 src/graphical-interface.impl.cpp           | 15 +++++++++++++++
 src/graphical-interface.impl.hh            |  3 +++
 3 files changed, 19 insertions(+)

diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl
index 1e5de67..ea05421 100644
--- a/idl/gepetto/viewer/graphical-interface.idl
+++ b/idl/gepetto/viewer/graphical-interface.idl
@@ -36,6 +36,7 @@ typedef double Color [4];
     /// \param input name : name of the new window.
     /// return the ID of the newly create window.
     unsigned long createWindow(in string name) raises (Error);
+    unsigned long getWindowID (in string name) raises (Error);
 
 
     /// Print names of nodes on the SceneViewer-corbaserver terminal.
diff --git a/src/graphical-interface.impl.cpp b/src/graphical-interface.impl.cpp
index 4b42c2e..5d3bcfc 100644
--- a/src/graphical-interface.impl.cpp
+++ b/src/graphical-interface.impl.cpp
@@ -180,6 +180,7 @@ namespace graphics {
 	  std::string windowName (windowNameCorba);
           WindowManagerPtr_t newWindow = WindowManager::create ();
           WindowID windowId = windowManagers_.size ();
+          windowIDmap_ [windowNameCorba] = windowId;
           windowManagers_.push_back (newWindow);
           boost::thread refreshThread (boost::bind
               (&GraphicalInterface::threadRefreshing,
@@ -190,6 +191,20 @@ namespace graphics {
 	}
       }
 
+      GraphicalInterface::WindowID GraphicalInterface::getWindowID (const char* windowNameCorba)
+	throw (Error)
+      {
+	try {
+	  std::string windowName (windowNameCorba);
+          WindowIDMap_t::iterator it = windowIDmap_.find (windowName);
+          if (it == windowIDmap_.end ())
+            throw Error ("There is no windows with that name");
+          return it->second;
+	} catch (const std::exception& exc) {
+	  throw Error (exc.what ());
+	}
+      }
+
       void GraphicalInterface::refresh () throw (Error)
       {
 	try {
diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh
index 628b1e0..d754acf 100644
--- a/src/graphical-interface.impl.hh
+++ b/src/graphical-interface.impl.hh
@@ -49,7 +49,9 @@ private:
     typedef gepetto::Error Error;
     typedef CORBA::ULong WindowID;
     typedef std::vector <WindowManagerPtr_t> WindowManagers_t;
+    typedef std::map <std::string, WindowID> WindowIDMap_t;
     WindowManagers_t windowManagers_;
+    WindowIDMap_t windowIDmap_;
     std::map<std::string, NodePtr_t> nodes_;
     std::map<std::string, GroupNodePtr_t> groupNodes_;
     corbaServer::Server* server_;
@@ -85,6 +87,7 @@ public:
   virtual void refresh() throw (Error);
 
   virtual WindowID createWindow(const char* windowNameCorba) throw (Error);
+  virtual WindowID getWindowID (const char* windowNameCorba) throw (Error);
 
   virtual void createScene(const char* sceneNameCorba)  throw (Error);
   virtual void createSceneWithFloor(const char* sceneNameCorba)  throw (Error);
-- 
GitLab