From 6ffb7583292220848aa6081d79f5768acfe7c5d5 Mon Sep 17 00:00:00 2001
From: Nikolaus Vahrenkamp <vahrenkamp@kit.edu>
Date: Tue, 26 May 2015 11:22:34 +0200
Subject: [PATCH] Added method to RobotStateComponent that allows to get all
 dependent ArmarXPackages. Updated RobotState gui plugin in order to search
 loacl robot in data paths of all dependent ArmarXPackages

---
 .../robotstate/RobotStateComponent.cpp        | 19 ++++++++++-
 .../robotstate/RobotStateComponent.h          |  6 ++++
 .../RobotViewerGuiPlugin.cpp                  | 34 ++++++++++++++++++-
 source/RobotAPI/interface/core/RobotState.ice |  7 ++++
 4 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/source/RobotAPI/components/robotstate/RobotStateComponent.cpp b/source/RobotAPI/components/robotstate/RobotStateComponent.cpp
index ed04fbe08..b874c7b9c 100644
--- a/source/RobotAPI/components/robotstate/RobotStateComponent.cpp
+++ b/source/RobotAPI/components/robotstate/RobotStateComponent.cpp
@@ -31,6 +31,7 @@
 #include <Core/core/system/ArmarXDataPath.h>
 #include <Core/core/ArmarXManager.h>
 #include <Core/core/ArmarXObjectScheduler.h>
+#include <Core/core/application/Application.h>
 
 using namespace std;
 using namespace VirtualRobot;
@@ -182,7 +183,23 @@ namespace armarx
     std::string RobotStateComponent::getRobotFilename(const Ice::Current&) const
     {		
         return relativeRobotFile;
-	}
+    }
+
+    std::vector<string> RobotStateComponent::getArmarXPackages(const Current &) const
+    {
+        std::vector<string> result;
+        auto packages = armarx::Application::GetProjectDependencies();
+        packages.push_back(Application::GetProjectName());
+        for(const std::string &projectName : packages)
+        {
+            if(projectName.empty())
+                continue;
+
+            result.push_back(projectName);
+        }
+
+        return result;
+    }
 	
     void RobotStateComponent::reportControlModeChanged(const NameControlModeMap& jointModes,  bool aValueChanged,const Current& c){}
     void RobotStateComponent::reportJointVelocities(const NameValueMap& jointVelocities,  bool aValueChanged,const Current& c)
diff --git a/source/RobotAPI/components/robotstate/RobotStateComponent.h b/source/RobotAPI/components/robotstate/RobotStateComponent.h
index ab2f9f220..b7fed65a8 100644
--- a/source/RobotAPI/components/robotstate/RobotStateComponent.h
+++ b/source/RobotAPI/components/robotstate/RobotStateComponent.h
@@ -92,6 +92,12 @@ namespace armarx
          */
         virtual std::string getRobotFilename(const Ice::Current&) const;
 
+        /*!
+         * \brief getArmarXPackages
+         * \return All dependent packages, which might contain a robot file.
+         */
+        virtual std::vector< std::string > getArmarXPackages(const Ice::Current&) const;
+
         /**
          *
          * \return  The name of this robot instance.
diff --git a/source/RobotAPI/gui-plugins/RobotViewerPlugin/RobotViewerGuiPlugin.cpp b/source/RobotAPI/gui-plugins/RobotViewerPlugin/RobotViewerGuiPlugin.cpp
index 4b5939c2f..ebaaa0294 100644
--- a/source/RobotAPI/gui-plugins/RobotViewerPlugin/RobotViewerGuiPlugin.cpp
+++ b/source/RobotAPI/gui-plugins/RobotViewerPlugin/RobotViewerGuiPlugin.cpp
@@ -6,6 +6,8 @@
 #include <Core/core/system/ArmarXDataPath.h>
 #include <Core/core/ArmarXObjectScheduler.h>
 #include <Core/core/ArmarXManager.h>
+#include <Core/core/system/cmake/CMakePackageFinder.h>
+#include <Core/core/application/Application.h>
 
 #include <VirtualRobot/XML/RobotIO.h>
 
@@ -108,10 +110,40 @@ void RobotViewerWidgetController::onConnectComponent()
         robotVisu->removeAllChildren();
     robot.reset();
 
+     std::string rfile;
+     StringList includePaths;
+
+    // get robot filename
     try {
 
-        std::string rfile = robotStateComponentPrx->getRobotFilename();
+        StringList packages = robotStateComponentPrx->getArmarXPackages();
+        packages.push_back(Application::GetProjectName());
+        ARMARX_VERBOSE << "ArmarX packages " << packages;
+        for(const std::string &projectName : packages)
+        {
+            if(projectName.empty())
+                continue;
+            CMakePackageFinder project(projectName);
+            StringList projectIncludePaths;
+            auto pathsString = project.getDataDir();
+            boost::split(projectIncludePaths,
+                         pathsString,
+                         boost::is_any_of(";,"),
+                         boost::token_compress_on);
+            includePaths.insert(includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
 
+        }
+        rfile = robotStateComponentPrx->getRobotFilename();
+        ARMARX_VERBOSE << "Relative robot file " << rfile;
+        ArmarXDataPath::getAbsolutePath(rfile, rfile, includePaths);
+        ARMARX_VERBOSE << "Absolute robot file " << rfile;
+     } catch (...)
+     {
+         ARMARX_ERROR << "Unable to retrieve robot filename";
+     }
+
+    try {
+        ARMARX_INFO << "Loading robot from file " << rfile;
         robot = loadRobotFile(rfile);
     } catch (...)
     {
diff --git a/source/RobotAPI/interface/core/RobotState.ice b/source/RobotAPI/interface/core/RobotState.ice
index 4b7fcbd5c..ad1053ae9 100644
--- a/source/RobotAPI/interface/core/RobotState.ice
+++ b/source/RobotAPI/interface/core/RobotState.ice
@@ -143,6 +143,13 @@ module armarx
         string getRobotFilename();
 
         /**
+         * @return All dependent packages, which might contain a robot file.
+         */
+        ["cpp:const"]
+        idempotent
+        StringList getArmarXPackages();
+
+         /**
           * @return The name of the robot represented by this component. Same as
           * getSynchronizedRobot()->getName()
           *
-- 
GitLab