diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl index b0b3febd9d0fffa4a1daa9bd179fff4e54435497..0e6aeb78c2873ba2fe08b1417d13b88e3872f519 100644 --- a/idl/gepetto/viewer/graphical-interface.idl +++ b/idl/gepetto/viewer/graphical-interface.idl @@ -1,5 +1,11 @@ // file graphicalinterface.idl module gepetto { + /// Corba exception travelling through the Corba channel + exception Error + { + string msg; + }; + module corbaserver { // Comments : @@ -9,7 +15,7 @@ module corbaserver { // SceneViewer-corbaserver window for more information) // 3) applyConfiguration doesn't move object straigh forward, you need to used // the "refresh" function each time you want actualize position of the Viewer. -// This system is used to synchronize movement of all objects. +// This system is used to synchronize movement of all objects. typedef double Transform [7]; typedef double Position [3]; @@ -20,39 +26,36 @@ typedef double Color [4]; /// Set time between window frames /// \param input rate : waiting time (ms) between two frames. - boolean setRate(in long rate); + boolean setRate(in long rate) raises (Error); /// Change configurations according to the last applyConfigurations.d - void refresh(); + void refresh() raises (Error); /// Create a new window. /// \param input name : name of the new window. - boolean createWindow(in string name); + boolean createWindow(in string name) raises (Error); /// Print names of nodes on the SceneViewer-corbaserver terminal. - void getNodeList(); + void getNodeList() raises (Error); /// Print names of windows on the SceneViewer-corbaserver terminal. - void getWindowList(); - - //void createWindow(in string name, in unsigned long x, in unsigned long y, in unsigned long width, in unsigned long height) ; - + void getWindowList() raises (Error); /// Create a group node. /// \param input sceneName : name of the group. - boolean createScene(in string sceneName) ; + boolean createScene(in string sceneName) raises (Error); /// Create a group node and a GroudNode ("sceneName/floor") as child /// \param input sceneName : name of the group - boolean createSceneWithFloor(in string sceneName) ; + boolean createSceneWithFloor(in string sceneName) raises (Error); /// 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) ; + boolean addSceneToWindow(in string sceneName, in string windowName) raises (Error); /// create a box called boxName. /// \param input boxName : name of the box. @@ -60,112 +63,103 @@ typedef double Color [4]; /// \param input boxSize2 : lenght of the box (y axis). /// \param input boxSize3 : lenght of the box (z axis). /// \param input RGBAcolor : Color of the box. - boolean addBox(in string boxName, in float boxSize1, in float boxSize2, in float boxSize3, in Color RGBAcolor) ; - - //boolean addBox(in string boxName, in float boxSize1, in float boxSize2, in float boxSize3) ; - - //boolean addCapsule(in string capsuleName, in float radius, in float height) ; + boolean addBox(in string boxName, in float boxSize1, in float boxSize2, in float boxSize3, in Color RGBAcolor) raises (Error); /// create a box called CapsuleName. /// \param input CapsuleName : name of the capsule. /// \param input radius : radius of the capsule. /// \param input height : lenght of the segment that generates the capsule. /// \param input RGBAcolor : Color of the capsule. - boolean addCapsule(in string capsuleName, in float radius, in float height, in Color RGBAcolorid) ; + boolean addCapsule(in string capsuleName, in float radius, in float height, in Color RGBAcolorid) raises (Error); /// create a node to display a mesh (works for .dae, .obj and some other formats) /// \param input meshName : name of the new meshNode. /// \param input meshPath : full path to the mesh file. - boolean addMesh(in string meshName, in string meshPath) ; - - //boolean addCone(in string coneName, in float radius, in float height) ; + boolean addMesh(in string meshName, in string meshPath) raises (Error); /// create a node to display a mesh (works for .dae, .obj and some other formats) /// \param input meshName : name of the new meshNode. /// \param input meshPath : full path to the mesh file. - boolean addCone(in string coneName, in float radius, in float height, in Color RGBAcolor) ; - - //boolean addCylinder(in string cylinderName, in float radius, in float height) ; + boolean addCone(in string coneName, in float radius, in float height, in Color RGBAcolor) raises (Error); /// create a Cyllinder called cylinderName /// \param input cylinderName : name of the cylinder. /// \param input radius : radius of the cylinder. /// \param input height : lenght of the cylinder. /// \param input RGBAcolor : color of the cylinder. - boolean addCylinder(in string cylinderName, in float radius, in float height, in Color RGBAcolor) ; - - //boolean addSphere(in string sphereName, in float radius) ; + boolean addCylinder(in string cylinderName, in float radius, in float height, in Color RGBAcolor) raises (Error); /// create a sphere called sphereName /// \param input sphereName : name of the sphere. /// \param input radius : radius of the sphere. /// \param input RGBAcolor : color of the sphere. - boolean addSphere(in string sphereName, in float radius, in Color RGBAcolor) ; + boolean addSphere(in string sphereName, in float radius, in Color RGBAcolor) raises (Error); /// create a line called lineName. /// \param input lineName : name of the line. /// \param input pos1 : position one extremity of the line. /// \param input pos2 : position the other extremity of the line. /// \param input RGBAcolor : color of the line. - boolean addLine(in string lineName, in Position pos1, in Position pos2, in Color RGBAcolor) ; + boolean addLine(in string lineName, in Position pos1, in Position pos2, in Color RGBAcolor) raises (Error); /// create a four vertices face called faceName. /// \param input faceName : name of the face. /// \param input pos1, pos2, pos3, pos4 : position of the vertices. /// \param input RGBAcolor : color of the face. - boolean addSquareFace(in string faceName, in Position pos1, in Position pos2, in Position pos3, in Position pos4, in Color RGBAcolor) ; + boolean addSquareFace(in string faceName, in Position pos1, in Position pos2, in Position pos3, in Position pos4, in Color RGBAcolor) raises (Error); /// create a three vertices face called faceName. /// \param input faceName : name of the face. /// \param input pos1, pos2, pos3 : position of the vertices. /// \param input RGBAcolor : color of the face. - boolean addTriangleFace(in string faceName, in Position pos1, in Position pos2, in Position pos3, in Color RGBAcolor) ; + boolean addTriangleFace(in string faceName, in Position pos1, in Position pos2, in Position pos3, in Color RGBAcolor) raises (Error); /// parse an URDF model /// a groupNode will be created and each link will be child node of this node. - /// Links will be named "urdfName/linkName", linkName is the name of the link in the URDF file. - /// \param input urdfName : name of the groupNode that will be created. + /// Links will be named "prefix/linkName", linkName is the name of the link + /// in the URDF file. + /// \param input prefix: name of the groupNode that will be created. /// \param input urdfPath : full path to the URDF file. - /// \param input urddfPackage : path of the package to the package folder of the robot (this path should finish by "/"). - boolean addURDF(in string urdfName, in string urdfPath, in string urdfPackage) ; + /// \param input urdfPackage : path of the package to the package folder of the robot (this path should finish by "/"). + boolean addURDF(in string prefix, in string urdfPath, in string urdfPackage) raises (Error); /// create a groupNode called groupName /// \param input groupName : name of the group. - boolean createGroup(in string groupName) ; + boolean createGroup(in string groupName) raises (Error); /// set a node as child to a group node. /// \param input nodeName : name of the child node. - /// \param input groupName : name of the mother node (=group node). - boolean addToGroup(in string nodeName, in string groupName) ; + /// \param input groupName : name of the mother node (=group node). + boolean addToGroup(in string nodeName, in string groupName) raises (Error); /// Set a new configuration to a node. THIS CONFIGURATION WILL AFFECTIVE ONLY AFTER CALLING REFRESH FUNCTION!!! /// \param input nodeName : name of the node. /// \param input configuration : Double[7] new configuration. - boolean applyConfiguration(in string nodeName, in Transform configuration) ; + boolean applyConfiguration(in string nodeName, in Transform configuration) raises (Error); /// Add Landmark at the center of a node (x=blue, y=green, z=red). /// \param input nodeName : name of the node /// \param input size : lenght of axises. - boolean addLandmark(in string nodeName, in float size) ; + boolean addLandmark(in string nodeName, in float size) raises (Error); /// delete Landmark of a node. /// \param input nodeName : name of the node - boolean deleteLandmark(in string nodeName) ; + boolean deleteLandmark(in string nodeName) raises (Error); /// Change the visibility of a node. If this node is a group node, visibility mode will be apply to all children. /// \param input nodeName : name of the node. /// \param input visibilityMode : visibility mode can be "ON", "OFF" or "ALWAYS_ON_TOP". - boolean setVisibility(in string nodeName, in string visibilityMode) ; + boolean setVisibility(in string nodeName, in string visibilityMode) raises (Error); /// Change wireframe mode of a node. If this node is a group node, wireframe mode will be apply to all children. /// \param input nodeName : name of the node. /// \param input wireframeMode : wiredframe mode can be "FILL", "WIREFRAME" or "FILL_AND_WIREFRAME". - boolean setWireFrameMode(in string nodeName, in string wireFrameMode) ; + boolean setWireFrameMode(in string nodeName, in string wireFrameMode) raises (Error); /// Change lighting mode of a node. If this node is a group node, lighting mode will be apply to all children. /// \param input nodeName : name of the node. /// \param input lightingMode : lighting mode can be "ON" or "OFF". - boolean setLightingMode(in string nodeName, in string lightingMode) ; + boolean setLightingMode(in string nodeName, in string lightingMode) raises (Error); }; }; }; diff --git a/src/graphical-interface.impl.cpp b/src/graphical-interface.impl.cpp index ae3b775a1e8a289c4fbe3fd212429facded45a26..f55a7f701e9e441c7044d505e55d0e8f2b8e765e 100644 --- a/src/graphical-interface.impl.cpp +++ b/src/graphical-interface.impl.cpp @@ -8,611 +8,714 @@ #include "graphical-interface.impl.hh" -namespace graphics { -namespace corbaServer { -namespace impl { - -GraphicalInterface::GraphicalInterface(corbaServer::Server* server) : - windowManagers_(), nodes_(), groupNodes_(), server_(server), mtx_(), rate_(20), newNodeConfigurations_() -{ -} - -osgVector4 GraphicalInterface::getColor(const std::string& colorName) -{ - if (colorName == "blue") - return osgVector4(0.f, 0.f, 1.f, 1.f); - else if (colorName == "green") - return osgVector4(0.f, 1.f, 0.f, 1.f); - else if (colorName == "red") - return osgVector4(1.f, 0.f, 0.f, 1.f); - else if (colorName == "white") - return osgVector4(1.f, 1.f, 1.f, 1.f); - else - return osgVector4(0.f, 0.f, 0.f, 1.f); -} - -osgVector4 GraphicalInterface::getColor(const double* colorCorba) -{ - return osgVector4(colorCorba[0], colorCorba[1], colorCorba[2], colorCorba[3]); -} - -VisibilityMode GraphicalInterface::getVisibility(const std::string& visibilityName) -{ - if (visibilityName == "OFF") - return VISIBILITY_OFF; - else if (visibilityName == "ALWAYS_ON_TOP") - return ALWAYS_ON_TOP; - else if (visibilityName == "ON") - return VISIBILITY_ON; - else { - std::cout << "Visibility mode not known, visibility mode can be \"ON\",\"OFF\" or \"ALWAYS_ON_TOP\"." << std::endl; - std::cout << "Visibility mode set to default = \"ON\"." << std::endl; - return VISIBILITY_ON; - } -} - -WireFrameMode GraphicalInterface::getWire(const std::string& wireName) -{ - if (wireName == "WIREFRAME") - return WIREFRAME; - else if (wireName == "FILL_AND_WIREFRAME") - return FILL_AND_WIREFRAME; - else if (wireName == "FILL") - return FILL; - else { - std::cout << "Wire mode not known, wire mode can be \"FILL\",\"WIREFRAME\" or \"FILL_AND_WIREFRAME\"." << std::endl; - std::cout << "Wire mode set to default = \"FILL\"." << std::endl; - return FILL; - } -} - -LightingMode GraphicalInterface::getLight(const std::string& lightName) -{ - if (lightName == "OFF") - return LIGHT_INFLUENCE_OFF; - else if (lightName == "ON") - return LIGHT_INFLUENCE_ON; - else { - std::cout << "Lighting mode not known, lighting mode can be \"ON\" or \"OFF\"." << std::endl; - std::cout << "Lighting mode set to default = \"ON\"." << std::endl; - return LIGHT_INFLUENCE_ON; - } -} - -std::string GraphicalInterface::parentName(const std::string& name) -{ - std::string Name(name); - std::string::iterator parentNameIt; - for (std::string::iterator i = Name.end() ; (*i) != char('/') && i != Name.begin() ; i--) { - parentNameIt = i; - } - parentNameIt--; - - std::string parentName; - for (std::string::iterator i = Name.begin(); i != parentNameIt; i++ ) { - parentName.push_back(*i); - } - - return parentName; -} - -void GraphicalInterface::initParent(const std::string& nodeName, NodePtr_t node) -{ - GroupNodePtr_t groupNode = groupNodes_[GraphicalInterface::parentName(nodeName)]; - if ( groupNode ) { - groupNode->addChild(node); - } -} - -void GraphicalInterface::addNode(const std::string& nodeName, NodePtr_t node) -{ - nodes_[nodeName] = node; -} - -void GraphicalInterface::addGroup(const std::string& groupName, GroupNodePtr_t group) -{ - groupNodes_[groupName] = group; - nodes_[groupName] = group; -} - -void GraphicalInterface::threadRefreshing(WindowManagerPtr_t window) -{ - while (1) - { - mtx_.lock(); - window->frame(); - mtx_.unlock(); - boost::this_thread::sleep(boost::posix_time::milliseconds(rate_)); - } -} - -osgQuat GraphicalInterface::corbaConfToOsgQuat(const double* configurationCorba) -{ - // configurationCorba = trans (x, y, z), quat(w, x, y, z) - // osgQuat = quat(x, y, z, w) - return osgQuat(configurationCorba[4], configurationCorba[5], configurationCorba[6], configurationCorba[3]); -} - -osgVector3 GraphicalInterface::corbaConfToOsgVec3(const double* configurationCorba) -{ - return osgVector3(configurationCorba[0], configurationCorba[1], configurationCorba[2]); -} - - -//Public functions - -bool GraphicalInterface::setRate(CORBA::Long rate) -{ - if ( rate <= 0 ) { - std::cout << "You should specify a positive rate" << std::endl; - return false; - } - else { - rate_ = rate; - return true; - } -} - -bool GraphicalInterface::createWindow(const char* windowNameCorba) -{ - 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; - } -} - -void GraphicalInterface::refresh() -{ - mtx_.lock(); - //refresh scene with the new configuration - for (std::list<NodeConfiguration>::iterator it = newNodeConfigurations_.begin() ; it != newNodeConfigurations_.end() ; it++ ) { - (*it).node->applyConfiguration((*it).position, (*it).quat); - } - mtx_.unlock(); - newNodeConfigurations_.clear(); -} - -/*void GraphicalInterface::createWindow(const char* name, const unsigned int& x, const unsigned int& y, const unsigned int& width, const unsigned int& height) - - { - WindowManagerPtr_t newWindow = WindowManager::create(x, y, width, height); - windowManagers_[name] = newWindow; - }*/ - -bool GraphicalInterface::createScene(const char* sceneNameCorba) -{ - std::string sceneName(sceneNameCorba); - if (nodes_.find(sceneName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << sceneName << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t mainNode = GroupNode::create(sceneName); - addGroup(sceneName, mainNode); - return true; - } -} - -bool GraphicalInterface::createSceneWithFloor(const char* sceneNameCorba) - -{ - std::string sceneName(sceneNameCorba); - if (nodes_.find(sceneName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << sceneName << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t mainNode = GroupNode::create(sceneName); - addGroup(sceneName, mainNode); - std::string floorName = sceneName + "/floor"; - LeafNodeGroundPtr_t floor = LeafNodeGround::create(floorName); - addNode(floorName, floor); - mainNode->addChild(floor); - return true; - } -} - -bool GraphicalInterface::addSceneToWindow(const char* sceneNameCorba,const char* windowNameCorba) - -{ - std::string sceneName(sceneNameCorba); - std::string windowName(windowNameCorba); - if (windowManagers_.find(windowName) != windowManagers_.end() && groupNodes_.find(sceneName) != groupNodes_.end() ) { - windowManagers_[windowName]->addNode(groupNodes_[sceneName]); - return true; - } - else { - std::cout << "Window name \"" << windowName << "\" and/or scene name \"" << sceneName << "\" doesn't exist." << std::endl; - return false; - } -} - -bool GraphicalInterface::addBox(const char* boxNameCorba, const float boxSize1, const float boxSize2, const float boxSize3, const double* colorCorba) -{ - std::string boxName(boxNameCorba); - if (nodes_.find(boxName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << boxName << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeBoxPtr_t box = LeafNodeBox::create(boxName, osgVector3(boxSize1, boxSize2, boxSize3), getColor(colorCorba)); - GraphicalInterface::initParent(boxName, box); - addNode(boxName, box); - return true; - } -} - -/*bool GraphicalInterface::addBox(const char* boxNameCorba, const float boxSize1, const float boxSize2, const float boxSize3) -{ - std::string boxName(boxNameCorba); - if (nodes_.find(boxName) != nodes_.end()) { +namespace graphics { + namespace corbaServer { + namespace impl { + + GraphicalInterface::GraphicalInterface(corbaServer::Server* server) : + windowManagers_(), nodes_(), groupNodes_(), server_(server), mtx_(), rate_(20), newNodeConfigurations_() + { + } + + osgVector4 GraphicalInterface::getColor(const std::string& colorName) + { + if (colorName == "blue") + return osgVector4(0.f, 0.f, 1.f, 1.f); + else if (colorName == "green") + return osgVector4(0.f, 1.f, 0.f, 1.f); + else if (colorName == "red") + return osgVector4(1.f, 0.f, 0.f, 1.f); + else if (colorName == "white") + return osgVector4(1.f, 1.f, 1.f, 1.f); + else + return osgVector4(0.f, 0.f, 0.f, 1.f); + } + + osgVector4 GraphicalInterface::getColor(const double* colorCorba) + { + return osgVector4(colorCorba[0], colorCorba[1], colorCorba[2], colorCorba[3]); + } + + VisibilityMode GraphicalInterface::getVisibility(const std::string& visibilityName) + { + if (visibilityName == "OFF") + return VISIBILITY_OFF; + else if (visibilityName == "ALWAYS_ON_TOP") + return ALWAYS_ON_TOP; + else if (visibilityName == "ON") + return VISIBILITY_ON; + else { + std::cout << "Visibility mode not known, visibility mode can be \"ON\",\"OFF\" or \"ALWAYS_ON_TOP\"." << std::endl; + std::cout << "Visibility mode set to default = \"ON\"." << std::endl; + return VISIBILITY_ON; + } + } + + WireFrameMode GraphicalInterface::getWire(const std::string& wireName) + { + if (wireName == "WIREFRAME") + return WIREFRAME; + else if (wireName == "FILL_AND_WIREFRAME") + return FILL_AND_WIREFRAME; + else if (wireName == "FILL") + return FILL; + else { + std::cout << "Wire mode not known, wire mode can be \"FILL\",\"WIREFRAME\" or \"FILL_AND_WIREFRAME\"." << std::endl; + std::cout << "Wire mode set to default = \"FILL\"." << std::endl; + return FILL; + } + } + + LightingMode GraphicalInterface::getLight(const std::string& lightName) + { + if (lightName == "OFF") + return LIGHT_INFLUENCE_OFF; + else if (lightName == "ON") + return LIGHT_INFLUENCE_ON; + else { + std::cout << "Lighting mode not known, lighting mode can be \"ON\" or \"OFF\"." << std::endl; + std::cout << "Lighting mode set to default = \"ON\"." << std::endl; + return LIGHT_INFLUENCE_ON; + } + } + + std::string GraphicalInterface::parentName(const std::string& name) + { + std::string Name(name); + std::string::iterator parentNameIt; + for (std::string::iterator i = Name.end() ; (*i) != char('/') && i != Name.begin() ; i--) { + parentNameIt = i; + } + parentNameIt--; + + std::string parentName; + for (std::string::iterator i = Name.begin(); i != parentNameIt; i++ ) { + parentName.push_back(*i); + } + + return parentName; + } + + void GraphicalInterface::initParent(const std::string& nodeName, NodePtr_t node) + { + GroupNodePtr_t groupNode = groupNodes_[GraphicalInterface::parentName(nodeName)]; + if ( groupNode ) { + groupNode->addChild(node); + } + } + + void GraphicalInterface::addNode(const std::string& nodeName, NodePtr_t node) + { + nodes_[nodeName] = node; + } + + void GraphicalInterface::addGroup(const std::string& groupName, GroupNodePtr_t group) + { + groupNodes_[groupName] = group; + nodes_[groupName] = group; + } + + void GraphicalInterface::threadRefreshing(WindowManagerPtr_t window) + { + while (1) + { + mtx_.lock(); + window->frame(); + mtx_.unlock(); + boost::this_thread::sleep(boost::posix_time::milliseconds(rate_)); + } + } + + osgQuat GraphicalInterface::corbaConfToOsgQuat(const double* configurationCorba) + { + // configurationCorba = trans (x, y, z), quat(w, x, y, z) + // osgQuat = quat(x, y, z, w) + return osgQuat(configurationCorba[4], configurationCorba[5], configurationCorba[6], configurationCorba[3]); + } + + osgVector3 GraphicalInterface::corbaConfToOsgVec3(const double* configurationCorba) + { + return osgVector3(configurationCorba[0], configurationCorba[1], configurationCorba[2]); + } + + + //Public functions + + bool GraphicalInterface::setRate(CORBA::Long rate) throw (Error) + { + try { + if ( rate <= 0 ) { + std::cout << "You should specify a positive rate" << std::endl; + return false; + } + else { + rate_ = rate; + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool 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; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + void GraphicalInterface::refresh() throw (Error) + { + try { + mtx_.lock(); + //refresh scene with the new configuration + for (std::list<NodeConfiguration>::iterator it = newNodeConfigurations_.begin() ; it != newNodeConfigurations_.end() ; it++ ) { + (*it).node->applyConfiguration((*it).position, (*it).quat); + } + mtx_.unlock(); + newNodeConfigurations_.clear(); + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + /*void GraphicalInterface::createWindow(const char* name, const unsigned int& x, const unsigned int& y, const unsigned int& width, const unsigned int& height) + + { + WindowManagerPtr_t newWindow = WindowManager::create(x, y, width, height); + windowManagers_[name] = newWindow; + }*/ + + bool GraphicalInterface::createScene(const char* sceneNameCorba) throw (Error) + { + try { + std::string sceneName(sceneNameCorba); + if (nodes_.find(sceneName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << sceneName << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t mainNode = GroupNode::create(sceneName); + addGroup(sceneName, mainNode); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::createSceneWithFloor(const char* sceneNameCorba) throw (Error) + + { + try { + std::string sceneName(sceneNameCorba); + if (nodes_.find(sceneName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << sceneName << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t mainNode = GroupNode::create(sceneName); + addGroup(sceneName, mainNode); + std::string floorName = sceneName + "/floor"; + LeafNodeGroundPtr_t floor = LeafNodeGround::create(floorName); + addNode(floorName, floor); + mainNode->addChild(floor); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addSceneToWindow(const char* sceneNameCorba,const char* windowNameCorba) throw (Error) + { + try { + std::string sceneName(sceneNameCorba); + std::string windowName(windowNameCorba); + if (windowManagers_.find(windowName) != windowManagers_.end() && groupNodes_.find(sceneName) != groupNodes_.end() ) { + windowManagers_[windowName]->addNode(groupNodes_[sceneName]); + return true; + } + else { + std::cout << "Window name \"" << windowName << "\" and/or scene name \"" << sceneName << "\" doesn't exist." << std::endl; + return false; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addBox(const char* boxNameCorba, const float boxSize1, const float boxSize2, const float boxSize3, const double* colorCorba) throw (Error) + { + try { + std::string boxName(boxNameCorba); + if (nodes_.find(boxName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << boxName << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeBoxPtr_t box = LeafNodeBox::create(boxName, osgVector3(boxSize1, boxSize2, boxSize3), getColor(colorCorba)); + GraphicalInterface::initParent(boxName, box); + addNode(boxName, box); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + /*bool GraphicalInterface::addBox(const char* boxNameCorba, const float boxSize1, const float boxSize2, const float boxSize3) + { + std::string boxName(boxNameCorba); + if (nodes_.find(boxName) != nodes_.end()) { std::cout << "You need to chose an other name, \"" << boxName << "\" already exist." << std::endl; return false; - } - else { + } + else { LeafNodeBoxPtr_t box = LeafNodeBox::create(boxName, osgVector3(boxSize1, boxSize2, boxSize3)); GraphicalInterface::initParent(boxName, box); addNode(boxName, box); return true; - } -}*/ + } + }*/ -/*bool GraphicalInterface::addCapsule(const char* capsuleNameCorba, const float radius, const float height) -{ - const std::string capsuleName(capsuleNameCorba); - if (nodes_.find(capsuleName) != nodes_.end()) { + /*bool GraphicalInterface::addCapsule(const char* capsuleNameCorba, const float radius, const float height) + { + const std::string capsuleName(capsuleNameCorba); + if (nodes_.find(capsuleName) != nodes_.end()) { std::cout << "You need to chose an other name, \"" << capsuleName << "\" already exist." << std::endl; return false; - } - else { + } + else { LeafNodeCapsulePtr_t capsule = LeafNodeCapsule::create(capsuleName, radius, height); GraphicalInterface::initParent(capsuleName, capsule); addNode(capsuleName, capsule); return true; - } -}*/ - -bool GraphicalInterface::addCapsule(const char* capsuleNameCorba, const float radius, const float height, const double* colorCorba) -{ - const std::string capsuleName(capsuleNameCorba); - if (nodes_.find(capsuleName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << capsuleName << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeCapsulePtr_t capsule = LeafNodeCapsule::create(capsuleName, radius, height, getColor(colorCorba)); - GraphicalInterface::initParent(capsuleName, capsule); - addNode(capsuleName, capsule); - return true; - } -} - -bool GraphicalInterface::addMesh(const char* meshNameCorba, const char* meshPathCorba) -{ - std::string meshName(meshNameCorba); - std::string meshPath(meshPathCorba); - if (nodes_.find(meshName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << meshName << "\" already exist." << std::endl; - return false; - } - else { - try { + } + }*/ + + bool GraphicalInterface::addCapsule(const char* capsuleNameCorba, const float radius, const float height, const double* colorCorba) throw (Error) + { + try { + const std::string capsuleName(capsuleNameCorba); + if (nodes_.find(capsuleName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << capsuleName << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeCapsulePtr_t capsule = LeafNodeCapsule::create(capsuleName, radius, height, getColor(colorCorba)); + GraphicalInterface::initParent(capsuleName, capsule); + addNode(capsuleName, capsule); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addMesh(const char* meshNameCorba, const char* meshPathCorba) throw (Error) + { + try { + std::string meshName(meshNameCorba); + std::string meshPath(meshPathCorba); + if (nodes_.find(meshName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << meshName << "\" already exist." << std::endl; + return false; + } + else { + try { LeafNodeColladaPtr_t mesh = LeafNodeCollada::create(meshName, meshPath); GraphicalInterface::initParent(meshName, mesh); addNode(meshName, mesh); return true; - } catch (const std::exception& exc) { + } catch (const std::exception& exc) { std::cout << "Mesh \"" << meshPath << "\" not found." << std::endl; return false; - } - } -} - -/*bool GraphicalInterface::addCone(const char* coneNameCorba, const float radius, const float height) -{ - std::string coneName(coneNameCorba); - if (nodes_.find(coneName) != nodes_.end()) { + } + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + /*bool GraphicalInterface::addCone(const char* coneNameCorba, const float radius, const float height) + { + std::string coneName(coneNameCorba); + if (nodes_.find(coneName) != nodes_.end()) { std::cout << "You need to chose an other name, \"" << coneName << "\" already exist." << std::endl; return false; - } - else { + } + else { LeafNodeConePtr_t cone = LeafNodeCone::create(coneName, radius, height); GraphicalInterface::initParent(coneName, cone); addNode(coneName, cone); return true; - } -}*/ - -bool GraphicalInterface::addCone(const char* coneNameCorba, const float radius, const float height, const double* colorCorba) -{ - std::string coneName(coneNameCorba); - if (nodes_.find(coneName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << coneName << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeConePtr_t cone = LeafNodeCone::create(coneName, radius, height); - GraphicalInterface::initParent(coneName, cone); - addNode(coneName, cone); - return true; - } -} - -/*bool GraphicalInterface::addCylinder(const char* cylinderNameCorba, const float radius, const float height) - -{ - std::string cylinderName(cylinderNameCorba); - if (nodes_.find(cylinderName) != nodes_.end()) { + } + }*/ + + bool GraphicalInterface::addCone(const char* coneNameCorba, const float radius, const float height, const double*) throw (Error) + { + try { + std::string coneName(coneNameCorba); + if (nodes_.find(coneName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << coneName << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeConePtr_t cone = LeafNodeCone::create(coneName, radius, height); + GraphicalInterface::initParent(coneName, cone); + addNode(coneName, cone); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + /*bool GraphicalInterface::addCylinder(const char* cylinderNameCorba, const float radius, const float height) + + { + std::string cylinderName(cylinderNameCorba); + if (nodes_.find(cylinderName) != nodes_.end()) { std::cout << "You need to chose an other name, \"" << cylinderName << "\" already exist." << std::endl; return false; - } - else { + } + else { LeafNodeCylinderPtr_t cylinder = LeafNodeCylinder::create(cylinderName, radius, height); GraphicalInterface::initParent(cylinderName, cylinder); addNode(cylinderName, cylinder); return true; - } -}*/ - -bool GraphicalInterface::addCylinder(const char* cylinderNameCorba, const float radius, const float height, const double* colorCorba) -{ - std::string cylinderName(cylinderNameCorba); - if (nodes_.find(cylinderName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << cylinderName << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeCylinderPtr_t cylinder = LeafNodeCylinder::create(cylinderName, radius, height, getColor(colorCorba)); - GraphicalInterface::initParent(cylinderName, cylinder); - addNode(cylinderName, cylinder); - return true; - } -} - -/*bool GraphicalInterface::addSphere(const char* sphereNameCorba, const float radius) -{ - std::string sphereName(sphereNameCorba); - if (nodes_.find(sphereName) != nodes_.end()) { + } + }*/ + + bool GraphicalInterface::addCylinder(const char* cylinderNameCorba, const float radius, const float height, const double* colorCorba) throw (Error) + { + try { + std::string cylinderName(cylinderNameCorba); + if (nodes_.find(cylinderName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << cylinderName << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeCylinderPtr_t cylinder = LeafNodeCylinder::create(cylinderName, radius, height, getColor(colorCorba)); + GraphicalInterface::initParent(cylinderName, cylinder); + addNode(cylinderName, cylinder); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + /*bool GraphicalInterface::addSphere(const char* sphereNameCorba, const float radius) + { + std::string sphereName(sphereNameCorba); + if (nodes_.find(sphereName) != nodes_.end()) { std::cout << "You need to chose an other name, \"" << sphereName << "\" already exist." << std::endl; return false; - } - else { + } + else { LeafNodeSpherePtr_t sphere = LeafNodeSphere::create(sphereName, radius); GraphicalInterface::initParent(sphereName, sphere); addNode(sphereName, sphere); return true; - } -}*/ - -bool GraphicalInterface::addSphere(const char* sphereNameCorba, const float radius, const double* colorCorba) -{ - std::string sphereName(sphereNameCorba); - if (nodes_.find(sphereName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << sphereName << "\" already exist." << std::endl; - return false; - } - else { - LeafNodeSpherePtr_t sphere = LeafNodeSphere::create(sphereName, radius, getColor(colorCorba)); - GraphicalInterface::initParent(sphereName, sphere); - addNode(sphereName, sphere); - return true; - } -} - -bool GraphicalInterface::addLine(const char* lineNameCorba, const double* posCorba1, const double* posCorba2, const double* colorCorba) -{ - std::string lineName(lineNameCorba); - if (nodes_.find(lineName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << lineName << "\" already exist." << std::endl; - return false; - } - else { - osgVector3 pos1(posCorba1[0], posCorba1[1], posCorba1[2]); - osgVector3 pos2(posCorba2[0], posCorba2[1], posCorba2[2]); - LeafNodeLinePtr_t line = LeafNodeLine::create(lineName, pos1, pos2, getColor(colorCorba)); - GraphicalInterface::initParent(lineName, line); - addNode(lineName, line); - return true; - } -} - -bool GraphicalInterface::addTriangleFace(const char* faceNameCorba, const double* posCorba1, const double* posCorba2, const double* posCorba3, const double* colorCorba) -{ - std::string faceName(faceNameCorba); - if (nodes_.find(faceName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << faceName << "\" already exist." << std::endl; - return false; - } - else { - osgVector3 pos1(posCorba1[0], posCorba1[1], posCorba1[2]); - osgVector3 pos2(posCorba2[0], posCorba2[1], posCorba2[2]); - osgVector3 pos3(posCorba3[0], posCorba3[1], posCorba3[2]); - LeafNodeFacePtr_t face = LeafNodeFace::create(faceName, pos1, pos2, pos3, getColor(colorCorba)); - GraphicalInterface::initParent(faceName, face); - addNode(faceName, face); - return true; - } -} - -bool GraphicalInterface::addSquareFace(const char* faceNameCorba, const double* posCorba1, const double* posCorba2, const double* posCorba3, const double* posCorba4, const double* colorCorba) -{ - std::string faceName(faceNameCorba); - if (nodes_.find(faceName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << faceName << "\" already exist." << std::endl; - return false; - } - else { - osgVector3 pos1(posCorba1[0], posCorba1[1], posCorba1[2]); - osgVector3 pos2(posCorba2[0], posCorba2[1], posCorba2[2]); - osgVector3 pos3(posCorba3[0], posCorba3[1], posCorba3[2]); - osgVector3 pos4(posCorba4[0], posCorba4[1], posCorba4[2]); - LeafNodeFacePtr_t face = LeafNodeFace::create(faceName, pos1, pos2, pos3, pos3, getColor(colorCorba)); - GraphicalInterface::initParent(faceName, face); - addNode(faceName, face); - return true; - } -} - -void GraphicalInterface::getNodeList() -{ - std::cout << "List of Nodes :" << std::endl; - for (std::map<std::string, NodePtr_t>::iterator it=nodes_.begin(); it!=nodes_.end(); ++it) - std::cout << " " << it->first << std::endl; - std::cout << "List of GroupNodes :" << std::endl; - for (std::map<std::string, GroupNodePtr_t>::iterator it=groupNodes_.begin(); it!=groupNodes_.end(); ++it) - std::cout << " " << it->first << std::endl; -} - -void GraphicalInterface::getWindowList() -{ - 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; -} - -bool GraphicalInterface::createGroup(const char* groupNameCorba) -{ - const std::string groupName(groupNameCorba); - if (nodes_.find(groupName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << groupName << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t groupNode = GroupNode::create(groupName); - GraphicalInterface::initParent(groupName, groupNode); - addGroup(groupName, groupNode); - return true; - } -} - -bool GraphicalInterface::addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba) -{ - const std::string urdfName(urdfNameCorba); - const std::string urdfPath(urdfPathCorba); - const std::string urdfPackagePath(urdfPackagePathCorba); - if (nodes_.find(urdfName) != nodes_.end()) { - std::cout << "You need to chose an other name, \"" << urdfName << "\" already exist." << std::endl; - return false; - } - else { - GroupNodePtr_t urdf = urdfParser::parse - (urdfName, urdfPath, urdfPackagePath); - NodePtr_t link; - for (int i=0 ; i< urdf->getNumOfChildren() ; i++) { - link = urdf->getChild(i); - nodes_[link->getID()] = link; - } - GraphicalInterface::initParent(urdfName, urdf); - addGroup(urdfName, urdf); - return true; - } -} - -bool GraphicalInterface::addToGroup(const char* nodeNameCorba, const char* groupNameCorba) -{ - const std::string nodeName(nodeNameCorba); - const std::string groupName(groupNameCorba); - if (nodes_.find(nodeName) == nodes_.end() || groupNodes_.find(groupName) == groupNodes_.end()) { - std::cout << "Node name \"" << nodeName << "\" and/or groupNode \"" << groupName << "\" doesn't exist." << std::endl; - return false; - } - else { - groupNodes_[groupName]->addChild(nodes_[nodeName]); - return true; - } -} - -bool GraphicalInterface::applyConfiguration(const char* nodeNameCorba, const double* configurationCorba) -{ - const std::string nodeName(nodeNameCorba); - if (nodes_.find(nodeName) == nodes_.end()) { - //no node named nodeName - std::cout << "No Node named \"" << nodeName << "\"" << std::endl; - return false; - } - else { - NodeConfiguration newNodeConfiguration; - newNodeConfiguration.node = nodes_[nodeName]; - try { - newNodeConfiguration.position = GraphicalInterface::corbaConfToOsgVec3(configurationCorba); - newNodeConfiguration.quat = GraphicalInterface::corbaConfToOsgQuat(configurationCorba); - } catch (const std::exception& exc) { - std::cout << "Error when converting configuration, configuration should be DOUBLE[7] = [transX, transY, transZ, quatW, quatX, quatY, quatZ]" <<std::endl; - return false; - } - newNodeConfigurations_.push_back(newNodeConfiguration); - return true; - } -} - -bool GraphicalInterface::addLandmark(const char* nodeNameCorba, float size) -{ - const std::string nodeName(nodeNameCorba); - if (nodes_.find(nodeName) == nodes_.end()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; - return false; - } - nodes_[nodeName]->addLandmark(size); - return true; -} - - -bool GraphicalInterface::deleteLandmark(const char* nodeNameCorba) -{ - const std::string nodeName(nodeNameCorba); - if (nodes_.find(nodeName) == nodes_.end()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; - return false; - } - nodes_[nodeName]->deleteLandmark(); - return true; -} - -bool GraphicalInterface::setVisibility(const char* nodeNameCorba, const char* visibilityModeCorba) -{ - const std::string nodeName(nodeNameCorba); - const std::string visibilityMode(visibilityModeCorba); - VisibilityMode visibility = getVisibility(visibilityMode); - if (nodes_.find(nodeName) == nodes_.end()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; - return false; - } - nodes_[nodeName]->setVisibilityMode(visibility); - return true; -} - -bool GraphicalInterface::setWireFrameMode(const char* nodeNameCorba, const char* wireFrameModeCorba) -{ - const std::string nodeName(nodeNameCorba); - const std::string wireFrameMode(wireFrameModeCorba); - WireFrameMode wire = getWire(wireFrameMode); - if (nodes_.find(nodeName) == nodes_.end()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; - return false; - } - nodes_[nodeName]->setWireFrameMode(wire); - return true; -} - -bool GraphicalInterface::setLightingMode(const char* nodeNameCorba, const char* lightingModeCorba) -{ - const std::string nodeName(nodeNameCorba); - const std::string lightingMode(lightingModeCorba); - LightingMode light = getLight(lightingMode); - if (nodes_.find(nodeName) == nodes_.end()) { - std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; - return false; - } - nodes_[nodeName]->setLightingMode(light); - return true; -} -} //end namespace impl -} //end namespace corbaServer + } + }*/ + + bool GraphicalInterface::addSphere(const char* sphereNameCorba, const float radius, const double* colorCorba) throw (Error) + { + try { + std::string sphereName(sphereNameCorba); + if (nodes_.find(sphereName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << sphereName << "\" already exist." << std::endl; + return false; + } + else { + LeafNodeSpherePtr_t sphere = LeafNodeSphere::create(sphereName, radius, getColor(colorCorba)); + GraphicalInterface::initParent(sphereName, sphere); + addNode(sphereName, sphere); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addLine(const char* lineNameCorba, const double* posCorba1, const double* posCorba2, const double* colorCorba) throw (Error) + { + try { + std::string lineName(lineNameCorba); + if (nodes_.find(lineName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << lineName << "\" already exist." << std::endl; + return false; + } + else { + osgVector3 pos1(posCorba1[0], posCorba1[1], posCorba1[2]); + osgVector3 pos2(posCorba2[0], posCorba2[1], posCorba2[2]); + LeafNodeLinePtr_t line = LeafNodeLine::create(lineName, pos1, pos2, getColor(colorCorba)); + GraphicalInterface::initParent(lineName, line); + addNode(lineName, line); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addTriangleFace(const char* faceNameCorba, const double* posCorba1, const double* posCorba2, const double* posCorba3, const double* colorCorba) throw (Error) + { + try { + std::string faceName(faceNameCorba); + if (nodes_.find(faceName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << faceName << "\" already exist." << std::endl; + return false; + } + else { + osgVector3 pos1(posCorba1[0], posCorba1[1], posCorba1[2]); + osgVector3 pos2(posCorba2[0], posCorba2[1], posCorba2[2]); + osgVector3 pos3(posCorba3[0], posCorba3[1], posCorba3[2]); + LeafNodeFacePtr_t face = LeafNodeFace::create(faceName, pos1, pos2, pos3, getColor(colorCorba)); + GraphicalInterface::initParent(faceName, face); + addNode(faceName, face); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addSquareFace(const char* faceNameCorba, const double* posCorba1, const double* posCorba2, const double* posCorba3, const double* posCorba4, const double* colorCorba) throw (Error) + { + try { + std::string faceName(faceNameCorba); + if (nodes_.find(faceName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << faceName << "\" already exist." << std::endl; + return false; + } + else { + osgVector3 pos1(posCorba1[0], posCorba1[1], posCorba1[2]); + osgVector3 pos2(posCorba2[0], posCorba2[1], posCorba2[2]); + osgVector3 pos3(posCorba3[0], posCorba3[1], posCorba3[2]); + osgVector3 pos4(posCorba4[0], posCorba4[1], posCorba4[2]); + LeafNodeFacePtr_t face = LeafNodeFace::create(faceName, pos1, pos2, pos3, pos3, getColor(colorCorba)); + GraphicalInterface::initParent(faceName, face); + addNode(faceName, face); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + void GraphicalInterface::getNodeList() throw (Error) + { + try { + std::cout << "List of Nodes :" << std::endl; + for (std::map<std::string, NodePtr_t>::iterator it=nodes_.begin(); it!=nodes_.end(); ++it) + std::cout << " " << it->first << std::endl; + std::cout << "List of GroupNodes :" << std::endl; + for (std::map<std::string, GroupNodePtr_t>::iterator it=groupNodes_.begin(); it!=groupNodes_.end(); ++it) + std::cout << " " << it->first << std::endl; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + void GraphicalInterface::getWindowList() throw (Error) + { + 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; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::createGroup(const char* groupNameCorba) throw (Error) + { + try { + const std::string groupName(groupNameCorba); + if (nodes_.find(groupName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << groupName << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t groupNode = GroupNode::create(groupName); + GraphicalInterface::initParent(groupName, groupNode); + addGroup(groupName, groupNode); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba) throw (Error) + { + try { + const std::string urdfName(urdfNameCorba); + const std::string urdfPath(urdfPathCorba); + const std::string urdfPackagePath(urdfPackagePathCorba); + if (nodes_.find(urdfName) != nodes_.end()) { + std::cout << "You need to chose an other name, \"" << urdfName << "\" already exist." << std::endl; + return false; + } + else { + GroupNodePtr_t urdf = urdfParser::parse + (urdfName, urdfPath, urdfPackagePath); + NodePtr_t link; + for (int i=0 ; i< urdf->getNumOfChildren() ; i++) { + link = urdf->getChild(i); + nodes_[link->getID()] = link; + } + GraphicalInterface::initParent(urdfName, urdf); + addGroup(urdfName, urdf); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addToGroup(const char* nodeNameCorba, const char* groupNameCorba) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + const std::string groupName(groupNameCorba); + if (nodes_.find(nodeName) == nodes_.end() || groupNodes_.find(groupName) == groupNodes_.end()) { + std::cout << "Node name \"" << nodeName << "\" and/or groupNode \"" << groupName << "\" doesn't exist." << std::endl; + return false; + } + else { + groupNodes_[groupName]->addChild(nodes_[nodeName]); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::applyConfiguration(const char* nodeNameCorba, const double* configurationCorba) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + if (nodes_.find(nodeName) == nodes_.end()) { + //no node named nodeName + std::cout << "No Node named \"" << nodeName << "\"" << std::endl; + return false; + } + else { + NodeConfiguration newNodeConfiguration; + newNodeConfiguration.node = nodes_[nodeName]; + try { + newNodeConfiguration.position = GraphicalInterface::corbaConfToOsgVec3(configurationCorba); + newNodeConfiguration.quat = GraphicalInterface::corbaConfToOsgQuat(configurationCorba); + } catch (const std::exception& exc) { + std::cout << "Error when converting configuration, configuration should be DOUBLE[7] = [transX, transY, transZ, quatW, quatX, quatY, quatZ]" <<std::endl; + return false; + } + newNodeConfigurations_.push_back(newNodeConfiguration); + return true; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::addLandmark(const char* nodeNameCorba, float size) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + if (nodes_.find(nodeName) == nodes_.end()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; + return false; + } + nodes_[nodeName]->addLandmark(size); + return true; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + + bool GraphicalInterface::deleteLandmark(const char* nodeNameCorba) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + if (nodes_.find(nodeName) == nodes_.end()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; + return false; + } + nodes_[nodeName]->deleteLandmark(); + return true; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::setVisibility(const char* nodeNameCorba, const char* visibilityModeCorba) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + const std::string visibilityMode(visibilityModeCorba); + VisibilityMode visibility = getVisibility(visibilityMode); + if (nodes_.find(nodeName) == nodes_.end()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; + return false; + } + nodes_[nodeName]->setVisibilityMode(visibility); + return true; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::setWireFrameMode(const char* nodeNameCorba, const char* wireFrameModeCorba) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + const std::string wireFrameMode(wireFrameModeCorba); + WireFrameMode wire = getWire(wireFrameMode); + if (nodes_.find(nodeName) == nodes_.end()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; + return false; + } + nodes_[nodeName]->setWireFrameMode(wire); + return true; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::setLightingMode(const char* nodeNameCorba, const char* lightingModeCorba) throw (Error) + { + try { + const std::string nodeName(nodeNameCorba); + const std::string lightingMode(lightingModeCorba); + LightingMode light = getLight(lightingMode); + if (nodes_.find(nodeName) == nodes_.end()) { + std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; + return false; + } + nodes_[nodeName]->setLightingMode(light); + return true; + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + } //end namespace impl + } //end namespace corbaServer } //end namespace graphics diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh index 8f2f7630201a9d03850542d2a5413e5c7fbc5f2a..934e2b62e975fff6b0e60752566a05fdaa28c699 100644 --- a/src/graphical-interface.impl.hh +++ b/src/graphical-interface.impl.hh @@ -46,6 +46,7 @@ class GraphicalInterface : public virtual POA_gepetto::corbaserver::GraphicalInterface { private: + typedef gepetto::Error Error; std::map<std::string, WindowManagerPtr_t> windowManagers_; std::map<std::string, NodePtr_t> nodes_; std::map<std::string, GroupNodePtr_t> groupNodes_; @@ -75,55 +76,49 @@ public: */ GraphicalInterface (corbaServer::Server* server); - virtual void getNodeList(); - virtual void getWindowList(); + virtual void getNodeList() throw (Error); + virtual void getWindowList() throw (Error); - virtual bool setRate(CORBA::Long rate); - virtual void refresh(); + virtual bool setRate(CORBA::Long rate) throw (Error); + virtual void refresh() throw (Error); - virtual bool createWindow(const char* windowNameCorba); - //virtual void createWindow(const char* name, CORBA::ULong x, CORBA::ULong y, CORBA::ULong width, CORBA::ULong height) ; + virtual bool createWindow(const char* windowNameCorba) throw (Error); - virtual bool createScene(const char* sceneNameCorba) ; - virtual bool createSceneWithFloor(const char* sceneNameCorba) ; - virtual bool addSceneToWindow(const char* sceneNameCorba, const char* windowNameCorba) ; + virtual bool createScene(const char* sceneNameCorba) throw (Error); + virtual bool createSceneWithFloor(const char* sceneNameCorba) throw (Error); + virtual bool addSceneToWindow(const char* sceneNameCorba, const char* windowNameCorba) throw (Error); - virtual bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3, const double* color); - //virtual bool addBox(const char* boxNameCorba, float boxSize1, float boxSize2, float boxSize3) ; + virtual bool addBox(const char* boxName, float boxSize1, float boxSize2, float boxSize3, const double* color) throw (Error); - //virtual bool addCapsule(const char* capsuleNameCorba, float radius, float height) ; - virtual bool addCapsule(const char* capsuleName, float radius, float height, const double* color); + virtual bool addCapsule(const char* capsuleName, float radius, float height, const double* color) throw (Error); - virtual bool addMesh(const char* meshNameCorba, const char* meshPathCorba) ; + virtual bool addMesh(const char* meshNameCorba, const char* meshPathCorba) throw (Error); - //virtual bool addCone(const char* coneNameCorba, float radius, float height) ; - virtual bool addCone(const char* coneName, float radius, float height, const double* color); + virtual bool addCone(const char* coneName, float radius, float height, const double* color) throw (Error); - //virtual bool addCylinder(const char* cylinderNameCorba, float radius, float height) ; - virtual bool addCylinder(const char* cylinderName, float radius, float height, const double* color); + virtual bool addCylinder(const char* cylinderName, float radius, float height, const double* color) throw (Error); - //virtual bool addSphere(const char* sphereNameCorba, float radius) ; - virtual bool addSphere(const char* sphereName, float radius, const double* color); + virtual bool addSphere(const char* sphereName, float radius, const double* color) throw (Error); - virtual bool addLine(const char* lineName, const double* pos1, const double* pos2, const double* color); + virtual bool addLine(const char* lineName, const double* pos1, const double* pos2, const double* color) throw (Error); - virtual bool addSquareFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* pos4, const double* color); - virtual bool addTriangleFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* color); + virtual bool addSquareFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* pos4, const double* color) throw (Error); + virtual bool addTriangleFace(const char* faceName, const double* pos1, const double* pos2, const double* pos3, const double* color) throw (Error); - virtual bool addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba); + virtual bool addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba) throw (Error); - virtual bool createGroup(const char* groupNameCorba) ; - virtual bool addToGroup(const char* nodeNameCorba, const char* groupNameCorba) ; + virtual bool createGroup(const char* groupNameCorba) throw (Error); + virtual bool addToGroup(const char* nodeNameCorba, const char* groupNameCorba) throw (Error); - virtual bool applyConfiguration(const char* nodeNameCorba, const double* configuration) ; + virtual bool applyConfiguration(const char* nodeNameCorba, const double* configuration) throw (Error); - virtual bool addLandmark(const char* nodeNameCorba, float size); - virtual bool deleteLandmark(const char* nodeNameCorba); + virtual bool addLandmark(const char* nodeNameCorba, float size) throw (Error); + virtual bool deleteLandmark(const char* nodeNameCorba) throw (Error); - virtual bool setVisibility(const char* nodeNameCorba, const char* visibilityModeCorba) ; - virtual bool setWireFrameMode(const char* nodeNameCorba, const char* wireFrameModeCorba) ; - virtual bool setLightingMode(const char* nodeNameCorba, const char* lightingModeCorba) ; + virtual bool setVisibility(const char* nodeNameCorba, const char* visibilityModeCorba) throw (Error); + virtual bool setWireFrameMode(const char* nodeNameCorba, const char* wireFrameModeCorba) throw (Error); + virtual bool setLightingMode(const char* nodeNameCorba, const char* lightingModeCorba) throw (Error); }; // end of class