|
From: Markus R. <rol...@us...> - 2006-01-24 19:16:43
|
Update of /cvsroot/simspark/simspark/spark/plugin/rosimporter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2613/rosimporter Added Files: Makefile.am export.cpp rosimporter.cpp rosimporter.h rosimporter_c.cpp Log Message: - added initial skeleton for a RosSim XML Importer --- NEW FILE: rosimporter_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: rosimporter_c.cpp,v 1.1 2006/01/24 19:16:32 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "rosimporter.h" void CLASS(RosImporter)::DefineClass() { DEFINE_BASECLASS(oxygen/SceneImporter); } --- NEW FILE: export.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: export.cpp,v 1.1 2006/01/24 19:16:32 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "rosimporter.h" ZEITGEIST_EXPORT_BEGIN() ZEITGEIST_EXPORT(RosImporter); ZEITGEIST_EXPORT_END() --- NEW FILE: Makefile.am --- pkglib_LTLIBRARIES = rosimporter.la rosimporter_la_SOURCES =\ export.cpp \ rosimporter.cpp\ rosimporter.h \ rosimporter_c.cpp # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name rosimporter_la_LDFLAGS = -module -avoid-version -L${top_srcdir}/utility/tinyxml rosimporter_la_LIBADD = -ltinyxml AM_CPPFLAGS = -I${top_srcdir}/lib -I${top_srcdir}/utility @RUBY_CPPFLAGS@ --- NEW FILE: rosimporter.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: rosimporter.cpp,v 1.1 2006/01/24 19:16:32 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "rosimporter.h" #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/fileserver/fileserver.h> #include <boost/scoped_array.hpp> using namespace zeitgeist; using namespace oxygen; using namespace boost; using namespace std; #define S_FROMSTRING "<from string>"; RosImporter::RosImporter() : SceneImporter() { } RosImporter::~RosImporter() { } TiXmlElement* RosImporter::GetFirstChild(TiXmlNode* node, const std::string& type) { TiXmlNode* childNode = node->FirstChild(type.c_str()); if ( (childNode == 0) || (childNode->Type() != TiXmlNode::ELEMENT) ) { return 0; } return static_cast<TiXmlElement*>(childNode); } TiXmlElement* RosImporter::IterateChildren(TiXmlNode* node, const std::string& type) { TiXmlNode* childNode = node->Parent()->IterateChildren(type.c_str(),node); if ( (childNode == 0) || (childNode->Type() != TiXmlNode::ELEMENT) ) { return 0; } return static_cast<TiXmlElement*>(childNode); } bool RosImporter::ImportScene(const std::string& fileName, shared_ptr<BaseNode> root, shared_ptr<ParameterList> parameter) { // try to open the file shared_ptr<salt::RFile> file = GetFile()->Open(fileName); if (file.get() == 0) { GetLog()->Error() << "(RosImporter) ERROR: cannot open file '" << fileName << "'\n"; return false; } mFileName = fileName; // read entire file into a temporary buffer scoped_array<char> buffer(new char[file->Size() + 1]); file->Read(buffer.get(), file->Size()); buffer[file->Size()] = 0; return ParseScene(buffer.get(), file->Size(), root, parameter); } bool RosImporter::ParseScene(const std::string& scene, shared_ptr<BaseNode> root, shared_ptr<ParameterList> parameter) { mFileName = S_FROMSTRING; return ParseScene(scene.c_str(),scene.size(),root,parameter); } bool RosImporter::ParseScene(const char* scene, int size, boost::shared_ptr<oxygen::BaseNode> root, boost::shared_ptr<zeitgeist::ParameterList> parameter) { TiXmlDocument document; document.Parse(scene); if (document.Error()) { GetLog()->Error() << "(RosImporter) ERROR: xml parsing error: " << document.ErrorDesc() << std::endl; return false; } TiXmlElement* xmlRoot = document.RootElement(); if (xmlRoot == 0) { // empty doc return true; } for ( TiXmlNode* node = xmlRoot->FirstChild(); xmlRoot != 0; node = xmlRoot->IterateChildren(node) ) { TiXmlElement* element = static_cast<TiXmlElement*>(node); std::string value(node->Value()); } return true; } --- NEW FILE: rosimporter.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: rosimporter.h,v 1.1 2006/01/24 19:16:32 rollmark Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef ROSIMPORTER_H #define ROSIMPORTER_H #include <oxygen/sceneserver/sceneimporter.h> #include <oxygen/sceneserver/basenode.h> #include <tinyxml/tinyxml.h> class RosImporter : public oxygen::SceneImporter { public: RosImporter(); virtual ~RosImporter(); virtual bool ImportScene(const std::string& fileName, boost::shared_ptr<oxygen::BaseNode> root, boost::shared_ptr<zeitgeist::ParameterList> parameter); virtual bool ParseScene(const std::string& scene, boost::shared_ptr<oxygen::BaseNode> root, boost::shared_ptr<zeitgeist::ParameterList> parameter); protected: virtual bool ParseScene(const char* scene, int size, boost::shared_ptr<oxygen::BaseNode> root, boost::shared_ptr<zeitgeist::ParameterList> parameter); TiXmlElement* GetFirstChild(TiXmlNode* node, const std::string& type); TiXmlElement* IterateChildren(TiXmlNode* node, const std::string& type); protected: /** the last supplied fileName */ std::string mFileName; }; DECLARE_CLASS(RosImporter); #endif // ROSIMPORTER_H |