ed
load_model.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 // ROS
4 #include <ros/console.h>
5 
6 // TU/e Robotics
7 #include <tue/filesystem/path.h>
10 #include <tue/config/loaders/xml.h>
12 
13 // ED
14 #include "ed/update_request.h"
15 #include "ed/models/model_loader.h"
16 
17 namespace ed {
18 
19 namespace models {
20 
21 bool loadModel(const enum LoadType load_type, const std::string& source, ed::UpdateRequest& req)
22 {
23  ed::models::ModelLoader model_loader;
25  if (load_type == LoadType::FILE)
26  {
27  tue::filesystem::Path path(source);
28  if (!path.exists())
29  {
30  ROS_ERROR_STREAM("Couldn't open: '" << path << "', because it doesn't exist");
31  return false;
32  }
33 
35  std::string extension = tue::filesystem::Path(source).extension();
36  if ( extension == ".sdf" || extension == ".world")
38  else if (extension == ".xml")
40  else if (extension == ".yml" || extension == ".yaml")
42  else
43  {
44  ROS_ERROR_STREAM("[model_viewer] extension: '" << extension << "' is not supported.");
45  return false;
46  }
47 
48  if (!model_loader.create(config.data(), req, error))
49  {
50  ROS_ERROR_STREAM("File '" << source << "' could not be loaded:" <<
51  "\nError:\n" << error.str());
52  return false;
53  }
54  }
55  else if (load_type == LoadType::MODEL)
56  {
57  if (!model_loader.create("_root", source, req, error, true))
58  {
59  ROS_ERROR_STREAM("Model '" << source << "' could not be loaded:" <<
60  "\nError:\n" << error.str());
61  return false;
62  }
63  }
64  else
65  {
66  ROS_ERROR_STREAM("Unknown load type");
67  return false;
68  }
69 
70  return true;
71 
72 }
73 
74 } // End of namespace 'models'
75 
76 } // End of namespace 'ed'
ed::UpdateRequest
Definition: update_request.h:24
std::string
tue::config::loadFromXMLFile
bool loadFromXMLFile(const std::string &filename, ReaderWriter &config)
tue::filesystem::Path
tue::filesystem::Path::extension
std::string extension() const
std::stringstream
ed::models::ModelLoader
Definition: model_loader.h:18
tue::filesystem::Path::exists
bool exists() const
iostream
tue::config::ReaderWriter
tue::config::loadFromYAMLFile
bool loadFromYAMLFile(const std::string &filename, ReaderWriter &config, const ResolveConfig &resolve_config=ResolveConfig::defaultConfig())
ed::models::ModelLoader::create
bool create(const UUID &id, const std::string &type, UpdateRequest &req, std::stringstream &error, const bool allow_sdf=false)
create add entity to update_request with id 'id' of the type 'type'. If allow_sdf is true,...
Definition: model_loader.cpp:285
update_request.h
tue::config::ReaderWriter::data
DataPointer data() const
ed::log::error
std::ostream & error()
Definition: logging.cpp:74
sdf.h
ed::models::LoadType
LoadType
The LoadType enum indicates whether to load directly from a file or from a model that is part of the ...
Definition: model_loader.h:148
yaml.h
tue::config::loadFromSDFFile
bool loadFromSDFFile(const std::string &filename, ReaderWriter &config)
configuration.h
path.h
ed::models::MODEL
@ MODEL
Definition: shape_loader_private.h:27
ed
Definition: convex_hull.h:8
ed::models::FILE
@ FILE
Definition: shape_loader_private.h:28
ed::models::loadModel
bool loadModel(const LoadType load_type, const std::string &source, ed::UpdateRequest &req)
loadModel loads an ED model from file
Definition: load_model.cpp:21
xml.h
model_loader.h
config
tue::config::ReaderWriter config