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