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>
43 #include <utils/common/ToString.h>
44 #include <utils/common/StdDefs.h>
45 #include "ShapeContainer.h"
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
52 
54 
55 bool
56 ShapeContainer::addPolygon(const std::string& id, const std::string& type,
57  const RGBColor& color, double layer,
58  double angle, const std::string& imgFile,
59  const PositionVector& shape, bool fill, bool ignorePruning) {
60  return add(new SUMOPolygon(id, type, color, shape, fill, layer, angle, imgFile), ignorePruning);
61 }
62 
63 
64 bool
65 ShapeContainer::addPOI(const std::string& id, const std::string& type,
66  const RGBColor& color, double layer, double angle, const std::string& imgFile,
67  const Position& pos, double width, double height, bool ignorePruning) {
68  return add(new PointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height), ignorePruning);
69 }
70 
71 
72 bool
73 ShapeContainer::removePolygon(const std::string& id) {
74  return myPolygons.remove(id);
75 }
76 
77 
78 bool
79 ShapeContainer::removePOI(const std::string& id) {
80  return myPOIs.remove(id);
81 }
82 
83 
84 void
85 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
86  PointOfInterest* p = myPOIs.get(id);
87  if (p != 0) {
88  static_cast<Position*>(p)->set(pos);
89  }
90 }
91 
92 
93 void
94 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
95  SUMOPolygon* p = myPolygons.get(id);
96  if (p != 0) {
97  p->setShape(shape);
98  }
99 }
100 
101 
102 bool
103 ShapeContainer::add(SUMOPolygon* poly, bool /* ignorePruning */) {
104  if (!myPolygons.add(poly->getID(), poly)) {
105  delete poly;
106  return false;
107  }
108  return true;
109 }
110 
111 
112 bool
113 ShapeContainer::add(PointOfInterest* poi, bool /* ignorePruning */) {
114  if (!myPOIs.add(poi->getID(), poi)) {
115  delete poi;
116  return false;
117  }
118  return true;
119 }
120 
121 
122 /****************************************************************************/
123 
virtual bool add(const std::string &id, T item)
Adds an item.
POIs myPOIs
stored POIs
Polygons myPolygons
stored Polygons
ShapeContainer()
Constructor.
T get(const std::string &id) const
Retrieves an item.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:113
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 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.
virtual bool add(SUMOPolygon *poly, bool ignorePruning=false)
add 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.