From 432fb6276699a7c127cb99b55a420ec68b81be77 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Sat, 23 May 2015 21:21:43 +0200 Subject: [PATCH] Add class Client and make class ClientCpp deprecated. --- cmake | 2 +- idl/gepetto/viewer/graphical-interface.idl | 1 + include/gepetto/viewer/corba/client.hh | 24 +++++++- src/CMakeLists.txt | 22 ++----- src/client.cc | 68 ++++++++++++++++++++++ src/graphical-interface.impl.hh | 2 +- src/test-client-cpp.cc | 43 ++++++++++---- 7 files changed, 131 insertions(+), 31 deletions(-) create mode 100644 src/client.cc diff --git a/cmake b/cmake index a831f54..271ca4f 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit a831f5403a93b67c6cb8675625e79dd676a565f3 +Subproject commit 271ca4fb6fe78a3f8e2473e095d0f99a7f25e205 diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl index f871956..4e4cbe1 100644 --- a/idl/gepetto/viewer/graphical-interface.idl +++ b/idl/gepetto/viewer/graphical-interface.idl @@ -23,6 +23,7 @@ module corbaserver { typedef float Transform [7]; typedef float Position [3]; typedef float Color [4]; +typedef unsigned long WindowID; /// Corba exception travelling through the Corba channel interface GraphicalInterface { diff --git a/include/gepetto/viewer/corba/client.hh b/include/gepetto/viewer/corba/client.hh index b8f646d..e87a089 100644 --- a/include/gepetto/viewer/corba/client.hh +++ b/include/gepetto/viewer/corba/client.hh @@ -11,13 +11,35 @@ #include <iostream> #include <omniORB4/CORBA.h> +#include <gepetto/viewer/corba/deprecated.hh> #include <gepetto/viewer/corba/se3.hh> #include <gepetto/viewer/corba/graphical-interface.hh> namespace graphics { namespace corbaServer { + class Client + { + public: + typedef CORBA::ULong WindowID; + Client (int argc, char* argv[]); + + ~Client (); + + void connect (const char* iiop = "corbaloc:rir:/NameService"); + + gepetto::corbaserver::GraphicalInterface_var& gui () { + return gui_; + } + + private: + gepetto::corbaserver::GraphicalInterface_var gui_; + + CORBA::ORB_var orb_; + }; + +/// \deprecated Use class Client instead. class ClientCpp { private: @@ -89,7 +111,7 @@ public: bool startCapture (const WindowID windowId, const char* filename, const char* extension); bool stopCapture (const WindowID windowId); bool writeNodeFile (const WindowID windowId, const char* filename); -}; //end of class ClientCpp +} GEPETTO_VIEWER_CORBA_DEPRECATED; //end of class ClientCpp } //end of namespace corbaserver } //end of namespace graphics diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 57afced..7b16b08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,16 +29,17 @@ ENDFOREACH() ADD_LIBRARY(${LIBRARY_NAME} SHARED - graphical-interfaceSK.cc graphical-interface.impl.cpp graphical-interface.impl.hh windows-manager.cpp server.cc + client.cc server-private.cc server-private.hh client-cpp.cc ${CMAKE_CURRENT_BINARY_DIR}/gepetto/corbaserver/graphical-interface_idl.py ${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba/graphical-interface.hh + ${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba/graphical-interfaceSK.cc ) PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} omniORB4) @@ -63,23 +64,11 @@ FOREACH (IDL ${IDL_SOURCES}) MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/idl/gepetto/viewer/${IDL}.idl ) - ADD_CUSTOM_COMMAND( - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba/${IDL}.hh - COMMAND ${OMNIIDL} - ARGS -bcxx -C${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba - -I${CMAKE_SOURCE_DIR}/idl - ${CMAKE_SOURCE_DIR}/idl/gepetto/viewer/${IDL}.idl - MAIN_DEPENDENCY - ${CMAKE_SOURCE_DIR}/idl/gepetto/viewer/${IDL}.idl - ) SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_BINARY_DIR}/${IDL}_idl.py - ${CMAKE_CURRENT_BINARY_DIR}/${IDL}.hh - ${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba/${IDL}.hh - GENERATED=ON + PROPERTIES GENERATED ON ) - INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${IDL}.hh + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba/${IDL}.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gepetto/viewer/corba) STRING(REGEX REPLACE "-" "_" @@ -114,7 +103,8 @@ INSTALL( DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/idl/gepetto/corbaserver ) -INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/graphical-interface.hh +INSTALL (FILES + ${CMAKE_CURRENT_BINARY_DIR}/gepetto/viewer/corba/graphical-interface.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gepetto/viewer/corba ) diff --git a/src/client.cc b/src/client.cc new file mode 100644 index 0000000..b591749 --- /dev/null +++ b/src/client.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2015, Joseph Mirabel +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of gepetto-viewer-corba. +// gepetto-viewer-corba is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// gepetto-viewer-corba is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// gepetto-viewer-corba. If not, see <http://www.gnu.org/licenses/>. + +#include "gepetto/viewer/corba/client.hh" + +#include <iostream> + +namespace graphics { + namespace corbaServer { + using CORBA::Exception; + using CORBA::Object_var; + using CORBA::SystemException; + using CORBA::ORB_init; + using CORBA::PolicyList; + using omniORB::fatalException; + + Client::Client(int argc, char *argv[]) : + orb_ (CORBA::ORB_init (argc, argv)) + { + } + + void Client::connect (const char* iiop) + { + // Get a reference to the Naming Service + CORBA::Object_var rootContextObj = orb_->string_to_object(iiop); + CosNaming::NamingContext_var nc = + CosNaming::NamingContext::_narrow(rootContextObj.in()); + + // Bind robotObj with name Robot to the hppContext: + CosNaming::Name name; + name.length(2); + name[0].id = (const char *) "gepetto"; + name[0].kind = (const char *) "viewer"; + name[1].id = (const char *) "corbaserver"; + name[1].kind = (const char *) "gui"; + // Invoke the root context to retrieve the object reference + CORBA::Object_var managerObj = nc->resolve(name); + // Narrow the previous object to obtain the correct type + gui_ = gepetto::corbaserver::GraphicalInterface::_narrow(managerObj.in()); + } + + /// \brief Shutdown CORBA server + Client::~Client() + { + if (!CORBA::is_nil(orb_)) { + try { + orb_->destroy(); + std::cout << "Ending CORBA..." << std::endl; + } catch(const CORBA::Exception& e) { + std::cout << "orb->destroy failed" << std::endl; + } + } + } + } // end of namespace corbaServer. +} // end of namespace graphics. diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh index 04e806a..b27110b 100644 --- a/src/graphical-interface.impl.hh +++ b/src/graphical-interface.impl.hh @@ -12,7 +12,7 @@ #include <omniORB4/CORBA.h> #include "gepetto/viewer/corba/server.hh" -#include "graphical-interface.hh" +#include "gepetto/viewer/corba/graphical-interface.hh" namespace graphics { namespace corbaServer { diff --git a/src/test-client-cpp.cc b/src/test-client-cpp.cc index 4dfb52e..0e59fcc 100644 --- a/src/test-client-cpp.cc +++ b/src/test-client-cpp.cc @@ -8,24 +8,38 @@ #include <gepetto/viewer/corba/client.hh> +void se3ToCorba(CORBA::Float* corbaPosition, const se3::SE3& se3position) +{ + Eigen::Quaternion<float> q(se3position.rotation()); + corbaPosition[0] = se3position.translation()(0); + corbaPosition[1] = se3position.translation()(1); + corbaPosition[2] = se3position.translation()(2); + corbaPosition[3] = q.w(); + corbaPosition[4] = q.x(); + corbaPosition[5] = q.y(); + corbaPosition[6] = q.z(); +} + int main(int, const char **) { using namespace graphics; using namespace corbaServer; using namespace std; - ClientCpp client; + Client client (0, NULL); + client.connect (); se3::SE3 position1 = se3::SE3::Random(); se3::SE3 position2 = se3::SE3::Random(); se3::SE3 position3 = se3::SE3::Random(); se3::SE3 position4 = se3::SE3::Random(); se3::SE3 position5 = se3::SE3::Random(); + CORBA::Float pos[7]; - ClientCpp::WindowID windowId = client.createWindow("window1"); - client.createScene("scene1"); - 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/"); + Client::WindowID windowId = client.gui()->createWindow("window1"); + client.gui()->createScene("scene1"); + client.gui()->addSceneToWindow("scene1",windowId); + client.gui()->addURDF("scene1/hrp2", "/local/mgeisert/devel/src/hrp2/hrp2_14_description/urdf/hrp2_14_capsule.urdf", "/local/mgeisert/devel/src/hrp2/"); sleep(5); @@ -35,18 +49,23 @@ int main(int, const char **) float pos2[3] = {0.,1.,0.}; float pos3[3]= {0.,1.,1.}; float color[4] = {1.,1.,1.,1.}; - client.addTriangleFace("scene1/triangle", pos1, pos2, pos3, color); + client.gui()->addTriangleFace("scene1/triangle", pos1, pos2, pos3, color); sleep(15); - client.applyConfiguration("scene1/hrp2/RLEG_LINK0", position1); - client.applyConfiguration("scene1/hrp2/RLEG_LINK1", position2); - client.applyConfiguration("scene1/hrp2/LLEG_LINK1", position3); - client.applyConfiguration("scene1/hrp2/LLEG_LINK2", position4); - client.applyConfiguration("scene1/hrp2/BODY", position5); + se3ToCorba (pos, position1); + client.gui()->applyConfiguration("scene1/hrp2/RLEG_LINK0", pos); + se3ToCorba (pos, position2); + client.gui()->applyConfiguration("scene1/hrp2/RLEG_LINK1", pos); + se3ToCorba (pos, position3); + client.gui()->applyConfiguration("scene1/hrp2/LLEG_LINK1", pos); + se3ToCorba (pos, position4); + client.gui()->applyConfiguration("scene1/hrp2/LLEG_LINK2", pos); + se3ToCorba (pos, position5); + client.gui()->applyConfiguration("scene1/hrp2/BODY", pos); - client.refresh(); + client.gui()->refresh(); return 0; } -- GitLab