SUMO - Simulation of Urban MObility
GNENet.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A visual container for GNE-network-components such as GNEEdge and GNEJunction.
8 // GNE components wrap netbuild-components and supply visualisation and editing
9 // capabilities (adapted from GUINet)
10 //
11 // Workflow (rough draft)
12 // use NILoader to fill
13 // do netedit stuff
14 // call compute to save results
15 //
16 /****************************************************************************/
17 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
18 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
19 /****************************************************************************/
20 //
21 // This file is part of SUMO.
22 // SUMO is free software: you can redistribute it and/or modify
23 // it under the terms of the GNU General Public License as published by
24 // the Free Software Foundation, either version 3 of the License, or
25 // (at your option) any later version.
26 //
27 /****************************************************************************/
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <map>
40 #include <set>
41 #include <vector>
42 
43 #include <netbuild/NBAlgorithms.h>
44 #include <netwrite/NWFrame.h>
45 #include <netwrite/NWWriter_XML.h>
46 #include <utility>
48 #include <utils/common/RGBColor.h>
59 
60 #include "GNEAdditional.h"
61 #include "GNEAdditionalFrame.h"
62 #include "GNEApplicationWindow.h"
63 #include "GNEChange_Additional.h"
64 #include "GNEChange_Attribute.h"
65 #include "GNEChange_Connection.h"
66 #include "GNEChange_Crossing.h"
67 #include "GNEChange_Edge.h"
68 #include "GNEChange_Junction.h"
69 #include "GNEChange_Lane.h"
70 #include "GNEChange_Selection.h"
71 #include "GNEConnection.h"
72 #include "GNECrossing.h"
73 #include "GNEDetector.h"
74 #include "GNEEdge.h"
75 #include "GNEJunction.h"
76 #include "GNEPoly.h"
77 #include "GNEPOI.h"
78 #include "GNELane.h"
79 #include "GNENet.h"
80 #include "GNEStoppingPlace.h"
81 #include "GNEUndoList.h"
82 #include "GNEViewNet.h"
83 #include "GNEViewParent.h"
84 #include "GNERerouter.h"
85 
86 
87 
88 // ===========================================================================
89 // static members
90 // ===========================================================================
91 const RGBColor GNENet::selectionColor(0, 0, 204, 255);
92 const RGBColor GNENet::selectedLaneColor(0, 0, 128, 255);
93 const RGBColor GNENet::selectedConnectionColor(0, 0, 100, 255);
94 const double GNENet::Z_INITIALIZED = 1;
95 
96 // ===========================================================================
97 // member method definitions
98 // ===========================================================================
101  myViewNet(0),
102  myNetBuilder(netBuilder),
103  myJunctions(),
104  myEdges(),
105  myEdgeIDSupplier("gneE", netBuilder->getEdgeCont().getAllNames()),
106  myJunctionIDSupplier("gneJ", netBuilder->getNodeCont().getAllNames()),
107  myShapeContainer(myGrid),
108  myNeedRecompute(true),
109  myAdditionalsSaved(true) {
111 
112  // init junctions (by default Crossing and walking areas aren't created)
114  const std::vector<std::string>& nodeNames = nc.getAllNames();
115  for (std::vector<std::string>::const_iterator name_it = nodeNames.begin(); name_it != nodeNames.end(); ++name_it) {
116  NBNode* nbn = nc.retrieve(*name_it);
117  registerJunction(new GNEJunction(*nbn, this, true));
118  }
119 
120  // init edges
122  const std::vector<std::string>& edgeNames = ec.getAllNames();
123  for (std::vector<std::string>::const_iterator name_it = edgeNames.begin(); name_it != edgeNames.end(); ++name_it) {
124  NBEdge* nbe = ec.retrieve(*name_it);
125  registerEdge(new GNEEdge(*nbe, this, false, true));
126  if (myGrid.getWidth() > 10e16 || myGrid.getHeight() > 10e16) {
127  throw ProcessError("Network size exceeds 1 Lightyear. Please reconsider your inputs.\n");
128  }
129  }
130 
131  // make sure myGrid is initialized even for an empty net
132  if (myEdges.size() == 0) {
133  myGrid.add(Boundary(0, 0, 100, 100));
134  }
135 
136  // sort nodes edges so that arrows can be drawn correctly
138 
139  /*
140  // initialise detector storage for gui
141  initDetectors();
142  // initialise the tl-map
143  initTLMap();
144  // initialise edge storage for gui
145  GUIEdge::fill(myEdgeWrapper);
146  */
147  //if (myGrid.count() == 0) // myGrid methods will return garbage
148 
149  // Init AdditionalHandler
150 
151  if (myZBoundary.ymin() != Z_INITIALIZED) {
152  myZBoundary.add(0, 0);
153  }
154 }
155 
156 
158  /*
159  // delete allocated wrappers
160  // of junctions
161  for (std::vector<GUIJunctionWrapper*>::iterator i1=myJunctionWrapper.begin(); i1!=myJunctionWrapper.end(); i1++) {
162  delete(*i1);
163  }
164  // of additional structures
165  GUIGlObject_AbstractAdd::clearDictionary();
166  // of tl-logics
167  for (Logics2WrapperMap::iterator i3=myLogics2Wrapper.begin(); i3!=myLogics2Wrapper.end(); i3++) {
168  delete(*i3).second;
169  }
170  // of detectors
171  for (std::map<std::string, GUIDetectorWrapper*>::iterator i=myDetectorDict.begin(); i!=myDetectorDict.end(); ++i) {
172  delete(*i).second;
173  }
174  */
175  for (GNEEdges::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
176  it->second->decRef("GNENet::~GNENet");
177  delete it->second;
178  }
179  for (GNEJunctions::iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
180  it->second->decRef("GNENet::~GNENet");
181  delete it->second;
182  }
183  delete myNetBuilder;
184 }
185 
186 
187 const Boundary&
189  // SUMORTree is also a Boundary
190  return myGrid;
191 }
192 
193 
196  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
197  buildPopupHeader(ret, app);
199  buildPositionCopyEntry(ret, false);
200  return ret;
201 }
202 
203 
206  return 0;
207 }
208 
209 
210 void
212 }
213 
214 
215 Boundary
217  return getBoundary();
218 }
219 
220 
221 const Boundary&
223  return myZBoundary;
224 }
225 
226 
227 SUMORTree&
229  return myGrid;
230 }
231 
232 
233 const SUMORTree&
235  return myGrid;
236 }
237 
238 
241  std::string id = myJunctionIDSupplier.getNext();
242  NBNode* nbn = new NBNode(id, pos);
243  GNEJunction* junction = new GNEJunction(*nbn, this);
244  undoList->add(new GNEChange_Junction(junction, true), true);
245  assert(myJunctions[id]);
246  return junction;
247 }
248 
249 
250 GNEEdge*
252  GNEJunction* src, GNEJunction* dest, GNEEdge* tpl, GNEUndoList* undoList,
253  const std::string& suggestedName,
254  bool wasSplit,
255  bool allowDuplicateGeom) {
256  // prevent duplicate edge (same geometry)
257  const EdgeVector& outgoing = src->getNBNode()->getOutgoingEdges();
258  for (EdgeVector::const_iterator it = outgoing.begin(); it != outgoing.end(); it++) {
259  if ((*it)->getToNode() == dest->getNBNode() && (*it)->getGeometry().size() == 2) {
260  if (!allowDuplicateGeom) {
261  return 0;
262  }
263  }
264  }
265 
266  std::string id;
267  if (suggestedName != "" && !retrieveEdge(suggestedName, false)) {
268  id = suggestedName;
269  reserveEdgeID(id);
270  } else {
271  id = myEdgeIDSupplier.getNext();
272  }
273 
274  GNEEdge* edge;
275  if (tpl) {
276  NBEdge* nbeTpl = tpl->getNBEdge();
277  NBEdge* nbe = new NBEdge(id, src->getNBNode(), dest->getNBNode(), nbeTpl);
278  edge = new GNEEdge(*nbe, this, wasSplit);
279  } else {
280  // default if no template is given
281  double defaultSpeed = 50 / 3.6;
282  std::string defaultType = "";
283  int defaultNrLanes = 1;
284  int defaultPriority = 1;
285  double defaultWidth = NBEdge::UNSPECIFIED_WIDTH;
286  double defaultOffset = NBEdge::UNSPECIFIED_OFFSET;
287  NBEdge* nbe = new NBEdge(id, src->getNBNode(), dest->getNBNode(),
288  defaultType, defaultSpeed,
289  defaultNrLanes, defaultPriority,
290  defaultWidth,
291  defaultOffset);
292  edge = new GNEEdge(*nbe, this, wasSplit);
293  }
294  undoList->p_begin("create " + toString(SUMO_TAG_EDGE));
295  undoList->add(new GNEChange_Edge(edge, true), true);
296  src->setLogicValid(false, undoList);
297  dest->setLogicValid(false, undoList);
299  undoList->p_end();
300  assert(myEdges[id]);
301  return edge;
302 }
303 
304 
305 void
307  // we have to delete all incident edges because they cannot exist without that junction
308  // all deletions must be undone/redone together so we start a new command group
309  // @todo if any of those edges are dead-ends should we remove their orphan junctions as well?
310  undoList->p_begin("delete " + toString(SUMO_TAG_JUNCTION));
311 
312  // delete all crossings vinculated with junction
313  while (junction->getGNECrossings().size() > 0) {
314  deleteCrossing(junction->getGNECrossings().front(), undoList);
315  }
316 
317  // deleting edges changes in the underlying EdgeVector so we have to make a copy
318  const EdgeVector incident = junction->getNBNode()->getEdges();
319  for (EdgeVector::const_iterator it = incident.begin(); it != incident.end(); it++) {
320  deleteEdge(myEdges[(*it)->getID()], undoList);
321  }
322 
323  // remove any traffic lights from the traffic light container (avoids lots of warnings)
324  junction->setAttribute(SUMO_ATTR_TYPE, toString(NODETYPE_PRIORITY), undoList);
325  undoList->add(new GNEChange_Junction(junction, false), true);
326  if (gSelected.isSelected(GLO_JUNCTION, junction->getGlID())) {
327  std::set<GUIGlID> deselected;
328  deselected.insert(junction->getGlID());
329  undoList->add(new GNEChange_Selection(this, std::set<GUIGlID>(), deselected, true), true);
330  }
331  undoList->p_end();
332 }
333 
334 
335 void
337  undoList->p_begin("delete " + toString(SUMO_TAG_EDGE));
338  // obtain a copy of GNERerouters of edge
339  std::vector<GNERerouter*> rerouters = edge->getGNERerouters();
340  // delete additionals childs of edge
341  std::vector<GNEAdditional*> copyOfEdgeAdditionals = edge->getAdditionalChilds();
342  for (std::vector<GNEAdditional*>::iterator i = copyOfEdgeAdditionals.begin(); i != copyOfEdgeAdditionals.end(); i++) {
343  undoList->add(new GNEChange_Additional((*i), false), true);
344  }
345  // delete additionals childs of lane
346  for (std::vector<GNELane*>::const_iterator i = edge->getLanes().begin(); i != edge->getLanes().end(); i++) {
347  std::vector<GNEAdditional*> copyOfLaneAdditionals = (*i)->getAdditionalChilds();
348  for (std::vector<GNEAdditional*>::iterator j = copyOfLaneAdditionals.begin(); j != copyOfLaneAdditionals.end(); j++) {
349  undoList->add(new GNEChange_Additional((*j), false), true);
350  }
351  }
352 
353  // invalidate junction (saving connections)
354  edge->getGNEJunctionSource()->removeFromCrossings(edge, undoList);
355  edge->getGNEJunctionDestiny()->removeFromCrossings(edge, undoList);
356  edge->getGNEJunctionSource()->setLogicValid(false, undoList);
357  edge->getGNEJunctionDestiny()->setLogicValid(false, undoList);
358 
359  // Delete edge
360  undoList->add(new GNEChange_Edge(edge, false), true);
361 
362  // If previously was selected
363  if (gSelected.isSelected(GLO_EDGE, edge->getGlID())) {
364  std::set<GUIGlID> deselected;
365  deselected.insert(edge->getGlID());
366  undoList->add(new GNEChange_Selection(this, std::set<GUIGlID>(), deselected, true), true);
367  }
368 
369  // check if after removing there are Rerouters without edge Childs
370  for (std::vector<GNERerouter*>::iterator i = rerouters.begin(); i != rerouters.end(); i++) {
371  if ((*i)->getEdgeChilds().size() == 0) {
372  undoList->add(new GNEChange_Additional((*i), false), true);
373  }
374  }
375  // remove edge requieres always a recompute (due geometry and connections)
377  undoList->p_end();
378 }
379 
380 
381 void
383  GNEEdge* edge = &lane->getParentEdge();
384  if (edge->getNBEdge()->getNumLanes() == 1) {
385  // remove the whole edge instead
386  deleteEdge(edge, undoList);
387  } else {
388  undoList->p_begin("delete " + toString(SUMO_TAG_LANE));
389  // delete additionals childs of lane
390  std::vector<GNEAdditional*> copyOfAdditionals = lane->getAdditionalChilds();
391  for (std::vector<GNEAdditional*>::const_iterator i = copyOfAdditionals.begin(); i != copyOfAdditionals.end(); i++) {
392  undoList->add(new GNEChange_Additional((*i), false), true);
393  }
394  // invalidate junctions (saving connections)
395  edge->getGNEJunctionSource()->removeFromCrossings(edge, undoList);
396  edge->getGNEJunctionDestiny()->removeFromCrossings(edge, undoList);
397  edge->getGNEJunctionSource()->setLogicValid(false, undoList);
398  edge->getGNEJunctionDestiny()->setLogicValid(false, undoList);
399 
400  // delete lane
401  const NBEdge::Lane& laneAttrs = edge->getNBEdge()->getLaneStruct(lane->getIndex());
402  undoList->add(new GNEChange_Lane(edge, lane, laneAttrs, false), true);
403  if (gSelected.isSelected(GLO_LANE, lane->getGlID())) {
404  std::set<GUIGlID> deselected;
405  deselected.insert(lane->getGlID());
406  undoList->add(new GNEChange_Selection(this, std::set<GUIGlID>(), deselected, true), true);
407  }
409  undoList->p_end();
410  }
411 }
412 
413 
414 void
416  undoList->p_begin("delete " + toString(SUMO_TAG_CONNECTION));
417  NBConnection deleted = connection->getNBConnection();
418  GNEJunction* affected = connection->getEdgeFrom()->getGNEJunctionDestiny();
419  affected->markAsModified(undoList);
420  undoList->add(new GNEChange_Connection(connection->getEdgeFrom(), connection->getNBEdgeConnection(), false), true);
421  affected->invalidateTLS(myViewNet->getUndoList(), deleted);
422  if (gSelected.isSelected(GLO_CONNECTION, connection->getGlID())) {
423  std::set<GUIGlID> deselected;
424  deselected.insert(connection->getGlID());
425  undoList->add(new GNEChange_Selection(this, std::set<GUIGlID>(), deselected, true), true);
426  }
428  undoList->p_end();
429 }
430 
431 
432 void
434  undoList->p_begin("delete crossing");
435  undoList->add(new GNEChange_Crossing(crossing->getParentJunction(), crossing->getNBCrossing().edges,
436  crossing->getNBCrossing().width, crossing->getNBCrossing().priority, false), true);
437  if (gSelected.isSelected(GLO_CROSSING, crossing->getGlID())) {
438  std::set<GUIGlID> deselected;
439  deselected.insert(crossing->getGlID());
440  undoList->add(new GNEChange_Selection(this, std::set<GUIGlID>(), deselected, true), true);
441  }
443  undoList->p_end();
444 }
445 
446 void
448  undoList->p_begin("duplicate " + toString(SUMO_TAG_LANE));
449  GNEEdge* edge = &lane->getParentEdge();
450  const NBEdge::Lane& laneAttrs = edge->getNBEdge()->getLaneStruct(lane->getIndex());
451  GNELane* newLane = new GNELane(*edge, lane->getIndex());
452  undoList->add(new GNEChange_Lane(edge, newLane, laneAttrs, true), true);
454  undoList->p_end();
455 }
456 
457 
458 bool
460  bool addRestriction = true;
461  if (vclass == SVC_PEDESTRIAN) {
462  GNEEdge& edge = lane->getParentEdge();
463  for (std::vector<GNELane*>::const_iterator i = edge.getLanes().begin(); i != edge.getLanes().end(); i++) {
464  if ((*i)->isRestricted(SVC_PEDESTRIAN)) {
465  // prevent adding a 2nd sidewalk
466  addRestriction = false;
467  } else {
468  // ensure that the sidewalk is used exclusively
469  const SVCPermissions allOldWithoutPeds = edge.getNBEdge()->getPermissions((*i)->getIndex()) & ~SVC_PEDESTRIAN;
470  (*i)->setAttribute(SUMO_ATTR_ALLOW, getVehicleClassNames(allOldWithoutPeds), undoList);
471  }
472  }
473  }
474  // restrict the lane
475  if (addRestriction) {
476  lane->setAttribute(SUMO_ATTR_ALLOW, toString(vclass), undoList);
477  return true;
478  } else {
479  return false;
480  }
481 }
482 
483 
484 bool
486  // First check that this lane is restricted
487  if (lane->isRestricted(SVC_PEDESTRIAN) == false &&
488  lane->isRestricted(SVC_BICYCLE) == false &&
489  lane->isRestricted(SVC_BUS) == false) {
490  return false;
491  }
492 
493  // Get all possible vehicle classes
494  std::vector<std::string> VClasses = SumoVehicleClassStrings.getStrings();
495  // Change allow and disallow attributes of lane
496  lane->setAttribute(SUMO_ATTR_ALLOW, joinToString(VClasses, " "), undoList);
497  lane->setAttribute(SUMO_ATTR_DISALLOW, std::string(), undoList);
498  return true;
499 }
500 
501 
502 bool
504  // First check that edge don't have a sidewalk
505  for (std::vector<GNELane*>::const_iterator i = edge.getLanes().begin(); i != edge.getLanes().end(); i++) {
506  if ((*i)->isRestricted(vclass)) {
507  return false;
508  }
509  }
510  // duplicate last lane
511  duplicateLane(edge.getLanes().at(0), undoList);
512  // transform the created (last) lane to a sidewalk
513  return restrictLane(vclass, edge.getLanes()[0], undoList);
514 }
515 
516 
517 bool
519  // iterate over lanes of edge
520  for (std::vector<GNELane*>::const_iterator i = edge.getLanes().begin(); i != edge.getLanes().end(); i++) {
521  if ((*i)->isRestricted(vclass)) {
522  // Delete lane
523  deleteLane(*i, undoList);
524  return true;
525  }
526  }
527  return false;
528 }
529 
530 
531 void
533  if (!edge->deleteGeometry(pos, undoList)) {
534  deleteEdge(edge, undoList);
535  }
536 }
537 
538 
540 GNENet::splitEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList, GNEJunction* newJunction) {
541  undoList->p_begin("split " + toString(SUMO_TAG_EDGE));
542  deleteEdge(edge, undoList); // still exists. we delete it so we can reuse the name in case of resplit
543  // compute geometry
544  const PositionVector& oldGeom = edge->getNBEdge()->getGeometry();
545  const double linePos = oldGeom.nearest_offset_to_point2D(pos, false);
546  std::pair<PositionVector, PositionVector> newGeoms = oldGeom.splitAt(linePos);
547  // figure out the new name
548  int posBase = 0;
549  std::string baseName = edge->getMicrosimID();
550  if (edge->wasSplit()) {
551  const std::string::size_type sep_index = baseName.rfind('.');
552  if (sep_index != std::string::npos) { // edge may have been renamed in between
553  std::string posString = baseName.substr(sep_index + 1);
554  try {
555  posBase = GNEAttributeCarrier::parse<int>(posString.c_str());
556  baseName = baseName.substr(0, sep_index); // includes the .
557  } catch (NumberFormatException) {
558  }
559  }
560  }
561  baseName += '.';
562  // create edges
563  if (newJunction == 0) {
564  newJunction = createJunction(pos, undoList);
565  }
566  GNEEdge* firstPart = createEdge(edge->getGNEJunctionSource(), newJunction, edge,
567  undoList, baseName + toString(posBase), true);
568  GNEEdge* secondPart = createEdge(newJunction, edge->getGNEJunctionDestiny(), edge,
569  undoList, baseName + toString(posBase + (int)linePos), true);
570  // fix geometry
571  firstPart->setAttribute(GNE_ATTR_SHAPE_START, toString(newGeoms.first[0]), undoList);
572  firstPart->setAttribute(GNE_ATTR_SHAPE_END, toString(newGeoms.first[-1]), undoList);
573  newGeoms.first.pop_back();
574  newGeoms.first.erase(newGeoms.first.begin());
575  firstPart->setAttribute(SUMO_ATTR_SHAPE, toString(newGeoms.first), undoList);
576 
577  secondPart->setAttribute(GNE_ATTR_SHAPE_START, toString(newGeoms.second[0]), undoList);
578  secondPart->setAttribute(GNE_ATTR_SHAPE_END, toString(newGeoms.second[-1]), undoList);
579  newGeoms.second.pop_back();
580  newGeoms.second.erase(newGeoms.second.begin());
581  secondPart->setAttribute(SUMO_ATTR_SHAPE, toString(newGeoms.second), undoList);
582  // fix connections
583  std::vector<NBEdge::Connection>& connections = edge->getNBEdge()->getConnections();
584  for (std::vector<NBEdge::Connection>::iterator con_it = connections.begin(); con_it != connections.end(); con_it++) {
585  undoList->add(new GNEChange_Connection(secondPart, *con_it, true), true);
586  }
587  undoList->p_end();
588  return newJunction;
589 }
590 
591 
592 void
593 GNENet::splitEdgesBidi(const std::set<GNEEdge*>& edges, const Position& pos, GNEUndoList* undoList) {
594  GNEJunction* newJunction = 0;
595  undoList->p_begin("split " + toString(SUMO_TAG_EDGE) + "s");
596  for (std::set<GNEEdge*>::const_iterator it = edges.begin(); it != edges.end(); ++it) {
597  newJunction = splitEdge(*it, pos, undoList, newJunction);
598  }
599  undoList->p_end();
600 }
601 
602 
603 void
605  undoList->p_begin("reverse " + toString(SUMO_TAG_EDGE));
606  deleteEdge(edge, undoList); // still exists. we delete it so we can reuse the name in case of resplit
607  GNEEdge* reversed = createEdge(edge->getGNEJunctionDestiny(), edge->getGNEJunctionSource(), edge, undoList, edge->getID(), false, true);
608  assert(reversed != 0);
609  reversed->setAttribute(SUMO_ATTR_SHAPE, toString(edge->getNBEdge()->getInnerGeometry().reverse()), undoList);
610  undoList->p_end();
611 }
612 
613 
614 GNEEdge*
616  undoList->p_begin("add reversed " + toString(SUMO_TAG_EDGE));
617  GNEEdge* reversed = 0;
619  // for rail edges, we assume bi-directional tracks are wanted
620  GNEEdge* reversed = createEdge(edge->getGNEJunctionDestiny(), edge->getGNEJunctionSource(), edge, undoList, "-" + edge->getID(), false, true);
621  assert(reversed != 0);
622  reversed->setAttribute(SUMO_ATTR_SHAPE, toString(edge->getNBEdge()->getInnerGeometry().reverse()), undoList);
623  } else {
624  // if the edge is centered it should probably connect somewhere else
625  // make it easy to move and reconnect it
626  PositionVector orig = edge->getNBEdge()->getGeometry();
627  PositionVector origInner = edge->getNBEdge()->getInnerGeometry();
628  const double tentativeShift = edge->getNBEdge()->getTotalWidth() + 2;
629  orig.move2side(-tentativeShift);
630  origInner.move2side(-tentativeShift);
631  GNEJunction* src = createJunction(orig.back(), undoList);
632  GNEJunction* dest = createJunction(orig.front(), undoList);
633  GNEEdge* reversed = createEdge(src, dest, edge, undoList, "-" + edge->getID(), false, true);
634  assert(reversed != 0);
635  reversed->setAttribute(SUMO_ATTR_SHAPE, toString(origInner.reverse()), undoList);
636  // select the new edge and its nodes
637  std::set<GUIGlID> toSelect;
638  toSelect.insert(reversed->getGlID());
639  toSelect.insert(src->getGlID());
640  toSelect.insert(dest->getGlID());
641  undoList->add(new GNEChange_Selection(this, toSelect, gSelected.getSelected(), true), true);
642  }
643  undoList->p_end();
644  return reversed;
645 }
646 
647 
648 void
650  undoList->p_begin("merge " + toString(SUMO_TAG_JUNCTION) + "s");
651  // position of moved and target are probably a bit different (snap radius)
652  moved->move(target->getNBNode()->getPosition());
653  // register the move with undolist (must happend within the undo group)
654  moved->registerMove(undoList);
655  // deleting edges changes in the underlying EdgeVector so we have to make a copy
656  const EdgeVector incoming = moved->getNBNode()->getIncomingEdges();
657  for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); it++) {
658  GNEEdge* oldEdge = myEdges[(*it)->getID()];
659  remapEdge(oldEdge, oldEdge->getGNEJunctionSource(), target, undoList);
660  }
661  // deleting edges changes in the underlying EdgeVector so we have to make a copy
662  const EdgeVector outgoing = moved->getNBNode()->getOutgoingEdges();
663  for (EdgeVector::const_iterator it = outgoing.begin(); it != outgoing.end(); it++) {
664  GNEEdge* oldEdge = myEdges[(*it)->getID()];
665  remapEdge(oldEdge, target, oldEdge->getGNEJunctionDestiny(), undoList);
666  }
667  deleteJunction(moved, undoList);
668  undoList->p_end();
669 }
670 
671 
672 void
673 GNENet::remapEdge(GNEEdge* oldEdge, GNEJunction* from, GNEJunction* to, GNEUndoList* undoList, bool keepEndpoints) {
674  deleteEdge(oldEdge, undoList); // delete first so we can reuse the name, reference stays valid
675  if (from != to) {
676  GNEEdge* newEdge = createEdge(from, to, oldEdge, undoList, oldEdge->getMicrosimID(), false, true);
677  newEdge->setAttribute(SUMO_ATTR_SHAPE, oldEdge->getAttribute(SUMO_ATTR_SHAPE), undoList);
678  if (keepEndpoints) {
680  newEdge->setAttribute(GNE_ATTR_SHAPE_END, oldEdge->getAttribute(GNE_ATTR_SHAPE_END), undoList);
681  }
682  }
683  // @todo remap connectivity as well
684 }
685 
686 
687 void
689  // compute and update network
690  computeAndUpdate(oc);
691  // write network
693 }
694 
695 
696 void
697 GNENet::saveAdditionals(const std::string& filename) {
698  OutputDevice& device = OutputDevice::getDevice(filename);
699  device.openTag("additionals");
700  for (GNEAdditionals::const_iterator i = myAdditionals.begin(); i != myAdditionals.end(); ++i) {
701  i->second->writeAdditional(device);
702  }
703  device.close();
704  // change value of flag
705  myAdditionalsSaved = true;
706 }
707 
708 
709 void
711  computeAndUpdate(oc);
713 }
714 
715 
716 void
718  computeAndUpdate(oc);
720 }
721 
722 
723 void
725  myViewNet = viewNet;
726 }
727 
728 
730 GNENet::retrieveJunction(const std::string& id, bool failHard) {
731  if (myJunctions.count(id)) {
732  return myJunctions[id];
733  } else if (failHard) {
734  // If junction wasn't found, throw exception
735  throw UnknownElement("Junction " + id);
736  } else {
737  return NULL;
738  }
739 }
740 
741 
742 GNEEdge*
743 GNENet::retrieveEdge(const std::string& id, bool failHard) {
744  GNEEdges::const_iterator i = myEdges.find(id);
745  // If edge was fund
746  if (i != myEdges.end()) {
747  return i->second;
748  } else if (failHard) {
749  // If edge wasn't found, throw exception
750  throw UnknownElement("Edge " + id);
751  } else {
752  return NULL;
753  }
754 }
755 
756 
757 std::vector<GNEEdge*>
758 GNENet::retrieveEdges(bool onlySelected) {
759  std::vector<GNEEdge*> result;
760  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
761  if (!onlySelected || gSelected.isSelected(GLO_EDGE, it->second->getGlID())) {
762  result.push_back(it->second);
763  }
764  }
765  return result;
766 }
767 
768 
769 std::vector<GNELane*>
770 GNENet::retrieveLanes(bool onlySelected) {
771  std::vector<GNELane*> result;
772  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
773  const GNEEdge::LaneVector& lanes = it->second->getLanes();
774  for (GNEEdge::LaneVector::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) {
775  if (!onlySelected || gSelected.isSelected(GLO_LANE, (*it_lane)->getGlID())) {
776  result.push_back(*it_lane);
777  }
778  }
779  }
780  return result;
781 }
782 
783 
784 GNELane*
785 GNENet::retrieveLane(const std::string& id, bool failHard) {
786  const std::string edge_id = SUMOXMLDefinitions::getEdgeIDFromLane(id);
787  GNEEdge* edge = retrieveEdge(edge_id, failHard);
788  if (edge != 0) {
789  const GNEEdge::LaneVector& lanes = edge->getLanes();
790  for (GNEEdge::LaneVector::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) {
791  if ((*it_lane)->getID() == id) {
792  return (*it_lane);
793  }
794  }
795  if (failHard) {
796  // Throw exception if failHard is enabled
797  throw UnknownElement(toString(SUMO_TAG_LANE) + " " + id);
798  }
799  }
800  return 0;
801 }
802 
803 
804 std::vector<GNEJunction*>
805 GNENet::retrieveJunctions(bool onlySelected) {
806  std::vector<GNEJunction*> result;
807  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
808  if (!onlySelected || gSelected.isSelected(GLO_JUNCTION, it->second->getGlID())) {
809  result.push_back(it->second);
810  }
811  }
812  return result;
813 }
814 
815 
816 void
820  update();
821 }
822 
823 
824 void
826  GNEAdditionals::iterator positionToRemove = myAdditionals.find(std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag()));
827  // Check if additional element exists before refresh
828  if (positionToRemove != myAdditionals.end()) {
829  myGrid.removeAdditionalGLObject(additional);
830  myGrid.addAdditionalGLObject(additional);
831  update();
832  }
833 }
834 
835 
836 std::string
838  int counter = 0;
839  while (myAdditionals.find(std::pair<std::string, SumoXMLTag>("vaporizer_" + toString(counter), SUMO_TAG_VAPORIZER)) != myAdditionals.end()) {
840  counter++;
841  }
842  return "vaporizer_" + toString(counter);
843 }
844 
845 
846 std::vector<GNEAttributeCarrier*>
847 GNENet::retrieveAttributeCarriers(const std::set<GUIGlID>& ids, GUIGlObjectType type) {
848  std::vector<GNEAttributeCarrier*> result;
849  for (std::set<GUIGlID>::iterator it = ids.begin(); it != ids.end(); it++) {
851  if (object != 0) {
852  std::string id = object->getMicrosimID();
854  GNEAttributeCarrier* ac = 0;
855  switch (type) {
856  case GLO_JUNCTION:
857  ac = dynamic_cast<GNEJunction*>(object);
858  break;
859  case GLO_EDGE:
860  ac = dynamic_cast<GNEEdge*>(object);
861  break;
862  case GLO_LANE:
863  ac = dynamic_cast<GNELane*>(object);
864  break;
865  case GLO_ADDITIONAL:
866  ac = dynamic_cast<GNEAdditional*>(object);
867  break;
868  case GLO_CONNECTION:
869  ac = dynamic_cast<GNEConnection*>(object);
870  break;
871  case GLO_CROSSING:
872  ac = dynamic_cast<GNECrossing*>(object);
873  break;
874  case GLO_POLYGON:
875  ac = dynamic_cast<GNEPoly*>(object);
876  break;
877  case GLO_POI:
878  ac = dynamic_cast<GNEPOI*>(object);
879  break;
880  default:
881  break;
882  }
883  if (ac == 0) {
884  throw ProcessError("GUIGlObject does not match the declared type");
885  } else {
886  result.push_back(ac);
887  }
888  } else {
889  throw ProcessError("Attempted to retrieve non-existant GUIGlObject");
890  }
891  }
892  return result;
893 }
894 
895 
896 std::set<GUIGlID>
898  std::set<GUIGlID> result;
899  switch (type) {
900  case GLO_MAX: {
901  std::set<GUIGlObjectType> knownTypes;
902  knownTypes.insert(GLO_JUNCTION);
903  knownTypes.insert(GLO_EDGE);
904  knownTypes.insert(GLO_LANE);
905  // knownTypes.insert(GLO_TLLOGIC); makes no sense to include them
906  knownTypes.insert(GLO_ADDITIONAL);
907  knownTypes.insert(GLO_CONNECTION);
908  knownTypes.insert(GLO_CROSSING);
909  for (std::set<GUIGlObjectType>::const_iterator it = knownTypes.begin(); it != knownTypes.end(); it++) {
910  const std::set<GUIGlID> tmp = getGlIDs(*it);
911  result.insert(tmp.begin(), tmp.end());
912  }
913  break;
914  }
915  case GLO_JUNCTION:
916  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
917  result.insert(it->second->getGlID());
918  }
919  break;
920  case GLO_EDGE:
921  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
922  result.insert(it->second->getGlID());
923  }
924  break;
925  case GLO_LANE: {
926  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
927  const std::set<GUIGlID> laneIDs = it->second->getLaneGlIDs();
928  for (std::set<GUIGlID>::const_iterator lid_it = laneIDs.begin(); lid_it != laneIDs.end(); lid_it++) {
929  result.insert(*lid_it);
930  }
931  }
932  break;
933  }
934  case GLO_TLLOGIC: {
935  // return all junctions which have a traffic light (we do not have a GUIGlObject for each traffic light)
936  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
937  if (it->second->getNBNode()->isTLControlled()) {
938  result.insert(it->second->getGlID());
939  }
940  }
941  break;
942  }
943  case GLO_ADDITIONAL: {
944  // Iterate over all additionals of net
945  for (GNEAdditionals::iterator it = myAdditionals.begin(); it != myAdditionals.end(); it++) {
946  // Insert every additional in result
947  result.insert(it->second->getGlID());
948  }
949  break;
950  }
951  case GLO_CONNECTION: {
952  for (GNEEdges::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
953  // Get connections of edge
954  const std::vector<GNEConnection*>& connections = i->second->getGNEConnections();
955  // Iterate over connections
956  for (std::vector<GNEConnection*>::const_iterator j = connections.begin(); j != connections.end(); j++) {
957  // Insert every connection of edge in result
958  result.insert((*j)->getGlID());
959  }
960  }
961  break;
962  }
963  case GLO_CROSSING: {
964  for (GNEJunctions::const_iterator i = myJunctions.begin(); i != myJunctions.end(); i++) {
965  // Get crossings of junction
966  const std::vector<GNECrossing*>& crossings = i->second->getGNECrossings();
967  // Iterate over crossings
968  for (std::vector<GNECrossing*>::const_iterator j = crossings.begin(); j != crossings.end(); j++) {
969  // Insert every crossing of junction in result
970  result.insert((*j)->getGlID());
971  }
972  }
973  break;
974  }
975  default: // add other types once we know them
976  break;
977  }
978  return result;
979 }
980 
981 
982 void
984  if (!myNeedRecompute) {
985  if (force) {
986  window->setStatusBarText("Forced computing junctions ...");
987  } else {
988  return;
989  }
990  } else {
991  window->setStatusBarText("Computing junctions ...");
992  }
993  // compute
995  computeAndUpdate(oc);
996  WRITE_MESSAGE("\nFinished computing junctions.");
997 
998  window->getApp()->endWaitCursor();
999  window->setStatusBarText("Finished computing junctions.");
1000  update();
1001 }
1002 
1003 
1004 void
1006  // recompute tl-logics
1009 
1010  NBNode* nbn = junction->getNBNode();
1011  std::set<NBTrafficLightDefinition*> tldefs = nbn->getControllingTLS();
1012  for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
1013  NBTrafficLightDefinition* def = *it;
1016  tllCont.computeSingleLogic(oc, def);
1017  }
1018 
1019  // @todo compute connections etc...
1020 }
1021 
1022 
1023 void
1025  myNeedRecompute = true;
1026 }
1027 
1028 
1029 bool
1031  for (std::map<std::string, NBNode*>::const_iterator i = myNetBuilder->getNodeCont().begin(); i != myNetBuilder->getNodeCont().end() ; i++) {
1032  if (i->second->getCrossings().size() > 0) {
1033  return true;
1034  }
1035  }
1036  return false;
1037 }
1038 
1039 
1040 FXApp*
1042  return myViewNet->getApp();
1043 }
1044 
1045 
1046 NBNetBuilder*
1048  return myNetBuilder;
1049 }
1050 
1051 
1052 void
1054  std::vector<GNEJunction*> selected = retrieveJunctions(true);
1055  if (selected.size() < 2) {
1056  return;
1057  }
1058  undoList->p_begin("Join selected " + toString(SUMO_TAG_JUNCTION) + "s");
1059 
1060  EdgeVector allIncoming;
1061  EdgeVector allOutgoing;
1062  std::set<NBNode*> cluster;
1063  for (std::vector<GNEJunction*>::iterator it = selected.begin(); it != selected.end(); it++) {
1064  cluster.insert((*it)->getNBNode());
1065  const EdgeVector& incoming = (*it)->getNBNode()->getIncomingEdges();
1066  allIncoming.insert(allIncoming.end(), incoming.begin(), incoming.end());
1067  const EdgeVector& outgoing = (*it)->getNBNode()->getOutgoingEdges();
1068  allOutgoing.insert(allOutgoing.end(), outgoing.begin(), outgoing.end());
1069  }
1070  // create new junction
1071  Position pos;
1072  bool setTL;
1073  std::string id;
1074  TrafficLightType type;
1075  myNetBuilder->getNodeCont().analyzeCluster(cluster, id, pos, setTL, type);
1076  // XXX this is not undone when calling 'undo'
1078  GNEJunction* joined = createJunction(pos, undoList);
1079  if (setTL) {
1081  // XXX ticket831
1082  //joined-><getTrafficLight>->setAttribute(SUMO_ATTR_TYPE, toString(type), undoList);
1083  }
1084  // remap edges
1085  for (EdgeVector::const_iterator it = allIncoming.begin(); it != allIncoming.end(); it++) {
1086  GNEEdge* oldEdge = myEdges[(*it)->getID()];
1087  remapEdge(oldEdge, oldEdge->getGNEJunctionSource(), joined, undoList, true);
1088  }
1089  for (EdgeVector::const_iterator it = allOutgoing.begin(); it != allOutgoing.end(); it++) {
1090  GNEEdge* oldEdge = myEdges[(*it)->getID()];
1091  remapEdge(oldEdge, joined, oldEdge->getGNEJunctionDestiny(), undoList, true);
1092  }
1093  // delete original junctions
1094  for (std::vector<GNEJunction*>::iterator it = selected.begin(); it != selected.end(); it++) {
1095  deleteJunction(*it, undoList);
1096  }
1097  joined->setAttribute(SUMO_ATTR_ID, id, undoList);
1098  undoList->p_end();
1099 }
1100 
1101 
1102 void
1104  undoList->p_begin("Clean " + toString(SUMO_TAG_JUNCTION) + "s");
1105  std::vector<GNEJunction*> toRemove;
1106  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
1107  GNEJunction* junction = it->second;
1108  if (junction->getNBNode()->getEdges().size() == 0) {
1109  toRemove.push_back(junction);
1110  }
1111  }
1112  for (std::vector<GNEJunction*>::iterator it = toRemove.begin(); it != toRemove.end(); ++it) {
1113  deleteJunction(*it, undoList);
1114  }
1115  undoList->p_end();
1116 }
1117 
1118 
1119 void
1121  undoList->p_begin("Replace junction by geometry");
1122  assert(junction->getNBNode()->checkIsRemovable());
1123  std::vector<std::pair<NBEdge*, NBEdge*> > toJoin = junction->getNBNode()->getEdgesToJoin();
1124  for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
1125  GNEEdge* begin = myEdges[(*j).first->getID()];
1126  GNEEdge* continuation = myEdges[(*j).second->getID()];
1127  deleteEdge(begin, undoList);
1128  deleteEdge(continuation, undoList);
1129  GNEEdge* newEdge = createEdge(begin->getGNEJunctionSource(), continuation->getGNEJunctionDestiny(), begin, undoList, begin->getMicrosimID(), false, true);
1130  PositionVector newShape = begin->getNBEdge()->getInnerGeometry();
1131  newShape.push_back(junction->getNBNode()->getPosition());
1132  newShape.append(continuation->getNBEdge()->getInnerGeometry());
1133  newEdge->setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
1134  // @todo what about trafficlights at the end of oontinuation?
1135  }
1136  deleteJunction(junction, undoList);
1137  undoList->p_end();
1138 }
1139 
1140 
1141 void
1142 GNENet::renameEdge(GNEEdge* edge, const std::string& newID) {
1143  myEdges.erase(edge->getNBEdge()->getID());
1144  myNetBuilder->getEdgeCont().rename(edge->getNBEdge(), newID);
1145  edge->setMicrosimID(newID);
1146  myEdges[newID] = edge;
1147  // rename all connections related to this edge
1148  for (std::vector<GNELane*>::const_iterator i = edge->getLanes().begin(); i != edge->getLanes().end(); i++) {
1149  (*i)->updateConnectionIDs();
1150  }
1151 }
1152 
1153 
1154 void
1155 GNENet::changeEdgeEndpoints(GNEEdge* edge, const std::string& newSource, const std::string& newDest) {
1156  NBNode* from = retrieveJunction(newSource)->getNBNode();
1157  NBNode* to = retrieveJunction(newDest)->getNBNode();
1158  edge->getNBEdge()->reinitNodes(from, to);
1159  requireRecompute();
1160  update();
1161 }
1162 
1163 
1164 GNEViewNet*
1166  return myViewNet;
1167 }
1168 
1169 
1172  return myNetBuilder->getTLLogicCont();
1173 }
1174 
1175 
1176 void
1177 GNENet::renameJunction(GNEJunction* junction, const std::string& newID) {
1178  myJunctions.erase(junction->getNBNode()->getID());
1179  myNetBuilder->getNodeCont().rename(junction->getNBNode(), newID);
1180  junction->setMicrosimID(newID);
1181  myJunctions[newID] = junction;
1182 }
1183 
1184 
1185 void
1187  myExplicitTurnarounds.insert(id);
1188 }
1189 
1190 
1191 void
1193  myExplicitTurnarounds.erase(id);
1194 }
1195 
1196 
1197 void
1198 GNENet::moveSelection(const Position& moveSrc, const Position& moveDest) {
1199  Position delta = moveDest - moveSrc;
1200  // move junctions
1201  std::set<GNEJunction*> junctionSet;
1202  std::vector<GNEJunction*> junctions = retrieveJunctions(true);
1203  for (std::vector<GNEJunction*>::iterator it = junctions.begin(); it != junctions.end(); it++) {
1204  Position newPos = (*it)->getNBNode()->getPosition() + delta;
1205  (*it)->move(newPos);
1206  junctionSet.insert(*it);
1207  }
1208 
1209  // move edge geometry (endpoints are already moved)
1210  std::vector<GNEEdge*> edges = retrieveEdges(true);
1211  for (std::vector<GNEEdge*>::iterator it = edges.begin(); it != edges.end(); it++) {
1212  GNEEdge* edge = *it;
1213  if (edge) {
1214  if (junctionSet.count(edge->getGNEJunctionSource()) > 0 &&
1215  junctionSet.count(edge->getGNEJunctionDestiny()) > 0) {
1216  // edge and its endpoints are selected, move all the inner points as well
1217  edge->moveGeometry(delta);
1218  } else {
1219  // move only geometry near mouse
1220  edge->moveGeometry(moveSrc, delta, true);
1221  }
1222  }
1223  }
1224 }
1225 
1226 
1227 void
1229  undoList->p_begin("move selection");
1230  // register moved junctions
1231  std::set<GNEJunction*> junctionSet;
1232  std::vector<GNEJunction*> junctions = retrieveJunctions(true);
1233  for (std::vector<GNEJunction*>::iterator it = junctions.begin(); it != junctions.end(); it++) {
1234  (*it)->registerMove(undoList);
1235  junctionSet.insert(*it);
1236  }
1237 
1238  // register moved edge geometry (endpoints are already moved)
1239  std::vector<GNEEdge*> edges = retrieveEdges(true);
1240  for (std::vector<GNEEdge*>::iterator it = edges.begin(); it != edges.end(); it++) {
1241  GNEEdge* edge = *it;
1242  if (edge) {
1243  const std::string& newShape = edge->getAttribute(SUMO_ATTR_SHAPE);
1244  edge->setAttribute(SUMO_ATTR_SHAPE, newShape, undoList);
1245  }
1246  }
1247  undoList->p_end();
1248 }
1249 
1250 
1253  return myShapeContainer;
1254 }
1255 
1256 
1257 void
1258 GNENet::insertAdditional(GNEAdditional* additional, bool hardFail) {
1259  // Check if additional element exists before insertion
1260  if (myAdditionals.find(std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag())) != myAdditionals.end()) {
1261  // Throw exception only if hardFail is enabled
1262  if (hardFail) {
1263  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' already exist");
1264  }
1265  } else {
1266  myAdditionals[std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag())] = additional;
1267  myGrid.addAdditionalGLObject(additional);
1268  update();
1269  myAdditionalsSaved = false;
1270  }
1271 }
1272 
1273 
1274 void
1276  GNEAdditionals::iterator additionalToRemove = myAdditionals.find(std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag()));
1277  // Check if additional element exists before deletion
1278  if (additionalToRemove == myAdditionals.end()) {
1279  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' doesn't exist");
1280  } else {
1281  myAdditionals.erase(additionalToRemove);
1282  myGrid.removeAdditionalGLObject(additional);
1283  update();
1284  myAdditionalsSaved = false;
1285  }
1286 }
1287 
1288 
1289 void
1290 GNENet::updateAdditionalID(const std::string& oldID, GNEAdditional* additional) {
1291  GNEAdditionals::iterator additionalToUpdate = myAdditionals.find(std::pair<std::string, SumoXMLTag>(oldID, additional->getTag()));
1292  if (additionalToUpdate == myAdditionals.end()) {
1293  throw ProcessError(toString(additional->getTag()) + " with old ID='" + oldID + "' doesn't exist");
1294  } else {
1295  // remove an insert additional again into container
1296  myAdditionals.erase(additionalToUpdate);
1297  myAdditionals[std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag())] = additional;
1298  myAdditionalsSaved = false;
1299  }
1300 }
1301 
1302 
1304 GNENet::retrieveAdditional(const std::string& id, bool hardFail) const {
1305  for (GNEAdditionals::const_iterator i = myAdditionals.begin(); i != myAdditionals.end(); i++) {
1306  if (i->second->getID() == id) {
1307  return i->second;
1308  }
1309  }
1310  if (hardFail) {
1311  throw ProcessError("Attempted to retrieve non-existant additional");
1312  } else {
1313  return NULL;
1314  }
1315 }
1316 
1317 
1318 std::vector<GNEAdditional*>
1319 GNENet::retrieveAdditionals(bool onlySelected) {
1320  std::vector<GNEAdditional*> result;
1321  for (GNEAdditionals::const_iterator it = myAdditionals.begin(); it != myAdditionals.end(); ++it) {
1322  if (!onlySelected || gSelected.isSelected(GLO_ADDITIONAL, it->second->getGlID())) {
1323  result.push_back(it->second);
1324  }
1325  }
1326  return result;
1327 }
1328 
1329 
1331 GNENet::getAdditional(SumoXMLTag type, const std::string& id) const {
1332  if (myAdditionals.empty()) {
1333  return NULL;
1334  } else if (myAdditionals.find(std::pair<std::string, SumoXMLTag>(id, type)) != myAdditionals.end()) {
1335  return myAdditionals.at(std::pair<std::string, SumoXMLTag>(id, type));
1336  } else {
1337  return NULL;
1338  }
1339 }
1340 
1341 
1342 std::string
1343 GNENet::getAdditionalID(SumoXMLTag type, const GNELane* lane, const double pos) const {
1344  for (GNEAdditionals::const_iterator it = myAdditionals.begin(); it != myAdditionals.end(); ++it) {
1345  if ((it->second->getTag() == type) && (it->second->getLane() != NULL) && (it->second->getLane() == lane) && (fabs(it->second->getPositionInView().x() - pos) < POSITION_EPS)) {
1346  return it->second->getID();
1347  }
1348  }
1349  return "";
1350 }
1351 
1352 
1353 std::vector<GNEAdditional*>
1355  std::vector<GNEAdditional*> vectorOfAdditionals;
1356  for (GNEAdditionals::const_iterator i = myAdditionals.begin(); i != myAdditionals.end(); i++) {
1357  if (type == SUMO_TAG_NOTHING || type == i->second->getTag()) {
1358  vectorOfAdditionals.push_back(i->second);
1359  }
1360  }
1361  return vectorOfAdditionals;
1362 }
1363 
1364 
1365 int
1367  int counter = 0;
1368  for (GNEAdditionals::const_iterator i = myAdditionals.begin(); i != myAdditionals.end(); i++) {
1369  if (type == SUMO_TAG_NOTHING || type == i->second->getTag()) {
1370  counter++;
1371  }
1372  }
1373  return counter;
1374 }
1375 
1376 
1377 const GNECalibratorRoute&
1378 GNENet::getGNECalibratorRoute(const std::string& calibratorRouteID) const {
1379  std::vector<GNEAdditional*> calibrators = getAdditionals(SUMO_TAG_CALIBRATOR);
1380  for (std::vector<GNEAdditional*>::iterator i = calibrators.begin(); i != calibrators.end(); i++) {
1381  GNECalibrator* calibrator = dynamic_cast<GNECalibrator*>(*i);
1382  if (calibrator->routeExists(calibratorRouteID)) {
1383  return calibrator->getCalibratorRoute(calibratorRouteID);
1384  }
1385  }
1386  throw InvalidArgument("A " + toString(SUMO_TAG_VTYPE) + "'s " + toString(SUMO_TAG_VTYPE) + " with ID = '" + calibratorRouteID + "' doesn't exists");
1387 }
1388 
1389 
1391 GNENet::getGNECalibratorVehicleType(const std::string& calibratorVehicleTypeID) const {
1392  std::vector<GNEAdditional*> calibrators = getAdditionals(SUMO_TAG_CALIBRATOR);
1393  for (std::vector<GNEAdditional*>::iterator i = calibrators.begin(); i != calibrators.end(); i++) {
1394  GNECalibrator* calibrator = dynamic_cast<GNECalibrator*>(*i);
1395  if (calibrator->vehicleTypeExists(calibratorVehicleTypeID)) {
1396  return calibrator->getCalibratorVehicleType(calibratorVehicleTypeID);
1397  }
1398  }
1399  throw InvalidArgument("A " + toString(SUMO_TAG_VTYPE) + "'s " + toString(SUMO_TAG_VTYPE) + " with ID = '" + calibratorVehicleTypeID + "' doesn't exists");
1400 }
1401 
1402 
1403 const GNECalibratorFlow&
1404 GNENet::getGNECalibratorFlow(const std::string& calibratorFlowID) const {
1405  std::vector<GNEAdditional*> calibrators = getAdditionals(SUMO_TAG_CALIBRATOR);
1406  for (std::vector<GNEAdditional*>::iterator i = calibrators.begin(); i != calibrators.end(); i++) {
1407  GNECalibrator* calibrator = dynamic_cast<GNECalibrator*>(*i);
1408  if (calibrator->flowExists(calibratorFlowID)) {
1409  return calibrator->getCalibratorFlow(calibratorFlowID);
1410  }
1411  }
1412  throw InvalidArgument("A " + toString(SUMO_TAG_VTYPE) + "'s " + toString(SUMO_TAG_VTYPE) + " with ID = '" + calibratorFlowID + "' doesn't exists");
1413 }
1414 
1415 
1416 bool
1417 GNENet::routeExists(const std::string& routeID) const {
1418  std::vector<GNEAdditional*> calibrators = getAdditionals(SUMO_TAG_CALIBRATOR);
1419  for (std::vector<GNEAdditional*>::iterator i = calibrators.begin(); i != calibrators.end(); i++) {
1420  GNECalibrator* calibrator = dynamic_cast<GNECalibrator*>(*i);
1421  if (calibrator->routeExists(routeID)) {
1422  return true;
1423  }
1424  }
1425  return false;
1426 }
1427 
1428 
1429 bool
1430 GNENet::vehicleTypeExists(const std::string& vehicleTypeID) const {
1431  std::vector<GNEAdditional*> calibrators = getAdditionals(SUMO_TAG_CALIBRATOR);
1432  for (std::vector<GNEAdditional*>::iterator i = calibrators.begin(); i != calibrators.end(); i++) {
1433  GNECalibrator* calibrator = dynamic_cast<GNECalibrator*>(*i);
1434  if (calibrator->vehicleTypeExists(vehicleTypeID)) {
1435  return true;
1436  }
1437  }
1438  return false;
1439 }
1440 
1441 
1442 bool
1443 GNENet::flowExists(const std::string& flowID) const {
1444  std::vector<GNEAdditional*> calibrators = getAdditionals(SUMO_TAG_CALIBRATOR);
1445  for (std::vector<GNEAdditional*>::iterator i = calibrators.begin(); i != calibrators.end(); i++) {
1446  GNECalibrator* calibrator = dynamic_cast<GNECalibrator*>(*i);
1447  if (calibrator->flowExists(flowID)) {
1448  return true;
1449  }
1450  }
1451  return false;
1452 }
1453 
1454 // ===========================================================================
1455 // private
1456 // ===========================================================================
1457 
1458 void
1460  myNetBuilder->getNodeCont().insert(junction->getNBNode());
1461  registerJunction(junction);
1462 }
1463 
1464 
1465 void
1467  NBEdge* nbe = edge->getNBEdge();
1468  myNetBuilder->getEdgeCont().insert(nbe); // should we ignore pruning double edges?
1469  // if this edge was previouls extracted from the edgeContainer we have to rewire the nodes
1470  nbe->getFromNode()->addOutgoingEdge(nbe);
1471  nbe->getToNode()->addIncomingEdge(nbe);
1472  registerEdge(edge);
1473 }
1474 
1475 
1476 GNEJunction*
1478  junction->incRef("GNENet::registerJunction");
1479  junction->setResponsible(false);
1480  myJunctions[junction->getMicrosimID()] = junction;
1481  myGrid.add(junction->getBoundary());
1482  myGrid.addAdditionalGLObject(junction);
1483  // @todo let Boundary class track z-coordinate natively
1484  const double z = junction->getNBNode()->getPosition().z();
1485  if (z != 0) {
1487  }
1488  update();
1489  return junction;
1490 }
1491 
1492 
1493 GNEEdge*
1495  edge->incRef("GNENet::registerEdge");
1496  edge->setResponsible(false);
1497  // add edge to internal container of GNENet
1498  myEdges[edge->getMicrosimID()] = edge;
1499  // add edge to grid
1500  myGrid.add(edge->getBoundary());
1502  // Add references into GNEJunctions
1505  // update view
1506  update();
1507  return edge;
1508 }
1509 
1510 
1511 void
1513  myGrid.removeAdditionalGLObject(junction);
1514  myJunctions.erase(junction->getMicrosimID());
1515  myNetBuilder->getNodeCont().extract(junction->getNBNode());
1516  junction->decRef("GNENet::deleteSingleJunction");
1517  junction->setResponsible(true);
1518  // selection status is lost when removing junction via undo and the selection operation was not part of a command group
1519  gSelected.deselect(junction->getGlID());
1520  update();
1521 }
1522 
1523 
1524 void
1526  // remove edge from visual grid and container
1528  myEdges.erase(edge->getMicrosimID());
1529  // extract edge of district container
1531  edge->decRef("GNENet::deleteSingleEdge");
1532  edge->setResponsible(true);
1533  // selection status is lost when removing edge via undo and the selection operation was not part of a command group
1534  gSelected.deselect(edge->getGlID());
1535  // Remove refrences from GNEJunctions
1538  // invalidate junction logic
1539  update();
1540 }
1541 
1542 
1543 void
1545  if (myViewNet) {
1546  myViewNet->update();
1547  }
1548 }
1549 
1550 
1551 void
1552 GNENet::reserveEdgeID(const std::string& id) {
1553  myEdgeIDSupplier.avoid(id);
1554 }
1555 
1556 
1557 void
1558 GNENet::reserveJunctionID(const std::string& id) {
1560 }
1561 
1562 
1563 void
1565  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1566  it->second->remakeGNEConnections();
1567  }
1568  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1569  it->second->updateGeometry();
1570  }
1571 }
1572 
1573 void
1575  // make sure we only add turn arounds to edges which currently exist within the network
1576  std::set<std::string> liveExplicitTurnarounds;
1577  for (std::set<std::string>::const_iterator it = myExplicitTurnarounds.begin(); it != myExplicitTurnarounds.end(); it++) {
1578  if (myEdges.count(*it) > 0) {
1579  liveExplicitTurnarounds.insert(*it);
1580  }
1581  }
1582  myNetBuilder->compute(oc, liveExplicitTurnarounds, false);
1583  // update ids if necessary
1584  if (oc.getBool("numerical-ids") || oc.isSet("reserved-ids")) {
1585  GNEEdges newEdgeMap;
1586  GNEJunctions newJunctionMap;
1587  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1588  it->second->setMicrosimID(it->second->getNBEdge()->getID());
1589  newEdgeMap[it->second->getNBEdge()->getID()] = it->second;
1590  }
1591  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
1592  newJunctionMap[it->second->getNBNode()->getID()] = it->second;
1593  it->second->setMicrosimID(it->second->getNBNode()->getID());
1594  }
1595  myEdges = newEdgeMap;
1596  myJunctions = newJunctionMap;
1597  }
1598  // update rtree if necessary
1599  if (!oc.getBool("offset.disable-normalization")) {
1600  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1601  refreshElement(it->second);
1602  }
1603  }
1604  myGrid.reset();
1605  myGrid.add(GeoConvHelper::getFinal().getConvBoundary());
1606  // update precomputed geometries
1608 
1609  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
1610  it->second->setLogicValid(true);
1611  // updated shape
1612  it->second->updateGeometry();
1613  refreshElement(it->second);
1614  }
1615 
1616  myNeedRecompute = false;
1617 }
1618 
1619 
1620 bool
1622  return myAdditionalsSaved;
1623 }
1624 
1625 
1626 void
1628  myAdditionalsSaved = value;
1629 }
1630 
1631 
1632 /****************************************************************************/
void setViewNet(GNEViewNet *viewNet)
Set the viewNet to be notified of network changes.
Definition: GNENet.cpp:724
GNEJunction * splitEdge(GNEEdge *edge, const Position &pos, GNEUndoList *undoList, GNEJunction *newJunction=0)
split edge at position by inserting a new junction
Definition: GNENet.cpp:540
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge&#39;s lanes&#39; lateral offset is computed.
Definition: NBEdge.h:677
void computeAndUpdate(OptionsCont &oc)
recompute the network and update lane geometries
Definition: GNENet.cpp:1574
std::vector< GNEJunction * > retrieveJunctions(bool onlySelected=false)
return all junctions
Definition: GNENet.cpp:805
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:106
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNENet.cpp:195
void setResponsible(bool newVal)
set responsibility for deleting internal strctures
std::string getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a &#39; &#39;.
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return list of additionals associated with this edge
Definition: GNEEdge.cpp:1062
a tl-logic
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
ShapeContainer & getShapeContainer()
get shape container
Definition: GNENet.cpp:1252
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:138
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
Definition: GNENet.cpp:770
void close()
Closes the device and removes it from the dictionary.
GNEViewNet * myViewNet
The viewNet to be notofied of about changes.
Definition: GNENet.h:523
SumoXMLTag
Numbers representing SUMO-XML - element names.
const std::set< GUIGlID > & getSelected() const
Returns the set of ids of all selected objects.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
void registerJoinedCluster(const std::set< NBNode *> &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:766
void addIncomingGNEEdge(GNEEdge *edge)
add incoming GNEEdge
bool isRestricted(SUMOVehicleClass vclass) const
check if this lane is restricted
Definition: GNELane.cpp:774
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:743
IDSupplier myEdgeIDSupplier
Definition: GNENet.h:546
description of a vehicle type
void setStatusBarText(const std::string &statusBarText)
set text of the statusBar
is a pedestrian
void setAdditionalSaved(bool value)
set manually the flag of additionals
Definition: GNENet.cpp:1627
a polygon
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:114
void append(const PositionVector &v, double sameThreshold=2.0)
void removeIncomingGNEEdge(GNEEdge *edge)
remove incoming GNEEdge
SUMORTree myGrid
the rtree which contains all GUIGlObjects (so named for historical reasons)
Definition: GNENet.h:520
double z() const
Returns the z-position.
Definition: Position.h:73
void joinSelectedJunctions(GNEUndoList *undoList)
Definition: GNENet.cpp:1053
GUIGlObjectType
begin/end of the description of a junction
begin/end of the description of a single lane
FXApp * getApp()
get pointer to the main App
Definition: GNENet.cpp:1041
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool routeExists(const std::string &routeID) const
Check if exist a route with these ID.
Definition: GNENet.cpp:1417
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:817
GNEAdditionals myAdditionals
map with the name and pointer to additional elements of net
Definition: GNENet.h:542
The main window of the Netedit.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:119
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1047
static const RGBColor selectedLaneColor
color of selected lane
Definition: GNENet.h:100
void setMicrosimID(const std::string &newID)
override to also set lane ids
Definition: GNEEdge.cpp:1026
bool revertLaneRestriction(GNELane *lane, GNEUndoList *undoList)
revert prevously restricted lane
Definition: GNENet.cpp:485
A container for traffic light definitions and built programs.
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1331
void setLogicValid(bool valid, GNEUndoList *undoList=0, const std::string &status=GUESSED)
Definition: GNEPOI.h:51
connectio between two lanes
Stores the information about how to visualize structures.
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
Definition: GNENet.cpp:897
a connection
vehicle is a bicycle
void addIncomingEdge(NBEdge *edge)
adds an incoming edge
Definition: NBNode.cpp:412
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:71
void reinitNodes(NBNode *from, NBNode *to)
Resets nodes but keeps all other values the same (used when joining)
Definition: NBEdge.cpp:375
Position moveGeometry(const Position &oldPos, const Position &newPos, bool relative=false)
change the edge geometry It is up to the Edge to decide whether an new geometry node should be genera...
Definition: GNEEdge.cpp:281
static void writeJoinedJunctions(const OptionsCont &oc, NBNodeCont &nc)
Writes the joined-juncionts to file.
void computeEverything(GNEApplicationWindow *window, bool force=false)
Definition: GNENet.cpp:983
bool vehicleTypeExists(const std::string &vehicleTypeID) const
Check if exist a vehicle type with these ID.
Definition: GNENet.cpp:1430
std::vector< GNELane * > LaneVector
Definition of the lane&#39;s vector.
Definition: GNEEdge.h:65
const GNECalibratorRoute & getGNECalibratorRoute(const std::string &calibratorRouteID) const
Returns a reference to a calibrator route finding in all calibrators of net.
Definition: GNENet.cpp:1378
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:141
void avoid(const std::string &id)
make sure that the given id is never supplied
Definition: IDSupplier.cpp:67
void reverseEdge(GNEEdge *edge, GNEUndoList *undoList)
reverse edge
Definition: GNENet.cpp:604
The base class for traffic light logic definitions.
void update()
notify myViewNet
Definition: GNENet.cpp:1544
void insertJunction(GNEJunction *junction)
inserts a single junction into the net and into the underlying netbuild-container ...
Definition: GNENet.cpp:1459
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:258
void deleteConnection(GNEConnection *connection, GNEUndoList *undoList)
remove connection
Definition: GNENet.cpp:415
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:162
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
GNEEdge * createEdge(GNEJunction *src, GNEJunction *dest, GNEEdge *tpl, GNEUndoList *undoList, const std::string &suggestedName="", bool wasSplit=false, bool allowDuplicateGeom=false)
creates a new edge (unless an edge with the same geometry already exists)
Definition: GNENet.cpp:251
bool vehicleTypeExists(std::string vehicleTypeID) const
check if a vehicelType with ID = vehicleTypeID exists
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:82
void addExplicitTurnaround(std::string id)
add edge id to the list of explicit turnarounds
Definition: GNENet.cpp:1186
void rename(NBEdge *edge, const std::string &newID)
Renames the edge. Throws exception if newID already exists.
Definition: NBEdgeCont.cpp:404
PositionVector reverse() const
reverse position vector
GUIShapeContainer myShapeContainer
the container for additional pois and polygons
Definition: GNENet.h:551
int getNumberOfAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING) const
Returns the number of additionals of the net.
Definition: GNENet.cpp:1366
Storage for geometrical objects.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNENet.cpp:211
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void insertEdge(GNEEdge *edge)
inserts a single edge into the net and into the underlying netbuild-container
Definition: GNENet.cpp:1466
const std::string & getID() const
Returns the id.
Definition: Named.h:66
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
Lane & getLaneStruct(int lane)
Definition: NBEdge.h:1154
void deleteEdge(GNEEdge *edge, GNEUndoList *undoList)
removes edge
Definition: GNENet.cpp:336
const Boundary & getBoundary() const
returns the bounder of the network
Definition: GNENet.cpp:188
static void sortNodesEdges(NBNodeCont &nc, bool useNodeShape=false)
Sorts a node&#39;s edges clockwise regarding driving direction.
void registerMove(GNEUndoList *undoList)
registers completed movement with the undoList
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:74
first coordinate of edge shape
bool routeExists(std::string routeID) const
check if a route with ID = routeID exists
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
void addOutgoingEdge(NBEdge *edge)
adds an outgoing edge
Definition: NBNode.cpp:422
Boundary getBoundary() const
Returns the boundary of the junction.
void remapEdge(GNEEdge *oldEdge, GNEJunction *from, GNEJunction *to, GNEUndoList *undoList, bool keepEndpoints=false)
Definition: GNENet.cpp:673
std::pair< PositionVector, PositionVector > splitAt(double where) const
Returns the two lists made when this list vector is splitted at the given point.
GNEJunction * registerJunction(GNEJunction *junction)
registers a junction with GNENet containers
Definition: GNENet.cpp:1477
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:255
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool myNeedRecompute
whether the net needs recomputation
Definition: GNENet.h:557
NBNetBuilder * myNetBuilder
The internal netbuilder.
Definition: GNENet.h:526
void setNetObject(GUIGlObject *object)
Sets the given object as the "network" object.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges (The edges which start at this node)
Definition: NBNode.h:245
bool priority
whether the pedestrians have priority
Definition: NBNode.h:159
bool restrictLane(SUMOVehicleClass vclass, GNELane *lane, GNEUndoList *undoList)
transform lane to restricted lane
Definition: GNENet.cpp:459
bool myAdditionalsSaved
Flag to check if additionals must be saved.
Definition: GNENet.h:560
void renameJunction(GNEJunction *junction, const std::string &newID)
updates the map and reserves new id
Definition: GNENet.cpp:1177
void removeOutgoingGNEEdge(GNEEdge *edge)
remove outgoing GNEEdge
IDSupplier myJunctionIDSupplier
Definition: GNENet.h:547
const std::vector< GNECrossing * > & getGNECrossings() const
Returns GNECrossings.
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:124
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEEdge.cpp:561
static const double Z_INITIALIZED
marker for whether the z-boundary is initialized
Definition: GNENet.h:605
GNEUndoList * getUndoList() const
get the undoList object
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:697
friend class GNEChange_Connection
Definition: GNENet.h:93
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1290
std::string getNext()
Returns the next id.
Definition: IDSupplier.cpp:59
bool removeRestrictedLane(SUMOVehicleClass vclass, GNEEdge &edge, GNEUndoList *undoList)
remove restricted lane
Definition: GNENet.cpp:518
std::map< std::string, GNEJunction * > GNEJunctions
Definition: GNENet.h:530
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:158
const GNECalibratorRoute & getCalibratorRoute(const std::string &routeID)
get reference calibrator route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
Definition: GNECrossing.h:51
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1078
const GNECalibratorFlow & getGNECalibratorFlow(const std::string &calibratorFlowID) const
Returns a reference to a calibrator flow finding in all calibrators of net.
Definition: GNENet.cpp:1404
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Definition: GNELane.cpp:812
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNENet.cpp:205
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
void extract(NBDistrictCont &dc, NBEdge *edge, bool remember=false)
Removes the given edge from the container like erase but does not delete it.
Definition: NBEdgeCont.cpp:392
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:413
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:89
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
Definition: GNENet.cpp:730
GNEJunctions myJunctions
map with the name and pointer to junctions of net
Definition: GNENet.h:536
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:155
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:785
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
Boundary myZBoundary
the z boundary (stored in the x-coordinate), values of 0 are ignored
Definition: GNENet.h:602
const PositionVector getInnerGeometry() const
Returns the geometry of the edge without the endpoints.
Definition: NBEdge.cpp:482
void deleteLane(GNELane *lane, GNEUndoList *undoList)
removes lane
Definition: GNENet.cpp:382
void deleteGeometryOrEdge(GNEEdge *edge, const Position &pos, GNEUndoList *undoList)
removes geometry when pos is close to a geometry node, deletes the whole edge otherwise ...
Definition: GNENet.cpp:532
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:165
void removeFromCrossings(GNEEdge *edge, GNEUndoList *undoList)
removes the given edge from all pedestrian crossings
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node) ...
Definition: NBNode.h:250
void computeJunction(GNEJunction *junction)
Definition: GNENet.cpp:1005
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
void initGNEConnections()
initialize GNEConnections
Definition: GNENet.cpp:1564
NBNode::Crossing & getNBCrossing() const
get referente to NBode::Crossing
#define POSITION_EPS
Definition: config.h:175
bool isAdditionalsSaved() const
check if additional are saved
Definition: GNENet.cpp:1621
const std::vector< GNERerouter * > & getGNERerouters() const
get rerouters vinculated with this edge
Definition: GNEEdge.cpp:1089
const GNECalibratorVehicleType & getCalibratorVehicleType(const std::string &vehicleTypeID)
get reference to calibrator vehicle type
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
void save(OptionsCont &oc)
save the network
Definition: GNENet.cpp:688
edge: the shape in xml-definition
std::vector< GNEAttributeCarrier * > retrieveAttributeCarriers(const std::set< GUIGlID > &ids, GUIGlObjectType type)
get the attribute carriers based on GlIDs
Definition: GNENet.cpp:847
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void deleteCrossing(GNECrossing *crossing, GNEUndoList *undoList)
remove crossing
Definition: GNENet.cpp:433
void addOutgoingGNEEdge(GNEEdge *edge)
add outgoing GNEEdge
const std::string getID() const
function to support debugging
friend class GNEChange_Edge
Definition: GNENet.h:92
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
void moveSelection(const Position &moveSrc, const Position &moveDest)
move all selected junctions and edges
Definition: GNENet.cpp:1198
GNEJunction * createJunction(const Position &pos, GNEUndoList *undoList)
creates a new junction
Definition: GNENet.cpp:240
void splitEdgesBidi(const std::set< GNEEdge *> &edges, const Position &pos, GNEUndoList *undoList)
split all edges at position by inserting one new junction
Definition: GNENet.cpp:593
GNEJunction * getGNEJunctionSource() const
returns the source-junction
Definition: GNEEdge.cpp:159
void incRef(const std::string &debugMsg="")
void analyzeCluster(std::set< NBNode *> cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:776
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:2913
void move2side(double amount)
move position vector to side using certain ammount
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GNENet.cpp:228
std::set< std::string > myExplicitTurnarounds
list of edge ids for which turn-arounds must be added explicitly
Definition: GNENet.h:554
void decRef(const std::string &debugMsg="")
std::string generateVaporizerID() const
generate an ID for vaporizers
Definition: GNENet.cpp:837
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
void invalidateTLS(GNEUndoList *undoList, const NBConnection &deletedConnection=NBConnection::InvalidConnection)
begin/end of the description of an edge
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:154
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:595
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNENet.cpp:216
void replaceJunctionByGeometry(GNEJunction *junction, GNEUndoList *undoList)
replace the selected junction by geometry node(s) and merge the edges
Definition: GNENet.cpp:1120
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
void reserveJunctionID(const std::string &id)
reserve junction ID (To avoid duplicates)
Definition: GNENet.cpp:1558
compound additional
vehicle is a bus
void reset()
Resets the boundary.
Definition: Boundary.cpp:74
void setResponsible(bool newVal)
set responsibility for deleting internal strctures
Definition: GNEEdge.cpp:778
std::vector< std::string > getAllNames() const
get all node names
void deleteSingleJunction(GNEJunction *junction)
deletes a single junction
Definition: GNENet.cpp:1512
double width
This lane&#39;s width.
Definition: NBNode.h:151
~GNENet()
Destructor.
Definition: GNENet.cpp:157
void deselect(GUIGlID id)
Deselects the object with the given id.
const Boundary & getZBoundary() const
Returns the Z boundary (stored in the x() coordinate) values of 0 do not affect the boundary...
Definition: GNENet.cpp:222
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:543
bool deleteGeometry(const Position &pos, GNEUndoList *undoList)
deletes the closest geometry node within SNAP_RADIUS.
Definition: GNEEdge.cpp:347
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges (The edges which yield in this node)
Definition: NBNode.h:240
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
Definition: GNENet.cpp:758
NBConnection getNBConnection() const
get NBConnection
GNEEdge * registerEdge(GNEEdge *edge)
registers an edge with GNENet containers
Definition: GNENet.cpp:1494
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:160
double getHeight() const
Returns the height of the boundary (y-axis)
Definition: Boundary.cpp:168
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:129
bool computeSingleLogic(OptionsCont &oc, NBTrafficLightDefinition *def)
Computes a specific traffic light logic (using by NETEDIT)
GNENet(NBNetBuilder *netBuilder)
Constructor.
Definition: GNENet.cpp:99
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
friend class GNEChange_Junction
declare friend class
Definition: GNENet.h:91
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node) ...
Definition: NBNode.h:298
void removeSolitaryJunctions(GNEUndoList *undoList)
removes junctions that have no edges
Definition: GNENet.cpp:1103
GNEAdditional * retrieveAdditional(const std::string &idl, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1304
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:41
double getTotalWidth() const
Returns the combined width of all lanes of this edge.
Definition: NBEdge.cpp:2831
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:251
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:103
void move(Position pos)
reposition the node at pos and informs the edges
A storage for options typed value containers)
Definition: OptionsCont.h:99
std::vector< GNEAdditional * > getAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING) const
get vector with additionals
Definition: GNENet.cpp:1354
The popup menu of a globject.
an edge
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:77
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:170
void renameEdge(GNEEdge *edge, const std::string &newID)
updates the map and reserves new id
Definition: GNENet.cpp:1142
bool flowExists(std::string flowID) const
check if a flow with ID = flowID exists
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
vaporizer of vehicles
void deleteJunction(GNEJunction *junction, GNEUndoList *undoList)
removes junction and all incident edges
Definition: GNENet.cpp:306
The network - empty.
std::string getAdditionalID(SumoXMLTag type, const GNELane *lane, const double pos) const
Returns the additional close to the given position.
Definition: GNENet.cpp:1343
const Position & getPosition() const
Definition: NBNode.h:232
void removeExplicitTurnaround(std::string id)
remove edge id from the list of explicit turnarounds
Definition: GNENet.cpp:1192
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:147
Represents a single node (junction) during network building.
Definition: NBNode.h:75
void saveJoined(OptionsCont &oc)
save log of joined junctions (and nothing else)
Definition: GNENet.cpp:717
bool flowExists(const std::string &flowID) const
Check if exist a flow with these ID.
Definition: GNENet.cpp:1443
GUIGlID getGlID() const
Returns the numerical id of the object.
std::vector< GNEAdditional * > retrieveAdditionals(bool onlySelected=false)
return all additionals
Definition: GNENet.cpp:1319
void deleteAdditional(GNEAdditional *additional)
delete additional element previously inserted
Definition: GNENet.cpp:1275
GNEEdge * addReversedEdge(GNEEdge *edge, GNEUndoList *undoList)
add reversed edge
Definition: GNENet.cpp:615
bool netHasCrossings() const
check if net has crossings
Definition: GNENet.cpp:1030
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
GNEEdges myEdges
map with the name and pointer to edges of net
Definition: GNENet.h:539
last coordinate of edge shape
static const RGBColor selectionColor
color of selection
Definition: GNENet.h:97
empty max
void unblockObject(GUIGlID id)
Marks an object as unblocked.
void reserveEdgeID(const std::string &id)
reserve edge ID (To avoid duplicates)
Definition: GNENet.cpp:1552
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:427
void deleteSingleEdge(GNEEdge *edge)
deletes a single edge
Definition: GNENet.cpp:1525
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
std::map< std::string, GNEEdge * > GNEEdges
Definition: GNENet.h:531
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:261
const GNECalibratorVehicleType & getGNECalibratorVehicleType(const std::string &calibratorVehicleTypeID) const
Returns a reference to a calibrator vehicle type finding in all calibrators of net.
Definition: GNENet.cpp:1391
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:86
void mergeJunctions(GNEJunction *moved, GNEJunction *target, GNEUndoList *undoList)
merge the given junctions edges between the given junctions will be deleted
Definition: GNENet.cpp:649
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:147
Boundary getBoundary() const
Returns the street&#39;s geometry.
Definition: GNEEdge.cpp:128
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1258
const GNECalibratorFlow & getCalibratorFlow(const std::string &flowID)
get reference to calibrator flow
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:175
bool checkIsRemovable() const
check if node is removable
Definition: NBNode.cpp:1642
NBNode * getNBNode() const
Return net build node.
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
Definition: NBEdgeCont.cpp:542
std::vector< std::pair< NBEdge *, NBEdge * > > getEdgesToJoin() const
get edges to join
Definition: NBNode.cpp:1693
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Definition: GNEEdge.cpp:635
bool addSRestrictedLane(SUMOVehicleClass vclass, GNEEdge &edge, GNEUndoList *undoList)
add restricted lane to edge
Definition: GNENet.cpp:503
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
void changeEdgeEndpoints(GNEEdge *edge, const std::string &newSourceID, const std::string &newDestID)
modifies endpoins of the given edge
Definition: GNENet.cpp:1155
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition: GNENet.cpp:1171
bool wasSplit()
whether this edge was created from a split
Definition: GNEEdge.cpp:555
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:434
void saveAdditionals(const std::string &filename)
save additional elements of the network
Definition: GNENet.cpp:697
void savePlain(OptionsCont &oc)
save plain xml representation of the network (and nothing else)
Definition: GNENet.cpp:710
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:228
void requireRecompute()
inform the net about the need for recomputation
Definition: GNENet.cpp:1024
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual void setTLControllingInformation() const =0
Informs edges about being controlled by a tls.
void duplicateLane(GNELane *lane, GNEUndoList *undoList)
duplicates lane
Definition: GNENet.cpp:447
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
TrafficLightType
void markAsModified(GNEUndoList *undoList)
prevent re-guessing connections at this junction
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1165
const std::vector< GNEAdditional * > & getAdditionalChilds() const
get additional childs of lane
Definition: GNELane.cpp:768
a junction
GNEJunction * getParentJunction() const
get parent Junction
Definition: GNECrossing.cpp:94
void finishMoveSelection(GNEUndoList *undoList)
register changes to junction and edge positions with the undoList
Definition: GNENet.cpp:1228
SumoXMLTag getTag() const
get XML Tag assigned to this object