SUMO - Simulation of Urban MObility
TraCI_Polygon.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // C++ TraCI client API implementation
18 /****************************************************************************/
19 
20 
21 
22 #include <microsim/MSNet.h>
25 
26 #include "TraCI_Polygon.h"
27 #include "TraCI.h"
28 
29 std::vector<std::string> TraCI_Polygon::getIDList() {
30  std::vector<std::string> ids;
32  shapeCont.getPolygons().insertIDs(ids);
33  return ids;
34 }
35 std::string TraCI_Polygon::getType(const std::string& polygonID) {
36  return getPolygon(polygonID)->getType();
37 }
38 TraCIPositionVector TraCI_Polygon::getShape(const std::string& polygonID) {
39  SUMOPolygon* p = getPolygon(polygonID);
41 }
42 bool TraCI_Polygon::getFilled(const std::string& polygonID) {
43  return getPolygon(polygonID)->getFill();
44 }
45 TraCIColor TraCI_Polygon::getColor(const std::string& polygonID) {
46  SUMOPolygon* p = getPolygon(polygonID);
47  return TraCI::makeTraCIColor(p->getColor());
48 }
49 std::string TraCI_Polygon::getParameter(const std::string& polygonID, const std::string& paramName) {
50  return getPolygon(polygonID)->getParameter(paramName, "");
51 }
52 void TraCI_Polygon::setType(const std::string& polygonID, const std::string& setType) {
53  SUMOPolygon* p = getPolygon(polygonID);
54  p->setType(setType);
55 }
56 void TraCI_Polygon::setShape(const std::string& polygonID, const TraCIPositionVector& shape) {
57  PositionVector positionVector = TraCI::makePositionVector(shape);
58  getPolygon(polygonID); // just to check whether it exists
60  shapeCont.reshapePolygon(polygonID, positionVector);
61 }
62 void TraCI_Polygon::setColor(const std::string& polygonID, const TraCIColor& c) {
63  getPolygon(polygonID)->setColor(TraCI::makeRGBColor(c));
64 }
65 void
66 TraCI_Polygon::add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) {
70  if (!shapeCont.addPolygon(polygonID, type, col, (double)layer, Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, pShape, false, fill)) {
71  throw TraCIException("Could not add polygon '" + polygonID + "'");
72  }
73 }
74 void TraCI_Polygon::remove(const std::string& polygonID, int /* layer */) {
75  // !!! layer not used yet (shouldn't the id be enough?)
77  if (!shapeCont.removePolygon(polygonID)) {
78  throw TraCIException("Could not remove polygon '" + polygonID + "'");
79  }
80 }
81 
82 void TraCI_Polygon::setFilled(std::string polygonID, bool filled) {
83  SUMOPolygon* p = getPolygon(polygonID);
84  p->setFill(filled);
85 }
86 
87 SUMOPolygon* TraCI_Polygon::getPolygon(const std::string& id) {
89  if (p == 0) {
90  throw TraCIException("Polygon '" + id + "' is not known");
91  }
92  return p;
93 }
94 void TraCI_Polygon::setParameter(std::string& id, std::string& name, std::string& value) {
95  SUMOPolygon* p = getPolygon(id);
96  p->setParameter(name, value);
97 }
98 
99 
static TraCIColor getColor(const std::string &polygonID)
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:151
static void add(const std::string &polygonID, const TraCIPositionVector &shape, const TraCIColor &c, bool fill, const std::string &type, int layer)
static std::string getParameter(const std::string &polygonID, const std::string &paramName)
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: TraCI.cpp:139
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: SUMOPolygon.h:84
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
static void remove(const std::string &polygonID, int layer=0)
Storage for geometrical objects.
const Polygons & getPolygons() const
Returns all polygons.
static void setParameter(std::string &name, std::string &value, std::string &string)
static void setColor(const std::string &polygonID, const TraCIColor &c)
static bool getFilled(const std::string &polygonID)
static std::string getType(const std::string &polygonID)
T get(const std::string &id) const
Retrieves an item.
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const PositionVector &shape, bool geo, bool fill, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
static void setFilled(std::string polygonID, bool filled)
static std::vector< std::string > getIDList()
static PositionVector makePositionVector(const TraCIPositionVector &vector)
Definition: TraCI.cpp:129
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:429
A list of positions.
void insertIDs(std::vector< std::string > &into) const
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
bool getFill() const
Returns whether the polygon is filled.
Definition: SUMOPolygon.h:92
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
const RGBColor & getColor() const
Returns the color of the Shape.
Definition: Shape.h:78
virtual void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
static SUMOPolygon * getPolygon(const std::string &id)
void setType(const std::string &type)
Sets a new type.
Definition: Shape.h:112
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition: TraCI.cpp:119
static TraCIPositionVector getShape(const std::string &polygonID)
A color.
Definition: TraCIDefs.h:77
static void setType(const std::string &polygonID, const std::string &setType)
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: TraCI.cpp:149
const std::string & getType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:70
static void setShape(const std::string &polygonID, const TraCIPositionVector &shape)
A list of positions.
void setColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:120
void setFill(bool fill)
Sets whether the polygon shall be filled.
Definition: SUMOPolygon.h:104
static const double DEFAULT_ANGLE
Definition: Shape.h:150