SUMO - Simulation of Urban MObility
ShapeContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Storage for geometrical objects, sorted by the layers they are in
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2002-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <fstream>
35 #include <stdlib.h>
36 #include <iostream>
37 #include <utility>
38 #include <string>
39 #include <cmath>
42 #include <utils/shapes/Polygon.h>
46 #include <utils/common/ToString.h>
47 #include <utils/common/StdDefs.h>
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
54 
56 
57 bool
58 ShapeContainer::addPolygon(const std::string& id, const std::string& type,
59  const RGBColor& color, double layer,
60  double angle, const std::string& imgFile,
61  const PositionVector& shape, bool fill, bool ignorePruning) {
62  return add(new SUMO::Polygon(id, type, color, shape, fill, layer, angle, imgFile), ignorePruning);
63 }
64 
65 
66 bool
67 ShapeContainer::addPOI(const std::string& id, const std::string& type,
68  const RGBColor& color, double layer, double angle, const std::string& imgFile,
69  const Position& pos, double width, double height, bool ignorePruning) {
70  return add(new PointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height), ignorePruning);
71 }
72 
73 
74 bool
75 ShapeContainer::removePolygon(const std::string& id) {
76  return myPolygons.remove(id);
77 }
78 
79 
80 bool
81 ShapeContainer::removePOI(const std::string& id) {
82  return myPOIs.remove(id);
83 }
84 
85 
86 
87 void
88 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
89  PointOfInterest* p = myPOIs.get(id);
90  if (p != 0) {
91  static_cast<Position*>(p)->set(pos);
92  }
93 }
94 
95 
96 void
97 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
98  SUMO::Polygon* p = myPolygons.get(id);
99  if (p != 0) {
100  p->setShape(shape);
101  }
102 }
103 
104 
105 bool
106 ShapeContainer::add(SUMO::Polygon* poly, bool /* ignorePruning */) {
107  if (!myPolygons.add(poly->getID(), poly)) {
108  delete poly;
109  return false;
110  }
111  return true;
112 }
113 
114 
115 bool
116 ShapeContainer::add(PointOfInterest* poi, bool /* ignorePruning */) {
117  if (!myPOIs.add(poi->getID(), poi)) {
118  delete poi;
119  return false;
120  }
121  return true;
122 }
123 
124 
125 /****************************************************************************/
126 
virtual bool add(const std::string &id, T item)
Adds an item.
T get(const std::string &id) const
Retrieves an item.
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
Definition: Polygon.h:116
POIs myPOIs
stored POIs
Polygons myPolygons
stored Polygons
ShapeContainer()
Constructor.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A 2D- or 3D-polygon.
Definition: Polygon.h:57
virtual void movePOI(const std::string &id, const Position &pos)
Assigns a new position to the named PoI.
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:46
virtual bool add(SUMO::Polygon *poly, bool ignorePruning=false)
virtual bool removePOI(const std::string &id)
Removes a PoI from the container.
A list of positions.
virtual bool remove(const std::string &id)
Removes 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 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.
A point-of-interest.
virtual bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const Position &pos, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
virtual ~ShapeContainer()
Destructor.