Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAdditional.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// A abstract class for representation of additional elements
19/****************************************************************************/
20#include <config.h>
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
31#include "GNEAdditional.h"
32
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
38GNEAdditional::GNEAdditional(const std::string& id, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, std::string additionalName,
39 const std::vector<GNEJunction*>& junctionParents,
40 const std::vector<GNEEdge*>& edgeParents,
41 const std::vector<GNELane*>& laneParents,
42 const std::vector<GNEAdditional*>& additionalParents,
43 const std::vector<GNEDemandElement*>& demandElementParents,
44 const std::vector<GNEGenericData*>& genericDataParents) :
45 GNEPathManager::PathElement(type, id, icon, GNEPathManager::PathElement::Options::ADDITIONAL_ELEMENT),
46 GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
47 myAdditionalName(additionalName) {
48 // check if is template
49 myIsTemplate = (id == "");
50}
51
52
53GNEAdditional::GNEAdditional(GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, std::string additionalName,
54 const std::vector<GNEJunction*>& junctionParents,
55 const std::vector<GNEEdge*>& edgeParents,
56 const std::vector<GNELane*>& laneParents,
57 const std::vector<GNEAdditional*>& additionalParents,
58 const std::vector<GNEDemandElement*>& demandElementParents,
59 const std::vector<GNEGenericData*>& genericDataParents) :
60 GNEPathManager::PathElement(type, additionalParents.front()->getID(), icon, GNEPathManager::PathElement::Options::ADDITIONAL_ELEMENT),
61 GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
62 myAdditionalName(additionalName) {
63}
64
65
67
68
69void
70GNEAdditional::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
71 // currently there isn't additionals with removable geometry points
72}
73
74
77 return this;
78}
79
80
81const std::string
83 try {
85 } catch (InvalidArgument&) {
86 return "";
87 }
88}
89
90
91const GUIGeometry&
95
96
97void
101
102
103bool
105 return true;
106}
107
108
109std::string
111 return "";
112}
113
114
115void
117 throw InvalidArgument(getTagStr() + " cannot fix any problem");
118}
119
120
121void
123 throw InvalidArgument(getTagStr() + " doesn't have an additional dialog");
124}
125
126
127double
131
132
137
138
141 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
142 // build header
143 buildPopupHeader(ret, app);
144 // build menu command for center button and copy cursor position to clipboard
146 // build menu commands for names
147 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % name to clipboard", getTagStr()), nullptr, ret, MID_COPY_NAME);
148 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % typed name to clipboard", getTagStr()), nullptr, ret, MID_COPY_TYPED_NAME);
149 new FXMenuSeparator(ret);
150 // build selection and show parameters menu
153 buildPositionCopyEntry(ret, app);
154 // show option to open additional dialog
155 if (myTagProperty.hasDialog()) {
156 GUIDesigns::buildFXMenuCommand(ret, TL("Open ") + getTagStr() + TL(" Dialog"), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
157 new FXMenuSeparator(ret);
158 }
159 // Show position parameters
162 // Show menu command inner position
164 GUIDesigns::buildFXMenuCommand(ret, TL("Cursor position over additional shape: ") + toString(innerPos), nullptr, nullptr, 0);
165 // If shape isn't empty, show menu command lane position
166 if (myAdditionalGeometry.getShape().size() > 0) {
167 const double lanePos = lane->getLaneShape().nearest_offset_to_point2D(myAdditionalGeometry.getShape().front());
168 GUIDesigns::buildFXMenuCommand(ret, TL("Cursor position over lane: ") + toString(innerPos + lanePos), nullptr, nullptr, 0);
169 }
172 // Show menu command inner position
174 GUIDesigns::buildFXMenuCommand(ret, TL("Cursor position over additional shape: ") + toString(innerPos), nullptr, nullptr, 0);
175 // If shape isn't empty, show menu command edge position
176 if (myAdditionalGeometry.getShape().size() > 0) {
177 const double edgePos = edge->getLanes().at(0)->getLaneShape().nearest_offset_to_point2D(myAdditionalGeometry.getShape().front());
178 GUIDesigns::buildFXMenuCommand(ret, TL("Mouse position over edge: ") + toString(innerPos + edgePos), nullptr, nullptr, 0);
179 }
180 } else {
181 GUIDesigns::buildFXMenuCommand(ret, TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y()), nullptr, nullptr, 0);
182 }
183 return ret;
184}
185
186
189 // Create table
191 // Iterate over attributes
192 for (const auto& i : myTagProperty) {
193 // Add attribute and set it dynamic if aren't unique
194 if (i.isUnique()) {
195 ret->mkItem(i.getAttrStr().c_str(), false, getAttribute(i.getAttr()));
196 } else {
197 ret->mkItem(i.getAttrStr().c_str(), true, getAttribute(i.getAttr()));
198 }
199 }
200 // close building
201 ret->closeBuilding();
202 return ret;
203}
204
205
206const std::string&
210
211
212bool
220
221
222void
226
227
228void
232
233
234void
244
245
249
250
251void
253 // Nothing to compute
254}
255
256
257bool
261
262
263void
264GNEAdditional::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
265 // Nothing to draw
266}
267
268
269void
270GNEAdditional::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
271 // Nothing to draw
272}
273
274// ---------------------------------------------------------------------------
275// GNEAdditional - protected methods
276// ---------------------------------------------------------------------------
277
278bool
279GNEAdditional::isValidAdditionalID(const std::string& newID) const {
281 return true;
282 } else {
283 return false;
284 }
285}
286
287
288bool
289GNEAdditional::isValidDetectorID(const std::string& newID) const {
291 return true;
292 } else {
293 return false;
294 }
295}
296
297
298void
301 // calculate middle point
302 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
303 // calculate position
305 // calculate rotation
307 // draw additional ID
310 } else {
312 }
313 }
314}
315
316
317void
320 // calculate middle point
321 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
322 // calculate position
324 // calculate rotation
326 // draw additional name
329 } else {
331 }
332 }
333}
334
335
336void
338 replaceParentElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
339}
340
341
342void
344 replaceParentElements(this, parse<std::vector<GNELane*> >(getNet(), value));
345}
346
347
348void
350 replaceChildElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
351}
352
353
354void
356 replaceChildElements(this, parse<std::vector<GNELane*> >(getNet(), value));
357}
358
359
360void
361GNEAdditional::replaceAdditionalParent(SumoXMLTag tag, const std::string& value, const int parentIndex) {
362 std::vector<GNEAdditional*> parentAdditionals;
363 // special case for calibrators and routeprobes
364 if (value.size() > 0) {
365 parentAdditionals = getParentAdditionals();
366 if ((parentAdditionals.size() == 0) && (parentIndex == 0)) {
367 parentAdditionals.push_back(myNet->getAttributeCarriers()->retrieveAdditional(tag, value));
368 } else {
369 parentAdditionals[parentIndex] = myNet->getAttributeCarriers()->retrieveAdditional(tag, value);
370 }
371 }
372 // replace parent additionals
373 replaceParentElements(this, parentAdditionals);
374}
375
376
377void
378GNEAdditional::replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex) {
379 std::vector<GNEDemandElement*> parentDemandElements = getParentDemandElements();
380 parentDemandElements[parentIndex] = myNet->getAttributeCarriers()->retrieveDemandElement(tag, value);
381 // replace parent demand elements
382 replaceParentElements(this, parentDemandElements);
383}
384
385
386void
388 // get new lane parent vector
389 std::vector<GNELane*> newLane = {getParentLanes().front()->getParentEdge()->getLanes().at(getParentLanes().front()->getIndex() + 1)};
390 // replace parent elements
391 replaceParentElements(this, newLane);
392}
393
394
395void
396GNEAdditional::calculatePerpendicularLine(const double endLaneposition) {
397 if (getParentEdges().empty()) {
398 throw ProcessError(TL("Invalid number of edges"));
399 } else {
400 // get lanes
401 const GNELane* firstLane = getParentEdges().front()->getLanes().front();
402 const GNELane* lastLane = getParentEdges().front()->getLanes().back();
403 // get first and back lane shapes
404 PositionVector firstLaneShape = firstLane->getLaneShape();
405 PositionVector lastLaneShape = lastLane->getLaneShape();
406 // move shapes
407 firstLaneShape.move2side((firstLane->getParentEdge()->getNBEdge()->getLaneWidth(firstLane->getIndex()) * 0.5) + 1);
408 lastLaneShape.move2side(lastLane->getParentEdge()->getNBEdge()->getLaneWidth(lastLane->getIndex()) * -0.5);
409 // calculate lane postion
410 const double lanePosition = firstLaneShape.length2D() >= endLaneposition ? endLaneposition : firstLaneShape.length2D();
411 // update geometry
412 myAdditionalGeometry.updateGeometry({firstLaneShape.positionAtOffset2D(lanePosition), lastLaneShape.positionAtOffset2D(lanePosition)});
413 }
414}
415
416
417void
418GNEAdditional::drawSquaredAdditional(const GUIVisualizationSettings& s, const Position& pos, const double size, GUITexture texture, GUITexture selectedTexture) const {
419 // Obtain drawing exaggeration
420 const double exaggeration = getExaggeration(s);
421 // first check if additional has to be drawn
422 if (s.drawAdditionals(exaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
423 // check if boundary has to be drawn
424 if (s.drawBoundaries) {
426 }
427 // Start drawing adding an gl identificator
429 // Add layer matrix
431 // translate to front
433 // translate to position
434 glTranslated(pos.x(), pos.y(), 0);
435 // scale
436 glScaled(exaggeration, exaggeration, 1);
437 // set White color
438 glColor3d(1, 1, 1);
439 // rotate
440 glRotated(180, 0, 0, 1);
441 // draw texture
442 if (drawUsingSelectColor()) {
444 } else {
446 }
447 // Pop layer matrix
449 // Pop name
451 // draw lock icon
452 GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), pos, exaggeration, 0.4, 0.5, 0.5);
453 // check if mouse is over element
454 mouseWithinGeometry(pos, size, size, 0, 0, 0);
455 // inspect contour
458 }
459 // front element contour
460 if ((myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
462 }
463 // delete contour
464 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
466 }
467 // select contour
468 if (myNet->getViewNet()->drawSelectContour(this, this)) {
470 }
471 // Draw additional ID
473 // draw additional name
475 }
476}
477
478
479void
480GNEAdditional::drawListedAddtional(const GUIVisualizationSettings& s, const Position& parentPosition, const double offsetX, const double extraOffsetY,
481 const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const {
482 // first check if additional has to be drawn
484 // declare offsets
485 const double lineOffset = 0.1875;
486 const double baseOffsetX = 6.25;
487 const double baseOffsetY = 0.6;
488 // get draw position index
489 const int drawPositionIndex = getDrawPositionIndex();
490 // calculate lineA position (from parent to middle)
491 Position positionLineA = parentPosition;
492 const double positionLineA_Y = (0 - extraOffsetY + baseOffsetY);
493 // set position depending of indexes
494 positionLineA.add(1 + lineOffset + (baseOffsetX * offsetX), positionLineA_Y, 0);
495 // calculate lineC position (From middle until current listenAdditional
496 Position positionLineB = parentPosition;
497 const double positionLineB_Y = ((drawPositionIndex * -1) - extraOffsetY + baseOffsetY);
498 // set position depending of indexes
499 positionLineB.add(1 + lineOffset + (baseOffsetX * offsetX) + (2 * lineOffset), positionLineB_Y, 0);
500 // calculate signPosition position
501 Position signPosition = parentPosition;
502 // set position depending of indexes
503 signPosition.add(4.5 + (baseOffsetX * offsetX), (drawPositionIndex * -1) - extraOffsetY + 1, 0);
504 // check if boundary has to be drawn
505 if (s.drawBoundaries) {
507 }
508 // Start drawing adding an gl identificator
510 // calculate colors
512 const RGBColor secondColor = baseColor.changedBrightness(-30);
514 // Add layer matrix
516 // translate to front
518 // set line color
520 // draw both lines
521 GLHelper::drawBoxLine(positionLineA, 0, 0.1, lineOffset);
522 GLHelper::drawBoxLine(positionLineB, 0, 0.1, lineOffset);
523 // check if draw middle lane
524 if (drawPositionIndex != 0) {
525 // calculate length
526 const double length = std::abs(positionLineA_Y - positionLineB_Y);
527 // push middle lane matrix
529 //move and rotate
530 glTranslated(positionLineA.x() + lineOffset, positionLineA.y(), 0);
531 glRotated(90, 0, 0, 1);
532 glTranslated((length * -0.5), 0, 0);
533 // draw line
534 GLHelper::drawBoxLine(Position(0, 0), 0, 0.1, length * 0.5);
535 // pop middle lane matrix
537 }
538 // draw extern rectangle
539 GLHelper::setColor(secondColor);
540 GLHelper::drawBoxLine(signPosition, 0, 0.96, 2.75);
541 // move to front
542 glTranslated(0, -0.06, 0.1);
543 // draw intern rectangle
544 GLHelper::setColor(baseColor);
545 GLHelper::drawBoxLine(signPosition, 0, 0.84, 2.69);
546 // move position down
547 signPosition.add(-2, -0.43, 0);
548 // draw interval
549 GLHelper::drawText(adjustListedAdditionalText(text), signPosition, .1, 0.5, textColor, 0, (FONS_ALIGN_LEFT | FONS_ALIGN_MIDDLE));
550 // move to icon position
551 signPosition.add(-0.3, 0);
552 // check if draw lock icon or rerouter interval icon
554 // pop layer matrix
556 // Pop name
558 // draw lock icon
559 GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), signPosition, 1, 0.4, 0.0, -0.05);
560 } else {
561 // translate to front
562 glTranslated(signPosition.x(), signPosition.y(), 0.1);
563 // set White color
564 glColor3d(1, 1, 1);
565 // rotate
566 glRotated(180, 0, 0, 1);
567 // draw texture
569 // pop layer matrix
571 // Pop name
573 }
574 // check if dotted contour has to be drawn
577 }
578 if ((myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
580 }
581 }
582}
583
584
586GNEAdditional::getMoveOperationSingleLane(const double startPos, const double endPos) {
587 // get allow change lane
588 const bool allowChangeLane = myNet->getViewNet()->getViewParent()->getMoveFrame()->getCommonModeOptions()->getAllowChangeLane();
589 // fist check if we're moving only extremes
591 // get snap radius
593 // get mouse position
594 const Position mousePosition = myNet->getViewNet()->getPositionInformation();
595 // check if we clicked over start or end position
596 if (myAdditionalGeometry.getShape().front().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
597 // move only start position
598 return new GNEMoveOperation(this, getParentLanes().front(), startPos, endPos,
600 } else if (myAdditionalGeometry.getShape().back().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
601 // move only end position
602 return new GNEMoveOperation(this, getParentLanes().front(), startPos, endPos,
604 } else {
605 return nullptr;
606 }
607 } else {
608 // move both start and end positions
609 return new GNEMoveOperation(this, getParentLanes().front(), startPos, endPos,
611 }
612}
613
614
616GNEAdditional::getMoveOperationMultiLane(const double startPos, const double endPos) {
617 // check if shift is pressed
618 const bool shift = myNet->getViewNet()->getMouseButtonKeyPressed().shiftKeyPressed();
619 // get snap radius
621 // get mouse position
622 const Position mousePosition = myNet->getViewNet()->getPositionInformation();
623 // calculate both geometries
624 GUIGeometry fromGeometry, toGeometry;
625 fromGeometry.updateGeometry(getParentLanes().front()->getLaneGeometry().getShape(), startPos, 0);
626 toGeometry.updateGeometry(getParentLanes().back()->getLaneGeometry().getShape(), endPos, 0);
627 // check if we clicked over start or end position
628 if (fromGeometry.getShape().front().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
629 // move using start position
630 return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
632 } else if (toGeometry.getShape().back().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
633 // move using end position
634 return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
636 } else {
637 return nullptr;
638 }
639}
640
641
642GNELane*
644 return getParentLanes().front();
645}
646
647
648GNELane*
650 return getParentLanes().back();
651}
652
653
654double
658
659
664
665
666double
670
671
676
677
680 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
681}
682
683
684void
685GNEAdditional::drawParentChildLines(const GUIVisualizationSettings& s, const RGBColor& color, const bool onlySymbols) const {
686 // check if current additional is inspected, front or selected
687 const bool currentDrawEntire = myNet->getViewNet()->isAttributeCarrierInspected(this) ||
689 // push layer matrix
691 // translate to parentChildLine layer
692 glTranslated(0, 0, GLO_PARENTCHILDLINE);
693 // iterate over parent additionals
694 for (const auto& parent : getParentAdditionals()) {
695 // get inspected flag
696 const bool inspected = myNet->getViewNet()->isAttributeCarrierInspected(parent);
697 // draw parent lines
698 GUIGeometry::drawParentLine(s, getPositionInView(), parent->getPositionInView(),
699 (isAttributeCarrierSelected() || parent->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
700 currentDrawEntire || inspected || parent->isAttributeCarrierSelected(), .05);
701 }
702 // special case for Parking area reroutes
704 // iterate over rerouter elements
705 for (const auto& rerouterInterval : getChildAdditionals()) {
706 for (const auto& rerouterElement : rerouterInterval->getChildAdditionals()) {
707 if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
708 // get parking area
709 const auto parkingArea = rerouterElement->getParentAdditionals().at(1);
710 // get inspected flag
711 const bool inspected = myNet->getViewNet()->isAttributeCarrierInspected(parkingArea);
712 // draw parent lines
713 GUIGeometry::drawParentLine(s, getPositionInView(), parkingArea->getPositionInView(),
714 (isAttributeCarrierSelected() || parkingArea->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
715 currentDrawEntire || inspected || parkingArea->isAttributeCarrierSelected(), .05);
716 }
717 }
718 }
719 }
720 // iterate over child additionals
721 for (const auto& child : getChildAdditionals()) {
722 // get inspected flag
723 const bool inspected = myNet->getViewNet()->isAttributeCarrierInspected(child);
724 // special case for parking zone reroute
725 if (child->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
726 // draw child line between parking area and rerouter
727 GUIGeometry::drawChildLine(s, getPositionInView(), child->getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView(),
728 (isAttributeCarrierSelected() || child->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
729 currentDrawEntire || inspected || child->isAttributeCarrierSelected(), .05);
730 } else if (!onlySymbols || child->getTagProperty().isSymbol()) {
731 // draw child line
732 GUIGeometry::drawChildLine(s, getPositionInView(), child->getPositionInView(),
733 (isAttributeCarrierSelected() || child->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
734 currentDrawEntire || inspected || child->isAttributeCarrierSelected(), .05);
735 }
736 }
737 // pop layer matrix
739}
740
741
742void
743GNEAdditional::drawUpGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
744 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, -90, 90, ignoreShift);
745}
746
747
748void
749GNEAdditional::drawDownGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
750 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, 90, 270, ignoreShift);
751}
752
753
754void
755GNEAdditional::drawLeftGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
756 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, -90, 90, ignoreShift);
757}
758
759
760void
761GNEAdditional::drawRightGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
762 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, 270, 90, ignoreShift);
763}
764
765
766int
768 // filter symbols
769 std::vector<GNEAdditional*> children;
770 for (const auto& child : getParentAdditionals().front()->getChildAdditionals()) {
771 if (!child->getTagProperty().isSymbol()) {
772 children.push_back(child);
773 }
774 }
775 // now get index
776 for (int i = 0; i < (int)children.size(); i++) {
777 if (children.at(i) == this) {
778 return i;
779 }
780 }
781 return 0;
782}
783
784
785bool
786GNEAdditional::areLaneConsecutives(const std::vector<GNELane*>& lanes) {
787 // declare lane iterator
788 int laneIt = 0;
789 // iterate over all lanes
790 while (laneIt < ((int)lanes.size() - 1)) {
791 // we assume that lanes aren't consecutives
792 bool consecutiveFound = false;
793 // get lanes
794 const auto lane = lanes.at(laneIt);
795 const auto nextLane = lanes.at(laneIt + 1);
796 // if there is a connection betwen "from" lane and "to" lane of connection, change connectionFound to true
797 for (const auto& outgoingEdge : lane->getParentEdge()->getToJunction()->getGNEOutgoingEdges()) {
798 for (const auto& outgoingLane : outgoingEdge->getLanes()) {
799 if (outgoingLane == nextLane) {
800 consecutiveFound = true;
801 }
802 }
803 }
804 // abort if consecutiveFound is false
805 if (!consecutiveFound) {
806 return false;
807 }
808 // update iterator
809 laneIt++;
810 }
811 // lanes are consecutive, then return true
812 return true;
813}
814
815
816bool
817GNEAdditional::areLaneConnected(const std::vector<GNELane*>& lanes) {
818 // declare lane iterator
819 int laneIt = 0;
820 // iterate over all lanes, and stop if myE2valid is false
821 while (laneIt < ((int)lanes.size() - 1)) {
822 // we assume that E2 is invalid
823 bool connectionFound = false;
824 // get lanes
825 const auto lane = lanes.at(laneIt);
826 const auto nextLane = lanes.at(laneIt + 1);
827 // check if both lanes are sidewalks
828 if ((lane->getAttribute(SUMO_ATTR_ALLOW) == "pedestrian") && (nextLane->getAttribute(SUMO_ATTR_ALLOW) == "pedestrian")) {
829 connectionFound = true;
830 }
831 // if there is a connection betwen "from" lane and "to" lane of connection, change connectionFound to true
832 for (const auto& connection : lane->getParentEdge()->getNBEdge()->getConnections()) {
833 if ((connection.toEdge == nextLane->getParentEdge()->getNBEdge()) &&
834 (connection.fromLane == lane->getIndex()) &&
835 (connection.toLane == nextLane->getIndex())) {
836 connectionFound = true;
837 }
838 }
839 // abort if connectionFound is false
840 if (!connectionFound) {
841 return false;
842 }
843 // update iterator
844 laneIt++;
845 }
846 // there are connections between all lanes, then return true
847 return true;
848}
849
850
851bool
853 // throw exception because this function mus be implemented in child (see GNEE3Detector)
854 throw ProcessError(StringUtils::format("Calling non-implemented function checkChildAdditionalRestriction during saving of %. It muss be reimplemented in child class", getTagStr()));
855}
856
857
858void
859GNEAdditional::drawSemiCircleGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor,
860 const double fromAngle, const double toAngle, const bool ignoreShift) {
861 // first check that we're in move mode and shift key is pressed
863 (viewNet->getMouseButtonKeyPressed().shiftKeyPressed() || ignoreShift)) {
864 // calculate new color
865 const RGBColor color = baseColor.changedBrightness(-50);
866 // push matrix
868 // translated to front
869 glTranslated(0, 0, 0.1);
870 // set color
871 GLHelper::setColor(color);
872 // push geometry point matrix
874 // translate and rotate
875 glTranslated(pos.x(), pos.y(), 0.1);
876 glRotated(rot, 0, 0, 1);
877 // draw geometry point
879 viewNet->getVisualisationSettings().getCircleResolution(), fromAngle, toAngle);
880 // pop geometry point matrix
882 // pop draw matrix
884 }
885}
886
887
888std::string
889GNEAdditional::adjustListedAdditionalText(const std::string& text) const {
890 // 10 + 3 + 10
891 if (text.size() <= 23) {
892 return text;
893 } else {
894 // get text size
895 const int textPosition = (int)text.size() - 10;
896 // declare strings
897 std::string partA, partB;
898 // resize
899 partA.reserve(10);
900 partB.reserve(10);
901 // fill both
902 for (int i = 0; i < 10; i++) {
903 partA.push_back(text.at(i));
904 partB.push_back(text.at(textPosition + i));
905 }
906 // return composition
907 return (partA + "..." + partB);
908 }
909}
910
911/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition GUIAppEnum.h:450
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition GUIAppEnum.h:462
@ MID_COPY_NAME
Copy object name - popup entry.
Definition GUIAppEnum.h:448
GUIGlObjectType
@ GLO_MAX
empty max
@ GLO_PARENTCHILDLINE
line between parent and childrens
GUITexture
An enumeration of gifs used by the gui applications.
Definition GUITextures.h:31
#define TL(string)
Definition MsgHandler.h:287
#define TLF(string,...)
Definition MsgHandler.h:288
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_LANE
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_NAME
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition GLHelper.cpp:897
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:498
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:277
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
virtual const std::string getOptionalName() const
Returns the name of the object (default "")
virtual std::string getAttribute(SumoXMLAttr key) const =0
GNELane * getLastPathLane() const
get last path lane
virtual void updateGeometry()=0
update pre-computed geometry information
double getPathElementArrivalValue() const
get path element arrival lane pos
void deleteGLObject()
delete element
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
static bool areLaneConnected(const std::vector< GNELane * > &lanes)
check if the given lanes are connected
virtual bool isAdditionalValid() const =0
check if current additional is valid to be written into XML (by default true, can be reimplemented in...
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw right geometry point
virtual std::string getAdditionalProblem() const =0
return a string with the current additional problem (by default empty, can be reimplemented in childr...
std::string adjustListedAdditionalText(const std::string &text) const
adjust listed additional text
virtual void openAdditionalDialog()
open Additional Dialog
void replaceAdditionalChildLanes(const std::string &value)
replace additional child lanes
bool isPathElementSelected() const
check if path element is selected
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentEdges(const std::string &value)
replace additional parent edges
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
GNELane * getFirstPathLane() const
get first path lane
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
virtual Position getAttributePosition(SumoXMLAttr key) const
double getPathElementDepartValue() const
get path element depart lane pos
static void drawSemiCircleGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const double fromAngle, const double toAngle, const bool ignoreShift)
draw geometry point
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
virtual GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GNEAdditional(const std::string &id, GNENet *net, GUIGlObjectType type, SumoXMLTag tag, FXIcon *icon, std::string additionalName, const std::vector< GNEJunction * > &junctionParents, const std::vector< GNEEdge * > &edgeParents, const std::vector< GNELane * > &laneParents, const std::vector< GNEAdditional * > &additionalParents, const std::vector< GNEDemandElement * > &demandElementParents, const std::vector< GNEGenericData * > &genericDataParents)
Constructor.
void calculatePerpendicularLine(const double endLaneposition)
calculate perpendicular line between lane parents
GNEMoveOperation * getMoveOperationMultiLane(const double startPos, const double endPos)
get moveOperation for an element over multi lane
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
std::string myAdditionalName
name of additional
void drawListedAddtional(const GUIVisualizationSettings &s, const Position &parentPosition, const double offsetX, const double extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
void selectGLObject()
select element
static void drawUpGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw up geometry point
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void updateGLObject()
update GLObject (geometry, ID, etc.)
void setSpecialColor(const RGBColor *color)
set special color
const RGBColor * mySpecialColor
pointer to special color (used for drawing Additional with a certain color, mainly used for selection...
static void drawDownGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw down geometry point
void drawSquaredAdditional(const GUIVisualizationSettings &s, const Position &pos, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
virtual bool checkChildAdditionalRestriction() const
check restriction with the number of children
static bool areLaneConsecutives(const std::vector< GNELane * > &lanes)
check if the given lanes are consecutive
void replaceAdditionalChildEdges(const std::string &value)
replace additional child edges
bool isGLObjectLocked()
check if element is locked
virtual double getAttributeDouble(SumoXMLAttr key) const =0
virtual void computePathElement()
compute pathElement
Position getPathElementDepartPos() const
get path element depart position
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
const GUIGeometry & getAdditionalGeometry() const
obtain additional geometry
Boundary myAdditionalBoundary
Additional Boundary.
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
~GNEAdditional()
Destructor.
const std::string & getOptionalAdditionalName() const
Returns the additional name.
virtual void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object (lane)
Position getPathElementArrivalPos() const
get path element arrival position
GNEMoveOperation * getMoveOperationSingleLane(const double startPos, const double endPos)
get moveOperation for an element over single lane
virtual Position getPositionInView() const =0
Returns position of additional in view.
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position (Currently unused in shapes)
static void drawLeftGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw left geometry point
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
virtual void fixAdditionalProblem()=0
fix additional problem (by default throw an exception, has to be reimplemented in children)
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.
void markAsFrontElement()
mark element as front element
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
bool myIsTemplate
whether the current object is a template object (not drawn in the view)
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
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition GNEEdge.cpp:480
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition GNEEdge.cpp:840
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
void replaceParentElements(T *elementChild, const U &newParents)
replace parent elements
void replaceChildElements(T *elementChild, const U &newChildren)
replace child elements
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
int getIndex() const
returns the index of the lane
Definition GNELane.cpp:788
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:118
bool getAllowChangeLane() const
allow change lane
CommonModeOptions * getCommonModeOptions() const
get common mode options
move operation
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
void deleteAdditional(GNEAdditional *additional, GNEUndoList *undoList)
remove additional
Definition GNENet.cpp:620
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
void updateInformationLabel()
update information label
SelectionInformation * getSelectionInformation() const
get modul for selection information
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool hasDialog() const
return true if tag correspond to an element that can be edited using a dialog
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
bool isObjectLocked(GUIGlObjectType objectType, const bool selected) const
check if given GLObject is locked for inspect, select, delete and move
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
void setFrontAttributeCarrier(GNEAttributeCarrier *AC)
set front attributeCarrier
const GNEViewNetHelper::MouseButtonKeyPressed & getMouseButtonKeyPressed() const
get Key Pressed module
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
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
GNEViewNetHelper::LockManager & getLockManager()
get lock manager
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
GNEMoveFrame * getMoveFrame() const
get frame for move elements
GNESelectorFrame * getSelectorFrame() const
get frame for select elements
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
static void drawDottedSquaredShape(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
The popup menu of a globject.
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawChildLine(const GUIVisualizationSettings &s, const Position &child, const Position &parent, const RGBColor &color, const bool drawEntire, const double lineWidth)
draw line between child and parent (used in netedit)
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
static void drawParentLine(const GUIVisualizationSettings &s, const Position &parent, const Position &child, const RGBColor &color, const bool drawEntire, const double lineWidth)
draw line between parent and children (used in netedit)
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
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)
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
GUIGlID getGlID() const
Returns the numerical id of the object.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
bool drawBoundaries
enable or disable draw boundaries
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
GUIVisualizationTextSettings addFullName
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)
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition NBEdge.h:632
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:55
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:125
double y() const
Returns the y-position.
Definition Position.h:60
A list of positions.
double length2D() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
static bool isValidAdditionalID(const std::string &value)
whether the given string is a valid id for an additional object
static bool isValidDetectorID(const std::string &value)
whether the given string is a valid id for an detector
static const std::string format(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
@ FONS_ALIGN_MIDDLE
Definition fontstash.h:47
@ FONS_ALIGN_LEFT
Definition fontstash.h:42
bool showAdditionals() const
check if additionals has to be drawn
NetworkEditMode networkEditMode
the current Network edit mode
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
static bool checkDrawing(const GNEAttributeCarrier *AC, GUIGlObjectType type, const double exaggeration)
check if icon can be drawn
bool shiftKeyPressed() const
check if SHIFT is pressed during current event
static const RGBColor connectionColor
connection color
static const RGBColor connectionColorSelected
connection color selected
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double additionalGeometryPointRadius
moving additional geometry point radius
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool show(const GUIGlObject *o) const
whether to show the text
double scaledSize(double scale, double constFactor=0.1) const
get scale size