SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShapeContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Storage for geometrical objects, sorted by the layers they are in
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
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>
41 #include <utils/shapes/Polygon.h>
45 #include <utils/common/ToString.h>
46 #include <utils/common/StdDefs.h>
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57 
59 
60 bool
61 ShapeContainer::addPolygon(const std::string& id, const std::string& type,
62  const RGBColor& color, SUMOReal layer,
63  SUMOReal angle, const std::string& imgFile,
64  const PositionVector& shape, bool fill) {
65  Polygon* p = new Polygon(id, type, color, shape, fill, layer, angle, imgFile);
66  if (!myPolygons.add(id, p)) {
67  delete p;
68  return false;
69  }
70  return true;
71 }
72 
73 
74 bool
75 ShapeContainer::addPOI(const std::string& id, const std::string& type,
76  const RGBColor& color, SUMOReal layer, SUMOReal angle, const std::string& imgFile,
77  const Position& pos, SUMOReal width, SUMOReal height) {
78  PointOfInterest* p = new PointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height);
79  if (!myPOIs.add(id, p)) {
80  delete p;
81  return false;
82  }
83  return true;
84 }
85 
86 
87 bool
88 ShapeContainer::removePolygon(const std::string& id) {
89  return myPolygons.remove(id);
90 }
91 
92 
93 bool
94 ShapeContainer::removePOI(const std::string& id) {
95  return myPOIs.remove(id);
96 }
97 
98 
99 
100 void
101 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
102  PointOfInterest* p = myPOIs.get(id);
103  if (p != 0) {
104  static_cast<Position*>(p)->set(pos);
105  }
106 }
107 
108 
109 void
110 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
111  Polygon* p = myPolygons.get(id);
112  if (p != 0) {
113  p->setShape(shape);
114  }
115 }
116 
117 /****************************************************************************/
118 
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:107
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:48
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 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 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)
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 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)
Builds a polygon using the given values and adds it to the container.
#define SUMOReal
Definition: config.h:215
A point-of-interest.
virtual ~ShapeContainer()
Destructor.