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-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 /****************************************************************************/
20 // Storage for geometrical objects, sorted by the layers they are in
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <fstream>
34 #include <stdlib.h>
35 #include <iostream>
36 #include <utility>
37 #include <string>
38 #include <cmath>
42 #include <utils/common/ToString.h>
43 #include <utils/common/StdDefs.h>
44 #include "ShapeContainer.h"
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
51 
53 
54 bool
55 ShapeContainer::addPolygon(const std::string& id, const std::string& type,
56  const RGBColor& color, double layer,
57  double angle, const std::string& imgFile,
58  const PositionVector& shape, bool geo, bool fill, bool ignorePruning) {
59  return add(new SUMOPolygon(id, type, color, shape, geo, fill, layer, angle, imgFile), ignorePruning);
60 }
61 
62 
63 bool
64 ShapeContainer::addPOI(const std::string& id, const std::string& type, const RGBColor& color, const Position& pos, bool geo,
65  const std::string& lane, double posOverLane, double posLat, double layer, double angle,
66  const std::string& imgFile, double width, double height, bool ignorePruning) {
67  return add(new PointOfInterest(id, type, color, pos, geo, lane, posOverLane, posLat, layer, angle, imgFile, width, height), ignorePruning);
68 }
69 
70 
71 bool
72 ShapeContainer::removePolygon(const std::string& id) {
73  return myPolygons.remove(id);
74 }
75 
76 
77 bool
78 ShapeContainer::removePOI(const std::string& id) {
79  return myPOIs.remove(id);
80 }
81 
82 
83 void
84 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
85  PointOfInterest* p = myPOIs.get(id);
86  if (p != 0) {
87  static_cast<Position*>(p)->set(pos);
88  }
89 }
90 
91 
92 void
93 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
94  SUMOPolygon* p = myPolygons.get(id);
95  if (p != 0) {
96  p->setShape(shape);
97  }
98 }
99 
100 
101 bool
102 ShapeContainer::add(SUMOPolygon* poly, bool /* ignorePruning */) {
103  if (!myPolygons.add(poly->getID(), poly)) {
104  delete poly;
105  return false;
106  }
107  return true;
108 }
109 
110 
111 bool
112 ShapeContainer::add(PointOfInterest* poi, bool /* ignorePruning */) {
113  if (!myPOIs.add(poi->getID(), poi)) {
114  delete poi;
115  return false;
116  }
117  return true;
118 }
119 
120 
121 /****************************************************************************/
122 
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:74
bool add(const std::string &id, T item)
Adds 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.
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:112
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:45
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
A list of positions.
virtual void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
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, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
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.