Revision: 6403
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6403&view=rev
Author:   robotos
Date:     2008-05-08 06:40:05 -0700 (Thu, 08 May 2008)

Log Message:
-----------
A new class to manage the Gazebo configuration file
It is small, and use is only one place so it doesn't really matter where to put 
this code. 
Get almost rid of Global.

Modified Paths:
--------------
    code/gazebo/trunk/server/Global.cc
    code/gazebo/trunk/server/Global.hh
    code/gazebo/trunk/server/SConscript
    code/gazebo/trunk/server/Simulator.cc
    code/gazebo/trunk/server/Simulator.hh
    code/gazebo/trunk/server/main.cc
    code/gazebo/trunk/server/rendering/OgreAdaptor.cc

Added Paths:
-----------
    code/gazebo/trunk/server/GazeboConfig.cc
    code/gazebo/trunk/server/GazeboConfig.hh

Added: code/gazebo/trunk/server/GazeboConfig.cc
===================================================================
--- code/gazebo/trunk/server/GazeboConfig.cc                            (rev 0)
+++ code/gazebo/trunk/server/GazeboConfig.cc    2008-05-08 13:40:05 UTC (rev 
6403)
@@ -0,0 +1,106 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003
+ *     Nate Koenig & Andrew Howard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* Desc: Local Gazebo configuration 
+ * Author: Jordi Polo
+ * Date: 3 May 2008
+ * SVN: $Id:$
+ */
+#include <assert.h>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+#include "XMLConfig.hh"
+#include "GazeboConfig.hh"
+
+using namespace gazebo;
+
+////////////////////////////////////////////////////////////////////////////////
+/// Constructor
+GazeboConfig::GazeboConfig()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Destructor
+GazeboConfig::~GazeboConfig()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Loads the configuration file 
+void GazeboConfig::Load()
+{
+  std::ifstream cfgFile;
+
+  std::string rcFilename = getenv("HOME");
+  rcFilename += "/.gazeborc";
+
+  cfgFile.open(rcFilename.c_str(), std::ios::in);
+
+  if (cfgFile)
+  {
+    XMLConfig rc;
+    XMLConfigNode *node;
+    rc.Load(rcFilename);
+
+    node = rc.GetRootNode()->GetChild("gazeboPath");
+    while (node)
+    {
+      std::cout << "Gazebo Path[" << node->GetValue() << "]\n";
+      this->gazeboPaths.push_back(node->GetValue());
+      node = node->GetNext("gazeboPath");
+    }
+
+    node = rc.GetRootNode()->GetChild("ogrePath");
+    while (node)
+    {
+      std::cout << "Ogre Path[" << node->GetValue() << "]\n";
+      this->ogrePaths.push_back( node->GetValue() );
+      node = node->GetNext("ogrePath");
+    }
+    this->RTTMode = rc.GetRootNode()->GetString("RTTMode", "PBuffer");
+
+  }
+  else
+  {
+    std::cout << "Unable to find the file ~/.gazeborc. Using default paths. 
This may cause OGRE to fail.\n";
+    this->gazeboPaths.push_back("/usr/local/share/gazebo");
+    this->ogrePaths.push_back("/usr/local/lib/OGRE");
+    this->ogrePaths.push_back("/usr/lib/OGRE");
+    this->RTTMode="PBuffer";
+  }
+}
+
+std::list<std::string> GazeboConfig::GetGazeboPaths() const
+{
+  return this->gazeboPaths;
+}
+
+std::list<std::string> GazeboConfig::GetOgrePaths() const
+{
+  return this->ogrePaths;
+}
+
+std::string GazeboConfig::GetRTTMode() const
+{
+  return this->RTTMode;
+}
+

Added: code/gazebo/trunk/server/GazeboConfig.hh
===================================================================
--- code/gazebo/trunk/server/GazeboConfig.hh                            (rev 0)
+++ code/gazebo/trunk/server/GazeboConfig.hh    2008-05-08 13:40:05 UTC (rev 
6403)
@@ -0,0 +1,72 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* Desc: Gazebo configuration on this computer 
+ * Author: Jordi Polo
+ * Date: 3 May 2008
+ * SVN: $Id:$
+ */
+
+#ifndef GAZEBOCONFIG_HH
+#define GAZEBOCONFIG_HH
+
+#include <string>
+#include <list>
+
+namespace gazebo
+{
+
+/// \addtogroup gazebo_server
+/// \brief Local configuration on this computer about how gazebo server should 
work 
+/// \{
+
+  class GazeboConfig
+  {
+    /// \brief Constructor
+    public: GazeboConfig();
+
+    /// \brief destructor
+    public: ~GazeboConfig();
+
+    /// \brief True if the string is null
+    public: void Load();
+
+    /// \brief Get paths to Gazebo install 
+    public: std::list<std::string> GetGazeboPaths() const;
+
+    /// \brief Get paths to ogre install
+    public: std::list<std::string> GetOgrePaths() const;
+ 
+    public: std::string GetRTTMode() const;
+
+    /// Paths gazebo install
+    private: std::list<std::string> gazeboPaths;
+    
+    /// Paths to the ogre install
+    private: std::list<std::string> ogrePaths;
+
+    private: std::string RTTMode;
+
+  };
+
+
+/// \}
+}
+
+#endif

Modified: code/gazebo/trunk/server/Global.cc
===================================================================
--- code/gazebo/trunk/server/Global.cc  2008-05-08 12:15:41 UTC (rev 6402)
+++ code/gazebo/trunk/server/Global.cc  2008-05-08 13:40:05 UTC (rev 6403)
@@ -26,15 +26,10 @@
 
 #include "Global.hh"
 
-
 using namespace gazebo;
 
 Pose3d Global::poseOffset;
 
-std::list<std::string> Global::gazeboPaths;
-std::list<std::string> Global::ogrePaths;
-std::string Global::RTTMode;
-
 
////////////////////////////////////////////////////////////////////////////////
 Global::Global()
 {

Modified: code/gazebo/trunk/server/Global.hh
===================================================================
--- code/gazebo/trunk/server/Global.hh  2008-05-08 12:15:41 UTC (rev 6402)
+++ code/gazebo/trunk/server/Global.hh  2008-05-08 13:40:05 UTC (rev 6403)
@@ -31,7 +31,6 @@
 // Includes
 /////////////////////////////////////////////////////////////////////////////
 
-#include <list>
 #include <math.h>
 
 #include "Pose3d.hh"
@@ -116,14 +115,6 @@
   class Global
   {
 
-    /// Paths gazebo install
-    public: static std::list<std::string> gazeboPaths;
-
-    /// Paths to the ogre install
-    public: static std::list<std::string> ogrePaths;
-
-    public: static std::string RTTMode;
-
     /// Global pose offset
     public: static Pose3d poseOffset;
 

Modified: code/gazebo/trunk/server/SConscript
===================================================================
--- code/gazebo/trunk/server/SConscript 2008-05-08 12:15:41 UTC (rev 6402)
+++ code/gazebo/trunk/server/SConscript 2008-05-08 13:40:05 UTC (rev 6403)
@@ -13,6 +13,7 @@
            'Pose3d.cc',
            'World.cc',
            'XMLConfig.cc',
+           'GazeboConfig.cc',
            'Time.cc',
            'Entity.cc',
            'GazeboError.cc',
@@ -41,6 +42,7 @@
            '#/server/Vector3.hh',
            '#/server/World.hh',
            '#/server/XMLConfig.hh'
+           '#/server/GazeboConfig.hh'
            ] )
 
 staticObjs.append( env.StaticObject(sources) )

Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc       2008-05-08 12:15:41 UTC (rev 
6402)
+++ code/gazebo/trunk/server/Simulator.cc       2008-05-08 13:40:05 UTC (rev 
6403)
@@ -35,12 +35,13 @@
 #include "Gui.hh"
 #include "DummyGui.hh"
 #include "XMLConfig.hh"
-#include "Global.hh"
+#include "GazeboConfig.hh"
 #include "gazebo.h"
 #include "PhysicsEngine.hh"
 #include "OgreAdaptor.hh"
 #include "OgreCreator.hh"
 #include "GazeboMessage.hh"
+#include "Global.hh"
 
 #include "Simulator.hh"
 
@@ -66,6 +67,7 @@
   this->userStepInc = false;
 
   this->xmlFile=NULL;
+  this->gazeboConfig=NULL;
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -84,6 +86,7 @@
 
   GZ_DELETE (this->gui)
   GZ_DELETE (this->xmlFile)
+  GZ_DELETE (this->gazeboConfig)
   gazebo::World::Instance()->Close();
   gazebo::OgreAdaptor::Instance()->Close();
 }
@@ -99,11 +102,23 @@
     loaded=false;
   }
 
+  // load the configuration options 
+  this->gazeboConfig=new gazebo::GazeboConfig();
+  try
+  {
+    this->gazeboConfig->Load();
+  }
+  catch (GazeboError e)
+  {
+    gzthrow("Error loading the Gazebo configuration file, check the .gazeborc 
file on your HOME directory \n" << e); 
+  }
+
+
   // Load the world file
   this->xmlFile=new gazebo::XMLConfig();
   try
   {
-    xmlFile->Load(worldFileName);
+    this->xmlFile->Load(worldFileName);
   }
   catch (GazeboError e)
   {
@@ -253,6 +268,14 @@
 }
 
 
////////////////////////////////////////////////////////////////////////////////
+/// Gets local configuration for this computer
+GazeboConfig *Simulator::GetGazeboConfig() const
+{
+  return this->gazeboConfig;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
 // Return when this simulator is paused
 bool Simulator::IsPaused() const
 {

Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh       2008-05-08 12:15:41 UTC (rev 
6402)
+++ code/gazebo/trunk/server/Simulator.hh       2008-05-08 13:40:05 UTC (rev 
6403)
@@ -42,6 +42,7 @@
   class SimulationIface;
   class XMLConfig;
   class XMLConfigNode;
+  class GazeboConfig;
 
 /// \brief The World
 /*
@@ -77,6 +78,9 @@
     /// \brief Gets our current GUI interface
     public: Gui *GetUI() const;
 
+    /// \brief Gets the local configuration for this computer
+    public: gazebo::GazeboConfig *GetGazeboConfig() const;
+
     /// \brief Returns the state of the simulation true if paused
     public: bool IsPaused() const;
 
@@ -137,11 +141,13 @@
 
   
     ///pointer to the XML Data
-    private:gazebo::XMLConfig *xmlFile;
+    private: gazebo::XMLConfig *xmlFile;
 
     /// Pointer to the selected Gui 
     private: Gui *gui;
 
+/// Pointer to the selected Gui 
+    private: gazebo::GazeboConfig *gazeboConfig;
 
     /// Flag to know if we have a simulation loaded
     private: bool loaded;

Modified: code/gazebo/trunk/server/main.cc
===================================================================
--- code/gazebo/trunk/server/main.cc    2008-05-08 12:15:41 UTC (rev 6402)
+++ code/gazebo/trunk/server/main.cc    2008-05-08 13:40:05 UTC (rev 6403)
@@ -104,10 +104,9 @@
 #include <signal.h>
 #include <errno.h>
 #include <iostream>
-#include "Global.hh"
 #include "Simulator.hh"
-#include "XMLConfig.hh"
 #include "GazeboError.hh"
+#include "Global.hh"
 
 // Command line options
 const char *worldFileName;
@@ -230,53 +229,7 @@
   return;
 }
 
-
 
////////////////////////////////////////////////////////////////////////////////
-// Loads the Gazebo configuration file
-void LoadConfigFile()
-{
-  std::ifstream cfgFile;
-
-  std::string rcFilename = getenv("HOME");
-  rcFilename += "/.gazeborc";
-
-  cfgFile.open(rcFilename.c_str(), std::ios::in);
-
-  if (cfgFile)
-  {
-    gazebo::XMLConfig rc;
-    gazebo::XMLConfigNode *node;
-    rc.Load(rcFilename);
-
-    node = rc.GetRootNode()->GetChild("gazeboPath");
-    while (node)
-    {
-      std::cout << "Gazebo Path[" << node->GetValue() << "]\n";
-      gazebo::Global::gazeboPaths.push_back(node->GetValue());
-      node = node->GetNext("gazeboPath");
-    }
-
-    node = rc.GetRootNode()->GetChild("ogrePath");
-    while (node)
-    {
-      std::cout << "Ogre Path[" << node->GetValue() << "]\n";
-      gazebo::Global::ogrePaths.push_back( node->GetValue() );
-      node = node->GetNext("ogrePath");
-    }
-    gazebo::Global::RTTMode = rc.GetRootNode()->GetString("RTTMode", 
"PBuffer");
-
-  }
-  else
-  {
-    std::cout << "Unable to find the file ~/.gazeborc. Using default paths. 
This may cause OGRE to fail.\n";
-    gazebo::Global::gazeboPaths.push_back("/usr/local/share/gazebo");
-    gazebo::Global::ogrePaths.push_back("/usr/local/lib/OGRE");
-    gazebo::Global::ogrePaths.push_back("/usr/lib/OGRE");
-  }
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
 // Main function
 int main(int argc, char **argv)
 {
@@ -296,7 +249,6 @@
   //Load the simulator
   try
   {
-    LoadConfigFile();
     gazebo::Simulator::Instance()->Load(worldFileName, optServerId);
   }
   catch (gazebo::GazeboError e)

Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2008-05-08 12:15:41 UTC 
(rev 6402)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2008-05-08 13:40:05 UTC 
(rev 6403)
@@ -39,8 +39,8 @@
 #include "Entity.hh"
 #include "GazeboError.hh"
 #include "GazeboMessage.hh"
+#include "GazeboConfig.hh"
 #include "Global.hh"
-#include "GazeboError.hh"
 #include "XMLConfig.hh"
 #include "Simulator.hh"
 #include "Gui.hh"
@@ -300,8 +300,10 @@
   std::string pluginStr;
   XMLConfigNode *pluginNode;
   std::list<std::string>::iterator iter;
+ 
 
-  for (iter=Global::ogrePaths.begin(); iter!=Global::ogrePaths.end(); iter++)
+  for (iter=Simulator::Instance()->GetGazeboConfig()->GetOgrePaths().begin(); 
+       iter!=Simulator::Instance()->GetGazeboConfig()->GetOgrePaths().end(); 
iter++)
   {
     DIR *dir;
     if ((dir=opendir((*iter).c_str())) == NULL)
@@ -342,8 +344,8 @@
   std::vector<std::string>::iterator aiter;
   std::list<std::string>::iterator iter;
 
-  for (iter=Global::gazeboPaths.begin();
-       iter!=Global::gazeboPaths.end(); iter++)
+  for (iter=Simulator::Instance()->GetGazeboConfig()->GetGazeboPaths().begin();
+       iter!=Simulator::Instance()->GetGazeboConfig()->GetGazeboPaths().end(); 
iter++)
   {
     DIR *dir;
     if ((dir=opendir((*iter).c_str())) == NULL)
@@ -423,7 +425,7 @@
     this->renderSys->setConfigOption("FSAA","2");
 
     // Set the preferred RRT mode. Options are: "PBuffer", "FBO", and "Copy", 
can be set in the .gazeborc file
-    this->renderSys->setConfigOption("RTT Preferred Mode", Global::RTTMode);
+    this->renderSys->setConfigOption("RTT Preferred Mode", 
Simulator::Instance()->GetGazeboConfig()->GetRTTMode());
 
     if (create && this->videoMode != "None")
     {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to