Eclipse SUMO - Simulation of Urban MObility
GNEConnection.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A class for visualizing connections between lanes
19 /****************************************************************************/
20 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
28 #include <utils/gui/div/GLHelper.h>
34 
35 #include "GNEConnection.h"
36 #include "GNEInternalLane.h"
37 
38 
39 // ===========================================================================
40 // static member definitions
41 // ===========================================================================
42 int NUM_POINTS = 5;
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 
49  GNENetworkElement(from->getNet(), "from" + from->getID() + "to" + to->getID(),
51 {}, {}, {}, {}, {}, {}, {}, {}),
52 myFromLane(from),
53 myToLane(to),
54 myLinkState(LINKSTATE_TL_OFF_NOSIGNAL),
55 mySpecialColor(nullptr),
56 myShapeDeprecated(true) {
57  // update centering boundary without updating grid
58  updateCenteringBoundary(false);
59 }
60 
61 
63 }
64 
65 
66 const PositionVector&
68  if (myConnectionGeometry.getShape().size() > 0) {
70  } else {
72  }
73 }
74 
75 
76 void
78  // Get shape of from and to lanes
80  if (myShapeDeprecated) {
81  // obtain lane shape from
82  PositionVector laneShapeFrom;
83  if ((int)getEdgeFrom()->getNBEdge()->getLanes().size() > nbCon.fromLane) {
84  laneShapeFrom = getEdgeFrom()->getNBEdge()->getLanes().at(nbCon.fromLane).shape;
85  } else {
86  return;
87  }
88  // obtain lane shape to
89  PositionVector laneShapeTo;
90  if ((int)nbCon.toEdge->getLanes().size() > nbCon.toLane) {
91  laneShapeTo = nbCon.toEdge->getLanes().at(nbCon.toLane).shape;
92  } else {
93  return;
94  }
95  // Calculate shape of connection depending of the size of Junction shape
96  // value obtanied from GNEJunction::drawgl
97  if (nbCon.customShape.size() != 0) {
99  } else if (getEdgeFrom()->getNBEdge()->getToNode()->getShape().area() > 4) {
100  if (nbCon.shape.size() != 0) {
101  PositionVector connectionShape = nbCon.shape;
102  // only append via shape if it exists
103  if (nbCon.haveVia) {
104  connectionShape.append(nbCon.viaShape);
105  }
106  myConnectionGeometry.updateGeometry(connectionShape);
107  } else {
108  // Calculate shape so something can be drawn immidiately
109  myConnectionGeometry.updateGeometry(getEdgeFrom()->getNBEdge()->getToNode()->computeSmoothShape(
110  laneShapeFrom, laneShapeTo, NUM_POINTS,
111  getEdgeFrom()->getNBEdge()->getTurnDestination() == nbCon.toEdge,
112  (double) 5. * (double) getEdgeFrom()->getNBEdge()->getNumLanes(),
113  (double) 5. * (double) nbCon.toEdge->getNumLanes()));
114  }
115  } else {
116  myConnectionGeometry.updateGeometry({laneShapeFrom.positionAtOffset(MAX2(0.0, laneShapeFrom.length() - 1)),
117  laneShapeTo.positionAtOffset(MIN2(1.0, laneShapeFrom.length()))});
118  }
119  // check if internal junction marker must be calculated
120  if (nbCon.haveVia && (nbCon.shape.size() != 0)) {
121  // create marker for interal junction waiting position (contPos)
122  const double orthoLength = 0.5;
123  Position pos = nbCon.shape.back();
124  myInternalJunctionMarker = nbCon.shape.getOrthogonal(pos, 10, true, 0.1);
125  if (myInternalJunctionMarker.length() < orthoLength) {
127  }
128  } else {
129  myInternalJunctionMarker.clear();
130  }
131  // mark connection as non-deprecated
132  myShapeDeprecated = false;
133  }
134 }
135 
136 
137 Position
139  // currently unused
140  return Position(0, 0);
141 }
142 
143 
145 GNEConnection::getMoveOperation(const double shapeOffset) {
146  // edit depending if shape is being edited
147  if (isShapeEdited()) {
148  // get connection
149  const auto& connection = getNBEdgeConnection();
150  // get original shape
151  const PositionVector originalShape = connection.customShape.size() > 0 ? connection.customShape : connection.shape;
152  // declare shape to move
153  PositionVector shapeToMove = originalShape;
154  // first check if in the given shapeOffset there is a geometry point
155  const Position positionAtOffset = shapeToMove.positionAtOffset2D(shapeOffset);
156  // check if position is valid
157  if (positionAtOffset == Position::INVALID) {
158  return nullptr;
159  } else {
160  // obtain index
161  const int index = originalShape.indexOfClosest(positionAtOffset);
162  // declare new index
163  int newIndex = index;
164  // get snap radius
166  // check if we have to create a new index
167  if (positionAtOffset.distanceSquaredTo2D(shapeToMove[index]) > (snap_radius * snap_radius)) {
168  newIndex = shapeToMove.insertAtClosest(positionAtOffset, true);
169  }
170  // return move operation for edit shape
171  return new GNEMoveOperation(this, originalShape, {index}, shapeToMove, {newIndex});
172  }
173  } else {
174  return nullptr;
175  }
176 }
177 
178 
179 void
180 GNEConnection::removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) {
181  // edit depending if shape is being edited
182  if (isShapeEdited()) {
183  // get connection
184  const auto& connection = getNBEdgeConnection();
185  // get original shape
186  PositionVector shape = connection.customShape.size() > 0 ? connection.customShape : connection.shape;
187  // check shape size
188  if (shape.size() > 2) {
189  // obtain index
190  int index = shape.indexOfClosest(clickedPosition);
191  // get snap radius
193  // check if we have to create a new index
194  if ((index != -1) && shape[index].distanceSquaredTo2D(clickedPosition) < (snap_radius * snap_radius)) {
195  // remove geometry point
196  shape.erase(shape.begin() + index);
197  // commit new shape
198  undoList->p_begin("remove geometry point of " + getTagStr());
199  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_CUSTOMSHAPE, toString(shape)));
200  undoList->p_end();
201  }
202  }
203  }
204 }
205 
206 
207 GNEEdge*
209  return myFromLane->getParentEdge();
210 }
211 
212 
213 GNEEdge*
215  return myToLane->getParentEdge();
216 }
217 
218 
219 GNELane*
221  return myFromLane;
222 }
223 
224 
225 GNELane*
227  return myToLane;
228 }
229 
230 
231 int
233  return myFromLane->getIndex();
234 }
235 
236 
237 int
239  return myToLane->getIndex();
240 }
241 
242 
246 }
247 
248 
252  return NBConnection(getEdgeFrom()->getNBEdge(), getFromLaneIndex(),
253  getEdgeTo()->getNBEdge(), getToLaneIndex(),
254  (int)c.tlLinkIndex, (int)c.tlLinkIndex2);
255 }
256 
257 
258 void
260  setMicrosimID(myFromLane->getID() + " -> " + myToLane->getID());
261 }
262 
263 
264 LinkState
266  return myLinkState;
267 }
268 
269 
270 void
272  myShapeDeprecated = true;
273 }
274 
275 
276 void
280  nbCon.toEdge,
281  nbCon.fromLane,
282  nbCon.toLane,
283  nbCon.mayDefinitelyPass,
284  nbCon.tlID);
285 }
286 
287 
290  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
291  buildPopupHeader(ret, app);
294  // build selection and show parameters menu
297  // build position copy entry
298  buildPositionCopyEntry(ret, false);
299  // check if we're in supermode network
301  // create menu commands
302  FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom connection shape", nullptr, &parent, MID_GNE_CONNECTION_EDIT_SHAPE);
303  // check if menu commands has to be disabled
305  // check if we're in the correct edit mode
306  if ((editMode == NetworkEditMode::NETWORK_CONNECT) || (editMode == NetworkEditMode::NETWORK_TLS) || (editMode == NetworkEditMode::NETWORK_CREATE_EDGE)) {
307  mcCustomShape->disable();
308  }
309  }
310  return ret;
311 }
312 
313 
314 void
315 GNEConnection::updateCenteringBoundary(const bool /*updateGrid*/) {
316  // calculate boundary
317  if (myConnectionGeometry.getShape().size() == 0) {
318  // we need to use the center of junction parent as boundary if shape is empty
319  const Position junctionParentPosition = myFromLane->getParentEdge()->getParentJunctions().back()->getPositionInView();
320  myBoundary = Boundary(junctionParentPosition.x() - 0.1, junctionParentPosition.y() - 0.1,
321  junctionParentPosition.x() + 0.1, junctionParentPosition.x() + 0.1);
322  } else {
324  }
325  // grow
326  myBoundary.grow(10);
327 }
328 
329 
330 void
332  // declare a flag to check if shape has to be draw
333  bool drawConnection = true;
336  drawConnection = !myShapeDeprecated;
339  drawConnection = !myShapeDeprecated;
340  } else {
341  drawConnection = false;
342  }
343  // check if we're editing this connection
345  drawConnection = true;
346  }
347  // Check if connection must be drawed
348  if (drawConnection) {
349  // draw connection checking whether it is not too small if isn't being drawn for selecting
350  const double selectionScale = isAttributeCarrierSelected() ? s.selectorFrameScale : 1;
351  // get color
352  RGBColor connectionColor;
353  // first check if we're editing shape
354  if (myShapeEdited) {
355  connectionColor = s.colorSettings.editShape;
356  } else if (drawUsingSelectColor()) {
357  // override with special colors (unless the color scheme is based on selection)
358  connectionColor = s.colorSettings.selectedConnectionColor;
359  } else if (mySpecialColor != nullptr) {
360  connectionColor = *mySpecialColor;
361  } else {
362  // Set color depending of the link state
364  }
365  // check if boundary has to be drawn
366  if (s.drawBoundaries) {
368  }
369  // Push name
370  glPushName(getGlID());
371  // Push layer matrix
372  glPushMatrix();
373  // translate to front
375  // Set color
376  GLHelper::setColor(connectionColor);
377  if ((s.scale * selectionScale < 5.) && !s.drawForRectangleSelection) {
378  // If it's small, draw a simple line
380  } else {
381  // draw a list of lines
382  const bool spreadSuperposed = s.scale >= 1 && s.spreadSuperposed && myFromLane->drawAsRailway(s) && getEdgeFrom()->getNBEdge()->isBidiRail();
383  PositionVector shapeSuperposed = myConnectionGeometry.getShape();
384  if (spreadSuperposed) {
385  shapeSuperposed.move2side(0.5);
386  }
388  glTranslated(0, 0, 0.1);
389  GLHelper::setColor(GLHelper::getColor().changedBrightness(51));
390  // check if internal junction marker has to be drawn
391  if (myInternalJunctionMarker.size() > 0) {
393  }
394  // draw shape points only in Network supemode
396  // color
397  const RGBColor darkerColor = connectionColor.changedBrightness(-32);
398  // draw geometry points
400  // draw moving hint
402  }
403  // Pop layer matrix
404  glPopMatrix();
405  // check if edge value has to be shown
406  if (s.edgeValue.show) {
408  std::string value = nbCon.getParameter(s.edgeParam, "");
409  if (value != "") {
410  int shapeIndex = (int)myConnectionGeometry.getShape().size() / 2;
411  Position p = (myConnectionGeometry.getShape().size() == 2
412  ? (myConnectionGeometry.getShape().front() * 0.67 + myConnectionGeometry.getShape().back() * 0.33)
413  : myConnectionGeometry.getShape()[shapeIndex]);
414  GLHelper::drawTextSettings(s.edgeValue, value, p, s.scale, 0);
415  }
416  }
417  // Pop name
418  glPopName();
419  // check if dotted contour has to be drawn (not useful at high zoom)
421  // calculate dotted geometry
422  GNEGeometry::DottedGeometry dottedConnectionGeometry(s, shapeSuperposed, false);
423  dottedConnectionGeometry.setWidth(0.1);
424  // use drawDottedContourLane to draw it
425  GNEGeometry::drawDottedContourLane(GNEGeometry::DottedContourType::INSPECT, s, dottedConnectionGeometry, s.connectionSettings.connectionWidth * selectionScale, true, true);
426  }
427  // check if front contour has to be drawn (not useful at high zoom)
428  if (s.drawDottedContour() || (myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
429  // calculate dotted geometry
430  GNEGeometry::DottedGeometry dottedConnectionGeometry(s, shapeSuperposed, false);
431  dottedConnectionGeometry.setWidth(0.1);
432  // use drawDottedContourLane to draw it
433  GNEGeometry::drawDottedContourLane(GNEGeometry::DottedContourType::FRONT, s, dottedConnectionGeometry, s.connectionSettings.connectionWidth * selectionScale, true, true);
434  }
435  }
436  }
437 }
438 
439 
440 void
442  mySpecialColor = color;
443 }
444 
445 
446 std::string
448  if (key == SUMO_ATTR_ID) {
449  // used by GNEReferenceCounter
450  // @note: may be called for connections without a valid nbCon reference
451  return getID();
452  }
454  switch (key) {
455  case SUMO_ATTR_FROM:
456  return getEdgeFrom()->getID();
457  case SUMO_ATTR_TO:
458  return nbCon.toEdge->getID();
459  case SUMO_ATTR_FROM_LANE:
460  return toString(nbCon.fromLane);
461  case SUMO_ATTR_TO_LANE:
462  return toString(nbCon.toLane);
463  case SUMO_ATTR_PASS:
464  return toString(nbCon.mayDefinitelyPass);
466  return toString(nbCon.keepClear);
467  case SUMO_ATTR_CONTPOS:
468  return toString(nbCon.contPos);
470  return toString(nbCon.uncontrolled);
472  return toString(nbCon.visibility);
474  return toString(nbCon.tlLinkIndex);
476  return toString(nbCon.tlLinkIndex2);
477  case SUMO_ATTR_ALLOW:
478  if (nbCon.permissions == SVC_UNSPECIFIED) {
479  return getVehicleClassNames(nbCon.toEdge->getLanes()[nbCon.toLane].permissions);
480  } else {
481  return getVehicleClassNames(nbCon.permissions);
482  }
483  case SUMO_ATTR_DISALLOW:
484  if (nbCon.permissions == SVC_UNSPECIFIED) {
485  return getVehicleClassNames(invertPermissions(nbCon.toEdge->getLanes()[nbCon.toLane].permissions));
486  } else {
488  }
489  case SUMO_ATTR_SPEED:
490  return toString(nbCon.speed);
491  case SUMO_ATTR_LENGTH:
492  return toString(nbCon.customLength);
493  case SUMO_ATTR_DIR:
494  return toString(getEdgeFrom()->getNBEdge()->getToNode()->getDirection(
495  getEdgeFrom()->getNBEdge(), nbCon.toEdge, OptionsCont::getOptions().getBool("lefthand")));
496  case SUMO_ATTR_STATE:
497  return toString(getEdgeFrom()->getNBEdge()->getToNode()->getLinkState(
498  getEdgeFrom()->getNBEdge(), nbCon.toEdge, nbCon.fromLane, nbCon.toLane, nbCon.mayDefinitelyPass, nbCon.tlID));
500  return toString(nbCon.customShape);
501  case GNE_ATTR_SELECTED:
503  case GNE_ATTR_PARAMETERS:
504  return nbCon.getParametersStr();
505  default:
506  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
507  }
508 }
509 
510 
511 void
512 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
514  switch (key) {
515  case SUMO_ATTR_FROM:
516  case SUMO_ATTR_TO:
517  case SUMO_ATTR_FROM_LANE:
518  case SUMO_ATTR_TO_LANE:
519  case SUMO_ATTR_PASS:
521  case SUMO_ATTR_CONTPOS:
524  case SUMO_ATTR_ALLOW:
525  case SUMO_ATTR_DISALLOW:
526  case SUMO_ATTR_SPEED:
527  case SUMO_ATTR_LENGTH:
529  case GNE_ATTR_SELECTED:
530  case GNE_ATTR_PARAMETERS:
531  // no special handling
532  undoList->p_add(new GNEChange_Attribute(this, key, value));
533  break;
535  if (isAttributeEnabled(SUMO_ATTR_TLLINKINDEX) && (value != getAttribute(key))) {
536  changeTLIndex(key, parse<int>(value), c.tlLinkIndex2, undoList);
537  }
538  break;
540  if (isAttributeEnabled(SUMO_ATTR_TLLINKINDEX) && (value != getAttribute(key))) {
541  changeTLIndex(key, c.tlLinkIndex, parse<int>(value), undoList);
542  }
543  break;
544  case SUMO_ATTR_DIR:
545  throw InvalidArgument("Attribute of '" + toString(key) + "' cannot be modified");
546  case SUMO_ATTR_STATE:
547  throw InvalidArgument("Attribute of '" + toString(key) + "' cannot be modified");
548  default:
549  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
550  }
551 }
552 
553 
554 void
555 GNEConnection::changeTLIndex(SumoXMLAttr key, int tlIndex, int tlIndex2, GNEUndoList* undoList) {
556  // trigger GNEChange_TLS
557  undoList->p_begin("change tls linkIndex for connection");
558  // make a copy
559  std::set<NBTrafficLightDefinition*> defs = getEdgeFrom()->getNBEdge()->getToNode()->getControllingTLS();
560  for (NBTrafficLightDefinition* tlDef : defs) {
561  NBLoadedSUMOTLDef* sumoDef = dynamic_cast<NBLoadedSUMOTLDef*>(tlDef);
562  NBTrafficLightLogic* tllogic = sumoDef ? sumoDef->getLogic() : tlDef->compute(OptionsCont::getOptions());
563  if (tllogic != nullptr) {
564  NBLoadedSUMOTLDef* newDef = new NBLoadedSUMOTLDef(*tlDef, *tllogic);
565  newDef->addConnection(getEdgeFrom()->getNBEdge(), getEdgeTo()->getNBEdge(),
566  getLaneFrom()->getIndex(), getLaneTo()->getIndex(), tlIndex, tlIndex2, false);
567  // make a copy
568  std::vector<NBNode*> nodes = tlDef->getNodes();
569  for (NBNode* node : nodes) {
570  GNEJunction* junction = getNet()->retrieveJunction(node->getID());
571  undoList->add(new GNEChange_TLS(junction, tlDef, false), true);
572  undoList->add(new GNEChange_TLS(junction, newDef, true), true);
573  }
574  } else {
575  WRITE_ERROR("Could not set attribute '" + toString(key) + "' (tls is broken)");
576  }
577  }
578  undoList->p_end();
579 }
580 
581 bool
582 GNEConnection::isValid(SumoXMLAttr key, const std::string& value) {
583  // Currently ignored before implementation to avoid warnings
584  switch (key) {
585  case SUMO_ATTR_FROM:
586  case SUMO_ATTR_TO:
587  case SUMO_ATTR_FROM_LANE:
588  case SUMO_ATTR_TO_LANE:
589  return false;
590  case SUMO_ATTR_PASS:
591  return canParse<bool>(value);
593  return canParse<bool>(value);
594  case SUMO_ATTR_CONTPOS:
595  return canParse<double>(value) && (parse<double>(value) >= -1);
597  return canParse<bool>(value);
599  return canParse<double>(value) && (parse<double>(value) >= -1);
603  (getNBEdgeConnection().uncontrolled == false) &&
604  (getEdgeFrom()->getNBEdge()->getToNode()->getControllingTLS().size() > 0) &&
605  canParse<int>(value) &&
606  (parse<int>(value) >= 0 || parse<int>(value) == -1)) {
607  // obtan Traffic light definition
609  return def->getMaxValidIndex() >= parse<int>(value);
610  } else {
611  return false;
612  }
613  case SUMO_ATTR_ALLOW:
614  case SUMO_ATTR_DISALLOW:
615  return canParseVehicleClasses(value);
616  case SUMO_ATTR_SPEED:
617  return canParse<double>(value) && (parse<double>(value) >= -1);
618  case SUMO_ATTR_LENGTH:
619  return canParse<double>(value) && (parse<double>(value) >= -1);
620  case SUMO_ATTR_CUSTOMSHAPE: {
621  // empty custom shapes are allowed
622  return canParse<PositionVector>(value);
623  }
624  case SUMO_ATTR_STATE:
625  return false;
626  case SUMO_ATTR_DIR:
627  return false;
628  case GNE_ATTR_SELECTED:
629  return canParse<bool>(value);
630  case GNE_ATTR_PARAMETERS:
631  return Parameterised::areParametersValid(value);
632  default:
633  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
634  }
635 }
636 
637 
638 bool
640  switch (key) {
641  case SUMO_ATTR_FROM:
642  case SUMO_ATTR_TO:
643  case SUMO_ATTR_FROM_LANE:
644  case SUMO_ATTR_TO_LANE:
645  case SUMO_ATTR_DIR:
646  case SUMO_ATTR_STATE:
647  // this attributes cannot be edited
648  return false;
651  // get Traffic Light definitions
652  if (getEdgeFrom()->getNBEdge()->getToNode()->isTLControlled()) {
654  NBLoadedSUMOTLDef* sumoDef = dynamic_cast<NBLoadedSUMOTLDef*>(tlDef);
655  NBTrafficLightLogic* tllogic = sumoDef != nullptr ? sumoDef->getLogic() : tlDef->compute(OptionsCont::getOptions());
656  if (tllogic != nullptr) {
657  return true;
658  } else {
659  return false;
660  }
661  }
662  return false;
663  default:
664  return true;
665  }
666 }
667 
668 
669 const std::map<std::string, std::string>&
672 }
673 
674 // ===========================================================================
675 // private
676 // ===========================================================================
677 
678 void
679 GNEConnection::setAttribute(SumoXMLAttr key, const std::string& value) {
681  switch (key) {
682  case SUMO_ATTR_PASS:
683  nbCon.mayDefinitelyPass = parse<bool>(value);
684  break;
686  nbCon.keepClear = parse<bool>(value) ? KEEPCLEAR_TRUE : KEEPCLEAR_FALSE;
687  break;
689  nbCon.uncontrolled = parse<bool>(value);
690  break;
691  case SUMO_ATTR_CONTPOS:
692  nbCon.contPos = parse<double>(value);
693  break;
695  nbCon.visibility = parse<double>(value);
696  break;
697  case SUMO_ATTR_SPEED:
698  nbCon.speed = parse<double>(value);
699  break;
700  case SUMO_ATTR_LENGTH:
701  nbCon.customLength = parse<double>(value);
702  break;
703  case SUMO_ATTR_ALLOW: {
704  const SVCPermissions successorAllows = nbCon.toEdge->getLanes()[nbCon.toLane].permissions;
705  SVCPermissions customPermissions = parseVehicleClasses(value);
706  if (successorAllows != customPermissions) {
707  nbCon.permissions = customPermissions;
708  }
709  break;
710  }
711  case SUMO_ATTR_DISALLOW: {
712  const SVCPermissions successorDisallows = invertPermissions(nbCon.toEdge->getLanes()[nbCon.toLane].permissions);
713  SVCPermissions customPermissions = invertPermissions(parseVehicleClasses(value));
714  if (successorDisallows != customPermissions) {
715  nbCon.permissions = customPermissions;
716  }
717  break;
718  }
719  case SUMO_ATTR_STATE:
720  throw InvalidArgument("Attribute of '" + toString(key) + "' cannot be modified");
721  case SUMO_ATTR_DIR:
722  throw InvalidArgument("Attribute of '" + toString(key) + "' cannot be modified");
723  case SUMO_ATTR_CUSTOMSHAPE: {
724  nbCon.customShape = parse<PositionVector>(value);
725  // update centering boundary
727  break;
728  }
729  case GNE_ATTR_SELECTED:
730  if (parse<bool>(value)) {
732  } else {
734  }
735  break;
736  case GNE_ATTR_PARAMETERS:
737  nbCon.setParametersStr(value);
738  break;
739  default:
740  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
741  }
742  // Update Geometry after setting a new attribute (but avoided for certain attributes)
743  if ((key != SUMO_ATTR_ID) && (key != GNE_ATTR_PARAMETERS) && (key != GNE_ATTR_SELECTED)) {
745  updateGeometry();
746  }
747 }
748 
749 
750 void
752  // set custom shape
754  // mark junction as deprecated
755  myShapeDeprecated = true;
756  // update geometry
757  updateGeometry();
758 }
759 
760 
761 void
763  // commit new shape
764  undoList->p_begin("moving " + toString(SUMO_ATTR_CUSTOMSHAPE) + " of " + getTagStr());
765  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_CUSTOMSHAPE, toString(moveResult.shapeToUpdate)));
766  undoList->p_end();
767 }
768 
769 /****************************************************************************/
int NUM_POINTS
NetworkEditMode
@brie enum for network edit modes
@ NETWORK_CREATE_EDGE
mode for creating new edges
@ NETWORK_TLS
mode for editing tls
@ NETWORK_CONNECT
mode for connecting lanes
@ MID_GNE_CONNECTION_EDIT_SHAPE
edit junction shape
Definition: GUIAppEnum.h:1005
@ GLO_CONNECTION
a connection
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:284
@ KEEPCLEAR_FALSE
Definition: NBCont.h:58
@ KEEPCLEAR_TRUE
Definition: NBCont.h:59
SVCPermissions invertPermissions(SVCPermissions permissions)
negate the given permissions and ensure that only relevant bits are set
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_CONNECTION
connectio between two lanes
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_TLLINKINDEX2
link: the index of the opposite direction link of a pedestrian crossing
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_FROM_LANE
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_CUSTOMSHAPE
whether a given shape is user-defined
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_PASS
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_TO_LANE
@ SUMO_ATTR_UNCONTROLLED
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_VISIBILITY_DISTANCE
foe visibility distance of a link
@ SUMO_ATTR_CONTPOS
@ SUMO_ATTR_DIR
The abstract direction of a link.
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
@ SUMO_ATTR_KEEP_CLEAR
Whether vehicles must keep the junction clear.
@ SUMO_ATTR_STATE
The state of a link.
T MIN2(T a, T b)
Definition: StdDefs.h:73
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:273
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:181
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:452
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:529
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
NBConnection getNBConnection() const
get NBConnection
Position getPositionInView() const
Returns position of hierarchical element in view.
GNELane * getLaneFrom() const
@briefthe get lane of the incoming lane
const PositionVector & getConnectionShape() const
GNELane * getLaneTo() const
@briefthe get lane of the outgoing lane
GNELane * myFromLane
incoming lane of this connection
LinkState getLinkState() const
get LinkState
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
int getFromLaneIndex() const
@briefthe get lane index of the incoming lane
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
GNELane * myToLane
outgoing lane of this connection
std::string getAttribute(SumoXMLAttr key) const
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
void markConnectionGeometryDeprecated()
check that connection's Geometry has to be updated
GNEConnection(GNELane *from, GNELane *to)
GNEEdge * getEdgeTo() const
get the name of the edge the vehicles may reach when leaving "from"
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
void setSpecialColor(const RGBColor *Color2)
void updateGeometry()
update pre-computed geometry information
GNEGeometry::Geometry myConnectionGeometry
connection geometry
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
bool isValid(SumoXMLAttr key, const std::string &value)
const RGBColor * mySpecialColor
optional special color
~GNEConnection()
Destructor.
int getToLaneIndex() const
@briefthe get lane index of the outgoing lane
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
bool myShapeDeprecated
flag to indicate that connection's shape has to be updated
void updateLinkState()
recompute cached myLinkState
PositionVector myInternalJunctionMarker
waiting position for internal junction
bool isAttributeEnabled(SumoXMLAttr key) const
LinkState myLinkState
Linkstate.
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
void updateID()
update internal ID of Connection
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
void changeTLIndex(SumoXMLAttr key, int tlIndex, int tlIndex2, GNEUndoList *undoList)
manage change of tlLinkindices
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:49
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:399
class for pack all variables related with DottedGeometry
Definition: GNEGeometry.h:187
void setWidth(const double width)
change default width
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< double > & getShapeLengths() const
The lengths of the single shape parts.
const std::vector< GNEJunction * > & getParentJunctions() const
get parent junctions
static RGBColor colorForLinksState(FXuint state)
return the color for each linkstate
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:733
bool drawAsRailway(const GUIVisualizationSettings &s) const
whether to draw this lane as a railway
Definition: GNELane.cpp:1332
GNEEdge * getParentEdge() const
get arent edge
Definition: GNELane.cpp:111
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true) const
get junction by id
Definition: GNENet.cpp:1113
bool myShapeEdited
flag to check if element shape is being edited
bool isShapeEdited() const
check if shape is being edited
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
const std::string & getID() const
get ID
Boundary myBoundary
object boundary
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
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:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape modul
Definition: GNEViewNet.cpp:503
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:479
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:368
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:40
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
GUIVisualizationTextSettings edgeValue
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawMovingGeometryPoint(const double exaggeration, const double radius) const
check if moving geometry point can be draw
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationConnectionSettings connectionSettings
connection settings
double scale
information about a lane's width (temporary, used for a single view)
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
double selectorFrameScale
the current selection scaling in NETEDIT (set in SelectorFrame)
bool spreadSuperposed
Whether to improve visualisation of superposed (rail) edges.
std::string edgeParam
key for coloring by edge parameter
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
Connection & getConnectionRef(int fromLane, const NBEdge *to, int toLane)
Returns reference to the specified connection This method goes through "myConnections" and returns th...
Definition: NBEdge.cpp:1180
bool isBidiRail(bool ignoreSpread=false) const
whether this edge is part of a bidirectional railway
Definition: NBEdge.cpp:713
const std::string & getID() const
Definition: NBEdge.h:1423
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:677
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:516
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:490
A loaded (complete) traffic light logic.
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, int linkIndex2, bool reconstruct=true)
Adds a connection and immediately informs the edges.
NBTrafficLightLogic * getLogic()
Returns the internal logic.
Represents a single node (junction) during network building.
Definition: NBNode.h:66
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, int toLane, bool mayDefinitelyPass, const std::string &tlID) const
get link state
Definition: NBNode.cpp:2156
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:322
The base class for traffic light logic definitions.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
virtual int getMaxValidIndex()
Returns the maximum index controlled by this traffic light.
A SUMO-compliant built logic for a traffic light.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition: Position.h:246
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:282
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
void append(const PositionVector &v, double sameThreshold=2.0)
double length() const
Returns the length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
PositionVector getOrthogonal(const Position &p, double extend, bool before, double length=1.0, double deg=90) const
return orthogonal through p (extending this vector if necessary)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
int insertAtClosest(const Position &p, bool interpolateZ)
inserts p between the two closest positions
int indexOfClosest(const Position &p) const
index of the closest position to p
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
static void drawGeometryPoints(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &geometryPointColor, const RGBColor &textColor, const double radius, const double exaggeration)
draw geometry points
static void drawDottedContourLane(const DottedContourType type, const GUIVisualizationSettings &s, const DottedGeometry &dottedGeometry, const double width, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given dottedGeometry (used by lanes, routes, etc.)
static void drawMovingHint(const GUIVisualizationSettings &s, const GNEViewNet *viewNet, const PositionVector &shape, const RGBColor &hintColor, const double radius, const double exaggeration)
draw moving hint
NetworkEditMode networkEditMode
the current Network edit mode
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
bool showConnections() const
check if select show connections checkbox is enabled
static const RGBColor editShape
color for edited shapes (Junctions, crossings and connections)
RGBColor selectedConnectionColor
connection selection color
static const double connectionWidth
connection width
static const double connectionsDemandMode
draw connections in demand mode
static const double connectionGeometryPointRadius
moving connection geometry point radius
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:188
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:209
int toLane
The lane the connections yields in.
Definition: NBEdge.h:215
SVCPermissions permissions
List of vehicle types that are allowed on this connection.
Definition: NBEdge.h:248
double speed
custom speed for connection
Definition: NBEdge.h:239
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:212
KeepClear keepClear
whether the junction must be kept clear when using this connection
Definition: NBEdge.h:230
double customLength
custom length for connection
Definition: NBEdge.h:242
bool uncontrolled
check if Connection is uncontrolled
Definition: NBEdge.h:281
PositionVector customShape
custom shape for connection
Definition: NBEdge.h:245
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:227
PositionVector viaShape
shape of via
Definition: NBEdge.h:266
double contPos
custom position for internal junction on this connection
Definition: NBEdge.h:233
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:218
double visibility
custom foe visiblity for connection
Definition: NBEdge.h:236
int tlLinkIndex2
The index of the internal junction within the controlling traffic light (optional)
Definition: NBEdge.h:224
PositionVector shape
shape of Connection
Definition: NBEdge.h:254
bool haveVia
check if Connection have a Via
Definition: NBEdge.h:260
int tlLinkIndex
The index of this connection within the controlling traffic light.
Definition: NBEdge.h:221