SUMO - Simulation of Urban MObility
ShapeContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-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 /****************************************************************************/
18 // Storage for geometrical objects, sorted by the layers they are in
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <fstream>
28 #include <stdlib.h>
29 #include <iostream>
30 #include <utility>
31 #include <string>
32 #include <cmath>
36 #include <utils/common/ToString.h>
37 #include <utils/common/StdDefs.h>
38 #include "ShapeContainer.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45 
47 
48 bool
49 ShapeContainer::addPolygon(const std::string& id, const std::string& type,
50  const RGBColor& color, double layer,
51  double angle, const std::string& imgFile, bool relativePath,
52  const PositionVector& shape, bool geo, bool fill, double lineWidth, bool ignorePruning) {
53  return add(new SUMOPolygon(id, type, color, shape, geo, fill, lineWidth, layer, angle, imgFile, relativePath), ignorePruning);
54 }
55 
56 
57 bool
58 ShapeContainer::addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,
59  const std::string& lane, double posOverLane, double posLat, double layer, double angle,
60  const std::string& imgFile, bool relativePath, double width, double height, bool ignorePruning) {
61  return add(new PointOfInterest(id, type, color, pos, geo, lane, posOverLane, posLat, layer, angle, imgFile, relativePath, width, height), ignorePruning);
62 }
63 
64 
65 bool
66 ShapeContainer::removePolygon(const std::string& id) {
67  return myPolygons.remove(id);
68 }
69 
70 
71 bool
72 ShapeContainer::removePOI(const std::string& id) {
73  return myPOIs.remove(id);
74 }
75 
76 
77 void
78 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
79  PointOfInterest* p = myPOIs.get(id);
80  if (p != nullptr) {
81  static_cast<Position*>(p)->set(pos);
82  }
83 }
84 
85 
86 void
87 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
88  SUMOPolygon* p = myPolygons.get(id);
89  if (p != nullptr) {
90  p->setShape(shape);
91  }
92 }
93 
94 
95 bool
96 ShapeContainer::add(SUMOPolygon* poly, bool /* ignorePruning */) {
97  if (!myPolygons.add(poly->getID(), poly)) {
98  delete poly;
99  return false;
100  }
101  return true;
102 }
103 
104 
105 bool
106 ShapeContainer::add(PointOfInterest* poi, bool /* ignorePruning */) {
107  if (!myPOIs.add(poi->getID(), poi)) {
108  delete poi;
109  return false;
110  }
111  return true;
112 }
113 
114 
115 /****************************************************************************/
116 
T get(const std::string &id) const
Retrieves an item.
POIs myPOIs
stored POIs
Polygons myPolygons
stored Polygons
ShapeContainer()
Constructor.
const std::string & getID() const
Returns the id.
Definition: Named.h:78
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, bool relativePath, const PositionVector &shape, bool geo, bool fill, double lineWidth, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
bool add(const std::string &id, T item)
Adds an item.
virtual void movePOI(const std::string &id, const Position &pos)
Assigns a new position to the named PoI.
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
Definition: SUMOPolygon.h:120
virtual bool removePolygon(const std::string &id)
Removes a polygon from the container.
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.
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.
virtual void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
virtual bool add(SUMOPolygon *poly, bool ignorePruning=false)
add polygon
A point-of-interest.
bool remove(const std::string &id, const bool del=true)
Removes an item.
virtual ~ShapeContainer()
Destructor.