42 if (m_maps_storage.size() == 0)
45 return ReturnValue::return_code::return_value_error_method_failed;
54 return ReturnValue::return_code::return_value_error_method_failed;
59 for (
auto&
it : m_maps_storage)
74 return ReturnValue::return_code::return_value_error_method_failed;
88 return ReturnValue::return_code::return_value_error_method_failed;
94 std::getline(file,
buffer);
100 if (dummy ==
"mapfile:")
114 auto p = m_maps_storage.find(map_name);
115 if (
p == m_maps_storage.end())
118 map.
crop(-1, -1, -1, -1);
120 m_maps_storage[map_name] = map;
124 yCError(
MAP2DSTORAGE) <<
"A map with the same name '" << map_name <<
"'was found, skipping...";
144 return ReturnValue::return_code::return_value_error_method_failed;
156 yCInfo(
MAP2DSTORAGE) <<
"Parameter mapCollectionContext not given. No maps/locations will be loaded.";
183 if (m_maps_storage.size() > 0)
186 for (
auto&
it : m_maps_storage)
195 if (m_locations_storage.size() > 0)
198 for (
auto&
it : m_locations_storage)
208 if (m_areas_storage.size() > 0)
211 for (
auto&
it : m_areas_storage)
245bool Map2DStorage::priv_load_locations_and_areas_v1(std::ifstream& file)
248 std::getline(file,
buffer);
249 if (
buffer !=
"Locations:")
257 std::getline(file,
buffer);
280 m_locations_storage[name] =
location;
292 std::getline(file,
buffer);
314 m_areas_storage[name] = area;
319bool Map2DStorage::priv_load_locations_and_areas_v2(std::ifstream& file)
322 std::getline(file,
buffer);
323 if (
buffer !=
"Locations:")
331 std::getline(file,
buffer);
354 m_locations_storage[name] =
location;
366 std::getline(file,
buffer);
391 m_areas_storage[name] = area;
403 std::getline(file,
buffer);
419 if (
ll &&
ll->size() == 4)
423 loc.
x =
ll->get(1).asFloat64();
424 loc.
y =
ll->get(2).asFloat64();
425 loc.
theta =
ll->get(3).asFloat64();
440 m_paths_storage[name] = path;
446bool Map2DStorage::priv_load_locations_and_areas_v3(std::ifstream& file)
449 std::getline(file,
buffer);
450 if (
buffer !=
"Locations:")
458 std::getline(file,
buffer);
482 m_locations_storage[name] =
location;
494 std::getline(file,
buffer);
520 m_areas_storage[name] = area;
532 std::getline(file,
buffer);
548 if (
ll &&
ll->size() == 4)
552 loc.
x =
ll->get(1).asFloat64();
553 loc.
y =
ll->get(2).asFloat64();
554 loc.
theta =
ll->get(3).asFloat64();
570 m_paths_storage[name] = path;
584 return ReturnValue::return_code::return_value_error_method_failed;
589 std::getline(file,
buffer);
594 return ReturnValue::return_code::return_value_error_method_failed;
596 std::getline(file,
buffer);
601 if (!priv_load_locations_and_areas_v1(file))
605 return ReturnValue::return_code::return_value_error_method_failed;
610 if (!priv_load_locations_and_areas_v2(file))
614 return ReturnValue::return_code::return_value_error_method_failed;
619 if (!priv_load_locations_and_areas_v3(file))
623 return ReturnValue::return_code::return_value_error_method_failed;
630 return ReturnValue::return_code::return_value_error_method_failed;
636 << m_locations_storage.size() <<
"locations and "
637 << m_areas_storage.size() <<
" areas and "
638 << m_paths_storage.size() <<
" paths available";
650 return ReturnValue::return_code::return_value_error_method_failed;
654 std::string
q =
"\"";
656 file <<
"Version:\n";
661 file <<
"Locations:\n";
662 std::map<std::string, Map2DLocation>::iterator
it;
663 for (
it = m_locations_storage.begin();
it != m_locations_storage.end(); ++
it)
667 file <<
q <<
tmp_loc.description <<
q <<
"\n";
674 std::map<std::string, Map2DArea>::iterator
it2;
675 for (
it2 = m_areas_storage.begin();
it2 != m_areas_storage.end(); ++
it2)
679 for (
size_t i = 0;
i <
tmp_area.points.size();
i++)
693 std::map<std::string, Map2DPath>::iterator
it3;
694 for (
it3 = m_paths_storage.begin();
it3 != m_paths_storage.end(); ++
it3)
697 file <<
it3->first <<
" ";
698 for (
size_t i=0;
i<
it3->second.size();
i++)
716 m_maps_storage.clear();
723 auto it = m_maps_storage.find(map_name);
724 if (
it == m_maps_storage.end())
727 m_maps_storage[map_name] = map;
732 m_maps_storage[map_name] = map;
739 auto it = m_maps_storage.find(map_name);
740 if (
it != m_maps_storage.end())
745 return ReturnValue::return_code::return_value_error_method_failed;
751 for (
auto&
it : m_maps_storage)
753 map_names.push_back(
it.first);
760 size_t rem = m_maps_storage.erase(map_name);
763 return ReturnValue::return_code::return_value_error_method_failed;
773 m_locations_storage.insert(std::pair<std::string, Map2DLocation>(location_name, loc));
779 m_areas_storage.insert(std::pair<std::string, Map2DArea>(area_name, area));
785 m_paths_storage.insert(std::pair<std::string, Map2DPath>(path_name, path));
791 auto it = m_locations_storage.find(location_name);
792 if (
it != m_locations_storage.end())
797 return ReturnValue::return_code::return_value_error_method_failed;
802 auto it = m_areas_storage.find(area_name);
803 if (
it != m_areas_storage.end())
808 return ReturnValue::return_code::return_value_error_method_failed;
813 auto it = m_paths_storage.find(path_name);
814 if (
it != m_paths_storage.end())
819 return ReturnValue::return_code::return_value_error_method_failed;
825 for (
auto&
it : m_locations_storage)
827 locations.push_back(
it.first);
835 for (
auto&
it : m_areas_storage)
837 areas.push_back(
it.first);
845 for (
auto&
it : m_paths_storage)
847 paths.push_back(
it.first);
855 for (
auto&
it : m_locations_storage)
857 locations.push_back(
it.second);
864 for (
auto&
it : m_areas_storage)
866 areas.push_back(
it.second);
874 for (
auto&
it : m_paths_storage)
876 paths.push_back(
it.second);
883 std::map<std::string, Map2DLocation>::iterator
orig_it;
884 orig_it = m_locations_storage.find(original_name);
885 std::map<std::string, Map2DLocation>::iterator
new_it;
886 new_it = m_locations_storage.find(new_name);
888 if (
orig_it != m_locations_storage.end() &&
889 new_it == m_locations_storage.end())
892 m_locations_storage.erase(
orig_it);
893 m_locations_storage.insert(std::pair<std::string, Map2DLocation>(new_name, loc));
896 return ReturnValue::return_code::return_value_error_method_failed;
901 std::map<std::string, Map2DLocation>::iterator
it;
902 it = m_locations_storage.find(location_name);
903 if (
it != m_locations_storage.end())
905 m_locations_storage.erase(
it);
908 return ReturnValue::return_code::return_value_error_method_failed;
913 std::map<std::string, Map2DArea>::iterator
it;
914 it = m_areas_storage.find(area_name);
915 if (
it != m_areas_storage.end())
917 m_areas_storage.erase(
it);
920 return ReturnValue::return_code::return_value_error_method_failed;
925 std::map<std::string, Map2DPath>::iterator
it;
926 it = m_paths_storage.find(path_name);
927 if (
it != m_paths_storage.end())
929 m_paths_storage.erase(
it);
932 return ReturnValue::return_code::return_value_error_method_failed;
938 std::map<std::string, Map2DArea>::iterator
orig_it;
939 orig_it = m_areas_storage.find(original_name);
940 std::map<std::string, Map2DArea>::iterator
new_it;
941 new_it = m_areas_storage.find(new_name);
943 if (
orig_it != m_areas_storage.end() &&
944 new_it == m_areas_storage.end())
947 m_areas_storage.erase(
orig_it);
948 m_areas_storage.insert(std::pair<std::string, Map2DArea>(new_name, area));
951 return ReturnValue::return_code::return_value_error_method_failed;
957 std::map<std::string, Map2DPath>::iterator
orig_it;
958 orig_it = m_paths_storage.find(original_name);
959 std::map<std::string, Map2DPath>::iterator
new_it;
960 new_it = m_paths_storage.find(new_name);
962 if (
orig_it != m_paths_storage.end() &&
963 new_it == m_paths_storage.end())
966 m_paths_storage.erase(
orig_it);
967 m_paths_storage.insert(std::pair<std::string, Map2DPath>(new_name, area));
970 return ReturnValue::return_code::return_value_error_method_failed;
977 m_locations_storage.clear();
983 m_areas_storage.clear();
989 m_paths_storage.clear();
995 for (
auto it = m_maps_storage.begin();
it != m_maps_storage.end();
it++)
997 it->second.clearMapTemporaryFlags();
1004 auto it = m_maps_storage.find(map_name);
1005 if (
it != m_maps_storage.end())
1007 it->second.clearMapTemporaryFlags();
1012 return ReturnValue::return_code::return_value_error_method_failed;
1020 std::lock_guard<std::mutex> lock(m_mutex);
1053 auto p = m_maps_storage.find(map_name);
1054 if (
p == m_maps_storage.end())
1057 return ReturnValue::return_code::return_value_error_method_failed;
1061 bool b =
p->second.saveToFile(file_name);
1069 yCError(
MAP2DSTORAGE) <<
"save_map failed: unable to save " << map_name <<
" to " << file_name;
1070 return ReturnValue::return_code::return_value_error_method_failed;
1083 auto p = m_maps_storage.find(map_name);
1084 if (
p == m_maps_storage.end())
1086 m_maps_storage[map_name] = map;
1093 return ReturnValue::return_code::return_value_error_method_failed;
1099 return ReturnValue::return_code::return_value_error_method_failed;
1107 for (
auto it = m_maps_storage.begin();
it != m_maps_storage.end();
it++)
1109 b &=
it->second.enable_map_compression_over_network(enable);
1119 return ReturnValue::return_code::return_value_error_method_failed;
std::string m_mapLocationsFile
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::string m_mapCollectionContext
std::string m_mapCollectionFile
yarp::dev::ReturnValue store_map(const yarp::dev::Nav2D::MapGrid2D &map) override
Stores a map into the map server.
yarp::dev::ReturnValue saveMapsCollection(std::string maps_collection_file) override
Save a collection of maps to disk.
yarp::dev::ReturnValue deleteLocation(std::string location_name) override
Delete a location.
yarp::dev::ReturnValue getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getAllPaths(std::vector< yarp::dev::Nav2D::Map2DPath > &paths) override
Get a list of all stored paths.
yarp::dev::ReturnValue getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location specified by the user in the world reference frame.
yarp::dev::ReturnValue enableMapsCompression(bool enable) override
Enable/disables maps compression over the network.
yarp::dev::ReturnValue storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override
Store a location specified by the user in the world reference frame.
yarp::dev::ReturnValue storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override
Store an area.
yarp::dev::ReturnValue getAreasList(std::vector< std::string > &areas) override
Get a list of the names of all stored areas.
yarp::dev::ReturnValue clearAllPaths() override
Delete all stored paths.
yarp::dev::ReturnValue storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override
Store a path.
yarp::dev::ReturnValue clearMapTemporaryFlags(std::string map_name) override
Clear all temporary flags from a specific map.
Map2DStorage()
Map2DStorage.
yarp::dev::ReturnValue get_map_names(std::vector< std::string > &map_names) override
Gets a list containing the names of all registered maps.
yarp::dev::ReturnValue getPathsList(std::vector< std::string > &paths) override
Get a list of the names of all stored paths.
yarp::dev::ReturnValue saveLocationsAndExtras(std::string locations_file) override
Save a collection of locations/area/paths etc to disk.
yarp::dev::ReturnValue loadMapsCollection(std::string maps_collection_file) override
Load a collection of maps from disk.
yarp::dev::ReturnValue deletePath(std::string path_name) override
Delete a path.
yarp::dev::ReturnValue clearAllLocations() override
Delete all stored locations.
yarp::dev::ReturnValue getAllAreas(std::vector< yarp::dev::Nav2D::Map2DArea > &areas) override
Get a list of all stored areas.
yarp::dev::ReturnValue remove_map(std::string map_name) override
Removes a map from the map server.
yarp::dev::ReturnValue renameArea(std::string original_name, std::string new_name) override
Searches for an area and renames it.
yarp::dev::ReturnValue loadMapFromDisk(std::string file_name) override
Load a map from disk.
yarp::dev::ReturnValue clearAllMapsTemporaryFlags() override
Clear all temporary flags from all stored maps.
yarp::dev::ReturnValue deleteArea(std::string area_name) override
Delete an area.
yarp::dev::ReturnValue getAllLocations(std::vector< yarp::dev::Nav2D::Map2DLocation > &locations) override
Get a list of all stored locations.
yarp::dev::ReturnValue renamePath(std::string original_name, std::string new_name) override
Searches for a path and renames it.
yarp::dev::ReturnValue get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map) override
Gets a map from the map server.
yarp::dev::ReturnValue saveMapToDisk(std::string map_name, std::string file_name) override
Save a map to disk.
yarp::dev::ReturnValue clearAllAreas() override
Delete all stored areas.
yarp::dev::ReturnValue getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path) override
Retrieves a path.
yarp::dev::ReturnValue renameLocation(std::string original_name, std::string new_name) override
Searches for a location and renames it.
yarp::dev::ReturnValue loadLocationsAndExtras(std::string locations_file) override
Load a collection of locations/areas/paths etc from disk.
yarp::dev::ReturnValue getLocationsList(std::vector< std::string > &locations) override
Get a list of the names of all stored locations.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
yarp::dev::ReturnValue clearAllMaps() override
Removes all the registered maps from the server.
std::string description
user defined string
std::string map_id
name of the map
std::vector< yarp::math::Vec2D< double > > points
list of points which define the vertices of the area
std::string map_id
name of the map
double theta
orientation [deg] in the map reference frame
double y
y position of the location [m], expressed in the map reference frame
double x
x position of the location [m], expressed in the map reference frame
std::string description
user defined string
void push_back(yarp::dev::Nav2D::Map2DLocation loc)
Inserts a new location into the path @loc the location to be inserted.
std::string getMapName() const
Retrieves the map name.
bool crop(int left, int top, int right, int bottom)
Modifies the map, cropping pixels at the boundaries.
bool loadFromFile(std::string map_filename)
Loads a yarp map file from disk.
A simple collection of objects that can be described and transmitted in a portable way.
void fromString(const std::string &text)
Initializes bottle from a string.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
An interface for reading from a network connection.
An interface for writing to a network connection.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
std::string findFile(const std::string &name)
Find the full path to a file.
A base class for nested structures that can be searched.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isString() const
Checks if value is a string.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual bool isList() const
Checks if value is a list.
virtual Bottle * asList() const
Get list value.
virtual bool isVocab32() const
Checks if value is a vocabulary identifier.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.