Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNELaneAreaDetector.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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
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) + TL(" > lanes's length"));
175 }
176 } else {
177 // abort if lanes aren't consecutives
179 return TL("lanes aren't consecutives");
180 }
181 // abort if lanes aren't connected
183 return TL("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) + TL(" > 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) + TL(" > lanes's length"));
198 }
199 }
200 // check separator
201 if ((errorFirstLanePosition.size() > 0) && (errorLastLanePosition.size() > 0)) {
202 separator = TL(" 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 // avoid draw invisible elements
296 if (E2Color.alpha() != 0) {
297 // draw parent and child lines
299 // Start drawing adding an gl identificator
301 // push layer matrix
303 // translate to front
305 // set color
306 GLHelper::setColor(E2Color);
307 // draw geometry
309 // arrow
310 if (myAdditionalGeometry.getShape().size() > 1) {
311 glTranslated(0, 0, 0.1);
313 }
314 // Check if the distance is enought to draw details
315 if (s.drawDetail(s.detailSettings.detectorDetails, E2Exaggeration)) {
316 // draw E2 Logo
317 drawE2DetectorLogo(s, E2Exaggeration, "E2", textColor);
318 }
319 // draw geometry points
322 // pop layer matrix
324 // Pop name
326 // draw lock icon
328 }
329 // check if mouse is over element
331 // inspect contour
334 E2Exaggeration, true, true);
335 }
336 // front element contour
337 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
339 E2Exaggeration, true, true);
340 }
341 // delete contour
342 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
344 E2Exaggeration, true, true);
345 }
346 // select contour
347 if (myNet->getViewNet()->drawSelectContour(this, this)) {
349 E2Exaggeration, true, true);
350 }
351 }
352 // Draw additional ID
354 // draw additional name
356 }
357}
358
359
360void
365
366
367void
368GNELaneAreaDetector::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const GNEPathManager::Segment* segment, const double offsetFront) const {
369 // calculate E2Detector width
370 const double E2DetectorWidth = s.addSize.getExaggeration(s, lane);
371 // check if E2 can be drawn
372 if ((myTagProperty.getTag() == GNE_TAG_MULTI_LANE_AREA_DETECTOR) && s.drawAdditionals(E2DetectorWidth) &&
374 // calculate startPos
375 const double geometryDepartPos = getAttributeDouble(SUMO_ATTR_POSITION);
376 // get endPos
377 const double geometryEndPos = getAttributeDouble(SUMO_ATTR_ENDPOS);
378 // declare path geometry
379 GUIGeometry E2Geometry;
380 // update pathGeometry depending of first and last segment
381 if (segment->isFirstSegment() && segment->isLastSegment()) {
382 E2Geometry.updateGeometry(lane->getLaneGeometry().getShape(),
383 geometryDepartPos, geometryEndPos, // extrem positions
384 Position::INVALID, Position::INVALID); // extra positions
385 } else if (segment->isFirstSegment()) {
386 E2Geometry.updateGeometry(lane->getLaneGeometry().getShape(),
387 geometryDepartPos, -1, // extrem positions
388 Position::INVALID, Position::INVALID); // extra positions
389 } else if (segment->isLastSegment()) {
390 E2Geometry.updateGeometry(lane->getLaneGeometry().getShape(),
391 -1, geometryEndPos, // extrem positions
392 Position::INVALID, Position::INVALID); // extra positions
393 } else {
394 E2Geometry = lane->getLaneGeometry();
395 }
396 // obtain color
398 // Start drawing adding an gl identificator
400 // push layer matrix
402 // Start with the drawing of the area traslating matrix to origin
403 glTranslated(0, 0, getType() + offsetFront);
404 // Set color
405 GLHelper::setColor(E2Color);
406 // draw geometry
407 GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), E2Geometry, E2DetectorWidth);
408 // draw geometry points
409 if (segment->isFirstSegment() && segment->isLastSegment()) {
410 drawLeftGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().front(), E2Geometry.getShapeRotations().front(), E2Color, true);
411 drawRightGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().back(), E2Geometry.getShapeRotations().back(), E2Color, true);
412 } else if (segment->isFirstSegment()) {
413 drawLeftGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().front(), E2Geometry.getShapeRotations().front(), E2Color, true);
414 } else if (segment->isLastSegment()) {
415 drawRightGeometryPoint(myNet->getViewNet(), E2Geometry.getShape().back(), E2Geometry.getShapeRotations().back(), E2Color, true);
416 // draw arrow
417 if (E2Geometry.getShape().size() > 1) {
418 glTranslated(0, 0, 0.1);
419 GLHelper::drawTriangleAtEnd(E2Geometry.getShape()[-2], E2Geometry.getShape()[-1], (double) 0.5, (double) 1, 0.5);
420 }
421 }
422 // Pop layer matrix
424 // Pop name
426 // draw additional ID
428 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
429 // check if this is the label segment
430 if (segment->isLabelSegment()) {
431 // calculate middle point
432 const double middlePoint = (E2Geometry.getShape().length2D() * 0.5);
433 // calculate position
434 const Position pos = E2Geometry.getShape().positionAtOffset2D(middlePoint);
435 // calculate rotation
436 const double rot = s.getTextAngle((E2Geometry.getShape().rotationDegreeAtOffset(middlePoint) * -1) + 90);
437 // Start pushing matrix
439 // Traslate to position
440 glTranslated(pos.x(), pos.y(), getType() + offsetFront + 0.1);
441 // rotate
442 glRotated(rot, 0, 0, 1);
443 // move
444 glTranslated(-1, 0, 0);
445 // scale text
446 glScaled(E2DetectorWidth, E2DetectorWidth, 1);
447 // draw E1 logo
448 GLHelper::drawText("E2 Multilane", Position(), .1, 1.5, RGBColor::BLACK);
449 // pop matrix
451 }
452 }
453 // declare trim geometry to draw
454 const auto shape = (segment->isFirstSegment() || segment->isLastSegment()) ? E2Geometry.getShape() : lane->getLaneShape();
455 // check if mouse is over element
457 // inspect contour
460 }
461 // dotted contour
462 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
464 }
465 // delete contour
466 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
468 }
469 // select contour
470 if (myNet->getViewNet()->drawSelectContour(this, this)) {
472 }
473 }
474}
475
476
477void
478GNELaneAreaDetector::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* fromLane, const GNELane* toLane, const GNEPathManager::Segment* /*segment*/, const double offsetFront) const {
479 // calculate E2Detector width
480 const double E2DetectorWidth = s.addSize.getExaggeration(s, fromLane);
481 // check if E2 can be drawn
482 if ((myTagProperty.getTag() == GNE_TAG_MULTI_LANE_AREA_DETECTOR) && s.drawAdditionals(E2DetectorWidth) &&
484 // get flag for show only contour
486 // Start drawing adding an gl identificator
488 // Add a draw matrix
490 // Start with the drawing of the area traslating matrix to origin
491 glTranslated(0, 0, getType() + offsetFront);
492 // Set color of the base
493 if (drawUsingSelectColor()) {
495 } else {
497 }
498 // draw lane2lane
499 if (fromLane->getLane2laneConnections().exist(toLane)) {
500 // check if draw only contour
501 if (onlyContour) {
503 } else {
505 }
506 } else {
507 // Set invalid person plan color
509 // calculate invalid geometry
510 const GUIGeometry invalidGeometry({fromLane->getLaneShape().back(), toLane->getLaneShape().front()});
511 // check if draw only contour
512 if (onlyContour) {
513 GUIGeometry::drawContourGeometry(invalidGeometry, (0.5 * E2DetectorWidth));
514 } else {
515 // draw invalid geometry
516 GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), invalidGeometry, (0.5 * E2DetectorWidth));
517 }
518 }
519 // Pop last matrix
521 // Pop name
523 // continue with dotted contours
524 if (fromLane->getLane2laneConnections().exist(toLane)) {
525 // check if mouse is over element
527 // inspect contour
530 E2DetectorWidth, 1, false, false);
531 }
532 // front contour
533 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
535 E2DetectorWidth, 1, false, false);
536 }
537 // delete contour
538 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
540 E2DetectorWidth, 1, false, false);
541 }
542 // select contour
543 if (myNet->getViewNet()->drawSelectContour(this, this)) {
545 E2DetectorWidth, 1, false, false);
546 }
547 }
548 }
549}
550
551
552std::string
554 switch (key) {
555 case SUMO_ATTR_ID:
556 return getMicrosimID();
557 case SUMO_ATTR_LANE:
558 case SUMO_ATTR_LANES:
559 return parseIDs(getParentLanes());
563 case SUMO_ATTR_ENDPOS:
565 case SUMO_ATTR_PERIOD:
567 return "";
568 } else {
569 return time2string(myPeriod);
570 }
571 case SUMO_ATTR_TLID:
572 return myTrafficLight;
573 case SUMO_ATTR_LENGTH:
575 case SUMO_ATTR_NAME:
576 return myAdditionalName;
577 case SUMO_ATTR_FILE:
578 return myFilename;
579 case SUMO_ATTR_VTYPES:
580 return toString(myVehicleTypes);
586 return toString(myJamThreshold);
592 return getParametersStr();
594 return "";
595 default:
596 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
597 }
598}
599
600
601double
603 switch (key) {
605 return myPositionOverLane;
606 case SUMO_ATTR_LENGTH:
608 case SUMO_ATTR_ENDPOS:
610 default:
611 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
612 }
613}
614
615
616void
617GNELaneAreaDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
618 switch (key) {
619 case SUMO_ATTR_ID:
620 case SUMO_ATTR_LANE:
621 case SUMO_ATTR_LANES:
623 case SUMO_ATTR_ENDPOS:
624 case SUMO_ATTR_PERIOD:
625 case SUMO_ATTR_TLID:
626 case SUMO_ATTR_LENGTH:
627 case SUMO_ATTR_NAME:
628 case SUMO_ATTR_FILE:
629 case SUMO_ATTR_VTYPES:
637 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
638 break;
639 default:
640 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
641 }
642}
643
644
645bool
646GNELaneAreaDetector::isValid(SumoXMLAttr key, const std::string& value) {
647 switch (key) {
648 case SUMO_ATTR_ID:
649 if (value == getID()) {
650 return true;
651 } else if (isValidDetectorID(value)) {
652 return (myNet->getAttributeCarriers()->retrieveAdditional(GNE_TAG_MULTI_LANE_AREA_DETECTOR, value, false) == nullptr) &&
654 } else {
655 return false;
656 }
657 case SUMO_ATTR_LANE:
658 if (value.empty()) {
659 return false;
660 } else {
661 return canParse<std::vector<GNELane*> >(myNet, value, false);
662 }
663 case SUMO_ATTR_LANES:
664 if (value.empty()) {
665 return false;
666 } else if (canParse<std::vector<GNELane*> >(myNet, value, false)) {
667 // check if lanes are consecutives
668 return lanesConsecutives(parse<std::vector<GNELane*> >(myNet, value));
669 } else {
670 return false;
671 }
673 return canParse<double>(value);
674 case SUMO_ATTR_ENDPOS:
675 return canParse<double>(value);
676 case SUMO_ATTR_PERIOD:
677 if (value.empty()) {
678 return true;
679 } else {
680 return (canParse<double>(value) && (parse<double>(value) >= 0));
681 }
682 case SUMO_ATTR_TLID:
683 // temporal
685 case SUMO_ATTR_LENGTH:
686 return (canParse<double>(value) && (parse<double>(value) >= 0));
687 case SUMO_ATTR_NAME:
689 case SUMO_ATTR_FILE:
691 case SUMO_ATTR_VTYPES:
692 if (value.empty()) {
693 return true;
694 } else {
696 }
698 return canParse<SUMOTime>(value);
700 return (canParse<double>(value) && (parse<double>(value) >= 0));
702 return (canParse<double>(value) && (parse<double>(value) >= 0));
704 return canParse<bool>(value);
706 return canParse<bool>(value);
708 return areParametersValid(value);
709 default:
710 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
711 }
712}
713
714// ===========================================================================
715// private
716// ===========================================================================
717
718void
719GNELaneAreaDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
720 switch (key) {
721 case SUMO_ATTR_ID:
722 // update microsimID
723 setMicrosimID(value);
724 break;
725 case SUMO_ATTR_LANE:
726 case SUMO_ATTR_LANES:
728 break;
730 myPositionOverLane = parse<double>(value);
731 // update geometry (except for template)
732 if (getParentLanes().size() > 0) {
734 }
735 break;
736 case SUMO_ATTR_ENDPOS:
737 myEndPositionOverLane = parse<double>(value);
738 // update geometry (except for template)
739 if (getParentLanes().size() > 0) {
741 }
742 break;
743 case SUMO_ATTR_PERIOD:
744 if (value.empty()) {
746 } else {
747 myPeriod = string2time(value);
748 }
749 break;
750 case SUMO_ATTR_TLID:
751 myTrafficLight = value;
752 break;
753 case SUMO_ATTR_LENGTH:
754 myEndPositionOverLane = (myPositionOverLane + parse<double>(value));
755 // update geometry (except for template)
756 if (getParentLanes().size() > 0) {
758 }
759 break;
760 case SUMO_ATTR_NAME:
761 myAdditionalName = value;
762 break;
763 case SUMO_ATTR_FILE:
764 myFilename = value;
765 break;
766 case SUMO_ATTR_VTYPES:
767 myVehicleTypes = parse<std::vector<std::string> >(value);
768 break;
770 myTimeThreshold = TIME2STEPS(parse<double>(value));
771 break;
773 mySpeedThreshold = parse<double>(value);
774 break;
776 myJamThreshold = parse<double>(value);
777 break;
779 myFriendlyPosition = parse<bool>(value);
780 break;
782 if (parse<bool>(value)) {
784 } else {
786 }
787 break;
789 setParametersStr(value);
790 break;
793 break;
794 default:
795 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
796 }
797}
798
799
800void
804 // change only start position
805 myPositionOverLane = moveResult.newFirstPos;
808 // change only end position
810 } else {
811 // change both position
812 myPositionOverLane = moveResult.newFirstPos;
814 }
815 // update geometry
817}
818
819
820void
822 // begin change attribute
823 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
824 // set attributes depending of operation type
827 // set only start position
828 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
831 // set only end position
832 setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newFirstPos), undoList);
833 } else {
834 // set both positions
835 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
836 setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newSecondPos), undoList);
837 }
838 // end change attribute
839 undoList->end();
840}
841
842
843double
845 // get lane final and shape length
846 const double laneLength = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
847 // get startPosition
848 double fixedPos = myPositionOverLane;
849 // adjust fixedPos
850 if (fixedPos < 0) {
851 fixedPos += laneLength;
852 }
853 fixedPos *= getParentLanes().front()->getLengthGeometryFactor();
854 // return depending of fixedPos
855 if (fixedPos < 0) {
856 return 0;
857 } else if (fixedPos > (getParentLanes().front()->getLaneShapeLength() - POSITION_EPS)) {
858 return (getParentLanes().front()->getLaneShapeLength() - POSITION_EPS);
859 } else {
860 return fixedPos;
861 }
862}
863
864
865double
867 // get lane final and shape length
868 const double laneLength = getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength();
869 // get endPosition
870 double fixedPos = myEndPositionOverLane;
871 // adjust fixedPos
872 if (fixedPos < 0) {
873 fixedPos += laneLength;
874 }
875 fixedPos *= getParentLanes().back()->getLengthGeometryFactor();
876 // return depending of fixedPos
877 if (fixedPos < POSITION_EPS) {
878 return POSITION_EPS;
879 } else if (fixedPos > getParentLanes().back()->getLaneShapeLength()) {
880 return getParentLanes().back()->getLaneShapeLength();
881 } else {
882 return fixedPos;
883 }
884}
885
886/****************************************************************************/
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
#define TL(string)
Definition MsgHandler.h:287
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#define SUMOTime_MAX_PERIOD
Definition SUMOTime.h:36
#define TIME2STEPS(x)
Definition SUMOTime.h:57
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 drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth, const double extraOffset=0)
Draws a triangle at the end of the given line.
Definition GLHelper.cpp:558
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
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
the function-object for an editing operation (abstract base)
SUMOTime myPeriod
The aggregation period the values the detector collects shall be summed up.
std::string myFilename
The path to the output file.
double myPositionOverLane
position of detector over Lane
void drawE2DetectorLogo(const GUIVisualizationSettings &s, const double exaggeration, const std::string &logo, const RGBColor &textColor) const
draw E2 detector Logo
bool myFriendlyPosition
Flag for friendly position.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::vector< std::string > myVehicleTypes
attribute vehicle types
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.
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:136
const GNELane2laneConnection & getLane2laneConnections() const
get Lane2laneConnection struct
Definition GNELane.cpp:829
const GUIGeometry & getLaneGeometry() const
Definition GNELane.cpp:130
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:120
GNEPathManager * getPathManager()
get path manager
Definition GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
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
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
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)
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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
bool mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
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.
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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
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:300
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.
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
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