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-2016 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 <utility>
40 #include <set>
41 #include <vector>
42 #include <map>
43 
45 #include <utils/common/RGBColor.h>
56 #include <netbuild/NBEdgeCont.h>
57 #include <netbuild/NBNodeCont.h>
58 #include <netbuild/NBAlgorithms.h>
59 #include <netwrite/NWFrame.h>
60 #include <netwrite/NWWriter_XML.h>
61 #include "GNENet.h"
62 #include "GNEApplicationWindow.h"
63 #include "GNEJunction.h"
64 #include "GNEEdge.h"
65 #include "GNELane.h"
66 #include "GNEUndoList.h"
67 #include "GNEChange_Junction.h"
68 #include "GNEChange_Edge.h"
69 #include "GNEChange_Lane.h"
70 #include "GNEChange_Connection.h"
71 #include "GNEChange_Selection.h"
72 #include "GNEChange_Additional.h"
73 #include "GNEAdditional.h"
74 #include "GNEAdditionalSet.h"
75 #include "GNEStoppingPlace.h"
76 #include "GNEDetector.h"
77 
78 
79 #ifdef CHECK_MEMORY_LEAKS
80 #include <foreign/nvwa/debug_new.h>
81 #endif // CHECK_MEMORY_LEAKS
82 
83 
84 // ===========================================================================
85 // static members
86 // ===========================================================================
87 const RGBColor GNENet::selectionColor(0, 0, 204, 255);
88 const RGBColor GNENet::selectedLaneColor(0, 0, 128, 255);
90 
91 // ===========================================================================
92 // member method definitions
93 // ===========================================================================
96  myUpdateTarget(0),
97  myNetBuilder(netBuilder),
98  myJunctions(),
99  myEdges(),
100  myEdgeIDSupplier("gneE", netBuilder->getEdgeCont().getAllNames()),
101  myJunctionIDSupplier("gneJ", netBuilder->getNodeCont().getAllNames()),
102  myShapeContainer(myGrid),
103  myNeedRecompute(true) {
105 
106  // init edges
108  const std::vector<std::string>& edgeNames = ec.getAllNames();
109  for (std::vector<std::string>::const_iterator name_it = edgeNames.begin(); name_it != edgeNames.end(); ++name_it) {
110  NBEdge* nbe = ec.retrieve(*name_it);
111  registerEdge(new GNEEdge(*nbe, this, false, true));
112  if (myGrid.getWidth() > 10e16 || myGrid.getHeight() > 10e16) {
113  throw ProcessError("Network size exceeds 1 Lightyear. Please reconsider your inputs.\n");
114  }
115  }
116 
117  // init junctions
119  const std::vector<std::string>& nodeNames = nc.getAllNames();
120  for (std::vector<std::string>::const_iterator name_it = nodeNames.begin(); name_it != nodeNames.end(); ++name_it) {
121  NBNode* nbn = nc.retrieve(*name_it);
122  registerJunction(new GNEJunction(*nbn, this, true));
123  }
124  // make sure myGrid is initialized even for an empty net
125  if (myEdges.size() == 0) {
126  myGrid.add(Boundary(0, 0, 100, 100));
127  }
128 
129  // sort nodes edges so that arrows can be drawn correctly
131 
132  /*
133  // initialise detector storage for gui
134  initDetectors();
135  // initialise the tl-map
136  initTLMap();
137  // initialise edge storage for gui
138  GUIEdge::fill(myEdgeWrapper);
139  */
140  //if (myGrid.count() == 0) // myGrid methods will return garbage
141 
142  // Init AdditionalHandler
143 
144  if (myZBoundary.ymin() != Z_INITIALIZED) {
145  myZBoundary.add(0, 0);
146  }
147 
148 }
149 
150 
152  /*
153  // delete allocated wrappers
154  // of junctions
155  for (std::vector<GUIJunctionWrapper*>::iterator i1=myJunctionWrapper.begin(); i1!=myJunctionWrapper.end(); i1++) {
156  delete(*i1);
157  }
158  // of additional structures
159  GUIGlObject_AbstractAdd::clearDictionary();
160  // of tl-logics
161  for (Logics2WrapperMap::iterator i3=myLogics2Wrapper.begin(); i3!=myLogics2Wrapper.end(); i3++) {
162  delete(*i3).second;
163  }
164  // of detectors
165  for (std::map<std::string, GUIDetectorWrapper*>::iterator i=myDetectorDict.begin(); i!=myDetectorDict.end(); ++i) {
166  delete(*i).second;
167  }
168  */
169  for (GNEEdges::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
170  it->second->decRef("GNENet::~GNENet");
171  delete it->second;
172  }
173  for (GNEJunctions::iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
174  it->second->decRef("GNENet::~GNENet");
175  delete it->second;
176  }
177  delete myNetBuilder;
178 }
179 
180 
181 const Boundary&
183  // SUMORTree is also a Boundary
184  return myGrid;
185 }
186 
187 
190  GUISUMOAbstractView& parent) {
191  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
192  buildPopupHeader(ret, app);
194  buildPositionCopyEntry(ret, false);
195  return ret;
196 }
197 
198 
201  return 0;
202 }
203 
204 
205 void
207 }
208 
209 
210 Boundary
212  return getBoundary();
213 }
214 
215 
216 const Boundary&
218  return myZBoundary;
219 }
220 
221 
222 SUMORTree&
224  return myGrid;
225 }
226 
227 
228 const SUMORTree&
230  return myGrid;
231 }
232 
233 
236  std::string id = myJunctionIDSupplier.getNext();
237  NBNode* nbn = new NBNode(id, pos);
238  GNEJunction* junction = new GNEJunction(*nbn, this);
239  undoList->add(new GNEChange_Junction(this, junction, true), true);
240  assert(myJunctions[id]);
241  return junction;
242 }
243 
244 
245 GNEEdge*
247  GNEJunction* src, GNEJunction* dest, GNEEdge* tpl, GNEUndoList* undoList,
248  const std::string& suggestedName,
249  bool wasSplit,
250  bool allowDuplicateGeom) {
251  // prevent duplicate edge (same geometry)
252  const EdgeVector& outgoing = src->getNBNode()->getOutgoingEdges();
253  for (EdgeVector::const_iterator it = outgoing.begin(); it != outgoing.end(); it++) {
254  if ((*it)->getToNode() == dest->getNBNode() && (*it)->getGeometry().size() == 2) {
255  if (!allowDuplicateGeom) {
256  return 0;
257  }
258  }
259  }
260 
261  std::string id;
262  if (suggestedName != "" && !retrieveEdge(suggestedName, false)) {
263  id = suggestedName;
264  reserveEdgeID(id);
265  } else {
266  id = myEdgeIDSupplier.getNext();
267  }
268 
269  GNEEdge* edge;
270  if (tpl) {
271  NBEdge* nbeTpl = tpl->getNBEdge();
272  NBEdge* nbe = new NBEdge(id, src->getNBNode(), dest->getNBNode(), nbeTpl);
273  edge = new GNEEdge(*nbe, this, wasSplit);
274  } else {
275  // default if no template is given
276  SUMOReal defaultSpeed = 50 / 3.6;
277  std::string defaultType = "";
278  int defaultNrLanes = 1;
279  int defaultPriority = 1;
280  SUMOReal defaultWidth = NBEdge::UNSPECIFIED_WIDTH;
281  SUMOReal defaultOffset = NBEdge::UNSPECIFIED_OFFSET;
282  NBEdge* nbe = new NBEdge(id, src->getNBNode(), dest->getNBNode(),
283  defaultType, defaultSpeed,
284  defaultNrLanes, defaultPriority,
285  defaultWidth,
286  defaultOffset);
287  edge = new GNEEdge(*nbe, this, wasSplit);
288  }
289  undoList->p_begin("create edge");
290  undoList->add(new GNEChange_Edge(this, edge, true), true);
291  src->setLogicValid(false, undoList);
292  dest->setLogicValid(false, undoList);
294  undoList->p_end();
295  assert(myEdges[id]);
296  return edge;
297 }
298 
299 
300 void
302  // we have to delete all incident edges because they cannot exist without that junction
303  // all deletions must be undone/redone together so we start a new command group
304  // @todo if any of those edges are dead-ends should we remove their orphan junctions as well?
305  undoList->p_begin("delete junction");
306 
307  // deleting edges changes in the underlying EdgeVector so we have to make a copy
308  const EdgeVector incident = junction->getNBNode()->getEdges();
309  for (EdgeVector::const_iterator it = incident.begin(); it != incident.end(); it++) {
310  deleteEdge(myEdges[(*it)->getID()], undoList);
311  }
312 
313  // remove any traffic lights from the traffic light container (avoids lots of warnings)
314  junction->setAttribute(SUMO_ATTR_TYPE, toString(NODETYPE_PRIORITY), undoList);
315  undoList->add(new GNEChange_Junction(this, junction, false), true);
316  if (gSelected.isSelected(GLO_JUNCTION, junction->getGlID())) {
317  std::set<GUIGlID> deselected;
318  deselected.insert(junction->getGlID());
319  undoList->add(new GNEChange_Selection(std::set<GUIGlID>(), deselected, true), true);
320  }
321  undoList->p_end();
322 }
323 
324 
325 void
327  undoList->p_begin("delete edge");
328 
329  // Iterate over lanes to remove additionals
330  for (std::vector<GNELane*>::const_iterator i = edge->getLanes().begin(); i != edge->getLanes().end(); i++) {
331  for (std::vector<GNEAdditional*>::const_iterator j = (*i)->getAdditionals().begin(); j != (*i)->getAdditionals().end(); j++) {
332  undoList->add(new GNEChange_Additional(this, *j, false), true);
333  }
334  }
335 
336  // Remove additionals of edge
337  for (std::vector<GNEAdditional*>::const_iterator i = edge->getAdditionals().begin(); i != edge->getAdditionals().end(); i++) {
338  undoList->add(new GNEChange_Additional(this, *i, false), true);
339  }
340 
341  // Delete edge
342  undoList->add(new GNEChange_Edge(this, edge, false), true);
343 
344  // If previously was selected
345  if (gSelected.isSelected(GLO_EDGE, edge->getGlID())) {
346  std::set<GUIGlID> deselected;
347  deselected.insert(edge->getGlID());
348  undoList->add(new GNEChange_Selection(std::set<GUIGlID>(), deselected, true), true);
349  }
350 
351  edge->getSource()->removeFromCrossings(edge, undoList);
352  edge->getDest()->removeFromCrossings(edge, undoList);
353  edge->getSource()->setLogicValid(false, undoList);
354  edge->getDest()->setLogicValid(false, undoList);
356  undoList->p_end();
357 }
358 
359 
360 void
362  GNEEdge* edge = &lane->getParentEdge();
363  if (edge->getNBEdge()->getNumLanes() == 1) {
364  // remove the whole edge instead
365  deleteEdge(edge, undoList);
366  } else {
367  undoList->p_begin("delete lane");
368  const NBEdge::Lane& laneAttrs = edge->getNBEdge()->getLaneStruct(lane->getIndex());
369  const bool sidewalk = laneAttrs.permissions == SVC_PEDESTRIAN;
370  undoList->add(new GNEChange_Lane(edge, lane, laneAttrs, false), true);
371  if (gSelected.isSelected(GLO_LANE, lane->getGlID())) {
372  std::set<GUIGlID> deselected;
373  deselected.insert(lane->getGlID());
374  undoList->add(new GNEChange_Selection(std::set<GUIGlID>(), deselected, true), true);
375  }
376  if (sidewalk) {
377  edge->getSource()->removeFromCrossings(edge, undoList);
378  edge->getDest()->removeFromCrossings(edge, undoList);
379  edge->getSource()->setLogicValid(false, undoList);
380  edge->getDest()->setLogicValid(false, undoList);
381  }
383  undoList->p_end();
384  }
385 }
386 
387 
388 void
390  undoList->p_begin("duplicate lane");
391  GNEEdge* edge = &lane->getParentEdge();
392  const NBEdge::Lane& laneAttrs = edge->getNBEdge()->getLaneStruct(lane->getIndex());
393  GNELane* newLane = new GNELane(*edge, lane->getIndex());
394  undoList->add(new GNEChange_Lane(edge, newLane, laneAttrs, true), true);
396  undoList->p_end();
397 }
398 
399 
400 void
402  if (!edge->deleteGeometry(pos, undoList)) {
403  deleteEdge(edge, undoList);
404  }
405 }
406 
407 
409 GNENet::splitEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList, GNEJunction* newJunction) {
410  undoList->p_begin("split edge");
411  deleteEdge(edge, undoList); // still exists. we delete it so we can reuse the name in case of resplit
412  // compute geometry
413  const PositionVector& oldGeom = edge->getNBEdge()->getGeometry();
414  const SUMOReal linePos = oldGeom.nearest_offset_to_point2D(pos, false);
415  std::pair<PositionVector, PositionVector> newGeoms = oldGeom.splitAt(linePos);
416  // figure out the new name
417  int posBase = 0;
418  std::string baseName = edge->getMicrosimID();
419  if (edge->wasSplit()) {
420  const std::string::size_type sep_index = baseName.rfind('.');
421  if (sep_index != std::string::npos) { // edge may have been renamed in between
422  std::string posString = baseName.substr(sep_index + 1);
423  try {
424  posBase = TplConvert::_2int(posString.c_str());
425  baseName = baseName.substr(0, sep_index); // includes the .
426  } catch (NumberFormatException) {
427  }
428  }
429  }
430  baseName += '.';
431  // create edges
432  if (newJunction == 0) {
433  newJunction = createJunction(pos, undoList);
434  }
435  GNEEdge* firstPart = createEdge(edge->getSource(), newJunction, edge,
436  undoList, baseName + toString(posBase), true);
437  GNEEdge* secondPart = createEdge(newJunction, edge->getDest(), edge,
438  undoList, baseName + toString(posBase + (int)linePos), true);
439  // fix geometry
440  firstPart->setAttribute(GNE_ATTR_SHAPE_START, toString(newGeoms.first[0]), undoList);
441  firstPart->setAttribute(GNE_ATTR_SHAPE_END, toString(newGeoms.first[-1]), undoList);
442  newGeoms.first.pop_back();
443  newGeoms.first.erase(newGeoms.first.begin());
444  firstPart->setAttribute(SUMO_ATTR_SHAPE, toString(newGeoms.first), undoList);
445 
446  secondPart->setAttribute(GNE_ATTR_SHAPE_START, toString(newGeoms.second[0]), undoList);
447  secondPart->setAttribute(GNE_ATTR_SHAPE_END, toString(newGeoms.second[-1]), undoList);
448  newGeoms.second.pop_back();
449  newGeoms.second.erase(newGeoms.second.begin());
450  secondPart->setAttribute(SUMO_ATTR_SHAPE, toString(newGeoms.second), undoList);
451  // fix connections
452  std::vector<NBEdge::Connection>& connections = edge->getNBEdge()->getConnections();
453  for (std::vector<NBEdge::Connection>::iterator con_it = connections.begin(); con_it != connections.end(); con_it++) {
454  undoList->add(new GNEChange_Connection(
455  secondPart, con_it->fromLane, con_it->toEdge->getID(), con_it->toLane, false, true), true);
456  }
457  undoList->p_end();
458  return newJunction;
459 }
460 
461 
462 void
463 GNENet::splitEdgesBidi(const std::set<GNEEdge*>& edges, const Position& pos, GNEUndoList* undoList) {
464  GNEJunction* newJunction = 0;
465  undoList->p_begin("split edges");
466  for (std::set<GNEEdge*>::const_iterator it = edges.begin(); it != edges.end(); ++it) {
467  newJunction = splitEdge(*it, pos, undoList, newJunction);
468  }
469  undoList->p_end();
470 }
471 
472 
473 void
475  undoList->p_begin("reverse edge");
476  deleteEdge(edge, undoList); // still exists. we delete it so we can reuse the name in case of resplit
477  GNEEdge* reversed = createEdge(edge->getDest(), edge->getSource(), edge, undoList, edge->getID(), false, true);
478  assert(reversed != 0);
479  reversed->setAttribute(SUMO_ATTR_SHAPE, toString(edge->getNBEdge()->getInnerGeometry().reverse()), undoList);
480  undoList->p_end();
481 }
482 
483 
484 GNEEdge*
486  undoList->p_begin("add reversed edge");
487  GNEEdge* reversed = 0;
489  GNEEdge* reversed = createEdge(edge->getDest(), edge->getSource(), edge, undoList, "-" + edge->getID(), false, true);
490  assert(reversed != 0);
491  reversed->setAttribute(SUMO_ATTR_SHAPE, toString(edge->getNBEdge()->getInnerGeometry().reverse()), undoList);
492  } else {
493  // if the edge is centered it should probably connect somewhere else
494  // make it easy to move and reconnect it
495  PositionVector orig = edge->getNBEdge()->getGeometry();
496  PositionVector origInner = edge->getNBEdge()->getInnerGeometry();
497  const SUMOReal tentativeShift = edge->getNBEdge()->getTotalWidth() + 2;
498  orig.move2side(-tentativeShift);
499  origInner.move2side(-tentativeShift);
500  GNEJunction* src = createJunction(orig.back(), undoList);
501  GNEJunction* dest = createJunction(orig.front(), undoList);
502  GNEEdge* reversed = createEdge(src, dest, edge, undoList, "-" + edge->getID(), false, true);
503  assert(reversed != 0);
504  reversed->setAttribute(SUMO_ATTR_SHAPE, toString(origInner.reverse()), undoList);
505  // select the new edge and its nodes
506  std::set<GUIGlID> toSelect;
507  toSelect.insert(reversed->getGlID());
508  toSelect.insert(src->getGlID());
509  toSelect.insert(dest->getGlID());
510  undoList->add(new GNEChange_Selection(toSelect, gSelected.getSelected(), true), true);
511  }
512  undoList->p_end();
513  return reversed;
514 }
515 
516 
517 void
519  undoList->p_begin("merge junctions");
520  // position of moved and target are probably a bit different (snap radius)
521  moved->move(target->getNBNode()->getPosition());
522  // register the move with undolist (must happend within the undo group)
523  moved->registerMove(undoList);
524  // deleting edges changes in the underlying EdgeVector so we have to make a copy
525  const EdgeVector incoming = moved->getNBNode()->getIncomingEdges();
526  for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); it++) {
527  GNEEdge* oldEdge = myEdges[(*it)->getID()];
528  remapEdge(oldEdge, oldEdge->getSource(), target, undoList);
529  }
530  // deleting edges changes in the underlying EdgeVector so we have to make a copy
531  const EdgeVector outgoing = moved->getNBNode()->getOutgoingEdges();
532  for (EdgeVector::const_iterator it = outgoing.begin(); it != outgoing.end(); it++) {
533  GNEEdge* oldEdge = myEdges[(*it)->getID()];
534  remapEdge(oldEdge, target, oldEdge->getDest(), undoList);
535  }
536  deleteJunction(moved, undoList);
537  undoList->p_end();
538 }
539 
540 
541 void
542 GNENet::remapEdge(GNEEdge* oldEdge, GNEJunction* from, GNEJunction* to, GNEUndoList* undoList, bool keepEndpoints) {
543  deleteEdge(oldEdge, undoList); // delete first so we can reuse the name, reference stays valid
544  if (from != to) {
545  GNEEdge* newEdge = createEdge(from, to, oldEdge, undoList, oldEdge->getMicrosimID(), false, true);
546  newEdge->setAttribute(SUMO_ATTR_SHAPE, oldEdge->getAttribute(SUMO_ATTR_SHAPE), undoList);
547  if (keepEndpoints) {
549  newEdge->setAttribute(GNE_ATTR_SHAPE_END, oldEdge->getAttribute(GNE_ATTR_SHAPE_END), undoList);
550  }
551  }
552  // @todo remap connectivity as well
553 }
554 
555 
556 void
558  computeAndUpdate(oc);
560 }
561 
562 
563 void
564 GNENet::saveAdditionals(const std::string& filename) {
565  // Extract path of filename
566  std::string path = filename;
567  while (!path.empty() && path[path.size() - 1] != '\\') {
568  path = path.substr(0, path.size() - 1);
569  }
570  OutputDevice& device = OutputDevice::getDevice(filename);
571  device.openTag("additionals");
572  for (GNEAdditionals::const_iterator i = myAdditionals.begin(); i != myAdditionals.end(); ++i) {
573  // Only write additional if don't belong to another additionalSet
574  if (i->second->getAdditionalSetParent() == NULL) {
575  i->second->writeAdditional(device, path);
576  }
577  }
578  device.close();
579 }
580 
581 
582 void
584  computeAndUpdate(oc);
586 }
587 
588 
589 void
591  computeAndUpdate(oc);
593 }
594 
595 
596 void
597 GNENet::setUpdateTarget(FXWindow* updateTarget) {
598  myUpdateTarget = updateTarget;
599 }
600 
601 
603 GNENet::retrieveJunction(const std::string& id, bool failHard) {
604  if (myJunctions.count(id)) {
605  return myJunctions[id];
606  } else if (failHard) {
607  // If junction wasn't found, throw exception
608  throw UnknownElement("Junction " + id);
609  } else {
610  return NULL;
611  }
612 }
613 
614 
615 GNEEdge*
616 GNENet::retrieveEdge(const std::string& id, bool failHard) {
617  GNEEdges::const_iterator i = myEdges.find(id);
618  // If edge was fund
619  if (i != myEdges.end()) {
620  return i->second;
621  } else if (failHard) {
622  // If edge wasn't found, throw exception
623  throw UnknownElement("Edge " + id);
624  } else {
625  return NULL;
626  }
627 }
628 
629 
630 std::vector<GNEEdge*>
631 GNENet::retrieveEdges(bool onlySelected) {
632  std::vector<GNEEdge*> result;
633  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
634  if (!onlySelected || gSelected.isSelected(GLO_EDGE, it->second->getGlID())) {
635  result.push_back(it->second);
636  }
637  }
638  return result;
639 }
640 
641 
642 std::vector<GNELane*>
643 GNENet::retrieveLanes(bool onlySelected) {
644  std::vector<GNELane*> result;
645  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
646  const GNEEdge::LaneVector& lanes = it->second->getLanes();
647  for (GNEEdge::LaneVector::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) {
648  if (!onlySelected || gSelected.isSelected(GLO_LANE, (*it_lane)->getGlID())) {
649  result.push_back(*it_lane);
650  }
651  }
652  }
653  return result;
654 }
655 
656 
657 GNELane*
658 GNENet::retrieveLane(const std::string& id, bool failHard) {
659  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
660  const GNEEdge::LaneVector& lanes = it->second->getLanes();
661  for (GNEEdge::LaneVector::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) {
662  if ((*it_lane)->getID() == id) {
663  return (*it_lane);
664  }
665  }
666  }
667  // If lane wasn't found:
668  if (failHard) {
669  // Throw exception if failHard is enabled
670  throw UnknownElement("lane " + id);
671  } else {
672  return NULL;
673  }
674 }
675 
676 
677 std::vector<GNEJunction*>
678 GNENet::retrieveJunctions(bool onlySelected) {
679  std::vector<GNEJunction*> result;
680  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
681  if (!onlySelected || gSelected.isSelected(GLO_JUNCTION, it->second->getGlID())) {
682  result.push_back(it->second);
683  }
684  }
685  return result;
686 }
687 
688 
689 void
693  update();
694 }
695 
696 
697 std::vector<GNEAttributeCarrier*>
698 GNENet::retrieveAttributeCarriers(const std::set<GUIGlID>& ids, GUIGlObjectType type) {
699  std::vector<GNEAttributeCarrier*> result;
700  for (std::set<GUIGlID>::iterator it = ids.begin(); it != ids.end(); it++) {
702  if (object != 0) {
703  std::string id = object->getMicrosimID();
705  GNEAttributeCarrier* ac = 0;
706  switch (type) {
707  case GLO_JUNCTION:
708  ac = dynamic_cast<GNEJunction*>(object);
709  break;
710  case GLO_EDGE:
711  ac = dynamic_cast<GNEEdge*>(object);
712  break;
713  case GLO_LANE:
714  ac = dynamic_cast<GNELane*>(object);
715  break;
716  case GLO_ADDITIONAL:
717  if (dynamic_cast<GNEAdditional*>(object)) {
718  ac = dynamic_cast<GNEAdditional*>(object);
719  } else if (dynamic_cast<GNEAdditionalSet*>(object)) {
720  ac = dynamic_cast<GNEAdditionalSet*>(object);
721  }
722  break;
723  default:
724  break;
725  }
726  if (ac == 0) {
727  throw ProcessError("GUIGlObject does not match the declared type");
728  } else {
729  result.push_back(ac);
730  }
731  } else {
732  throw ProcessError("Attempted to retrieve non-existant GUIGlObject");
733  }
734  }
735  return result;
736 }
737 
738 
739 std::set<GUIGlID>
741  std::set<GUIGlID> result;
742  switch (type) {
743  case GLO_MAX: {
744  std::set<GUIGlObjectType> knownTypes;
745  knownTypes.insert(GLO_JUNCTION);
746  knownTypes.insert(GLO_EDGE);
747  knownTypes.insert(GLO_LANE);
748  // knownTypes.insert(GLO_TLLOGIC); makes no sense to include them
749  knownTypes.insert(GLO_ADDITIONAL);
750  for (std::set<GUIGlObjectType>::const_iterator it = knownTypes.begin(); it != knownTypes.end(); it++) {
751  const std::set<GUIGlID> tmp = getGlIDs(*it);
752  result.insert(tmp.begin(), tmp.end());
753  }
754  break;
755  }
756  case GLO_JUNCTION:
757  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
758  result.insert(it->second->getGlID());
759  }
760  break;
761  case GLO_EDGE:
762  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
763  result.insert(it->second->getGlID());
764  }
765  break;
766  case GLO_LANE: {
767  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
768  const std::set<GUIGlID> laneIDs = it->second->getLaneGlIDs();
769  for (std::set<GUIGlID>::const_iterator lid_it = laneIDs.begin(); lid_it != laneIDs.end(); lid_it++) {
770  result.insert(*lid_it);
771  }
772  }
773  break;
774  }
775  case GLO_TLLOGIC: {
776  // return all junctions which have a traffic light (we do not
777  // have a GUIGlObject for each traffic light)
778  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
779  if (it->second->getNBNode()->isTLControlled()) {
780  result.insert(it->second->getGlID());
781  }
782  }
783  break;
784  }
785  case GLO_ADDITIONAL: {
786  for (GNEAdditionals::iterator it = myAdditionals.begin(); it != myAdditionals.end(); it++) {
787  result.insert(it->second->getGlID());
788  }
789  break;
790  }
791  default: // add other types once we know them
792  break;
793  }
794  return result;
795 }
796 
797 
798 void
800  if (!myNeedRecompute) {
801  if (force) {
802  window->setStatusBarText("Forced computing junctions ...");
803  } else {
804  return;
805  }
806  } else {
807  window->setStatusBarText("Computing junctions ...");
808  }
809  // compute
811  computeAndUpdate(oc);
812  WRITE_MESSAGE("\nFinished computing junctions.");
813 
814  window->getApp()->endWaitCursor();
815  window->setStatusBarText("Finished computing junctions.");
816  update();
817 }
818 
819 
820 void
822  // recompute tl-logics
825 
826  NBNode* nbn = junction->getNBNode();
827  std::set<NBTrafficLightDefinition*> tldefs = nbn->getControllingTLS();
828  for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
829  NBTrafficLightDefinition* def = *it;
832  tllCont.computeSingleLogic(oc, def);
833  }
834 
835  // @todo compute connections etc...
836 }
837 
838 
839 void
841  myNeedRecompute = true;
842 }
843 
844 
845 FXApp*
847  return myUpdateTarget->getApp();
848 }
849 
850 
851 void
853  std::vector<GNEJunction*> selected = retrieveJunctions(true);
854  if (selected.size() < 2) {
855  return;
856  }
857  undoList->p_begin("Join selected junctions");
858 
859  EdgeVector allIncoming;
860  EdgeVector allOutgoing;
861  std::set<NBNode*> cluster;
862  for (std::vector<GNEJunction*>::iterator it = selected.begin(); it != selected.end(); it++) {
863  cluster.insert((*it)->getNBNode());
864  const EdgeVector& incoming = (*it)->getNBNode()->getIncomingEdges();
865  allIncoming.insert(allIncoming.end(), incoming.begin(), incoming.end());
866  const EdgeVector& outgoing = (*it)->getNBNode()->getOutgoingEdges();
867  allOutgoing.insert(allOutgoing.end(), outgoing.begin(), outgoing.end());
868  }
869  // create new junction
870  Position pos;
871  bool setTL;
872  std::string id;
873  TrafficLightType type;
874  myNetBuilder->getNodeCont().analyzeCluster(cluster, id, pos, setTL, type);
875  // XXX this is not undone when calling 'undo'
877  GNEJunction* joined = createJunction(pos, undoList);
878  if (setTL) {
880  // XXX ticket831
881  //joined-><getTrafficLight>->setAttribute(SUMO_ATTR_TYPE, toString(type), undoList);
882  }
883  // remap edges
884  for (EdgeVector::const_iterator it = allIncoming.begin(); it != allIncoming.end(); it++) {
885  GNEEdge* oldEdge = myEdges[(*it)->getID()];
886  remapEdge(oldEdge, oldEdge->getSource(), joined, undoList, true);
887  }
888  for (EdgeVector::const_iterator it = allOutgoing.begin(); it != allOutgoing.end(); it++) {
889  GNEEdge* oldEdge = myEdges[(*it)->getID()];
890  remapEdge(oldEdge, joined, oldEdge->getDest(), undoList, true);
891  }
892  // delete original junctions
893  for (std::vector<GNEJunction*>::iterator it = selected.begin(); it != selected.end(); it++) {
894  deleteJunction(*it, undoList);
895  }
896  joined->setAttribute(SUMO_ATTR_ID, id, undoList);
897  undoList->p_end();
898 }
899 
900 
901 void
903  undoList->p_begin("Clean junctions");
904  std::vector<GNEJunction*> toRemove;
905  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
906  GNEJunction* junction = it->second;
907  if (junction->getNBNode()->getEdges().size() == 0) {
908  toRemove.push_back(junction);
909  }
910  }
911  for (std::vector<GNEJunction*>::iterator it = toRemove.begin(); it != toRemove.end(); ++it) {
912  deleteJunction(*it, undoList);
913  }
914  undoList->p_end();
915 }
916 
917 
918 void
920  undoList->p_begin("Replace junction by geometry");
921  assert(junction->getNBNode()->checkIsRemovable());
922  std::vector<std::pair<NBEdge*, NBEdge*> > toJoin = junction->getNBNode()->getEdgesToJoin();
923  for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
924  GNEEdge* begin = myEdges[(*j).first->getID()];
925  GNEEdge* continuation = myEdges[(*j).second->getID()];
926  deleteEdge(begin, undoList);
927  deleteEdge(continuation, undoList);
928  GNEEdge* newEdge = createEdge(begin->getSource(), continuation->getDest(), begin, undoList, begin->getMicrosimID(), false, true);
929  PositionVector newShape = begin->getNBEdge()->getInnerGeometry();
930  newShape.push_back(junction->getNBNode()->getPosition());
931  newShape.append(continuation->getNBEdge()->getInnerGeometry());
932  newEdge->setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
933  // @todo what about trafficlights at the end of oontinuation?
934  }
935  deleteJunction(junction, undoList);
936  undoList->p_end();
937 }
938 
939 void
940 GNENet::renameEdge(GNEEdge* edge, const std::string& newID) {
941  myEdges.erase(edge->getNBEdge()->getID());
942  myNetBuilder->getEdgeCont().rename(edge->getNBEdge(), newID);
943  edge->setMicrosimID(newID);
944  myEdges[newID] = edge;
945 }
946 
947 
948 void
949 GNENet::changeEdgeEndpoints(GNEEdge* edge, const std::string& newSource, const std::string& newDest) {
950  NBNode* from = retrieveJunction(newSource)->getNBNode();
951  NBNode* to = retrieveJunction(newDest)->getNBNode();
952  edge->getNBEdge()->reinitNodes(from, to);
954  update();
955 }
956 
957 
960  return myNetBuilder->getTLLogicCont();
961 };
962 
963 
964 void
965 GNENet::renameJunction(GNEJunction* junction, const std::string& newID) {
966  myJunctions.erase(junction->getNBNode()->getID());
967  myNetBuilder->getNodeCont().rename(junction->getNBNode(), newID);
968  junction->setMicrosimID(newID);
969  myJunctions[newID] = junction;
970 }
971 
972 
973 void
975  myExplicitTurnarounds.insert(id);
976 }
977 
978 
979 void
981  myExplicitTurnarounds.erase(id);
982 }
983 
984 
985 void
986 GNENet::moveSelection(const Position& moveSrc, const Position& moveDest) {
987  Position delta = moveDest - moveSrc;
988  // move junctions
989  std::set<GNEJunction*> junctionSet;
990  std::vector<GNEJunction*> junctions = retrieveJunctions(true);
991  for (std::vector<GNEJunction*>::iterator it = junctions.begin(); it != junctions.end(); it++) {
992  Position newPos = (*it)->getNBNode()->getPosition() + delta;
993  (*it)->move(newPos);
994  junctionSet.insert(*it);
995  }
996 
997  // move edge geometry (endpoints are already moved)
998  std::vector<GNEEdge*> edges = retrieveEdges(true);
999  for (std::vector<GNEEdge*>::iterator it = edges.begin(); it != edges.end(); it++) {
1000  GNEEdge* edge = *it;
1001  if (edge) {
1002  if (junctionSet.count(edge->getSource()) > 0 &&
1003  junctionSet.count(edge->getDest()) > 0) {
1004  // edge and its endpoints are selected, move all the inner points as well
1005  edge->moveGeometry(delta);
1006  } else {
1007  // move only geometry near mouse
1008  edge->moveGeometry(moveSrc, delta, true);
1009  }
1010  }
1011  }
1012 }
1013 
1014 
1015 void
1017  undoList->p_begin("move selection");
1018  // register moved junctions
1019  std::set<GNEJunction*> junctionSet;
1020  std::vector<GNEJunction*> junctions = retrieveJunctions(true);
1021  for (std::vector<GNEJunction*>::iterator it = junctions.begin(); it != junctions.end(); it++) {
1022  (*it)->registerMove(undoList);
1023  junctionSet.insert(*it);
1024  }
1025 
1026  // register moved edge geometry (endpoints are already moved)
1027  std::vector<GNEEdge*> edges = retrieveEdges(true);
1028  for (std::vector<GNEEdge*>::iterator it = edges.begin(); it != edges.end(); it++) {
1029  GNEEdge* edge = *it;
1030  if (edge) {
1031  const std::string& newShape = edge->getAttribute(SUMO_ATTR_SHAPE);
1032  edge->setAttribute(SUMO_ATTR_SHAPE, newShape, undoList);
1033  }
1034  }
1035  undoList->p_end();
1036 }
1037 
1038 
1041  return myShapeContainer;
1042 }
1043 
1044 
1045 void
1046 GNENet::insertAdditional(GNEAdditional* additional, bool hardFail) {
1047  // Check if additional element exists before insertion
1048  if (myAdditionals.find(std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag())) != myAdditionals.end()) {
1049  // Throw exception only if hardFail is enabled
1050  if (hardFail) {
1051  throw ProcessError("additional element with ID='" + additional->getID() + "' already exist");
1052  }
1053  } else {
1054  myAdditionals[std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag())] = additional;
1055  myGrid.addAdditionalGLObject(additional);
1056  if (additional->getAdditionalSetParent() != NULL) {
1057  additional->getAdditionalSetParent()->addAdditionalChild(additional);
1058  }
1059  update();
1060  }
1061 }
1062 
1063 
1064 void
1066  GNEAdditionals::iterator positionToRemove = myAdditionals.find(std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag()));
1067  // Check if additional element exists before deletion
1068  if (positionToRemove == myAdditionals.end()) {
1069  throw ProcessError("additional element with ID='" + additional->getID() + "' don't exist");
1070  } else {
1071  myAdditionals.erase(positionToRemove);
1072  myGrid.removeAdditionalGLObject(additional);
1073  if (additional->getAdditionalSetParent() != NULL) {
1074  additional->getAdditionalSetParent()->removeAdditionalChild(additional);
1075  }
1076  update();
1077  }
1078 }
1079 
1080 
1081 void
1082 GNENet::updateAdditionalID(const std::string& oldID, GNEAdditional* additional) {
1083  GNEAdditionals::iterator additionalToUpdate = myAdditionals.find(std::pair<std::string, SumoXMLTag>(oldID, additional->getTag()));
1084  if (additionalToUpdate != myAdditionals.end()) {
1085  // remove an insert additional again into container
1086  myAdditionals.erase(additionalToUpdate);
1087  myAdditionals[std::pair<std::string, SumoXMLTag>(additional->getID(), additional->getTag())] = additional;
1088  }
1089 }
1090 
1091 
1093 GNENet::getAdditional(SumoXMLTag type, const std::string& id) const {
1094  if (myAdditionals.empty()) {
1095  return NULL;
1096  } else if (myAdditionals.find(std::pair<std::string, SumoXMLTag>(id, type)) != myAdditionals.end()) {
1097  return myAdditionals.at(std::pair<std::string, SumoXMLTag>(id, type));
1098  } else {
1099  return NULL;
1100  }
1101 }
1102 
1103 
1104 std::string
1105 GNENet::getAdditionalID(SumoXMLTag type, const GNELane* lane, const SUMOReal pos) const {
1106  for (GNEAdditionals::const_iterator it = myAdditionals.begin(); it != myAdditionals.end(); ++it) {
1107  if ((it->second->getTag() == type) && (it->second->getLane() != NULL) && (it->second->getLane() == lane) && (fabs(it->second->getPositionInView().x() - pos) < POSITION_EPS)) {
1108  return it->second->getID();
1109  }
1110  }
1111  return "";
1112 }
1113 
1114 
1115 std::vector<GNEAdditional*>
1117  std::vector<GNEAdditional*> vectorOfAdditionals;
1118  for (GNEAdditionals::iterator i = myAdditionals.begin(); i != myAdditionals.end(); i++) {
1119  if (type == SUMO_TAG_NOTHING || type == i->second->getTag()) {
1120  vectorOfAdditionals.push_back(i->second);
1121  }
1122  }
1123  return vectorOfAdditionals;
1124 }
1125 
1126 
1127 int
1129  int counter = 0;
1130  for (GNEAdditionals::iterator i = myAdditionals.begin(); i != myAdditionals.end(); i++) {
1131  if (type == SUMO_TAG_NOTHING || type == i->second->getTag()) {
1132  counter++;
1133  }
1134  }
1135  return counter;
1136 }
1137 
1138 // ===========================================================================
1139 // private
1140 // ===========================================================================
1141 
1142 void
1144  myNetBuilder->getNodeCont().insert(junction->getNBNode());
1145  registerJunction(junction);
1146 }
1147 
1148 
1149 void
1151  NBEdge* nbe = edge->getNBEdge();
1152  myNetBuilder->getEdgeCont().insert(nbe); // should we ignore pruning double edges?
1153  // if this edge was previouls extracted from the edgeContainer we have to
1154  // rewire the nodes
1155  nbe->getFromNode()->addOutgoingEdge(nbe);
1156  nbe->getToNode()->addIncomingEdge(nbe);
1157  registerEdge(edge);
1158 }
1159 
1160 
1161 GNEJunction*
1163  junction->incRef("GNENet::registerJunction");
1164  junction->setResponsible(false);
1165  myJunctions[junction->getMicrosimID()] = junction;
1166  myGrid.add(junction->getBoundary());
1167  myGrid.addAdditionalGLObject(junction);
1168  // @todo let Boundary class track z-coordinate natively
1169  const SUMOReal z = junction->getNBNode()->getPosition().z();
1170  if (z != 0) {
1172  }
1173  update();
1174  return junction;
1175 }
1176 
1177 
1178 GNEEdge*
1180  edge->incRef("GNENet::registerEdge");
1181  edge->setResponsible(false);
1182  myEdges[edge->getMicrosimID()] = edge;
1183  myGrid.add(edge->getBoundary());
1185  update();
1186  return edge;
1187 }
1188 
1189 
1190 void
1192  myGrid.removeAdditionalGLObject(junction);
1193  myJunctions.erase(junction->getMicrosimID());
1194  myNetBuilder->getNodeCont().extract(junction->getNBNode());
1195  junction->decRef("GNENet::deleteSingleJunction");
1196  junction->setResponsible(true);
1197  update();
1198 }
1199 
1200 
1201 void
1204  myEdges.erase(edge->getMicrosimID());
1206  myNetBuilder->getDistrictCont(), edge->getNBEdge());
1207  edge->decRef("GNENet::deleteSingleEdge");
1208  edge->setResponsible(true);
1209  // invalidate junction logic
1210  update();
1211 }
1212 
1213 
1214 void
1216  if (myUpdateTarget) {
1217  myUpdateTarget->update();
1218  }
1219 }
1220 
1221 
1222 void
1223 GNENet::reserveEdgeID(const std::string& id) {
1224  myEdgeIDSupplier.avoid(id);
1225 }
1226 
1227 
1228 void
1229 GNENet::reserveJunctionID(const std::string& id) {
1231 }
1232 
1233 
1234 void
1236  // make sure we only add turn arounds to edges which currently exist within the network
1237  std::set<std::string> liveExplicitTurnarounds;
1238  for (std::set<std::string>::const_iterator it = myExplicitTurnarounds.begin(); it != myExplicitTurnarounds.end(); it++) {
1239  if (myEdges.count(*it) > 0) {
1240  liveExplicitTurnarounds.insert(*it);
1241  }
1242  }
1243  myNetBuilder->compute(oc, liveExplicitTurnarounds, false);
1244  // update precomputed lane geometries
1245  for (GNEEdges::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1246  it->second->updateLaneGeometries();
1247  }
1248  for (GNEJunctions::const_iterator it = myJunctions.begin(); it != myJunctions.end(); it++) {
1249  it->second->setLogicValid(true);
1250  // updated shape
1251  it->second->updateGeometry();
1252  refreshElement(it->second);
1253  }
1254  myNeedRecompute = false;
1255 }
1256 /****************************************************************************/
GNEJunction * splitEdge(GNEEdge *edge, const Position &pos, GNEUndoList *undoList, GNEJunction *newJunction=0)
split edge at position by inserting a new junction
Definition: GNENet.cpp:409
void computeAndUpdate(OptionsCont &oc)
recompute the network and update lane geometries
Definition: GNENet.cpp:1235
std::vector< GNEJunction * > retrieveJunctions(bool onlySelected=false)
return all junctions
Definition: GNENet.cpp:678
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNENet.cpp:189
void setResponsible(bool newVal)
set responsibility for deleting internal strctures
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
ShapeContainer & getShapeContainer()
get shape container
Definition: GNENet.cpp:1040
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges.
Definition: NBNode.h:240
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
Definition: GNENet.cpp:643
void close()
Closes the device and removes it from the dictionary.
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEAdditionalSet * getAdditionalSetParent() const
get additionalSet parent, or NULL if don&#39;t belongs to an additionalSet
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
SUMOReal getHeight() const
Returns the height of the boundary.
Definition: Boundary.cpp:142
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:616
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:203
IDSupplier myEdgeIDSupplier
Definition: GNENet.h:451
is a pedestrian
SUMOReal getWidth() const
Returns the width of the boudary.
Definition: Boundary.cpp:136
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
Definition: NBEdgeCont.cpp:520
SUMORTree myGrid
the rtree which contains all GUIGlObjects (so named for historical reasons)
Definition: GNENet.h:425
void joinSelectedJunctions(GNEUndoList *undoList)
Definition: GNENet.cpp:852
GUIGlObjectType
FXApp * getApp()
get pointer to the main App
Definition: GNENet.cpp:846
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:690
GNEAdditionals myAdditionals
map with the name and pointer to additional elements of net
Definition: GNENet.h:447
The main window of the Netedit.
static const RGBColor selectedLaneColor
color of selected lane
Definition: GNENet.h:98
void setMicrosimID(const std::string &newID)
override to also set lane ids
Definition: GNEEdge.cpp:812
A container for traffic light definitions and built programs.
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool removeElements=true)
Performs the network building steps.
void setLogicValid(bool valid, GNEUndoList *undoList=0, const std::string &status=GUESSED)
SUMOReal ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:124
Stores the information about how to visualize structures.
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
Definition: GNENet.cpp:740
void addIncomingEdge(NBEdge *edge)
adds an incoming edge
Definition: NBNode.cpp:424
The representation of a single edge during network building.
Definition: NBEdge.h:70
void reinitNodes(NBNode *from, NBNode *to)
Resets nodes but keeps all other values the same (used when joining)
Definition: NBEdge.cpp:327
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:245
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNENet.cpp:211
static void writeJoinedJunctions(const OptionsCont &oc, NBNodeCont &nc)
Writes the joined-juncionts to file.
void computeEverything(GNEApplicationWindow *window, bool force=false)
Definition: GNENet.cpp:799
std::vector< GNELane * > LaneVector
Definition of the lane&#39;s positions vector.
Definition: GNEEdge.h:62
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:141
NBNode * getNBNode() const
Return net build node.
void avoid(const std::string &id)
make sure that the given id is never supplied
Definition: IDSupplier.cpp:71
void reverseEdge(GNEEdge *edge, GNEUndoList *undoList)
reverse edge
Definition: GNENet.cpp:474
The base class for traffic light logic definitions.
void update()
notify myUpdateTarget
Definition: GNENet.cpp:1215
void insertJunction(GNEJunction *junction)
inserts a single junction into the net and into the underlying netbuild-container ...
Definition: GNENet.cpp:1143
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
SUMOReal getTotalWidth() const
Returns the combined width of all lanes of this edge.
Definition: NBEdge.cpp:2500
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEEdge.cpp:436
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:463
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:246
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:86
void addExplicitTurnaround(std::string id)
add edge id to the list of explicit turnarounds
Definition: GNENet.cpp:974
void rename(NBEdge *edge, const std::string &newID)
Renames the edge. Throws exception if newID already exists.
Definition: NBEdgeCont.cpp:400
GUIShapeContainer myShapeContainer
the container for additional pois and polygons
Definition: GNENet.h:456
Storage for geometrical objects.
void insertEdge(GNEEdge *edge)
inserts a single edge into the net and into the underlying netbuild-container
Definition: GNENet.cpp:1150
bool checkIsRemovable() const
Definition: NBNode.cpp:1625
const std::vector< GNEAdditional * > & getAdditionals() const
return list of additionals associated with this edge
Definition: GNEEdge.cpp:849
Lane & getLaneStruct(int lane)
Definition: NBEdge.h:1090
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:205
An Element wich group additionalSet elements.
void deleteEdge(GNEEdge *edge, GNEUndoList *undoList)
removes edge
Definition: GNENet.cpp:326
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
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:434
std::string getAdditionalID(SumoXMLTag type, const GNELane *lane, const SUMOReal pos) const
Returns the additional close to the given position.
Definition: GNENet.cpp:1105
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:500
void remapEdge(GNEEdge *oldEdge, GNEJunction *from, GNEJunction *to, GNEUndoList *undoList, bool keepEndpoints=false)
Definition: GNENet.cpp:542
GUIGlID getGlID() const
Returns the numerical id of the object.
GNEJunction * registerJunction(GNEJunction *junction)
registers a junction with GNENet containers
Definition: GNENet.cpp:1162
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool myNeedRecompute
whether the net needs recomputation
Definition: GNENet.h:462
NBNetBuilder * myNetBuilder
The internal netbuilder.
Definition: GNENet.h:431
void setNetObject(GUIGlObject *object)
Sets the given object as the "network" object.
const Boundary & getBoundary() const
returns the bounder of the network
Definition: GNENet.cpp:182
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
PositionVector reverse() const
reverse position vector
void renameJunction(GNEJunction *junction, const std::string &newID)
updates the map and reserves new id
Definition: GNENet.cpp:965
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges.
Definition: NBNode.h:248
IDSupplier myJunctionIDSupplier
Definition: GNENet.h:452
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:122
const std::string & getID() const
Returns the id.
Definition: Named.h:66
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:132
const PositionVector getInnerGeometry() const
Returns the geometry of the edge without the endpoints.
Definition: NBEdge.cpp:430
friend class GNEChange_Connection
Definition: GNENet.h:91
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:228
const std::set< GUIGlID > & getSelected() const
Returns the list of ids of all selected objects.
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1082
std::string getNext()
Returns the next id.
Definition: IDSupplier.cpp:63
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node.
Definition: NBNode.h:318
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:162
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:870
FXWindow * myUpdateTarget
The window to be notofied of about changes.
Definition: GNENet.h:428
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNENet.cpp:200
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:388
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:93
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:603
GNEJunctions myJunctions
map with the name and pointer to junctions of net
Definition: GNENet.h:441
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:153
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:658
Boundary myZBoundary
the z boundary (stored in the x-coordinate), values of 0 are ignored
Definition: GNENet.h:506
void deleteLane(GNELane *lane, GNEUndoList *undoList)
removes lane
Definition: GNENet.cpp:361
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:401
bool addAdditionalChild(GNEAdditional *additional)
add additional element to this set
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
Boundary getBoundary() const
Returns the street&#39;s geometry.
Definition: GNEEdge.cpp:108
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
void removeFromCrossings(GNEEdge *edge, GNEUndoList *undoList)
removes the given edge from all pedestrian crossings
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:347
std::vector< GNEAdditional * > getAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING)
get vector with additionals
Definition: GNENet.cpp:1116
void computeJunction(GNEJunction *junction)
Definition: GNENet.cpp:821
const EdgeVector & getEdges() const
Returns all edges which participate in this node.
Definition: NBNode.h:256
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
#define POSITION_EPS
Definition: config.h:187
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
int getNumberOfAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING)
Returns the number of additionals of the net.
Definition: GNENet.cpp:1128
void save(OptionsCont &oc)
save the network
Definition: GNENet.cpp:557
std::vector< GNEAttributeCarrier * > retrieveAttributeCarriers(const std::set< GUIGlID > &ids, GUIGlObjectType type)
get the attribute carriers based on GlIDs
Definition: GNENet.cpp:698
bool removeAdditionalChild(GNEAdditional *additional)
remove additional element to this set
std::vector< std::string > getAllNames() const
get all node names
friend class GNEChange_Edge
Definition: GNENet.h:90
const std::string getID() const
function to support debugging
void moveSelection(const Position &moveSrc, const Position &moveDest)
move all selected junctions and edges
Definition: GNENet.cpp:986
GNEJunction * createJunction(const Position &pos, GNEUndoList *undoList)
creates a new junction
Definition: GNENet.cpp:235
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void incRef(const std::string &debugMsg="")
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GNENet.cpp:223
std::set< std::string > myExplicitTurnarounds
list of edge ids for which turn-arounds must be added explicitly
Definition: GNENet.h:459
void decRef(const std::string &debugMsg="")
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
std::vector< std::pair< NBEdge *, NBEdge * > > getEdgesToJoin() const
Definition: NBNode.cpp:1676
std::pair< PositionVector, PositionVector > splitAt(SUMOReal where) const
Returns the two lists made when this list vector is splitted at the given point.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:137
void replaceJunctionByGeometry(GNEJunction *junction, GNEUndoList *undoList)
Definition: GNENet.cpp:919
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
void reserveJunctionID(const std::string &id)
reserve junction ID (To avoid duplicates)
Definition: GNENet.cpp:1229
compound additional
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1093
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNENet.cpp:206
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
void setResponsible(bool newVal)
set responsibility for deleting internal strctures
Definition: GNEEdge.cpp:632
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
void deleteSingleJunction(GNEJunction *junction)
deletes a single junction
Definition: GNENet.cpp:1191
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:371
~GNENet()
Destructor.
Definition: GNENet.cpp:151
const Boundary & getZBoundary() const
Returns the Z boundary (stored in the x() coordinate) values of 0 do not affect the boundary...
Definition: GNENet.cpp:217
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:424
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:247
bool deleteGeometry(const Position &pos, GNEUndoList *undoList)
deletes the closest geometry node within SNAP_RADIUS.
Definition: GNEEdge.cpp:311
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
Definition: GNENet.cpp:631
GNEEdge * registerEdge(GNEEdge *edge)
registers an edge with GNENet containers
Definition: GNENet.cpp:1179
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:161
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:94
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
Boundary getBoundary() const
Returns the boundary of the junction.
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
friend class GNEChange_Junction
declare friend class
Definition: GNENet.h:89
void removeSolitaryJunctions(GNEUndoList *undoList)
Definition: GNENet.cpp:902
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
void analyzeCluster(std::set< NBNode * > cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:776
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:546
void move(Position pos)
reposition the node at pos and informs the edges
A storage for options typed value containers)
Definition: OptionsCont.h:99
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:81
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:177
GNEJunction * getDest() const
returns the destination-junction
Definition: GNEEdge.cpp:145
void renameEdge(GNEEdge *edge, const std::string &newID)
updates the map and reserves new id
Definition: GNENet.cpp:940
void deleteJunction(GNEJunction *junction, GNEUndoList *undoList)
removes junction and all incident edges
Definition: GNENet.cpp:301
The network - empty.
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge&#39;s lanes&#39; lateral offset is computed.
Definition: NBEdge.h:626
void removeExplicitTurnaround(std::string id)
remove edge id from the list of explicit turnarounds
Definition: GNENet.cpp:980
Represents a single node (junction) during network building.
Definition: NBNode.h:74
void saveJoined(OptionsCont &oc)
save log of joined junctions (and nothing else)
Definition: GNENet.cpp:590
void deleteAdditional(GNEAdditional *additional)
delete additional element previously inserted
Definition: GNENet.cpp:1065
SumoXMLTag getTag() const
get Tag assigned to this object
GNEEdge * addReversedEdge(GNEEdge *edge, GNEUndoList *undoList)
add reversed edge
Definition: GNENet.cpp:485
void move2side(SUMOReal amount)
move position vector to side using certain ammount
void setUpdateTarget(FXWindow *updateTarget)
Set the target to be notified of network changes.
Definition: GNENet.cpp:597
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
GNEEdges myEdges
map with the name and pointer to edges of net
Definition: GNENet.h:444
static const RGBColor selectionColor
color of selection
Definition: GNENet.h:95
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:1223
void deleteSingleEdge(GNEEdge *edge)
deletes a single edge
Definition: GNENet.cpp:1202
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:110
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:225
void mergeJunctions(GNEJunction *moved, GNEJunction *target, GNEUndoList *undoList)
merge the given junctions edges between the given junctions will be deleted
Definition: GNENet.cpp:518
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:151
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1046
NBDistrictCont & getDistrictCont()
Returns the districts container.
Definition: NBNetBuilder.h:185
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Definition: GNEEdge.cpp:502
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:949
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition: GNENet.cpp:959
bool wasSplit()
whether this edge was created from a split
Definition: GNEEdge.cpp:430
void setStatusBarText(const std::string &)
set text of the statusBar
GNEJunction * getSource() const
returns the source-junction
Definition: GNEEdge.cpp:139
void saveAdditionals(const std::string &filename)
save additional elements of the network
Definition: GNENet.cpp:564
void savePlain(OptionsCont &oc)
save plain xml representation of the network (and nothing else)
Definition: GNENet.cpp:583
void requireRecompute()
inform the net about the need for recomputation
Definition: GNENet.cpp:840
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual void setTLControllingInformation() const =0
Informs edges about being controlled by a tls.
static const SUMOReal Z_INITIALIZED
marker for whether the z-boundary is initialized
Definition: GNENet.h:509
void duplicateLane(GNELane *lane, GNEUndoList *undoList)
duplicates lane
Definition: GNENet.cpp:389
void append(const PositionVector &v, SUMOReal sameThreshold=2.0)
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
TrafficLightType
void registerJoinedCluster(const std::set< NBNode * > &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:766
a junction
void finishMoveSelection(GNEUndoList *undoList)
register changes to junction and edge positions with the undoList
Definition: GNENet.cpp:1016
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:363