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-2017 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(GNENet* net, 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  myNet(net) {
79 }
80 
81 
83 
84 
85 void
87  set(pos);
88  myNet->refreshElement(this);
89 }
90 
91 
92 //void
93 //GNEPOI::registerMove(GNEUndoList *undoList) {
94 // Position newPos = myNBNode.getPosition();
95 // std::string newPosValue = getAttribute(SUMO_ATTR_POSITION);
96 // // actually the geometry is already up to date
97 // // set the restore point to the end of the last change-set
98 // setPosition(myOrigPos);
99 // // do not execute the command to avoid changing the edge geometry twice
100 // undoList->add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, newPosValue), false);
101 // setPosition(newPos);
102 //}
103 
104 
105 std::string
107  switch (key) {
108  case SUMO_ATTR_ID:
109  return getMicrosimID();
110  break;
111  case SUMO_ATTR_POSITION:
112  return toString((Position&) * this);
113  break;
114  case SUMO_ATTR_TYPE:
116  break;
117  default:
118  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
119  }
120 }
121 
122 
123 void
124 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* /* undoList */) {
125  if (value == getAttribute(key)) {
126  return; //avoid needless changes, later logic relies on the fact that attributes have changed
127  }
128  //switch (key) {
129  //case SUMO_ATTR_ID:
130  //case SUMO_ATTR_POSITION:
131  //case GNE_ATTR_MODIFICATION_STATUS:
132  // undoList->add(new GNEChange_Attribute(this, key, value), true);
133  // break;
134  //case SUMO_ATTR_TYPE: {
135  // undoList->p_begin("change junction type");
136  // bool resetConnections = false;
137  // if (SUMOXMLDefinitions::NodeTypes.get(value) == NODETYPE_TRAFFIC_LIGHT) {
138  // // create new traffic light
139  // undoList->add(new GNEChange_TLS(this, 0, true), true);
140  // } else if (myNBNode.getType() == NODETYPE_TRAFFIC_LIGHT) {
141  // // delete old traffic light
142  // // make a copy because we will modify the original
143  // const std::set<NBTrafficLightDefinition*> tls = myNBNode.getControllingTLS();
144  // for (std::set<NBTrafficLightDefinition*>::iterator it=tls.begin(); it!=tls.end(); it++) {
145  // undoList->add(new GNEChange_TLS(this, *it, false), true);
146  // }
147  // }
148  // // must be the final step, otherwise we do not know which traffic lights to remove via GNEChange_TLS
149  // undoList->add(new GNEChange_Attribute(this, key, value), true);
150  // undoList->p_end();
151  // break;
152  //}
153  //default:
154  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
155  //}
156 }
157 
158 
159 bool
160 GNEPOI::isValid(SumoXMLAttr key, const std::string& /* value */) {
161  //switch (key) {
162  //case SUMO_ATTR_ID:
163  // return isValidID(value) && myNet->retrieveJunction(value, false) == 0;
164  // break;
165  //case SUMO_ATTR_TYPE:
166  // return SUMOXMLDefinitions::NodeTypes.hasString(value);
167  // break;
168  //case SUMO_ATTR_POSITION:
169  // bool ok;
170  // return GeomConvHelper::parseShapeReporting(value, "user-supplied position", 0, ok, false).size() == 1;
171  // break;
172  //default:
173  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
174  //}
175 }
176 
177 void
178 GNEPOI::saveToFile(const std::string& file) {
180  out.writeXMLHeader("additional", "additional_file.xsd");
182  const std::vector<GUIGlObject_AbstractAdd*>& additionals = GUIGlObject_AbstractAdd::getObjectList();
183  for (std::vector<GUIGlObject_AbstractAdd*>::const_iterator it = additionals.begin(); it != additionals.end(); ++it) {
184  PointOfInterest* poi = dynamic_cast<PointOfInterest*>(*it);
185  if (poi != 0) {
186  poi->writeXML(out);
187  }
188  }
189  out.close();
190  WRITE_MESSAGE(" " + toString(additionals.size()) + " POIs saved to '" + file + "'.");
191 }
192 
193 // ===========================================================================
194 // private
195 // ===========================================================================
196 
197 void
198 GNEPOI::setAttribute(SumoXMLAttr key, const std::string& /* value */) {
199  //switch (key) {
200  //case SUMO_ATTR_ID:
201  // myNet->renameJunction(this, value);
202  // break;
203  //case SUMO_ATTR_TYPE: {
204  // myNBNode.reinit(myNBNode.getPosition(), SUMOXMLDefinitions::NodeTypes.get(value));
205  // break;
206  //}
207  //case SUMO_ATTR_POSITION:
208  // bool ok;
209  // myOrigPos = GeomConvHelper::parseShapeReporting(value, "netedit-given", 0, ok, false)[0];
210  // move(myOrigPos);
211  // break;
212  //default:
213  throw InvalidArgument("POI attribute '" + toString(key) + "' not allowed");
214  //}
215 }
216 
217 /****************************************************************************/
void close()
Closes the device and removes it from the dictionary.
static void writeLocation(OutputDevice &into)
writes the location element
void move(Position pos)
reposition the POI at pos and informs the edges
Definition: GNEPOI.cpp:86
void writeXML(OutputDevice &out, const bool geo=false, const SUMOReal zOffset=0., const std::string laneID="", const SUMOReal pos=0.)
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:806
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Definition: GNEPOI.cpp:124
virtual ~GNEPOI()
Destructor.
Definition: GNEPOI.cpp:82
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:87
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
begin/end of the description of a polygon
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEPOI.cpp:106
GNEPOI(GNENet *net, 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)
declare friend class
Definition: GNEPOI.cpp:73
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
bool isValid(SumoXMLAttr key, const std::string &value)
Definition: GNEPOI.cpp:160
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
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:178
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:208
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
GNENet * myNet
the net for querying updates
Definition: GNEPOI.h:103