23 #include <mars/data_broker/DataBrokerInterface.h> 25 #include <mars/interfaces/sim/EntityManagerInterface.h> 26 #include <mars/interfaces/sim/SimulatorInterface.h> 27 #include <mars/interfaces/sim/NodeManagerInterface.h> 28 #include <mars/interfaces/sim/JointManagerInterface.h> 29 #include <mars/interfaces/graphics/GraphicsManagerInterface.h> 30 #include <mars/sim/SimEntity.h> 31 #include <mars/entity_generation/entity_factory/EntityFactoryManager.h> 32 #include <mars/interfaces/Logging.hpp> 34 #include <mars/utils/misc.h> 35 #include <mars/utils/mathUtils.h> 41 using namespace interfaces;
42 using namespace utils;
46 entity_generation::EntityFactoryInterface(
"primitive") {
49 "mars_entity_factory");
78 if (map->find(
"URI") != map->end()) {
79 std::string file = (std::string) (*map)[
"URI"][0];
80 if (!file.empty() && file[0] !=
'/') {
85 if (map->find(
"URIs") != map->end()) {
86 ConfigVector::iterator vIt = (*map)[
"URIs"].begin();
87 for (; vIt != (*map)[
"URIs"].end(); ++vIt) {
88 std::string file = (std::string) (*vIt);
89 if (!file.empty() && file[0] !=
'/') {
100 entityconfig = config;
101 std::string path = (std::string)entityconfig[
"path"];
104 std::string
primitivename = (std::string)entityconfig[
"name"];
105 if (primitivename ==
"")
106 primitivename =
"unnamed_primitive";
111 if (entityconfig.
hasKey(
"geometry") && entityconfig[
"geometry"].
hasKey(
"type")) {
112 std::string
type = entityconfig[
"geometry"][
"type"];
113 map[
"filename"] =
"PRIMITIVE";
114 if (type ==
"plane") {
116 map[
"physicmode"] =
"plane";
117 map[
"origname"] =
"plane";
118 map[
"extend"][
"x"] = 10.;
119 map[
"extend"][
"y"] = 10.;
123 map[
"physicmode"] =
"box";
124 map[
"origname"] =
"box";
125 map[
"extend"][
"x"] = 1.;
126 map[
"extend"][
"y"] = 1.;
127 map[
"extend"][
"z"] = 1.;
128 map[
"position"][
"z"] = 0.5;
129 map[
"movable"] =
true;
131 if (type ==
"sphere") {
133 map[
"physicmode"] =
"sphere";
134 map[
"visualType"] =
"sphere";
135 map[
"extend"][
"x"] = 0.5;
136 map[
"extend"][
"y"] = 1.;
137 map[
"extend"][
"z"] = 1.;
138 map[
"position"][
"z"] = 0.5;
139 map[
"movable"] =
true;
141 if (type ==
"cylinder") {
144 if (type ==
"capsule") {
148 map.append(entityconfig);
157 material[
"name"] =
"defaultGrey";
158 material[
"diffuseColor"][
"a"] = 1.0;
159 material[
"diffuseColor"][
"r"] = 0.33;
160 material[
"diffuseColor"][
"g"] = 0.39;
161 material[
"diffuseColor"][
"b"] = 0.5;
162 material[
"specularColor"][
"a"] = 1.0;
163 material[
"specularColor"][
"r"] = 0.5;
164 material[
"specularColor"][
"g"] = 0.5;
165 material[
"specularColor"][
"b"] = 0.5;
166 material[
"ambientColor"][
"a"] = 1.0;
167 material[
"ambientColor"][
"r"] = 0.53;
168 material[
"ambientColor"][
"g"] = 0.59;
169 material[
"ambientColor"][
"b"] = 0.7;
170 material[
"shininess"] = 80.0;
171 if (entityconfig.
hasKey(
"material")) {
172 material.append(entityconfig[
"material"]);
178 if (suffix ==
".stl" || suffix ==
".STL") {
184 std::string parentname;
185 if (entityconfig.
hasKey(
"parent")) {
186 parentname = (std::string)entityconfig[
"parent"];
187 if (parentname ==
"world") {
NodeManagerInterface * nodes
std::string getFilenameSuffix(const std::string &file)
given a filename "foobar.baz" this will return ".baz"
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix)
NodeData is a struct to exchange node information between the GUI and the simulation.
std::string filename
The filename of the node to load the visual representation from.
virtual void switchPluginUpdateMode(int mode, PluginInterface *pl)=0
static ConfigMap fromYamlFile(const std::string &filename, bool loadURI=false)
virtual NodeId addNode(NodeData *nodeS, bool reload=false, bool loadGraphics=true)=0
Add a node to the node pool of the simulation.
virtual sim::SimEntity * createEntity(const configmaps::ConfigMap &config)
int groupID
Several nodes can be grouped by setting the same groupID.
void update(mars::interfaces::sReal time_ms)
utils::Quaternion visual_offset_rot
In the same way as the visual_offset_pos, this quaternion can be used to differentiate the orientatio...
Quaternion eulerToQuaternion(const Vector &euler_v)
virtual void registerFactory(const std::string type, EntityFactoryInterface *factory)
void handleURI(configmaps::ConfigMap *map, std::string uri)
bool fromConfigMap(configmaps::ConfigMap *config, std::string filenamePrefix, LoadCenter *loadCenter=0)
T * acquireLibraryAs(const std::string &libName, bool load=false)
bool hasKey(std::string key)
Copyright 2012, DFKI GmbH Robotics Innovation Center.
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector
std::string primitivename
PRIMITIVES(lib_manager::LibManager *theManager)
CREATE_LIB(mars::smurf::PRIMITIVES)
DESTROY_LIB(mars::smurf::PRIMITIVES)
bool movable
This boolean variable defines if the physical representation is fixed in the world or if it's a movab...
void addNode(unsigned long nodeId, const std::string &name)
std::string name
The name of the node.
MaterialData material
The material struct defines the visual material of the node.
void handleURIs(configmaps::ConfigMap *map)
unsigned long index
The unique index of the node.
ErrorNumber releaseLibrary(const std::string &libName)
Releases a previously acquired library.