SUMO - Simulation of Urban MObility
TraCI_Polygon.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // C++ TraCI client API implementation
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2017 - 2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 
23 #include <microsim/MSNet.h>
24 #include <utils/shapes/Polygon.h>
26 
27 #include "TraCI_Polygon.h"
28 #include "TraCI.h"
29 
30 std::vector<std::string> TraCI_Polygon::getIDList() {
31  std::vector<std::string> ids;
33  shapeCont.getPolygons().insertIDs(ids);
34  return ids;
35 }
36 std::string TraCI_Polygon::getType(const std::string& polygonID) {
37  return getPolygon(polygonID)->getType();
38 }
39 TraCIPositionVector TraCI_Polygon::getShape(const std::string& polygonID) {
40  SUMO::Polygon* p = getPolygon(polygonID);
42 }
43 bool TraCI_Polygon::getFilled(const std::string& polygonID) {
44  return getPolygon(polygonID)->getFill();
45 }
46 TraCIColor TraCI_Polygon::getColor(const std::string& polygonID) {
47  SUMO::Polygon* p = getPolygon(polygonID);
48  return TraCI::makeTraCIColor(p->getColor());
49 }
50 std::string TraCI_Polygon::getParameter(const std::string& polygonID, const std::string& paramName) {
51  return getPolygon(polygonID)->getParameter(paramName, "");
52 }
53 void TraCI_Polygon::setType(const std::string& polygonID, const std::string& setType) {
54  SUMO::Polygon* p = getPolygon(polygonID);
55  p->setType(setType);
56 }
57 void TraCI_Polygon::setShape(const std::string& polygonID, const TraCIPositionVector& shape) {
58  PositionVector positionVector = TraCI::makePositionVector(shape);
59  getPolygon(polygonID); // just to check whether it exists
61  shapeCont.reshapePolygon(polygonID, positionVector);
62 }
63 void TraCI_Polygon::setColor(const std::string& polygonID, const TraCIColor& c) {
64  getPolygon(polygonID)->setColor(TraCI::makeRGBColor(c));
65 }
66 void
67 TraCI_Polygon::add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) {
71  if (!shapeCont.addPolygon(polygonID, type, col, (double)layer, Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, pShape, fill)) {
72  throw TraCIException("Could not add polygon '" + polygonID + "'");
73  }
74 }
75 void TraCI_Polygon::remove(const std::string& polygonID, int /* layer */) {
76  // !!! layer not used yet (shouldn't the id be enough?)
78  if (!shapeCont.removePolygon(polygonID)) {
79  throw TraCIException("Could not remove polygon '" + polygonID + "'");
80  }
81 }
82 
83 void TraCI_Polygon::setFilled(std::string polygonID, bool filled) {
84  SUMO::Polygon* p = getPolygon(polygonID);
85  p->setFill(filled);
86 }
87 
88 SUMO::Polygon* TraCI_Polygon::getPolygon(const std::string& id) {
90  if (p == 0) {
91  throw TraCIException("Polygon '" + id + "' is not known");
92  }
93  return p;
94 }
95 void TraCI_Polygon::setParameter(std::string& id, std::string& name, std::string& value) {
96  SUMO::Polygon* p = getPolygon(id);
97  p->addParameter(name, value);
98 }
99 
100 
static TraCIColor getColor(const std::string &polygonID)
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:152
static void add(const std::string &polygonID, const TraCIPositionVector &shape, const TraCIColor &c, bool fill, const std::string &type, int layer)
const Polygons & getPolygons() const
Returns all polygons.
bool getFill() const
Returns whether the polygon is filled.
Definition: Polygon.h:95
static std::string getParameter(const std::string &polygonID, const std::string &paramName)
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: TraCI.cpp:128
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
static void remove(const std::string &polygonID, int layer=0)
Storage for geometrical objects.
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: Polygon.h:87
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)
A 2D- or 3D-polygon.
Definition: Polygon.h:57
static void setFilled(std::string polygonID, bool filled)
static std::vector< std::string > getIDList()
static PositionVector makePositionVector(const TraCIPositionVector &vector)
Definition: TraCI.cpp:118
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:433
A list of positions.
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 fill, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
virtual void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
const std::string & getType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:71
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
void setType(const std::string &type)
Sets a new type.
Definition: Shape.h:113
const RGBColor & getColor() const
Returns the color of the Shape.
Definition: Shape.h:79
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition: TraCI.cpp:108
static TraCIPositionVector getShape(const std::string &polygonID)
static void setType(const std::string &polygonID, const std::string &setType)
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: TraCI.cpp:138
static void setShape(const std::string &polygonID, const TraCIPositionVector &shape)
void setFill(bool fill)
Sets whether the polygon shall be filled.
Definition: Polygon.h:108
A list of positions.
void setColor(const RGBColor &col)
Sets a new color.
Definition: Shape.h:121
static SUMO::Polygon * getPolygon(const std::string &id)
static const double DEFAULT_ANGLE
Definition: Shape.h:151