SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58 
60 
61 bool
62 ShapeContainer::addPolygon(const std::string& id, const std::string& type,
63  const RGBColor& color, SUMOReal layer,
64  SUMOReal angle, const std::string& imgFile,
65  const PositionVector& shape, bool fill, bool ignorePruning) {
66  return add(new SUMO::Polygon(id, type, color, shape, fill, layer, angle, imgFile), ignorePruning);
67 }
68 
69 
70 bool
71 ShapeContainer::addPOI(const std::string& id, const std::string& type,
72  const RGBColor& color, SUMOReal layer, SUMOReal angle, const std::string& imgFile,
73  const Position& pos, SUMOReal width, SUMOReal height, bool ignorePruning) {
74  return add(new PointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height), ignorePruning);
75 }
76 
77 
78 bool
79 ShapeContainer::removePolygon(const std::string& id) {
80  return myPolygons.remove(id);
81 }
82 
83 
84 bool
85 ShapeContainer::removePOI(const std::string& id) {
86  return myPOIs.remove(id);
87 }
88 
89 
90 
91 void
92 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
93  PointOfInterest* p = myPOIs.get(id);
94  if (p != 0) {
95  static_cast<Position*>(p)->set(pos);
96  }
97 }
98 
99 
100 void
101 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
102  SUMO::Polygon* p = myPolygons.get(id);
103  if (p != 0) {
104  p->setShape(shape);
105  }
106 }
107 
108 
109 bool
110 ShapeContainer::add(SUMO::Polygon* poly, bool /* ignorePruning */) {
111  if (!myPolygons.add(poly->getID(), poly)) {
112  delete poly;
113  return false;
114  }
115  return true;
116 }
117 
118 
119 bool
120 ShapeContainer::add(PointOfInterest* poi, bool /* ignorePruning */) {
121  if (!myPOIs.add(poi->getID(), poi)) {
122  delete poi;
123  return false;
124  }
125  return true;
126 }
127 
128 
129 /****************************************************************************/
130 
virtual bool add(const std::string &id, T item)
Adds 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.
T get(const std::string &id) const
Retrieves an item.
A 2D- or 3D-polygon.
Definition: Polygon.h:57
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 bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, SUMOReal layer, SUMOReal angle, const std::string &imgFile, const Position &pos, SUMOReal width, SUMOReal height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
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 void reshapePolygon(const std::string &id, const PositionVector &shape)
Assigns a shape to the named polygon.
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, SUMOReal layer, SUMOReal 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.
#define SUMOReal
Definition: config.h:214
A point-of-interest.
virtual ~ShapeContainer()
Destructor.