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-2015 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) {
66  Polygon* p = new Polygon(id, type, color, shape, fill, layer, angle, imgFile);
67  if (!myPolygons.add(id, p)) {
68  delete p;
69  return false;
70  }
71  return true;
72 }
73 
74 
75 bool
76 ShapeContainer::addPOI(const std::string& id, const std::string& type,
77  const RGBColor& color, SUMOReal layer, SUMOReal angle, const std::string& imgFile,
78  const Position& pos, SUMOReal width, SUMOReal height) {
79  PointOfInterest* p = new PointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height);
80  if (!myPOIs.add(id, p)) {
81  delete p;
82  return false;
83  }
84  return true;
85 }
86 
87 
88 bool
89 ShapeContainer::removePolygon(const std::string& id) {
90  return myPolygons.remove(id);
91 }
92 
93 
94 bool
95 ShapeContainer::removePOI(const std::string& id) {
96  return myPOIs.remove(id);
97 }
98 
99 
100 
101 void
102 ShapeContainer::movePOI(const std::string& id, const Position& pos) {
103  PointOfInterest* p = myPOIs.get(id);
104  if (p != 0) {
105  static_cast<Position*>(p)->set(pos);
106  }
107 }
108 
109 
110 void
111 ShapeContainer::reshapePolygon(const std::string& id, const PositionVector& shape) {
112  Polygon* p = myPolygons.get(id);
113  if (p != 0) {
114  p->setShape(shape);
115  }
116 }
117 
118 /****************************************************************************/
119 
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:111
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:52
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:218
A point-of-interest.
virtual ~ShapeContainer()
Destructor.