SUMO - Simulation of Urban MObility
GNEDetectorE2.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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
30 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEDetectorE2.h"
34 #include "GNEAdditionalHandler.h"
35 
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 GNEDetectorE2::GNEDetectorE2(const std::string& id, GNELane* lane, GNEViewNet* viewNet, double pos, double length, double freq, const std::string& filename, const std::string& vehicleTypes,
42  const std::string& name, const double timeThreshold, double speedThreshold, double jamThreshold, bool friendlyPos, bool blockMovement) :
43  GNEDetector(id, viewNet, GLO_E2DETECTOR, SUMO_TAG_E2DETECTOR, pos, freq, filename, vehicleTypes, name, friendlyPos, blockMovement),
44  myLanes({lane}),
45  myLength(length),
47  myTimeThreshold(timeThreshold),
48  mySpeedThreshold(speedThreshold),
49  myJamThreshold(jamThreshold),
50  myE2valid(true) {
51 }
52 
53 
54 GNEDetectorE2::GNEDetectorE2(const std::string& id, std::vector<GNELane*> lanes, GNEViewNet* viewNet, double pos, double endPos, double freq, const std::string& filename, const std::string& vehicleTypes,
55  const std::string& name, const double timeThreshold, double speedThreshold, double jamThreshold, bool friendlyPos, bool blockMovement) :
56  GNEDetector(id, viewNet, GLO_E2DETECTOR, SUMO_TAG_E2DETECTOR_MULTILANE, pos, freq, filename, vehicleTypes, name, friendlyPos, blockMovement),
57  myLanes(lanes),
58  myEndPositionOverLane(endPos),
59  myTimeThreshold(timeThreshold),
60  mySpeedThreshold(speedThreshold),
61  myJamThreshold(jamThreshold),
62  myE2valid(true) {
63 }
64 
65 
67 }
68 
69 
70 bool
72  if(myLanes.size() == 1) {
73  // with friendly position enabled position are "always fixed"
74  if (myFriendlyPosition) {
75  return true;
76  } else {
77  return (myPositionOverLane >= 0) && ((myPositionOverLane + myLength) <= myLanes.front()->getParentEdge().getNBEdge()->getFinalLength());
78  }
79  } else {
80  // first check if there is connection between all consecutive lanes
81  if (myE2valid) {
82  // with friendly position enabled position are "always fixed"
83  if (myFriendlyPosition) {
84  return true;
85  } else {
86  return (myPositionOverLane >= 0) && ((myPositionOverLane) <= myLanes.back()->getParentEdge().getNBEdge()->getFinalLength() &&
87  myEndPositionOverLane >= 0) && ((myEndPositionOverLane) <= myLanes.back()->getParentEdge().getNBEdge()->getFinalLength());
88  }
89  } else {
90  return false;
91  }
92  }
93 }
94 
95 
96 std::string
98  // declare variable for error position
99  std::string errorFirstLanePosition, separator, errorLastLanePosition;
100  if(myLanes.size() == 1) {
101  // check positions over lane
102  if (myPositionOverLane < 0) {
103  errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " < 0");
104  }
105  if (myPositionOverLane > myLanes.front()->getParentEdge().getNBEdge()->getFinalLength()) {
106  errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
107  }
108  if ((myPositionOverLane + myLength) > myLanes.front()->getParentEdge().getNBEdge()->getFinalLength()) {
109  errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " + " + toString(SUMO_ATTR_LENGTH) + " > lanes's length");
110  }
111  } else {
112  if (myE2valid) {
113  // check positions over first lane
114  if (myPositionOverLane < 0) {
115  errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " < 0");
116  }
117  if (myPositionOverLane > myLanes.front()->getParentEdge().getNBEdge()->getFinalLength()) {
118  errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
119  }
120  // check positions over last lane
121  if (myEndPositionOverLane < 0) {
122  errorLastLanePosition = (toString(SUMO_ATTR_ENDPOS) + " < 0");
123  }
124  if (myEndPositionOverLane > myLanes.back()->getParentEdge().getNBEdge()->getFinalLength()) {
125  errorLastLanePosition = (toString(SUMO_ATTR_ENDPOS) + " > lanes's length");
126  }
127  } else {
128  errorFirstLanePosition = "lanes aren't consecutives";
129  }
130  }
131  // check separator
132  if ((errorFirstLanePosition.size() > 0) && (errorLastLanePosition.size() > 0)) {
133  separator = " and ";
134  }
135  // return error message
136  return errorFirstLanePosition + separator + errorLastLanePosition;
137 }
138 
139 
140 void
142  if(myLanes.size() == 1) {
143  // obtain position and lenght
144  double newPositionOverLane = myPositionOverLane;
145  double newLength = myLength;
146  // fix pos and lenght using fixE2DetectorPosition
147  GNEAdditionalHandler::fixE2DetectorPosition(newPositionOverLane, newLength, myLanes.at(0)->getParentEdge().getNBEdge()->getFinalLength(), true);
148  // set new position and length
149  setAttribute(SUMO_ATTR_POSITION, toString(newPositionOverLane), myViewNet->getUndoList());
151  } else {
152  if(!myE2valid) {
153  // build connections between all consecutive lanes
154  bool foundConnection = true;
155  int i = 0;
156  // iterate over all lanes, and stop if myE2valid is false
157  while (i < ((int)myLanes.size()-1)) {
158  // change foundConnection to false
159  foundConnection = false;
160  // if a connection betwen "from" lane and "to" lane of connection is found, change myE2valid to true again
161  for (auto j : myLanes.at(i)->getParentEdge().getGNEConnections()) {
162  if(j->getLaneFrom() == myLanes.at(i) && j->getLaneTo() == myLanes.at(i+1)) {
163  foundConnection = true;
164  }
165  }
166  // if connection wasn't found
167  if(!foundConnection) {
168  // create new connection manually
169  NBEdge::Connection newCon(myLanes.at(i)->getIndex(), myLanes.at(i+1)->getParentEdge().getNBEdge(), myLanes.at(i+1)->getIndex());
170  // allow to undo creation of new lane
171  myViewNet->getUndoList()->add(new GNEChange_Connection(&myLanes.at(i)->getParentEdge(), newCon, false, true), true);
172  }
173  // update lane iterator
174  i++;
175  }
176  } else {
177  // declare new position
178  double newPositionOverLane = myPositionOverLane;
179  // fix pos and lenght checkAndFixDetectorPosition
180  GNEAdditionalHandler::checkAndFixDetectorPosition(newPositionOverLane, myLanes.front()->getParentEdge().getNBEdge()->getFinalLength(), true);
181  // set new position
182  setAttribute(SUMO_ATTR_POSITION, toString(newPositionOverLane), myViewNet->getUndoList());
183  // declare new end position
184  double newEndPositionOverLane = myEndPositionOverLane;
185  // fix pos and lenght checkAndFixDetectorPosition
186  GNEAdditionalHandler::checkAndFixDetectorPosition(newEndPositionOverLane, myLanes.back()->getParentEdge().getNBEdge()->getFinalLength(), true);
187  // set new position
188  setAttribute(SUMO_ATTR_ENDPOS, toString(newEndPositionOverLane), myViewNet->getUndoList());
189  }
190  }
191 }
192 
193 
194 void
196  // Calculate new position using old position
197  Position newPosition = myMove.originalViewPosition;
198  newPosition.add(offset);
199  // filtern position using snap to active grid
200  newPosition = myViewNet->snapToActiveGrid(newPosition);
201  double offsetLane = myLanes.front()->getShape().nearest_offset_to_point2D(newPosition, false) - myLanes.front()->getShape().nearest_offset_to_point2D(myMove.originalViewPosition, false);
202  // move geometry depending of number of lanes
203  if(myLanes.size() == 1) {
204  myPositionOverLane = parse<double>(myMove.firstOriginalLanePosition) + offsetLane;
205  } else {
206  // calculate new start and end positions
207  double newStartPosition = parse<double>(myMove.firstOriginalLanePosition) + offsetLane;
208  double newEndPosition = parse<double>(myMove.secondOriginalPosition) + offsetLane;
209  // change start and end position of E2 detector ONLY if both extremes aren't overpassed
210  if((newStartPosition >= 0) && (newStartPosition <= myLanes.front()->getLaneShapeLength()) &&
211  (newEndPosition >= 0) && (newEndPosition <= myLanes.back()->getLaneShapeLength())) {
212  myPositionOverLane = newStartPosition;
213  myEndPositionOverLane = newEndPosition;
214  }
215  }
216  // Update geometry
217  updateGeometry(false);
218 }
219 
220 
221 void
223  // commit geometry moving depending of number of lanes
224  if(myLanes.size() == 1) {
225  // commit new position allowing undo/redo
226  undoList->p_begin("position of " + getTagStr());
228  undoList->p_end();
229  } else {
230  undoList->p_begin("position of " + getTagStr());
233  undoList->p_end();
234  }
235 }
236 
237 
238 void
240  // first check if object has to be removed from grid (SUMOTree)
241  if (updateGrid) {
243  }
244 
245  // Clear all containers
247 
248  // declare variables for start and end positions
249  double startPosFixed, endPosFixed;
250 
251  // calculate start and end positions dependin of number of lanes
252  if (myLanes.size() == 1) {
253  // set shape lane as detector shape
254  myGeometry.shape = myLanes.front()->getShape();
255 
256  // set start position
257  if (myPositionOverLane < 0) {
258  startPosFixed = 0;
259  } else if (myPositionOverLane > myLanes.back()->getParentEdge().getNBEdge()->getFinalLength()) {
260  startPosFixed = myLanes.back()->getParentEdge().getNBEdge()->getFinalLength();
261  } else {
262  startPosFixed = myPositionOverLane;
263  }
264 
265  // set end position
266  if ((myPositionOverLane + myLength) < 0) {
267  endPosFixed = 0;
268  } else if ((myPositionOverLane + myLength) > myLanes.back()->getParentEdge().getNBEdge()->getFinalLength()) {
269  endPosFixed = myLanes.back()->getParentEdge().getNBEdge()->getFinalLength();
270  } else {
271  endPosFixed = (myPositionOverLane + myLength);
272  }
273 
274  // Cut shape using as delimitators fixed start position and fixed end position
275  myGeometry.shape = myGeometry.shape.getSubpart(startPosFixed * myLanes.front()->getLengthGeometryFactor(), endPosFixed * myLanes.back()->getLengthGeometryFactor());
276 
277  // Get calculate lenghts and rotations
279 
280  // Set block icon position
282 
283  } else if (myLanes.size() > 1) {
284  // start with the first lane shape
285  myGeometry.multiShape.push_back(myLanes.front()->getShape());
286 
287  // set start position
288  if (myPositionOverLane < 0) {
289  startPosFixed = 0;
290  } else if (myPositionOverLane > myLanes.front()->getParentEdge().getNBEdge()->getFinalLength()) {
291  startPosFixed = myLanes.front()->getParentEdge().getNBEdge()->getFinalLength();
292  } else {
293  startPosFixed = myPositionOverLane;
294  }
295  // Cut shape using as delimitators fixed start position and fixed end position
296  myGeometry.multiShape[0] = myGeometry.multiShape[0].getSubpart(startPosFixed * myLanes.front()->getLengthGeometryFactor(), myLanes.front()->getParentEdge().getNBEdge()->getFinalLength());
297 
298  // declare last shape
299  PositionVector lastShape = myLanes.back()->getShape();
300 
301  // set end position
302  if (myEndPositionOverLane < 0) {
303  endPosFixed = 0;
304  } else if (myEndPositionOverLane > myLanes.back()->getParentEdge().getNBEdge()->getFinalLength()) {
305  endPosFixed = myLanes.back()->getParentEdge().getNBEdge()->getFinalLength();
306  } else {
307  endPosFixed = myEndPositionOverLane;
308  }
309 
310  // Cut shape using as delimitators fixed start position and fixed end position
311  lastShape = lastShape.getSubpart(0, endPosFixed * myLanes.back()->getLengthGeometryFactor());
312 
313  // add first shape connection (if exist, in other case leave it empty)
314  myGeometry.multiShape.push_back(PositionVector{myLanes.at(0)->getShape().back(), myLanes.at(1)->getShape().front()});
315  for (auto j : myLanes.at(0)->getParentEdge().getGNEConnections()) {
316  if (j->getLaneTo() == myLanes.at(1)) {
317  myGeometry.multiShape.back() = j->getShape();
318  }
319  }
320 
321  // append shapes of intermediate lanes AND connections (if exist)
322  for (int i = 1; i < ((int)myLanes.size() - 1); i++) {
323  // add lane shape
324  myGeometry.multiShape.push_back(myLanes.at(i)->getShape());
325  // add empty shape for connection
326  myGeometry.multiShape.push_back(PositionVector{myLanes.at(i)->getShape().back(), myLanes.at(i+1)->getShape().front()});
327  // set connection shape (if exist). In other case, insert an empty shape
328  for (auto j : myLanes.at(i)->getParentEdge().getGNEConnections()) {
329  if (j->getLaneTo() == myLanes.at(i+1)) {
330  myGeometry.multiShape.back() = j->getShape();
331  }
332  }
333  }
334 
335  // append last shape
336  myGeometry.multiShape.push_back(lastShape);
337 
338  // calculate multi shape rotation and lengths
340 
341  // calculate unified shape
343 
344  // Set block icon position
345  myBlockIcon.position = myGeometry.multiShape.front().getLineCenter();
346 
347  // check integrity
349  }
350 
351  // Set offset of the block icon
352  myBlockIcon.offset = Position(-0.75, 0);
353 
354  // Set block icon rotation, and using their rotation for draw logo
356 
357  // last step is to check if object has to be added into grid (SUMOTree) again
358  if (updateGrid) {
360  }
361 }
362 
363 
364 double
366  return myLength;
367 }
368 
369 
370 void
372  // we assume that E2 is valid
373  myE2valid = true;
374  int i = 0;
375  // iterate over all lanes, and stop if myE2valid is false
376  while (i < ((int)myLanes.size()-1) && myE2valid) {
377  // set myE2valid to false
378  myE2valid = false;
379  // if a connection betwen "from" lane and "to" lane of connection is found, change myE2valid to true again
380  for (auto j : myLanes.at(i)->getParentEdge().getGNEConnections()) {
381  if(j->getLaneFrom() == myLanes.at(i) && j->getLaneTo() == myLanes.at(i+1)) {
382  myE2valid = true;
383  }
384  }
385  // update iterator
386  i++;
387  }
388 }
389 
390 
391 GNELane*
393  return myLanes.front();
394 }
395 
396 
397 void
399  // Start drawing adding an gl identificator
400  glPushName(getGlID());
401 
402  // Add a draw matrix
403  glPushMatrix();
404 
405  // Start with the drawing of the area traslating matrix to origin
406  glTranslated(0, 0, getType());
407 
408  // Set color of the base
411  } else {
412  // set color depending if is or isn't valid
413  if(myE2valid) {
415  } else {
417  }
418  }
419 
420  // Obtain exaggeration of the draw
421  const double exaggeration = s.addSize.getExaggeration(s, this);
422 
423  // check if we have to drawn a E2 single lane or a E2 multiLane
424  if(myGeometry.shape.size() > 0) {
425  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
427  } else {
428  // iterate over multishapes
429  for (int i = 0; i < (int)myGeometry.multiShape.size(); i++) {
430  // don't draw shapes over connections if "show connections" is enabled
431  if (!myViewNet->showConnections() || (i%2==0)) {
433  }
434  }
435  }
436 
437  // Pop last matrix
438  glPopMatrix();
439 
440  // Check if the distance is enougth to draw details and isn't being drawn for selecting
441  if ((s.scale * exaggeration >= 10) && !s.drawForSelecting) {
442  // draw logo depending if this is an Multilane E2 detector
444  // Push matrix
445  glPushMatrix();
446  // Traslate to center of detector
447  glTranslated(myGeometry.shape.getLineCenter().x(), myGeometry.shape.getLineCenter().y(), getType() + 0.1);
448  // Rotate depending of myBlockIcon.rotation
449  glRotated(myBlockIcon.rotation, 0, 0, -1);
450  //move to logo position
451  glTranslated(-0.75, 0, 0);
452  // draw E2 logo
454  GLHelper::drawText("E2", Position(), .1, 1.5, s.selectionColor);
455  } else {
456  GLHelper::drawText("E2", Position(), .1, 1.5, RGBColor::BLACK);
457  }
458  } else {
459  // Push matrix
460  glPushMatrix();
461  // Traslate to center of detector
462  glTranslated(myBlockIcon.position.x(), myBlockIcon.position.y(), getType() + 0.1);
463  // Rotate depending of myBlockIcon.rotation
464  glRotated(myBlockIcon.rotation, 0, 0, -1);
465  //move to logo position
466  glTranslated(-1.5, 0, 0);
467  // draw E2 logo
469  GLHelper::drawText("E2", Position(), .1, 1.5, s.selectionColor);
470  } else {
471  GLHelper::drawText("E2", Position(), .1, 1.5, RGBColor::BLACK);
472  }
473  //move to logo position
474  glTranslated(1.2, 0, 0);
475  // Rotate depending of myBlockIcon.rotation
476  glRotated(90, 0, 0, 1);
478  GLHelper::drawText("multi", Position(), .1, 0.9, s.selectedAdditionalColor);
479  } else {
480  GLHelper::drawText("multi", Position(), .1, 0.9, RGBColor::BLACK);
481  }
482  }
483  // pop matrix
484  glPopMatrix();
485 
486  // Show Lock icon depending of the Edit mode
487  myBlockIcon.draw();
488  }
489 
490  // Draw name if isn't being drawn for selecting
491  if (!s.drawForSelecting) {
492  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
493  }
494  // check if dotted contour has to be drawn
495  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
496  if(myGeometry.shape.size() > 0) {
498  } else {
500  }
501  }
502  // Pop name
503  glPopName();
504 }
505 
506 
507 std::string
509  switch (key) {
510  case SUMO_ATTR_ID:
511  return getAdditionalID();
512  case SUMO_ATTR_LANE:
513  case SUMO_ATTR_LANES:
514  return parseIDs(myLanes);
515  case SUMO_ATTR_POSITION:
517  case SUMO_ATTR_ENDPOS:
519  case SUMO_ATTR_FREQUENCY:
520  return toString(myFreq);
521  case SUMO_ATTR_LENGTH:
522  return toString(myLength);
523  case SUMO_ATTR_NAME:
524  return myAdditionalName;
525  case SUMO_ATTR_FILE:
526  return myFilename;
527  case SUMO_ATTR_VTYPES:
528  return myVehicleTypes;
530  return toString(myTimeThreshold);
532  return toString(mySpeedThreshold);
534  return toString(myJamThreshold);
538  return toString(myBlockMovement);
539  case GNE_ATTR_SELECTED:
541  case GNE_ATTR_GENERIC:
542  return getGenericParametersStr();
543  default:
544  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
545  }
546 }
547 
548 
549 void
550 GNEDetectorE2::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
551  if (value == getAttribute(key)) {
552  return; //avoid needless changes, later logic relies on the fact that attributes have changed
553  }
554  switch (key) {
555  case SUMO_ATTR_ID:
556  case SUMO_ATTR_LANE:
557  case SUMO_ATTR_LANES:
558  case SUMO_ATTR_POSITION:
559  case SUMO_ATTR_ENDPOS:
560  case SUMO_ATTR_FREQUENCY:
561  case SUMO_ATTR_LENGTH:
562  case SUMO_ATTR_NAME:
563  case SUMO_ATTR_FILE:
564  case SUMO_ATTR_VTYPES:
570  case GNE_ATTR_SELECTED:
571  case GNE_ATTR_GENERIC:
572  undoList->p_add(new GNEChange_Attribute(this, key, value));
573  break;
574  default:
575  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
576  }
577 }
578 
579 
580 bool
581 GNEDetectorE2::isValid(SumoXMLAttr key, const std::string& value) {
582  switch (key) {
583  case SUMO_ATTR_ID:
584  return isValidDetectorID(value);
585  case SUMO_ATTR_LANE:
586  if (value.empty()) {
587  return false;
588  } else {
589  return canParse<std::vector<GNELane*> >(myViewNet->getNet(), value, false);
590  }
591  case SUMO_ATTR_LANES:
592  if (value.empty()) {
593  return false;
594  } else if (canParse<std::vector<GNELane*> >(myViewNet->getNet(), value, false)) {
595  // check if lanes are consecutives
596  return lanesConsecutives(parse<std::vector<GNELane*> >(myViewNet->getNet(), value));
597  } else {
598  return false;
599  }
600  case SUMO_ATTR_POSITION:
601  return canParse<double>(value);
602  case SUMO_ATTR_ENDPOS:
603  return canParse<double>(value);
604  case SUMO_ATTR_FREQUENCY:
605  return (canParse<double>(value) && (parse<double>(value) >= 0));
606  case SUMO_ATTR_LENGTH:
607  return (canParse<double>(value) && (parse<double>(value) >= 0));
608  case SUMO_ATTR_NAME:
610  case SUMO_ATTR_FILE:
612  case SUMO_ATTR_VTYPES:
613  if (value.empty()) {
614  return true;
615  } else {
617  }
619  return (canParse<double>(value) && (parse<double>(value) >= 0));
621  return (canParse<double>(value) && (parse<double>(value) >= 0));
623  return (canParse<double>(value) && (parse<double>(value) >= 0));
625  return canParse<bool>(value);
627  return canParse<bool>(value);
628  case GNE_ATTR_SELECTED:
629  return canParse<bool>(value);
630  case GNE_ATTR_GENERIC:
631  return isGenericParametersValid(value);
632  default:
633  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
634  }
635 }
636 
637 // ===========================================================================
638 // private
639 // ===========================================================================
640 
641 void
642 GNEDetectorE2::setAttribute(SumoXMLAttr key, const std::string& value) {
643  switch (key) {
644  case SUMO_ATTR_ID:
645  changeAdditionalID(value);
646  break;
647  case SUMO_ATTR_LANE:
648  case SUMO_ATTR_LANES:
649  myLanes = parse<std::vector<GNELane*> >(myViewNet->getNet(), value);
651  break;
652  case SUMO_ATTR_POSITION:
653  myPositionOverLane = parse<double>(value);
654  break;
655  case SUMO_ATTR_ENDPOS:
656  myEndPositionOverLane = parse<double>(value);
657  break;
658  case SUMO_ATTR_FREQUENCY:
659  myFreq = parse<double>(value);
660  break;
661  case SUMO_ATTR_LENGTH:
662  myLength = parse<double>(value);
663  break;
664  case SUMO_ATTR_NAME:
665  myAdditionalName = value;
666  break;
667  case SUMO_ATTR_FILE:
668  myFilename = value;
669  break;
670  case SUMO_ATTR_VTYPES:
671  myVehicleTypes = value;
672  break;
674  myTimeThreshold = parse<double>(value);
675  break;
677  mySpeedThreshold = parse<double>(value);
678  break;
680  myJamThreshold = parse<double>(value);
681  break;
683  myFriendlyPosition = parse<bool>(value);
684  break;
686  myBlockMovement = parse<bool>(value);
687  break;
688  case GNE_ATTR_SELECTED:
689  if (parse<bool>(value)) {
691  } else {
693  }
694  break;
695  case GNE_ATTR_GENERIC:
697  break;
698  default:
699  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
700  }
701  // Update Geometry after setting a new attribute (but avoided for certain attributes)
702  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
703  updateGeometry(true);
704  }
705 }
706 
707 /****************************************************************************/
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:160
double scale
information about a lane&#39;s width (temporary, used for a single view)
PositionVector multiShapeUnified
multi shape unified
void calculateMultiShapeRotationsAndLengths()
calculate multi shape rotations and lenghts
static bool checkAndFixDetectorPosition(double &pos, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
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:178
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren&#39;t allowed) ...
GUIVisualizationTextSettings addName
std::vector< double > shapeRotations
The rotations of the single shape parts.
GNELane * getLane() const
get lane
a E2 detector
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
const std::string & getAdditionalID() const
returns Additional ID
std::string secondOriginalPosition
value for saving second original position over lane before moving
an e2 detector over multiple lanes (used by Netedit)
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
std::vector< GNELane * > myLanes
E2 lanes (Single lanes uses only the first lane)
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
double x() const
Returns the x-position.
Definition: Position.h:57
double myFreq
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:154
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
void clearGeometry()
reset geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Position originalViewPosition
value for saving first original position over lane before moving
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:73
double myEndPositionOverLane
end position over lane (only for Multilane E2 detectors)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static const RGBColor BLACK
Definition: RGBColor.h:192
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getLineCenter() const
get line center
double rotation
The rotation of the block icon.
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
static const RGBColor SUMO_color_E2
color for E2 detectors
~GNEDetectorE2()
Destructor.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
std::vector< std::vector< double > > multiShapeRotations
The rotations of the multi-shape parts.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting...
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
GNEUndoList * getUndoList() const
get the undoList object
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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:80
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
static bool lanesConsecutives(const std::vector< GNELane *> &lanes)
check if lanes are consecutives
A list of positions.
std::string myAdditionalName
name of additional
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (by default true, can be reimplemented in ...
void checkE2MultilaneIntegrity()
check if E2 is valid (all of their lanes are connected, it must called after every operation which in...
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
RGBColor selectionColor
NETEDIT special colors.
std::string myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:160
std::vector< std::vector< double > > multiShapeLengths
The lengths of the multi-shape shape parts.
bool myE2valid
flag to check if E2 multilane is valid or invalid
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
double myLength
E2 detector length.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
std::vector< PositionVector > multiShape
The multi-shape of the additional element (used by certain additionals)
GNEDetectorE2(const std::string &id, GNELane *lane, GNEViewNet *viewNet, double pos, double length, double freq, const std::string &filename, const std::string &vehicleTypes, const std::string &name, const double timeThreshold, double speedThreshold, double jamThreshold, bool friendlyPos, bool blockMovement)
Constructor for Single-Lane E2 detectors.
void fixAdditionalProblem()
fix additional problem
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:163
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:157
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
void calculateShapeRotationsAndLengths()
calculate shape rotations and lenghts
std::string getAttribute(SumoXMLAttr key) const
std::vector< double > shapeLengths
The lengths of the single shape parts.
double getLength() const
get length of E2 Detector
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
static const RGBColor RED
named colors
Definition: RGBColor.h:184
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
bool showConnections()
show connections over junctions
Definition: GNEViewNet.cpp:749
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
const std::string & getTagStr() const
get tag assigned to this object in string format
element is selected
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
double myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
double myJamThreshold
The minimum distance to the next standing vehicle in order to make this vehicle count as a participan...
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
static bool fixE2DetectorPosition(double &pos, double &length, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
std::string getAdditionalProblem() const
return a string with the current additional problem
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc.)
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:151
void draw(double size=0.5) const
draw lock icon
void calculateMultiShapeUnified()
calculate multi shape unified