Eclipse SUMO - Simulation of Urban MObility
GNEAdditional.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// A abstract class for representation of additional elements
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
31
32#include "GNEAdditional.h"
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 GUIGeometry&
84}
85
86
87void
89 mySpecialColor = color;
90}
91
92
93bool
95 return true;
96}
97
98
99std::string
101 return "";
102}
103
104
105void
107 throw InvalidArgument(getTagStr() + " cannot fix any problem");
108}
109
110
111void
113 throw InvalidArgument(getTagStr() + " doesn't have an additional dialog");
114}
115
116
117double
119 return s.addSize.getExaggeration(s, this);
120}
121
122
126}
127
128
131 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
132 // build header
133 buildPopupHeader(ret, app);
134 // build menu command for center button and copy cursor position to clipboard
136 buildPositionCopyEntry(ret, app);
137 // build menu commands for names
138 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
139 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
140 new FXMenuSeparator(ret);
141 // build selection and show parameters menu
144 // show option to open additional dialog
145 if (myTagProperty.hasDialog()) {
146 GUIDesigns::buildFXMenuCommand(ret, "Open " + getTagStr() + " Dialog", getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
147 new FXMenuSeparator(ret);
148 }
149 // Show position parameters
152 // Show menu command inner position
154 GUIDesigns::buildFXMenuCommand(ret, "Cursor position over additional shape: " + toString(innerPos), nullptr, nullptr, 0);
155 // If shape isn't empty, show menu command lane position
156 if (myAdditionalGeometry.getShape().size() > 0) {
157 const double lanePos = lane->getLaneShape().nearest_offset_to_point2D(myAdditionalGeometry.getShape().front());
158 GUIDesigns::buildFXMenuCommand(ret, "Cursor position over " + toString(SUMO_TAG_LANE) + ": " + toString(innerPos + lanePos), nullptr, nullptr, 0);
159 }
162 // Show menu command inner position
164 GUIDesigns::buildFXMenuCommand(ret, "Cursor position over additional shape: " + toString(innerPos), nullptr, nullptr, 0);
165 // If shape isn't empty, show menu command edge position
166 if (myAdditionalGeometry.getShape().size() > 0) {
167 const double edgePos = edge->getLanes().at(0)->getLaneShape().nearest_offset_to_point2D(myAdditionalGeometry.getShape().front());
168 GUIDesigns::buildFXMenuCommand(ret, "Mouse position over " + toString(SUMO_TAG_EDGE) + ": " + toString(innerPos + edgePos), nullptr, nullptr, 0);
169 }
170 } else {
171 GUIDesigns::buildFXMenuCommand(ret, "Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y()), nullptr, nullptr, 0);
172 }
173 return ret;
174}
175
176
179 // Create table
181 // Iterate over attributes
182 for (const auto& i : myTagProperty) {
183 // Add attribute and set it dynamic if aren't unique
184 if (i.isUnique()) {
185 ret->mkItem(i.getAttrStr().c_str(), false, getAttribute(i.getAttr()));
186 } else {
187 ret->mkItem(i.getAttrStr().c_str(), true, getAttribute(i.getAttr()));
188 }
189 }
190 // close building
191 ret->closeBuilding();
192 return ret;
193}
194
195
196const std::string&
198 return myAdditionalName;
199}
200
201
202bool
206 } else {
207 return true;
208 }
209}
210
211
212void
215}
216
217
218void
221}
222
223
224void
228 } else {
230 }
231 // update information label
233}
234
235
238}
239
240
241void
243 // Nothing to compute
244}
245
246
247void
248GNEAdditional::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
249 // Nothing to draw
250}
251
252
253void
254GNEAdditional::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
255 // Nothing to draw
256}
257
258// ---------------------------------------------------------------------------
259// GNEAdditional - protected methods
260// ---------------------------------------------------------------------------
261
262bool
263GNEAdditional::isValidAdditionalID(const std::string& newID) const {
265 return true;
266 } else {
267 return false;
268 }
269}
270
271
272bool
273GNEAdditional::isValidDetectorID(const std::string& newID) const {
275 return true;
276 } else {
277 return false;
278 }
279}
280
281
282void
285 // calculate middle point
286 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
287 // calculate position
289 // calculate rotation
291 // draw additional ID
294 } else {
296 }
297 }
298}
299
300
301void
304 // calculate middle point
305 const double middlePoint = (myAdditionalGeometry.getShape().length2D() * 0.5);
306 // calculate position
308 // calculate rotation
310 // draw additional name
313 } else {
315 }
316 }
317}
318
319
320void
322 replaceParentElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
323}
324
325
326void
328 replaceParentElements(this, parse<std::vector<GNELane*> >(getNet(), value));
329}
330
331
332void
334 replaceChildElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
335}
336
337
338void
340 replaceChildElements(this, parse<std::vector<GNELane*> >(getNet(), value));
341}
342
343
344void
345GNEAdditional::replaceAdditionalParent(SumoXMLTag tag, const std::string& value, const int parentIndex) {
346 std::vector<GNEAdditional*> parentAdditionals;
347 // special case for calibrators and routeprobes
348 if (value.size() > 0) {
349 parentAdditionals = getParentAdditionals();
350 if ((parentAdditionals.size() == 0) && (parentIndex == 0)) {
351 parentAdditionals.push_back(myNet->getAttributeCarriers()->retrieveAdditional(tag, value));
352 } else {
353 parentAdditionals[parentIndex] = myNet->getAttributeCarriers()->retrieveAdditional(tag, value);
354 }
355 }
356 // replace parent additionals
357 replaceParentElements(this, parentAdditionals);
358}
359
360
361void
362GNEAdditional::replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex) {
363 std::vector<GNEDemandElement*> parentDemandElements = getParentDemandElements();
364 parentDemandElements[parentIndex] = myNet->getAttributeCarriers()->retrieveDemandElement(tag, value);
365 // replace parent demand elements
366 replaceParentElements(this, parentDemandElements);
367}
368
369
370void
372 // get new lane parent vector
373 std::vector<GNELane*> newLane = {getParentLanes().front()->getParentEdge()->getLanes().at(getParentLanes().front()->getIndex() + 1)};
374 // replace parent elements
375 replaceParentElements(this, newLane);
376}
377
378
379void
380GNEAdditional::calculatePerpendicularLine(const double endLaneposition) {
381 if (getParentEdges().empty()) {
382 throw ProcessError("Invalid number of edges");
383 } else {
384 // get lanes
385 const GNELane* firstLane = getParentEdges().front()->getLanes().front();
386 const GNELane* lastLane = getParentEdges().front()->getLanes().back();
387 // get first and back lane shapes
388 PositionVector firstLaneShape = firstLane->getLaneShape();
389 PositionVector lastLaneShape = lastLane->getLaneShape();
390 // move shapes
391 firstLaneShape.move2side((firstLane->getParentEdge()->getNBEdge()->getLaneWidth(firstLane->getIndex()) * 0.5) + 1);
392 lastLaneShape.move2side(lastLane->getParentEdge()->getNBEdge()->getLaneWidth(lastLane->getIndex()) * -0.5);
393 // calculate lane postion
394 const double lanePosition = firstLaneShape.length2D() >= endLaneposition ? endLaneposition : firstLaneShape.length2D();
395 // update geometry
396 myAdditionalGeometry.updateGeometry({firstLaneShape.positionAtOffset2D(lanePosition), lastLaneShape.positionAtOffset2D(lanePosition)});
397 }
398}
399
400
401void
402GNEAdditional::drawSquaredAdditional(const GUIVisualizationSettings& s, const Position& pos, const double size, GUITexture texture, GUITexture selectedTexture) const {
403 // Obtain drawing exaggeration
404 const double exaggeration = getExaggeration(s);
405 // first check if additional has to be drawn
406 if (s.drawAdditionals(exaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
407 // check if boundary has to be drawn
408 if (s.drawBoundaries) {
410 }
411 // Start drawing adding an gl identificator
413 // Add layer matrix
415 // translate to front
417 // translate to position
418 glTranslated(pos.x(), pos.y(), 0);
419 // scale
420 glScaled(exaggeration, exaggeration, 1);
421 // set White color
422 glColor3d(1, 1, 1);
423 // rotate
424 glRotated(180, 0, 0, 1);
425 // draw texture
426 if (drawUsingSelectColor()) {
428 } else {
430 }
431 // Pop layer matrix
433 // Pop name
435 // draw lock icon
436 GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), pos, exaggeration, 0.4, 0.5, 0.5);
437 // check if mouse is over element
438 mouseWithinGeometry(pos, size, size, 0, 0, 0);
439 // inspect contour
442 }
443 // front element contour
444 if ((myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
446 }
447 // delete contour
448 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
450 }
451 // select contour
452 if (myNet->getViewNet()->drawSelectContour(this, this)) {
454 }
455 // Draw additional ID
457 // draw additional name
459 }
460}
461
462
463void
464GNEAdditional::drawListedAddtional(const GUIVisualizationSettings& s, const Position& parentPosition, const double offsetX, const double extraOffsetY,
465 const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const {
466 // first check if additional has to be drawn
468 // declare offsets
469 const double lineOffset = 0.1875;
470 const double baseOffsetX = 6.25;
471 const double baseOffsetY = 0.6;
472 // get draw position index
473 const int drawPositionIndex = getDrawPositionIndex();
474 // calculate lineA position (from parent to middle)
475 Position positionLineA = parentPosition;
476 const double positionLineA_Y = (0 - extraOffsetY + baseOffsetY);
477 // set position depending of indexes
478 positionLineA.add(1 + lineOffset + (baseOffsetX * offsetX), positionLineA_Y, 0);
479 // calculate lineC position (From middle until current listenAdditional
480 Position positionLineB = parentPosition;
481 const double positionLineB_Y = ((drawPositionIndex * -1) - extraOffsetY + baseOffsetY);
482 // set position depending of indexes
483 positionLineB.add(1 + lineOffset + (baseOffsetX * offsetX) + (2 * lineOffset), positionLineB_Y, 0);
484 // calculate signPosition position
485 Position signPosition = parentPosition;
486 // set position depending of indexes
487 signPosition.add(4.5 + (baseOffsetX * offsetX), (drawPositionIndex * -1) - extraOffsetY + 1, 0);
488 // check if boundary has to be drawn
489 if (s.drawBoundaries) {
491 }
492 // Start drawing adding an gl identificator
494 // calculate colors
496 const RGBColor secondColor = baseColor.changedBrightness(-30);
498 // Add layer matrix
500 // translate to front
502 // set line color
504 // draw both lines
505 GLHelper::drawBoxLine(positionLineA, 0, 0.1, lineOffset);
506 GLHelper::drawBoxLine(positionLineB, 0, 0.1, lineOffset);
507 // check if draw middle lane
508 if (drawPositionIndex != 0) {
509 // calculate length
510 const double length = std::abs(positionLineA_Y - positionLineB_Y);
511 // push middle lane matrix
513 //move and rotate
514 glTranslated(positionLineA.x() + lineOffset, positionLineA.y(), 0);
515 glRotated(90, 0, 0, 1);
516 glTranslated((length * -0.5), 0, 0);
517 // draw line
518 GLHelper::drawBoxLine(Position(0, 0), 0, 0.1, length * 0.5);
519 // pop middle lane matrix
521 }
522 // draw extern rectangle
523 GLHelper::setColor(secondColor);
524 GLHelper::drawBoxLine(signPosition, 0, 0.96, 2.75);
525 // move to front
526 glTranslated(0, -0.06, 0.1);
527 // draw intern rectangle
528 GLHelper::setColor(baseColor);
529 GLHelper::drawBoxLine(signPosition, 0, 0.84, 2.69);
530 // move position down
531 signPosition.add(-2, -0.43, 0);
532 // draw interval
533 GLHelper::drawText(adjustListedAdditionalText(text), signPosition, .1, 0.5, textColor, 0, (FONS_ALIGN_LEFT | FONS_ALIGN_MIDDLE));
534 // move to icon position
535 signPosition.add(-0.3, 0);
536 // check if draw lock icon or rerouter interval icon
538 // pop layer matrix
540 // Pop name
542 // draw lock icon
543 GNEViewNetHelper::LockIcon::drawLockIcon(this, getType(), signPosition, 1, 0.4, 0.0, -0.05);
544 } else {
545 // translate to front
546 glTranslated(signPosition.x(), signPosition.y(), 0.1);
547 // set White color
548 glColor3d(1, 1, 1);
549 // rotate
550 glRotated(180, 0, 0, 1);
551 // draw texture
553 // pop layer matrix
555 // Pop name
557 }
558 // check if dotted contour has to be drawn
561 }
562 if ((myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
564 }
565 }
566}
567
568
570GNEAdditional::getMoveOperationSingleLane(const double startPos, const double endPos) {
571 // get allow change lane
572 const bool allowChangeLane = myNet->getViewNet()->getViewParent()->getMoveFrame()->getCommonModeOptions()->getAllowChangeLane();
573 // fist check if we're moving only extremes
575 // get snap radius
577 // get mouse position
578 const Position mousePosition = myNet->getViewNet()->getPositionInformation();
579 // check if we clicked over start or end position
580 if (myAdditionalGeometry.getShape().front().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
581 // move only start position
582 return new GNEMoveOperation(this, getParentLanes().front(), startPos, endPos,
584 } else if (myAdditionalGeometry.getShape().back().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
585 // move only end position
586 return new GNEMoveOperation(this, getParentLanes().front(), startPos, endPos,
588 } else {
589 return nullptr;
590 }
591 } else {
592 // move both start and end positions
593 return new GNEMoveOperation(this, getParentLanes().front(), startPos, endPos,
595 }
596}
597
598
600GNEAdditional::getMoveOperationMultiLane(const double startPos, const double endPos) {
601 // check if shift is pressed
602 const bool shift = myNet->getViewNet()->getMouseButtonKeyPressed().shiftKeyPressed();
603 // get snap radius
605 // get mouse position
606 const Position mousePosition = myNet->getViewNet()->getPositionInformation();
607 // calculate both geometries
608 GUIGeometry fromGeometry, toGeometry;
609 fromGeometry.updateGeometry(getParentLanes().front()->getLaneGeometry().getShape(), startPos, 0);
610 toGeometry.updateGeometry(getParentLanes().back()->getLaneGeometry().getShape(), endPos, 0);
611 // check if we clicked over start or end position
612 if (fromGeometry.getShape().front().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
613 // move using start position
614 return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
616 } else if (toGeometry.getShape().back().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius)) {
617 // move using end position
618 return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
620 } else {
621 return nullptr;
622 }
623}
624
625
626GNELane*
628 return getParentLanes().front();
629}
630
631
632GNELane*
634 return getParentLanes().back();
635}
636
637
638double
641}
642
643
647}
648
649
650double
653}
654
655
659}
660
661
664 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
665}
666
667
668void
669GNEAdditional::drawParentChildLines(const GUIVisualizationSettings& s, const RGBColor& color, const bool onlySymbols) const {
670 // check if current additional is inspected, front or selected
671 const bool currentDrawEntire = myNet->getViewNet()->isAttributeCarrierInspected(this) ||
673 // push layer matrix
675 // translate to parentChildLine layer
676 glTranslated(0, 0, GLO_PARENTCHILDLINE);
677 // iterate over parent additionals
678 for (const auto& parent : getParentAdditionals()) {
679 // get inspected flag
680 const bool inspected = myNet->getViewNet()->isAttributeCarrierInspected(parent);
681 // draw parent lines
682 GUIGeometry::drawParentLine(s, getPositionInView(), parent->getPositionInView(),
683 (isAttributeCarrierSelected() || parent->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
684 currentDrawEntire || inspected || parent->isAttributeCarrierSelected(), .05);
685 }
686 // special case for Parking area reroutes
687 if (getTagProperty().getTag() == SUMO_TAG_REROUTER) {
688 // iterate over rerouter elements
689 for (const auto& rerouterInterval : getChildAdditionals()) {
690 for (const auto& rerouterElement : rerouterInterval->getChildAdditionals()) {
691 if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
692 // get parking area
693 const auto parkingArea = rerouterElement->getParentAdditionals().at(1);
694 // get inspected flag
695 const bool inspected = myNet->getViewNet()->isAttributeCarrierInspected(parkingArea);
696 // draw parent lines
697 GUIGeometry::drawParentLine(s, getPositionInView(), parkingArea->getPositionInView(),
698 (isAttributeCarrierSelected() || parkingArea->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
699 currentDrawEntire || inspected || parkingArea->isAttributeCarrierSelected(), .05);
700 }
701 }
702 }
703 }
704 // iterate over child additionals
705 for (const auto& child : getChildAdditionals()) {
706 // get inspected flag
707 const bool inspected = myNet->getViewNet()->isAttributeCarrierInspected(child);
708 // special case for parking zone reroute
709 if (child->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
710 // draw child line between parking area and rerouter
711 GUIGeometry::drawChildLine(s, getPositionInView(), child->getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView(),
712 (isAttributeCarrierSelected() || child->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
713 currentDrawEntire || inspected || child->isAttributeCarrierSelected(), .05);
714 } else if (!onlySymbols || child->getTagProperty().isSymbol()) {
715 // draw child line
716 GUIGeometry::drawChildLine(s, getPositionInView(), child->getPositionInView(),
717 (isAttributeCarrierSelected() || child->isAttributeCarrierSelected()) ? s.additionalSettings.connectionColorSelected : color,
718 currentDrawEntire || inspected || child->isAttributeCarrierSelected(), .05);
719 }
720 }
721 // pop layer matrix
723}
724
725
726void
727GNEAdditional::drawUpGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
728 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, -90, 90, ignoreShift);
729}
730
731
732void
733GNEAdditional::drawDownGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
734 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, 90, 270, ignoreShift);
735}
736
737
738void
739GNEAdditional::drawLeftGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
740 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, -90, 90, ignoreShift);
741}
742
743
744void
745GNEAdditional::drawRightGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor, const bool ignoreShift) {
746 drawSemiCircleGeometryPoint(viewNet, pos, rot, baseColor, 270, 90, ignoreShift);
747}
748
749
750int
752 // filter symbols
753 std::vector<GNEAdditional*> children;
754 for (const auto& child : getParentAdditionals().front()->getChildAdditionals()) {
755 if (!child->getTagProperty().isSymbol()) {
756 children.push_back(child);
757 }
758 }
759 // now get index
760 for (int i = 0; i < (int)children.size(); i++) {
761 if (children.at(i) == this) {
762 return i;
763 }
764 }
765 return 0;
766}
767
768
769bool
770GNEAdditional::areLaneConsecutives(const std::vector<GNELane*>& lanes) {
771 // declare lane iterator
772 int laneIt = 0;
773 // iterate over all lanes
774 while (laneIt < ((int)lanes.size() - 1)) {
775 // we assume that lanes aren't consecutives
776 bool consecutiveFound = false;
777 // get lanes
778 const auto lane = lanes.at(laneIt);
779 const auto nextLane = lanes.at(laneIt + 1);
780 // if there is a connection betwen "from" lane and "to" lane of connection, change connectionFound to true
781 for (const auto& outgoingEdge : lane->getParentEdge()->getToJunction()->getGNEOutgoingEdges()) {
782 for (const auto& outgoingLane : outgoingEdge->getLanes()) {
783 if (outgoingLane == nextLane) {
784 consecutiveFound = true;
785 }
786 }
787 }
788 // abort if consecutiveFound is false
789 if (!consecutiveFound) {
790 return false;
791 }
792 // update iterator
793 laneIt++;
794 }
795 // lanes are consecutive, then return true
796 return true;
797}
798
799
800bool
801GNEAdditional::areLaneConnected(const std::vector<GNELane*>& lanes) {
802 // declare lane iterator
803 int laneIt = 0;
804 // iterate over all lanes, and stop if myE2valid is false
805 while (laneIt < ((int)lanes.size() - 1)) {
806 // we assume that E2 is invalid
807 bool connectionFound = false;
808 // get lanes
809 const auto lane = lanes.at(laneIt);
810 const auto nextLane = lanes.at(laneIt + 1);
811 // check if both lanes are sidewalks
812 if ((lane->getAttribute(SUMO_ATTR_ALLOW) == "pedestrian") && (nextLane->getAttribute(SUMO_ATTR_ALLOW) == "pedestrian")) {
813 connectionFound = true;
814 }
815 // if there is a connection betwen "from" lane and "to" lane of connection, change connectionFound to true
816 for (const auto& connection : lane->getParentEdge()->getNBEdge()->getConnections()) {
817 if ((connection.toEdge == nextLane->getParentEdge()->getNBEdge()) &&
818 (connection.fromLane == lane->getIndex()) &&
819 (connection.toLane == nextLane->getIndex())) {
820 connectionFound = true;
821 }
822 }
823 // abort if connectionFound is false
824 if (!connectionFound) {
825 return false;
826 }
827 // update iterator
828 laneIt++;
829 }
830 // there are connections between all lanes, then return true
831 return true;
832}
833
834
835bool
837 // throw exception because this function mus be implemented in child (see GNEE3Detector)
838 throw ProcessError("Calling non-implemented function checkChildAdditionalRestriction during saving of " + getTagStr() + ". It muss be reimplemented in child class");
839}
840
841
842void
843GNEAdditional::drawSemiCircleGeometryPoint(const GNEViewNet* viewNet, const Position& pos, const double rot, const RGBColor& baseColor,
844 const double fromAngle, const double toAngle, const bool ignoreShift) {
845 // first check that we're in move mode and shift key is pressed
847 (viewNet->getMouseButtonKeyPressed().shiftKeyPressed() || ignoreShift)) {
848 // calculate new color
849 const RGBColor color = baseColor.changedBrightness(-50);
850 // push matrix
852 // translated to front
853 glTranslated(0, 0, 0.1);
854 // set color
855 GLHelper::setColor(color);
856 // push geometry point matrix
858 // translate and rotate
859 glTranslated(pos.x(), pos.y(), 0.1);
860 glRotated(rot, 0, 0, 1);
861 // draw geometry point
863 viewNet->getVisualisationSettings().getCircleResolution(), fromAngle, toAngle);
864 // pop geometry point matrix
866 // pop draw matrix
868 }
869}
870
871
872std::string
873GNEAdditional::adjustListedAdditionalText(const std::string& text) const {
874 // 10 + 3 + 10
875 if (text.size() <= 23) {
876 return text;
877 } else {
878 // get text size
879 const int textPosition = (int)text.size() - 10;
880 // declare strings
881 std::string partA, partB;
882 // resize
883 partA.reserve(10);
884 partB.reserve(10);
885 // fill both
886 for (int i = 0; i < 10; i++) {
887 partA.push_back(text.at(i));
888 partB.push_back(text.at(textPosition + i));
889 }
890 // return composition
891 return (partA + "..." + partB);
892 }
893}
894
895/****************************************************************************/
@ 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:460
@ 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
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_LANE
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_ENDPOS
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:894
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 std::string getAttribute(SumoXMLAttr key) const =0
GNELane * getLastPathLane() const
get last path lane
virtual bool isAdditionalValid() const
check if current additional is valid to be written into XML (by default true, can be reimplemented in...
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
static void drawRightGeometryPoint(const GNEViewNet *viewNet, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false)
draw right geometry point
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
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
virtual void fixAdditionalProblem()
fix additional problem (by default throw an exception, has to be reimplemented in children)
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
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.
virtual std::string getAdditionalProblem() const
return a string with the current additional problem (by default empty, can be reimplemented in childr...
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 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:481
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition: GNEEdge.cpp:839
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:142
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:876
GNEEdge * getParentEdge() const
get parent edge
Definition: GNELane.cpp:124
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:629
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
void setFrontAttributeCarrier(GNEAttributeCarrier *AC)
set front attributeCarrier
const GNEViewNetHelper::MouseButtonKeyPressed & getMouseButtonKeyPressed() const
get Key Pressed module
Definition: GNEViewNet.cpp:662
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.
Definition: GNEViewNet.cpp:474
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
Definition: GUIDesigns.cpp:42
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
Definition: GUIGeometry.cpp:58
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.
Definition: GUIGlObject.h:141
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 mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
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.
Definition: GUIGlObject.h:154
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.
Definition: GUIGlObject.h:102
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:648
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
@ 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