From 1830bb208eb1c4a9e094e960407ab653b64f0c5a Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Thu, 29 Jan 2015 15:07:20 +0100 Subject: [PATCH] WindowManager are referenced to by an ID instead of the string. --- idl/gepetto/viewer/graphical-interface.idl | 7 ++-- include/gepetto/viewer/corba/client.hh | 6 ++-- src/client-cpp.cc | 6 ++-- src/graphical-interface.impl.cpp | 38 +++++++++------------- src/graphical-interface.impl.hh | 10 +++--- src/test-client-cpp.cc | 4 +-- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl index 16377b7..90ef3cd 100644 --- a/idl/gepetto/viewer/graphical-interface.idl +++ b/idl/gepetto/viewer/graphical-interface.idl @@ -34,7 +34,8 @@ typedef double Color [4]; /// Create a new window. /// \param input name : name of the new window. - boolean createWindow(in string name) raises (Error); + /// return the ID of the newly create window. + unsigned long createWindow(in string name) raises (Error); /// Print names of nodes on the SceneViewer-corbaserver terminal. @@ -54,8 +55,8 @@ typedef double Color [4]; /// Add groupNode sceneName to the WindowManager windowName so /// sceneName and all its children will be displayed in the window windowName. /// \param input sceneName : name of the groupNode. - /// \param input windowName : name of rhe window. - boolean addSceneToWindow(in string sceneName, in string windowName) raises (Error); + /// \param input windowId : ID of rhe window. + boolean addSceneToWindow(in string sceneName, in unsigned long windowId) raises (Error); /// create a box called boxName. /// \param input boxName : name of the box. diff --git a/include/gepetto/viewer/corba/client.hh b/include/gepetto/viewer/corba/client.hh index 7f98e15..2b7aa18 100644 --- a/include/gepetto/viewer/corba/client.hh +++ b/include/gepetto/viewer/corba/client.hh @@ -29,6 +29,8 @@ private: protected: public: + typedef CORBA::ULong WindowID; + // Default constructor ClientCpp(); // Default destructor @@ -40,14 +42,14 @@ public: bool setRate(int rate); void refresh(); - bool createWindow(const char* windowName); + WindowID createWindow(const char* windowName); //void createWindow(const char* name, CORBA::ULong x, CORBA::ULong y, CORBA::ULong width, CORBA::ULong height) ; void createScene(const char* sceneName) ; void createSceneWithFloor(const char* sceneName) ; - bool addSceneToWindow(const char* sceneName, const char* windowName) ; + bool addSceneToWindow(const char* sceneName, const WindowID windowId) ; bool addBox(const char* boxName, const float boxSize1, const float boxSize2, const float boxSize3, const double* color); diff --git a/src/client-cpp.cc b/src/client-cpp.cc index e28c8d1..395e6f0 100644 --- a/src/client-cpp.cc +++ b/src/client-cpp.cc @@ -82,7 +82,7 @@ void ClientCpp::refresh() manager_->refresh(); } -bool ClientCpp::createWindow(const char* windowName) +ClientCpp::WindowID ClientCpp::createWindow(const char* windowName) { return manager_->createWindow(windowName); } @@ -100,9 +100,9 @@ void ClientCpp::createSceneWithFloor(const char* sceneName) manager_->createSceneWithFloor(sceneName); } -bool ClientCpp::addSceneToWindow(const char* sceneName, const char* windowName) +bool ClientCpp::addSceneToWindow(const char* sceneName, const ClientCpp::WindowID windowId) { - return manager_->addSceneToWindow(sceneName, windowName); + return manager_->addSceneToWindow(sceneName, windowId); } /*bool ClientCpp::addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3) diff --git a/src/graphical-interface.impl.cpp b/src/graphical-interface.impl.cpp index 6592050..5907fc8 100644 --- a/src/graphical-interface.impl.cpp +++ b/src/graphical-interface.impl.cpp @@ -173,24 +173,18 @@ namespace graphics { } } - bool GraphicalInterface::createWindow (const char* windowNameCorba) + GraphicalInterface::WindowID GraphicalInterface::createWindow (const char* windowNameCorba) throw (Error) { try { std::string windowName (windowNameCorba); - if (windowManagers_.find (windowName) != windowManagers_.end ()) { - std::cout << "You need to chose an other name, \"" << windowName - << "\" already exist." << std::endl; - return false; - } - else { - WindowManagerPtr_t newWindow = WindowManager::create (); - windowManagers_[windowName] = newWindow; - boost::thread refreshThread (boost::bind - (&GraphicalInterface::threadRefreshing, - this, newWindow)); - return true; - } + WindowManagerPtr_t newWindow = WindowManager::create (); + WindowID windowId = windowManagers_.size (); + windowManagers_.push_back (newWindow); + boost::thread refreshThread (boost::bind + (&GraphicalInterface::threadRefreshing, + this, newWindow)); + return windowId; } catch (const std::exception& exc) { throw Error (exc.what ()); } @@ -257,19 +251,18 @@ namespace graphics { } bool GraphicalInterface::addSceneToWindow (const char* sceneNameCorba, - const char* windowNameCorba) + WindowID windowId) throw (Error) { try { std::string sceneName (sceneNameCorba); - std::string windowName (windowNameCorba); - if (windowManagers_.find (windowName) != windowManagers_.end () && + if ((windowId >= 0 || windowId < windowManagers_.size ()) && groupNodes_.find (sceneName) != groupNodes_.end () ) { - windowManagers_[windowName]->addNode (groupNodes_[sceneName]); + windowManagers_[windowId]->addNode (groupNodes_[sceneName]); return true; } else { - std::cout << "Window name \"" << windowName + std::cout << "Window ID \"" << windowId << "\" and/or scene name \"" << sceneName << "\" doesn't exist." << std::endl; return false; @@ -536,9 +529,10 @@ namespace graphics { { try { std::cout << "List of Windows :" << std::endl; - for (std::map<std::string, WindowManagerPtr_t>::iterator it= - windowManagers_.begin (); it!=windowManagers_.end (); ++it) - std::cout << " " << it->first << std::endl; + size_t rank = 0; + for (WindowManagers_t::iterator it = windowManagers_.begin (); + it!=windowManagers_.end (); ++it) + std::cout << rank << " - " << (*it)->getViewerClone ()->getSlave (0)._camera->getGraphicsContext ()->getTraits ()->windowName << std::endl; } catch (const std::exception& exc) { throw Error (exc.what ()); } diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh index b02fef2..b7a6f18 100644 --- a/src/graphical-interface.impl.hh +++ b/src/graphical-interface.impl.hh @@ -46,8 +46,10 @@ class GraphicalInterface : public virtual POA_gepetto::corbaserver::GraphicalInterface { private: - typedef gepetto::Error Error; - std::map<std::string, WindowManagerPtr_t> windowManagers_; + typedef gepetto::Error Error; + typedef CORBA::ULong WindowID; + typedef std::vector <WindowManagerPtr_t> WindowManagers_t; + WindowManagers_t windowManagers_; std::map<std::string, NodePtr_t> nodes_; std::map<std::string, GroupNodePtr_t> groupNodes_; corbaServer::Server* server_; @@ -82,11 +84,11 @@ public: virtual bool setRate(CORBA::Long rate) throw (Error); virtual void refresh() throw (Error); - virtual bool createWindow(const char* windowNameCorba) throw (Error); + virtual WindowID createWindow(const char* windowNameCorba) throw (Error); virtual void createScene(const char* sceneNameCorba) throw (Error); virtual void createSceneWithFloor(const char* sceneNameCorba) throw (Error); - virtual bool addSceneToWindow(const char* sceneNameCorba, const char* windowNameCorba) throw (Error); + virtual bool addSceneToWindow(const char* sceneNameCorba, const WindowID windowId) throw (Error); virtual bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3, const double* color) throw (Error); diff --git a/src/test-client-cpp.cc b/src/test-client-cpp.cc index 15f0fe6..8690b2f 100644 --- a/src/test-client-cpp.cc +++ b/src/test-client-cpp.cc @@ -22,9 +22,9 @@ int main(int, const char **) se3::SE3 position4 = se3::SE3::Random(); se3::SE3 position5 = se3::SE3::Random(); - client.createWindow("window1"); + ClientCpp::WindowID windowId = client.createWindow("window1"); client.createScene("scene1"); - client.addSceneToWindow("scene1","window1"); + client.addSceneToWindow("scene1",windowId); client.addURDF("scene1/hrp2", "/local/mgeisert/devel/src/hrp2/hrp2_14_description/urdf/hrp2_14_capsule.urdf", "/local/mgeisert/devel/src/hrp2/"); sleep(5); -- GitLab