SUMO - Simulation of Urban MObility
GNEPOI.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing and editing POIS in netedit (adapted from
8 // GUIPointOfInterest and NLHandler)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <utility>
36 #include <utils/geom/Position.h>
41 #include <utils/xml/XMLSubSys.h>
47 #include <utils/gui/div/GLHelper.h>
53 #include <netwrite/NWWriter_SUMO.h>
54 #include "GNENet.h"
55 #include "GNEEdge.h"
56 #include "GNEUndoList.h"
57 #include "GNEViewNet.h"
58 #include "GNEChange_Attribute.h"
59 #include "GNEPOI.h"
60 
61 #ifdef CHECK_MEMORY_LEAKS
62 #include <foreign/nvwa/debug_new.h>
63 #endif // CHECK_MEMORY_LEAKS
64 
65 
66 // ===========================================================================
67 // static members
68 // ===========================================================================
69 
70 // ===========================================================================
71 // method definitions
72 // ===========================================================================
73 GNEPOI::GNEPOI(const std::string& id, const std::string& type,
74  const RGBColor& color, SUMOReal layer, SUMOReal angle, const std::string& imgFile,
75  const Position& pos, SUMOReal width, SUMOReal height) :
76  GUIPointOfInterest(id, type, color, pos, layer, angle, imgFile, width, height),
78 }
79 
80 
82 
83 
84 //void
85 //GNEPOI::move(Position pos) {
86 // const Position orig = myNBNode.getPosition();
87 // setPosition(pos);
88 // myNet->refreshElement(this);
89 // const EdgeVector& incident = getNBNode()->getEdges();
90 // for (EdgeVector::const_iterator it = incident.begin(); it != incident.end(); it++) {
91 // GNEEdge *edge = myNet->retrieveEdge((*it)->getID());
92 // edge->updateJunctionPosition(this, orig);
93 // }
94 //}
95 //
96 //
97 //void
98 //GNEPOI::registerMove(GNEUndoList *undoList) {
99 // Position newPos = myNBNode.getPosition();
100 // std::string newPosValue = getAttribute(SUMO_ATTR_POSITION);
101 // // actually the geometry is already up to date
102 // // set the restore point to the end of the last change-set
103 // setPosition(myOrigPos);
104 // // do not execute the command to avoid changing the edge geometry twice
105 // undoList->add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, newPosValue), false);
106 // setPosition(newPos);
107 //}
108 
109 
110 std::string
112  switch (key) {
113  case SUMO_ATTR_ID:
114  return getMicrosimID();
115  break;
116  case SUMO_ATTR_POSITION:
117  return toString((Position&) * this);
118  break;
119  case SUMO_ATTR_TYPE:
121  break;
122  default:
123  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
124  }
125 }
126 
127 
128 void
129 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* /* undoList */) {
130  if (value == getAttribute(key)) {
131  return; //avoid needless changes, later logic relies on the fact that attributes have changed
132  }
133  //switch (key) {
134  //case SUMO_ATTR_ID:
135  //case SUMO_ATTR_POSITION:
136  //case GNE_ATTR_MODIFICATION_STATUS:
137  // undoList->add(new GNEChange_Attribute(this, key, value), true);
138  // break;
139  //case SUMO_ATTR_TYPE: {
140  // undoList->p_begin("change junction type");
141  // bool resetConnections = false;
142  // if (SUMOXMLDefinitions::NodeTypes.get(value) == NODETYPE_TRAFFIC_LIGHT) {
143  // // create new traffic light
144  // undoList->add(new GNEChange_TLS(this, 0, true), true);
145  // } else if (myNBNode.getType() == NODETYPE_TRAFFIC_LIGHT) {
146  // // delete old traffic light
147  // // make a copy because we will modify the original
148  // const std::set<NBTrafficLightDefinition*> tls = myNBNode.getControllingTLS();
149  // for (std::set<NBTrafficLightDefinition*>::iterator it=tls.begin(); it!=tls.end(); it++) {
150  // undoList->add(new GNEChange_TLS(this, *it, false), true);
151  // }
152  // }
153  // // must be the final step, otherwise we do not know which traffic lights to remove via GNEChange_TLS
154  // undoList->add(new GNEChange_Attribute(this, key, value), true);
155  // undoList->p_end();
156  // break;
157  //}
158  //default:
159  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
160  //}
161 }
162 
163 
164 bool
165 GNEPOI::isValid(SumoXMLAttr key, const std::string& /* value */) {
166  //switch (key) {
167  //case SUMO_ATTR_ID:
168  // return isValidID(value) && myNet->retrieveJunction(value, false) == 0;
169  // break;
170  //case SUMO_ATTR_TYPE:
171  // return SUMOXMLDefinitions::NodeTypes.hasString(value);
172  // break;
173  //case SUMO_ATTR_POSITION:
174  // bool ok;
175  // return GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false).size() == 1;
176  // break;
177  //default:
178  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
179  //}
180 }
181 
182 void
183 GNEPOI::saveToFile(const std::string& file) {
185  out.writeXMLHeader("pois");
187  const std::vector<GUIGlObject_AbstractAdd*>& additionals = GUIGlObject_AbstractAdd::getObjectList();
188  for (std::vector<GUIGlObject_AbstractAdd*>::const_iterator it = additionals.begin(); it != additionals.end(); ++it) {
189  PointOfInterest* poi = dynamic_cast<PointOfInterest*>(*it);
190  if (poi != 0) {
191  poi->writeXML(out);
192  }
193  }
194  out.close();
195  WRITE_MESSAGE(" " + toString(additionals.size()) + " POIs saved to '" + file + "'.");
196 }
197 
198 // ===========================================================================
199 // private
200 // ===========================================================================
201 
202 void
203 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& /* value */) {
204  //switch (key) {
205  //case SUMO_ATTR_ID:
206  // myNet->renameJunction(this, value);
207  // break;
208  //case SUMO_ATTR_TYPE: {
209  // myNBNode.reinit(myNBNode.getPosition(), SUMOXMLDefinitions::NodeTypes.get(value));
210  // break;
211  //}
212  //case SUMO_ATTR_POSITION:
213  // bool ok;
214  // myOrigPos = GeomConvHelper::parseShapeReporting(value, "netedit-given", 0, ok, false)[0];
215  // move(myOrigPos);
216  // break;
217  //default:
218  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
219  //}
220 }
221 
222 /****************************************************************************/
void close()
Closes the device and removes it from the dictionary.
static void writeLocation(OutputDevice &into)
writes the location element
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Definition: GNEPOI.cpp:129
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:167
virtual ~GNEPOI()
Destructor.
Definition: GNEPOI.cpp:81
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string getAttribute(SumoXMLAttr key) const
reposition the node at pos and informs the edges
Definition: GNEPOI.cpp:111
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
bool isValid(SumoXMLAttr key, const std::string &value)
Definition: GNEPOI.cpp:165
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
static void saveToFile(const std::string &file)
save POIs to file
Definition: GNEPOI.cpp:183
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
void writeXML(OutputDevice &out, bool geo=false, const SUMOReal zOffset=0.)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
A point-of-interest.
static const std::vector< GUIGlObject_AbstractAdd * > & getObjectList()
Returns the list of all additional objects.
const std::string & getType() const
Returns the (abstract) type of the Shape.
Definition: Shape.h:71
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
GNEPOI(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)
Constructor.
Definition: GNEPOI.cpp:73