Eclipse SUMO - Simulation of Urban MObility
GNELaneAreaDetector.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-2022 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//
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEUndoList.h>
23#include <netedit/GNEViewNet.h>
32
33#include "GNELaneAreaDetector.h"
35
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
42 GNEDetector("", net, GLO_E2DETECTOR, tag, GUIIconSubSys::getIcon(GUIIcon::E2),
43 0, 0, {}, "", {}, "", false, Parameterised::Map()),
44 myEndPositionOverLane(0),
45 myTimeThreshold(0),
46 mySpeedThreshold(0),
47myJamThreshold(0) {
48 // reset default values
49 resetDefaultValues();
50}
51
52
53GNELaneAreaDetector::GNELaneAreaDetector(const std::string& id, GNELane* lane, GNENet* net, double pos, double length, const SUMOTime freq,
54 const std::string& trafficLight, const std::string& filename, const std::vector<std::string>& vehicleTypes, const std::string& name,
55 SUMOTime timeThreshold, double speedThreshold, double jamThreshold, bool friendlyPos, const Parameterised::Map& parameters) :
57 pos, freq, {
58 lane
59}, filename, vehicleTypes, name, friendlyPos, parameters),
60myEndPositionOverLane(pos + length),
61myTimeThreshold(timeThreshold),
62mySpeedThreshold(speedThreshold),
63myJamThreshold(jamThreshold),
64myTrafficLight(trafficLight) {
65 // update centering boundary without updating grid
66 updateCenteringBoundary(false);
67}
68
69
70GNELaneAreaDetector::GNELaneAreaDetector(const std::string& id, std::vector<GNELane*> lanes, GNENet* net, double pos, double endPos, const SUMOTime freq,
71 const std::string& trafficLight, const std::string& filename, const std::vector<std::string>& vehicleTypes, const std::string& name, SUMOTime timeThreshold,
72 double speedThreshold, double jamThreshold, bool friendlyPos, const Parameterised::Map& parameters) :
74 pos, freq, lanes, filename, vehicleTypes, name, friendlyPos, parameters),
75 myEndPositionOverLane(endPos),
76 myTimeThreshold(timeThreshold),
77 mySpeedThreshold(speedThreshold),
78 myJamThreshold(jamThreshold),
79 myTrafficLight(trafficLight) {
80 // update centering boundary without updating grid
82}
83
84
86}
87
88
89void
92 device.writeAttr(SUMO_ATTR_ID, getID());
93 if (!myAdditionalName.empty()) {
95 }
96 // continue depending of E2 type
98 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
101 } else {
105 }
106 if (myTrafficLight.size() > 0) {
108 }
109 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
111 }
112 if (myFilename.size() > 0) {
114 }
115 if (myVehicleTypes.size() > 0) {
117 }
120 }
123 }
126 }
127 if (myFriendlyPosition) {
128 device.writeAttr(SUMO_ATTR_FRIENDLY_POS, true);
129 }
130 // write parameters (Always after children to avoid problems with additionals.xsd)
131 writeParams(device);
132 device.closeTag();
133}
134
135
136bool
138 if (getParentLanes().size() == 1) {
139 // with friendly position enabled position are "always fixed"
140 if (myFriendlyPosition) {
141 return true;
142 } else {
143 return (myPositionOverLane >= 0) && (myEndPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
144 }
145 } else {
146 // first check if there is connection between all consecutive lanes
148 // with friendly position enabled position are "always fixed"
149 if (myFriendlyPosition) {
150 return true;
151 } else {
152 return (myPositionOverLane >= 0) &&
153 (myEndPositionOverLane >= 0) &&
154 (myPositionOverLane <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) &&
155 (myEndPositionOverLane <= getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength());
156 }
157 } else {
158 return false;
159 }
160 }
161}
162
163
164std::string
166 // declare variable for error position
167 std::string errorFirstLanePosition, separator, errorLastLanePosition;
168 if (getParentLanes().size() == 1) {
169 // check positions over lane
170 if (myPositionOverLane < 0) {
171 errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " < 0");
172 }
173 if (myPositionOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
174 errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
175 }
176 } else {
177 // abort if lanes aren't consecutives
179 return "lanes aren't consecutives";
180 }
181 // abort if lanes aren't connected
183 return "lanes aren't connected";
184 }
185 // check positions over first lane
186 if (myPositionOverLane < 0) {
187 errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " < 0");
188 }
189 if (myPositionOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
190 errorFirstLanePosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
191 }
192 // check positions over last lane
193 if (myEndPositionOverLane < 0) {
194 errorLastLanePosition = (toString(SUMO_ATTR_ENDPOS) + " < 0");
195 }
196 if (myEndPositionOverLane > getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength()) {
197 errorLastLanePosition = (toString(SUMO_ATTR_ENDPOS) + " > lanes's length");
198 }
199 }
200 // check separator
201 if ((errorFirstLanePosition.size() > 0) && (errorLastLanePosition.size() > 0)) {
202 separator = " and ";
203 }
204 // return error message
205 return errorFirstLanePosition + separator + errorLastLanePosition;
206}
207
208
209void
211 if (getParentLanes().size() == 1) {
212 // obtain position and length
213 double newPositionOverLane = myPositionOverLane;
214 double newLength = (myEndPositionOverLane - myPositionOverLane);
215 // fix pos and length using fixE2DetectorPosition
216 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, newLength, getParentLanes().at(0)->getParentEdge()->getNBEdge()->getFinalLength());
217 // set new position and length
220 } else {
222 // build connections between all consecutive lanes
223 bool foundConnection = true;
224 int i = 0;
225 // iterate over all lanes, and stop if myE2valid is false
226 while (i < ((int)getParentLanes().size() - 1)) {
227 // change foundConnection to false
228 foundConnection = false;
229 // if a connection betwen "from" lane and "to" lane of connection is found, change myE2valid to true again
230 for (const auto& connection : getParentLanes().at(i)->getParentEdge()->getGNEConnections()) {
231 if ((connection->getLaneFrom() == getParentLanes().at(i)) && (connection->getLaneTo() == getParentLanes().at(i + 1))) {
232 foundConnection = true;
233 }
234 }
235 // if connection wasn't found
236 if (!foundConnection) {
237 // create new connection manually
238 NBEdge::Connection newCon(getParentLanes().at(i)->getIndex(), getParentLanes().at(i + 1)->getParentEdge()->getNBEdge(), getParentLanes().at(i + 1)->getIndex());
239 // allow to undo creation of new lane
240 myNet->getViewNet()->getUndoList()->add(new GNEChange_Connection(getParentLanes().at(i)->getParentEdge(), newCon, false, true), true);
241 }
242 // update lane iterator
243 i++;
244 }
245 } else {
246 // declare new positions
247 double newPositionOverLane = myPositionOverLane;
248 double newEndPositionOverLane = myEndPositionOverLane;
249 // fix pos and length checkAndFixDetectorPosition
251 newPositionOverLane, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(),
252 newEndPositionOverLane, getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength());
253 // set new position and endPosition
255 setAttribute(SUMO_ATTR_ENDPOS, toString(newEndPositionOverLane), myNet->getViewNet()->getUndoList());
256 }
257 }
258}
259
260
261void
263 // check E2 detector
265 // compute path
267 } else {
268 // Cut shape using as delimitators fixed start position and fixed end position
270 // update centering boundary without updating grid
272 }
273}
274
275
276void
278 // check if additional has to be drawn
281 // Obtain exaggeration of the draw
282 const double E2Exaggeration = getExaggeration(s);
283 // check exaggeration
284 if (s.drawAdditionals(E2Exaggeration)) {
285 // declare color
286 RGBColor E2Color, textColor;
287 // set color
288 if (drawUsingSelectColor()) {
290 textColor = E2Color.changedBrightness(-32);
291 } else if (areLaneConsecutives(getParentLanes())) {
292 E2Color = s.detectorSettings.E2Color;
293 textColor = RGBColor::BLACK;
294 }
295 // draw parent and child lines
297 // Start drawing adding an gl identificator
299 // push layer matrix
301 // translate to front
303 // set color
304 GLHelper::setColor(E2Color);
305 // draw geometry
307 // Check if the distance is enought to draw details
308 if (s.drawDetail(s.detailSettings.detectorDetails, E2Exaggeration)) {
309 // draw E2 Logo
310 drawDetectorLogo(s, E2Exaggeration, "E2", textColor);
311 }
312 // draw geometry points
315 // pop layer matrix
317 // Pop name
319 // draw lock icon
321 // check if mouse is over element
323 // inspect contour
326 E2Exaggeration, true, true);
327 }
328 // front element contour
329 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
331 E2Exaggeration, true, true);
332 }
333 // delete contour
334 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
336 E2Exaggeration, true, true);
337 }
338 // select contour
339 if (myNet->getViewNet()->drawSelectContour(this, this)) {
341 E2Exaggeration, true, true);
342 }
343 }
344 // Draw additional ID
346 // draw additional name
348 }
349}
350
351
352void
354 // calculate path
356}
357
358
359void
360GNELaneAreaDetector::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const GNEPathManager::Segment* segment, const double offsetFront) const {
361 // calculate E2Detector width
362 const double E2DetectorWidth = s.addSize.getExaggeration(s, lane);
363 // check if E2 can be drawn
364 if (s.drawAdditionals(E2DetectorWidth) && myNet->getViewNet()->getDataViewOptions().showAdditionals() &&
366 // calculate startPos
367 const double geometryDepartPos = getAttributeDouble(SUMO_ATTR_POSITION);
368 // get endPos
369 const double geometryEndPos = getAttributeDouble(SUMO_ATTR_ENDPOS);
370 // declare path geometry
371 GUIGeometry E2Geometry;
372 // update pathGeometry depending of first and last segment
373 if (segment->isFirstSegment() && segment->isLastSegment()) {
374 E2Geometry.updateGeometry(lane->getLaneGeometry().getShape(),
375 geometryDepartPos, geometryEndPos, // extrem positions
376 Position::INVALID, Position::INVALID); // extra positions
377 } else if (segment->isFirstSegment()) {
378 E2Geometry.updateGeometry(lane->getLaneGeometry().getShape(),
379 geometryDepartPos, -1, // extrem positions
380 Position::INVALID, Position::INVALID); // extra positions
381 } else if (segment->isLastSegment()) {
382 E2Geometry.updateGeometry(lane->getLaneGeometry().getShape(),
383 -1, geometryEndPos, // extrem positions
384 Position::INVALID, Position::INVALID); // extra positions
385 } else {
386 E2Geometry = lane->getLaneGeometry();
387 }
388 // obtain color
390 // Start drawing adding an gl identificator
392 // push layer matrix
394 // Start with the drawing of the area traslating matrix to origin
395 glTranslated(0, 0, getType() + offsetFront);
396 // Set color
397 GLHelper::setColor(E2Color);
398 // draw geometry
399 GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), E2Geometry, E2DetectorWidth);
400 // draw geometry points
401 if (segment->isFirstSegment() && segment->isLastSegment()) {
402 drawLeftGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().front(), E2Geometry.getShapeRotations().front(), E2Color, true);
403 drawRightGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().back(), E2Geometry.getShapeRotations().back(), E2Color, true);
404 } else if (segment->isFirstSegment()) {
405 drawLeftGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().front(), E2Geometry.getShapeRotations().front(), E2Color, true);
406 } else if (segment->isLastSegment()) {
407 drawRightGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().back(), E2Geometry.getShapeRotations().back(), E2Color, true);
408 }
409 // Pop layer matrix
411 // Pop name
413 // draw additional ID
415 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
416 // check if this is the label segment
417 if (segment->isLabelSegment()) {
418 // calculate middle point
419 const double middlePoint = (E2Geometry.getShape().length2D() * 0.5);
420 // calculate position
421 const Position pos = E2Geometry.getShape().positionAtOffset2D(middlePoint);
422 // calculate rotation
423 const double rot = E2Geometry.getShape().rotationDegreeAtOffset(middlePoint);
424 // Start pushing matrix
426 // Traslate to position
427 glTranslated(pos.x(), pos.y(), getType() + offsetFront + 0.1);
428 // rotate over lane
430 // move
431 glTranslated(-1, 0, 0);
432 // scale text
433 glScaled(E2DetectorWidth, E2DetectorWidth, 1);
434 // draw E1 logo
435 GLHelper::drawText("E2 Multilane", Position(), .1, 1.5, RGBColor::BLACK);
436 // pop matrix
438 }
439 }
440 // declare trim geometry to draw
441 const auto shape = (segment->isFirstSegment() || segment->isLastSegment()) ? E2Geometry.getShape() : lane->getLaneShape();
442 // check if mouse is over element
444 // inspect contour
447 }
448 // dotted contour
449 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
451 }
452 // delete contour
453 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
455 }
456 // select contour
457 if (myNet->getViewNet()->drawSelectContour(this, this)) {
459 }
460 }
461}
462
463
464void
465GNELaneAreaDetector::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* fromLane, const GNELane* toLane, const GNEPathManager::Segment* /*segment*/, const double offsetFront) const {
466 // calculate E2Detector width
467 const double E2DetectorWidth = s.addSize.getExaggeration(s, fromLane);
468 // check if E2 can be drawn
470 // get flag for show only contour
472 // Start drawing adding an gl identificator
474 // Add a draw matrix
476 // Start with the drawing of the area traslating matrix to origin
477 glTranslated(0, 0, getType() + offsetFront);
478 // Set color of the base
479 if (drawUsingSelectColor()) {
481 } else {
483 }
484 // draw lane2lane
485 if (fromLane->getLane2laneConnections().exist(toLane)) {
486 // check if draw only contour
487 if (onlyContour) {
489 } else {
491 }
492 } else {
493 // Set invalid person plan color
495 // calculate invalid geometry
496 const GUIGeometry invalidGeometry({fromLane->getLaneShape().back(), toLane->getLaneShape().front()});
497 // check if draw only contour
498 if (onlyContour) {
499 GUIGeometry::drawContourGeometry(invalidGeometry, (0.5 * E2DetectorWidth));
500 } else {
501 // draw invalid geometry
502 GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), invalidGeometry, (0.5 * E2DetectorWidth));
503 }
504 }
505 // Pop last matrix
507 // Pop name
509 // continue with dotted contours
510 if (fromLane->getLane2laneConnections().exist(toLane)) {
511 // check if mouse is over element
513 // inspect contour
516 E2DetectorWidth, 1, false, false);
517 }
518 // front contour
519 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
521 E2DetectorWidth, 1, false, false);
522 }
523 // delete contour
524 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
526 E2DetectorWidth, 1, false, false);
527 }
528 // select contour
529 if (myNet->getViewNet()->drawSelectContour(this, this)) {
531 E2DetectorWidth, 1, false, false);
532 }
533 }
534 }
535}
536
537
538std::string
540 switch (key) {
541 case SUMO_ATTR_ID:
542 return getMicrosimID();
543 case SUMO_ATTR_LANE:
544 case SUMO_ATTR_LANES:
545 return parseIDs(getParentLanes());
549 case SUMO_ATTR_ENDPOS:
551 case SUMO_ATTR_PERIOD:
553 return "";
554 } else {
555 return time2string(myPeriod);
556 }
557 case SUMO_ATTR_TLID:
558 return myTrafficLight;
559 case SUMO_ATTR_LENGTH:
561 case SUMO_ATTR_NAME:
562 return myAdditionalName;
563 case SUMO_ATTR_FILE:
564 return myFilename;
565 case SUMO_ATTR_VTYPES:
566 return toString(myVehicleTypes);
572 return toString(myJamThreshold);
578 return getParametersStr();
580 return "";
581 default:
582 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
583 }
584}
585
586
587double
589 switch (key) {
591 return myPositionOverLane;
592 case SUMO_ATTR_LENGTH:
594 case SUMO_ATTR_ENDPOS:
596 default:
597 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
598 }
599}
600
601
602void
603GNELaneAreaDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
604 switch (key) {
605 case SUMO_ATTR_ID:
606 case SUMO_ATTR_LANE:
607 case SUMO_ATTR_LANES:
609 case SUMO_ATTR_ENDPOS:
610 case SUMO_ATTR_PERIOD:
611 case SUMO_ATTR_TLID:
612 case SUMO_ATTR_LENGTH:
613 case SUMO_ATTR_NAME:
614 case SUMO_ATTR_FILE:
615 case SUMO_ATTR_VTYPES:
623 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
624 break;
625 default:
626 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
627 }
628}
629
630
631bool
632GNELaneAreaDetector::isValid(SumoXMLAttr key, const std::string& value) {
633 switch (key) {
634 case SUMO_ATTR_ID:
635 if (value == getID()) {
636 return true;
637 } else if (isValidDetectorID(value)) {
638 return (myNet->getAttributeCarriers()->retrieveAdditional(GNE_TAG_MULTI_LANE_AREA_DETECTOR, value, false) == nullptr) &&
640 } else {
641 return false;
642 }
643 case SUMO_ATTR_LANE:
644 if (value.empty()) {
645 return false;
646 } else {
647 return canParse<std::vector<GNELane*> >(myNet, value, false);
648 }
649 case SUMO_ATTR_LANES:
650 if (value.empty()) {
651 return false;
652 } else if (canParse<std::vector<GNELane*> >(myNet, value, false)) {
653 // check if lanes are consecutives
654 return lanesConsecutives(parse<std::vector<GNELane*> >(myNet, value));
655 } else {
656 return false;
657 }
659 return canParse<double>(value);
660 case SUMO_ATTR_ENDPOS:
661 return canParse<double>(value);
662 case SUMO_ATTR_PERIOD:
663 if (value.empty()) {
664 return true;
665 } else {
666 return (canParse<double>(value) && (parse<double>(value) >= 0));
667 }
668 case SUMO_ATTR_TLID:
669 // temporal
671 case SUMO_ATTR_LENGTH:
672 return (canParse<double>(value) && (parse<double>(value) >= 0));
673 case SUMO_ATTR_NAME:
675 case SUMO_ATTR_FILE:
677 case SUMO_ATTR_VTYPES:
678 if (value.empty()) {
679 return true;
680 } else {
682 }
684 return canParse<SUMOTime>(value);
686 return (canParse<double>(value) && (parse<double>(value) >= 0));
688 return (canParse<double>(value) && (parse<double>(value) >= 0));
690 return canParse<bool>(value);
692 return canParse<bool>(value);
694 return areParametersValid(value);
695 default:
696 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
697 }
698}
699
700// ===========================================================================
701// private
702// ===========================================================================
703
704void
705GNELaneAreaDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
706 switch (key) {
707 case SUMO_ATTR_ID:
708 // update microsimID
709 setMicrosimID(value);
710 break;
711 case SUMO_ATTR_LANE:
712 case SUMO_ATTR_LANES:
714 break;
716 myPositionOverLane = parse<double>(value);
717 // update geometry (except for template)
718 if (getParentLanes().size() > 0) {
720 }
721 break;
722 case SUMO_ATTR_ENDPOS:
723 myEndPositionOverLane = parse<double>(value);
724 // update geometry (except for template)
725 if (getParentLanes().size() > 0) {
727 }
728 break;
729 case SUMO_ATTR_PERIOD:
730 if (value.empty()) {
732 } else {
733 myPeriod = string2time(value);
734 }
735 break;
736 case SUMO_ATTR_TLID:
737 myTrafficLight = value;
738 break;
739 case SUMO_ATTR_LENGTH:
740 myEndPositionOverLane = (myPositionOverLane + parse<double>(value));
741 // update geometry (except for template)
742 if (getParentLanes().size() > 0) {
744 }
745 break;
746 case SUMO_ATTR_NAME:
747 myAdditionalName = value;
748 break;
749 case SUMO_ATTR_FILE:
750 myFilename = value;
751 break;
752 case SUMO_ATTR_VTYPES:
753 myVehicleTypes = parse<std::vector<std::string> >(value);
754 break;
756 myTimeThreshold = TIME2STEPS(parse<double>(value));
757 break;
759 mySpeedThreshold = parse<double>(value);
760 break;
762 myJamThreshold = parse<double>(value);
763 break;
765 myFriendlyPosition = parse<bool>(value);
766 break;
768 if (parse<bool>(value)) {
770 } else {
772 }
773 break;
775 setParametersStr(value);
776 break;
779 break;
780 default:
781 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
782 }
783}
784
785
786void
790 // change only start position
791 myPositionOverLane = moveResult.newFirstPos;
794 // change only end position
796 } else {
797 // change both position
798 myPositionOverLane = moveResult.newFirstPos;
800 }
801 // update geometry
803}
804
805
806void
808 // begin change attribute
809 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
810 // set attributes depending of operation type
813 // set only start position
814 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
817 // set only end position
818 setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newFirstPos), undoList);
819 } else {
820 // set both positions
821 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
822 setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newSecondPos), undoList);
823 }
824 // end change attribute
825 undoList->end();
826}
827
828
829double
831 // get lane final and shape length
832 const double laneLength = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
833 // get startPosition
834 double fixedPos = myPositionOverLane;
835 // adjust fixedPos
836 if (fixedPos < 0) {
837 fixedPos += laneLength;
838 }
839 fixedPos *= getParentLanes().front()->getLengthGeometryFactor();
840 // return depending of fixedPos
841 if (fixedPos < 0) {
842 return 0;
843 } else if (fixedPos > (getParentLanes().front()->getLaneShapeLength() - POSITION_EPS)) {
844 return (getParentLanes().front()->getLaneShapeLength() - POSITION_EPS);
845 } else {
846 return fixedPos;
847 }
848}
849
850
851double
853 // get lane final and shape length
854 const double laneLength = getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength();
855 // get endPosition
856 double fixedPos = myEndPositionOverLane;
857 // adjust fixedPos
858 if (fixedPos < 0) {
859 fixedPos += laneLength;
860 }
861 fixedPos *= getParentLanes().back()->getLengthGeometryFactor();
862 // return depending of fixedPos
863 if (fixedPos < POSITION_EPS) {
864 return POSITION_EPS;
865 } else if (fixedPos > getParentLanes().back()->getLaneShapeLength()) {
866 return getParentLanes().back()->getLaneShapeLength();
867 } else {
868 return fixedPos;
869 }
870}
871
872/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ GLO_E2DETECTOR
a E2 detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define SUMOTime_MAX_PERIOD
Definition: SUMOTime.h:35
#define TIME2STEPS(x)
Definition: SUMOTime.h:56
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_MULTI_LANE_AREA_DETECTOR
an e2 detector over multiple lanes (placed here due create Additional Frame)
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LANE
@ SUMO_ATTR_FILE
@ SUMO_ATTR_JAM_DIST_THRESHOLD
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_LANES
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_TLID
link,node: the traffic light id responsible for this link
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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, const int align=0, double width=-1)
Definition: GLHelper.cpp:685
static void fixMultiLanePosition(double fromPos, const double fromLaneLength, double toPos, const double tolaneLength)
fix the given positions over two lanes
static void fixLanePosition(double &pos, double &length, const double laneLength)
fix given position over lane
static bool areLaneConnected(const std::vector< GNELane * > &lanes)
check if the given lanes are connected
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw right geometry point
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
static bool areLaneConsecutives(const std::vector< GNELane * > &lanes)
check if the given lanes are consecutive
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw left geometry point
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
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 (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
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.
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
static bool lanesConsecutives(const std::vector< GNELane * > &lanes)
check if lanes are consecutives
GNENet * myNet
pointer to net
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
SUMOTime myPeriod
The aggregation period the values the detector collects shall be summed up.
Definition: GNEDetector.h:175
std::string myFilename
The path to the output file.
Definition: GNEDetector.h:178
double myPositionOverLane
position of detector over Lane
Definition: GNEDetector.h:172
bool myFriendlyPosition
Flag for friendly position.
Definition: GNEDetector.h:184
void drawDetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw detector Logo
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::vector< std::string > myVehicleTypes
attribute vehicle types
Definition: GNEDetector.h:181
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
bool exist(const GNELane *toLane) const
check if exist a lane2lane geometry for the given toLane
const GUIGeometry & getLane2laneGeometry(const GNELane *toLane) const
get lane2lane geometry
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object (lane)
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void updateGeometry()
update pre-computed geometry information
double getAttributeDouble(SumoXMLAttr key) const
void fixAdditionalProblem()
fix additional problem
std::string getAttribute(SumoXMLAttr key) const
double myJamThreshold
The minimum distance to the next standing vehicle in order to make this vehicle count as a participan...
std::string myTrafficLight
Traffic light vinculated with this E2 Detector.
~GNELaneAreaDetector()
Destructor.
double myEndPositionOverLane
end position over lane (only for Multilane E2 detectors)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double getStartGeometryPositionOverLane() const
get start position over lane that is applicable to the shape
bool isAdditionalValid() const
check if current additional is valid to be writed into XML
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GNELaneAreaDetector(SumoXMLTag tag, GNENet *net)
default Constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting.
std::string getAdditionalProblem() const
return a string with the current additional problem
double getEndGeometryPositionOverLane() const
get end position over lane that is applicable to the shape
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
void computePathElement()
compute pathElement
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
const PositionVector & getLaneShape() const
get elements shape
Definition: GNELane.cpp:142
const GNELane2laneConnection & getLane2laneConnections() const
get Lane2laneConnection struct
Definition: GNELane.cpp:917
const GUIGeometry & getLaneGeometry() const
Definition: GNELane.cpp:136
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
move result
double newFirstPos
new first position
const GNEMoveOperation::OperationType operationType
move operation
double newSecondPos
new second position
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:138
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
bool isLabelSegment() const
check if segment is label segment
bool isLastSegment() const
check if segment is the last path's segment
bool isFirstSegment() const
check if segment is the first path's segment
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > lanes)
calculate consecutive path lanes
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:644
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
Definition: GNEViewNet.cpp:874
static void drawDottedContourShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double width, const double exaggeration, const bool drawFirstExtrem, const bool drawLastExtrem)
draw dotted contour for the given shape (used by additionals)
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings &s, const Position &mousePos, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
static void drawContourGeometry(const GUIGeometry &geometry, const double width, const bool drawExtremes=false)
draw contour geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GUIGeometry.cpp:58
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color 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...
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
GUIVisualizationDetectorSettings detectorSettings
Detector settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:298
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
double length2D() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
static const RGBColor BLACK
Definition: RGBColor.h:193
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
static const RGBColor RED
named colors
Definition: RGBColor.h:185
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
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't allowed)
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showAdditionals() const
check if additionals has to be drawn
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
bool showConnections() const
check if select show connections checkbox is enabled
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double detectorDetails
details for detectors
static const RGBColor E2Color
color for E2 detectors
static const double E2Width
E2 detector widths.
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:201