SUMO - Simulation of Urban MObility
POI.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // C++ TraCI client API implementation
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
30 #include <microsim/MSNet.h>
32 #include "POI.h"
33 #include "Helper.h"
34 
35 
36 namespace libsumo {
37 // ===========================================================================
38 // static member initializations
39 // ===========================================================================
42 
43 
44 // ===========================================================================
45 // static member definitions
46 // ===========================================================================
47 std::vector<std::string>
49  std::vector<std::string> ids;
51  shapeCont.getPOIs().insertIDs(ids);
52  return ids;
53 }
54 
55 
56 int
58  return (int)getIDList().size();
59 }
60 
61 
62 std::string
63 POI::getType(const std::string& poiID) {
64  return getPoI(poiID)->getShapeType();
65 }
66 
67 
69 POI::getColor(const std::string& poiID) {
70  return Helper::makeTraCIColor(getPoI(poiID)->getShapeColor());
71 }
72 
73 
75 POI::getPosition(const std::string& poiID, const bool includeZ) {
76  return Helper::makeTraCIPosition(*getPoI(poiID), includeZ);
77 }
78 
79 
80 std::string
81 POI::getParameter(const std::string& poiID, const std::string& key) {
82  return getPoI(poiID)->getParameter(key, "");
83 }
84 
85 
86 void
87 POI::setType(const std::string& poiID, const std::string& type) {
88  getPoI(poiID)->setShapeType(type);
89 }
90 
91 
92 void
93 POI::setPosition(const std::string& poiID, double x, double y) {
94  // try to retrieve so that the correct error is generated for unknown poiIDs
95  getPoI(poiID);
97 }
98 
99 
100 void
101 POI::setColor(const std::string& poiID, const TraCIColor& c) {
103 }
104 
105 
106 bool
107 POI::add(const std::string& poiID, double x, double y, const TraCIColor& color, const std::string& poiType, int layer) {
109  return shapeCont.addPOI(poiID, poiType, Helper::makeRGBColor(color), Position(x, y), false, "", 0, 0, (double)layer,
115 }
116 
117 
118 bool
119 POI::remove(const std::string& poiID, int /* layer */) {
121  return shapeCont.removePOI(poiID);
122 }
123 
124 
125 void
126 POI::setParameter(const std::string& poiID, const std::string& key, const std::string& value) {
127  PointOfInterest* p = getPoI(poiID);
128  p->setParameter(key, value);
129 }
130 
131 
133 
134 
136 POI::getPoI(const std::string& id) {
138  if (sumoPoi == nullptr) {
139  throw TraCIException("POI '" + id + "' is not known");
140  }
141  return sumoPoi;
142 }
143 
144 
145 NamedRTree*
147  NamedRTree* t = new NamedRTree();
149  for (const auto& i : shapeCont.getPOIs()) {
150  const float cmin[2] = {(float)i.second->x(), (float)i.second->y()};
151  const float cmax[2] = {(float)i.second->x(), (float)i.second->y()};
152  t->Insert(cmin, cmax, i.second);
153  }
154  return t;
155 }
156 
157 
158 void
159 POI::storeShape(const std::string& id, PositionVector& shape) {
160  shape.push_back(*getPoI(id));
161 }
162 
163 
164 std::shared_ptr<VariableWrapper>
166  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
167 }
168 
169 
170 bool
171 POI::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
172  switch (variable) {
173  case TRACI_ID_LIST:
174  return wrapper->wrapStringList(objID, variable, getIDList());
175  case ID_COUNT:
176  return wrapper->wrapInt(objID, variable, getIDCount());
177  case VAR_TYPE:
178  return wrapper->wrapString(objID, variable, getType(objID));
179  case VAR_COLOR:
180  return wrapper->wrapColor(objID, variable, getColor(objID));
181  case VAR_POSITION:
182  return wrapper->wrapPosition(objID, variable, getPosition(objID));
183  case VAR_POSITION3D:
184  return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
185  default:
186  return false;
187  }
188 }
189 
190 
191 }
192 
193 
194 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:83
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:230
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:48
static LIBSUMO_SUBSCRIPTION_API NamedRTree * getTree()
Returns a tree filled with PoI instances.
Definition: POI.cpp:146
static bool remove(const std::string &poiID, int layer=0)
Definition: POI.cpp:119
#define VAR_POSITION
void setShapeColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:130
static void setParameter(const std::string &poiID, const std::string &key, const std::string &value)
Definition: POI.cpp:126
static void setColor(const std::string &poiID, const TraCIColor &c)
Definition: POI.cpp:101
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:247
void setShapeType(const std::string &type)
Sets a new type.
Definition: Shape.h:123
T get(const std::string &id) const
Retrieves an item.
static const double DEFAULT_IMG_HEIGHT
Definition: Shape.h:51
#define VAR_TYPE
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:65
#define VAR_COLOR
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:200
Storage for geometrical objects.
static bool add(const std::string &poiID, double x, double y, const TraCIColor &color, const std::string &poiType="", int layer=0)
Definition: POI.cpp:107
virtual bool wrapString(const std::string &objID, const int variable, const std::string &value)=0
void insertIDs(std::vector< std::string > &into) const
#define VAR_POSITION3D
static std::shared_ptr< VariableWrapper > makeWrapper()
Definition: POI.cpp:165
const std::string & getShapeType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:76
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: Helper.cpp:241
virtual void movePOI(const std::string &id, const Position &pos)
Assigns a new position to the named PoI.
#define TRACI_ID_LIST
static int getIDCount()
Definition: POI.cpp:57
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:439
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
A list of positions.
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: POI.cpp:171
static const bool DEFAULT_RELATIVEPATH
Definition: Shape.h:49
virtual bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, double posLat, double layer, double angle, const std::string &imgFile, bool relativePath, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
static SubscriptionResults mySubscriptionResults
Definition: POI.h:90
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static void setType(const std::string &poiID, const std::string &setType)
Definition: POI.cpp:87
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:52
Definition: Edge.cpp:30
static std::vector< std::string > getIDList()
Definition: POI.cpp:48
virtual bool wrapPosition(const std::string &objID, const int variable, const TraCIPosition &value)=0
static std::string getParameter(const std::string &poiID, const std::string &key)
Definition: POI.cpp:81
virtual bool wrapColor(const std::string &objID, const int variable, const TraCIColor &value)=0
static ContextSubscriptionResults myContextSubscriptionResults
Definition: POI.h:91
static TraCIPosition getPosition(const std::string &poiID, const bool includeZ=false)
Definition: POI.cpp:75
static std::string getType(const std::string &poiID)
Definition: POI.cpp:63
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
static PointOfInterest * getPoI(const std::string &id)
Definition: POI.cpp:136
static const double DEFAULT_IMG_WIDTH
Definition: Shape.h:50
A point-of-interest.
#define ID_COUNT
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
A 3D-position.
Definition: TraCIDefs.h:107
static TraCIColor getColor(const std::string &poiID)
Definition: POI.cpp:69
static void storeShape(const std::string &id, PositionVector &shape)
Saves the shape of the requested object in the given container.
Definition: POI.cpp:159
static void setPosition(const std::string &poiID, double x, double y)
Definition: POI.cpp:93
static const double DEFAULT_ANGLE
Definition: Shape.h:47
const POIs & getPOIs() const
Returns all pois.