Line data Source code
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 : /****************************************************************************/
12 : /// @file TraCI_Polygon.cpp
13 : /// @author Gregor L\"ammel
14 : /// @date 15.03.2017
15 : /// @version $Id$
16 : ///
17 : // C++ TraCI client API implementation
18 : /****************************************************************************/
19 :
20 :
21 :
22 : #include <microsim/MSNet.h>
23 : #include <utils/shapes/SUMOPolygon.h>
24 : #include <utils/shapes/ShapeContainer.h>
25 :
26 : #include "TraCI_Polygon.h"
27 : #include "TraCI.h"
28 :
29 30 : std::vector<std::string> TraCI_Polygon::getIDList() {
30 30 : std::vector<std::string> ids;
31 30 : ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
32 30 : shapeCont.getPolygons().insertIDs(ids);
33 30 : return ids;
34 : }
35 9 : std::string TraCI_Polygon::getType(const std::string& polygonID) {
36 9 : return getPolygon(polygonID)->getType();
37 : }
38 6015 : TraCIPositionVector TraCI_Polygon::getShape(const std::string& polygonID) {
39 6015 : SUMOPolygon* p = getPolygon(polygonID);
40 6015 : return TraCI::makeTraCIPositionVector(p->getShape());
41 : }
42 9 : bool TraCI_Polygon::getFilled(const std::string& polygonID) {
43 9 : return getPolygon(polygonID)->getFill();
44 : }
45 11 : TraCIColor TraCI_Polygon::getColor(const std::string& polygonID) {
46 11 : SUMOPolygon* p = getPolygon(polygonID);
47 9 : return TraCI::makeTraCIColor(p->getColor());
48 : }
49 2 : std::string TraCI_Polygon::getParameter(const std::string& polygonID, const std::string& paramName) {
50 2 : return getPolygon(polygonID)->getParameter(paramName, "");
51 : }
52 2 : void TraCI_Polygon::setType(const std::string& polygonID, const std::string& setType) {
53 2 : SUMOPolygon* p = getPolygon(polygonID);
54 1 : p->setType(setType);
55 1 : }
56 2 : void TraCI_Polygon::setShape(const std::string& polygonID, const TraCIPositionVector& shape) {
57 2 : PositionVector positionVector = TraCI::makePositionVector(shape);
58 2 : getPolygon(polygonID); // just to check whether it exists
59 1 : ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
60 2 : shapeCont.reshapePolygon(polygonID, positionVector);
61 1 : }
62 2 : void TraCI_Polygon::setColor(const std::string& polygonID, const TraCIColor& c) {
63 3 : getPolygon(polygonID)->setColor(TraCI::makeRGBColor(c));
64 1 : }
65 : void
66 46 : TraCI_Polygon::add(const std::string& polygonID, const TraCIPositionVector& shape, const TraCIColor& c, bool fill, const std::string& type, int layer) {
67 46 : ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
68 46 : PositionVector pShape = TraCI::makePositionVector(shape);
69 92 : RGBColor col = TraCI::makeRGBColor(c);
70 46 : if (!shapeCont.addPolygon(polygonID, type, col, (double)layer, Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, pShape, false, fill)) {
71 0 : throw TraCIException("Could not add polygon '" + polygonID + "'");
72 46 : }
73 46 : }
74 2 : void TraCI_Polygon::remove(const std::string& polygonID, int /* layer */) {
75 : // !!! layer not used yet (shouldn't the id be enough?)
76 2 : ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
77 2 : if (!shapeCont.removePolygon(polygonID)) {
78 1 : throw TraCIException("Could not remove polygon '" + polygonID + "'");
79 : }
80 1 : }
81 :
82 5 : void TraCI_Polygon::setFilled(std::string polygonID, bool filled) {
83 5 : SUMOPolygon* p = getPolygon(polygonID);
84 4 : p->setFill(filled);
85 4 : }
86 :
87 6058 : SUMOPolygon* TraCI_Polygon::getPolygon(const std::string& id) {
88 6058 : SUMOPolygon* p = MSNet::getInstance()->getShapeContainer().getPolygons().get(id);
89 6058 : if (p == 0) {
90 6 : throw TraCIException("Polygon '" + id + "' is not known");
91 : }
92 6052 : return p;
93 : }
94 1 : void TraCI_Polygon::setParameter(std::string& id, std::string& name, std::string& value) {
95 1 : SUMOPolygon* p = getPolygon(id);
96 1 : p->setParameter(name, value);
97 43555 : }
98 :
99 :
|