Path: blob/main/src/netedit/elements/demand/GNERouteDistribution.cpp
185790 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNERouteDistribution.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 202216///17// Route distribution used in netedit18/****************************************************************************/1920#include <netedit/GNETagProperties.h>21#include <netedit/GNENet.h>22#include <netedit/changes/GNEChange_Attribute.h>23#include <utils/xml/NamespaceIDs.h>2425#include "GNERouteDistribution.h"2627// ===========================================================================28// member method definitions29// ===========================================================================3031GNERouteDistribution::GNERouteDistribution(GNENet* net) :32GNEDemandElement(net, SUMO_TAG_ROUTE_DISTRIBUTION) {33}343536GNERouteDistribution::GNERouteDistribution(const std::string& ID, GNENet* net, FileBucket* fileBucket) :37GNEDemandElement(ID, net, SUMO_TAG_ROUTE_DISTRIBUTION, fileBucket) {38}394041GNERouteDistribution::~GNERouteDistribution() {}424344GNEMoveElement*45GNERouteDistribution::getMoveElement() const {46return nullptr;47}484950Parameterised*51GNERouteDistribution::getParameters() {52return nullptr;53}545556const Parameterised*57GNERouteDistribution::getParameters() const {58return nullptr;59}606162void63GNERouteDistribution::writeDemandElement(OutputDevice& device) const {64// write attributes65device.openTag(getTagProperty()->getTag());66device.writeAttr(SUMO_ATTR_ID, getID());67// write references68for (const auto& refChild : getChildDemandElements()) {69if (refChild->getTagProperty()->isDistributionReference()) {70if (refChild->getTagProperty()->isDistributionReference() &&71(refChild->getParentDemandElements().front() == this)) {72refChild->writeDemandElement(device);73}74}75}76device.closeTag();77}787980GNEDemandElement::Problem81GNERouteDistribution::isDemandElementValid() const {82// currently distributions don't have problems83return GNEDemandElement::Problem::OK;84}858687std::string88GNERouteDistribution::getDemandElementProblem() const {89return "";90}919293void94GNERouteDistribution::fixDemandElementProblem() {95// nothing to fix96}979899SUMOVehicleClass100GNERouteDistribution::getVClass() const {101if (getChildDemandElements().size() > 0) {102return getChildDemandElements().front()->getVClass();103} else {104return SVC_IGNORING;105}106}107108109const RGBColor&110GNERouteDistribution::getColor() const {111if (getChildDemandElements().size() > 0) {112return getChildDemandElements().front()->getColor();113} else {114return RGBColor::INVISIBLE;115}116}117118119void120GNERouteDistribution::updateGeometry() {121// update geometries of all vehicles122for (auto vehicle : getChildDemandElements()) {123if (vehicle->getTagProperty()->isVehicle()) {124vehicle->updateGeometry();125}126}127}128129130Position131GNERouteDistribution::getPositionInView() const {132if (getChildDemandElements().size() > 0) {133return getChildDemandElements().front()->getPositionInView();134} else {135return Position();136}137}138139140std::string141GNERouteDistribution::getParentName() const {142return myNet->getMicrosimID();143}144145146Boundary147GNERouteDistribution::getCenteringBoundary() const {148if (getChildDemandElements().size() > 0) {149return getChildDemandElements().front()->getCenteringBoundary();150} else {151return Boundary(-0.1, -0.1, 0.1, 0.1);152}153}154155156void157GNERouteDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {158// geometry of this element cannot be splitted159}160161162void163GNERouteDistribution::drawGL(const GUIVisualizationSettings& s) const {164// draw all vehicles165for (auto vehicle : getChildDemandElements()) {166if (vehicle->getTagProperty()->isVehicle()) {167vehicle->drawGL(s);168}169}170}171172173void174GNERouteDistribution::computePathElement() {175// nothing to compute176}177178179void180GNERouteDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {181// route distributions don't use drawJunctionPartialGL182}183184185void186GNERouteDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {187// route distributions don't use drawJunctionPartialGL188}189190191GNELane*192GNERouteDistribution::getFirstPathLane() const {193if (getChildDemandElements().size() > 0) {194return getChildDemandElements().front()->getFirstPathLane();195} else {196return nullptr;197}198}199200201GNELane*202GNERouteDistribution::getLastPathLane() const {203if (getChildDemandElements().size() > 0) {204return getChildDemandElements().front()->getLastPathLane();205} else {206return nullptr;207}208}209210211std::string212GNERouteDistribution::getAttribute(SumoXMLAttr key) const {213switch (key) {214case SUMO_ATTR_ID:215return getMicrosimID();216default:217return getCommonAttribute(key);218}219}220221222double223GNERouteDistribution::getAttributeDouble(SumoXMLAttr key) const {224return getCommonAttributeDouble(key);225}226227228Position229GNERouteDistribution::getAttributePosition(SumoXMLAttr key) const {230return getCommonAttributePosition(key);231}232233234void235GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {236if (value == getAttribute(key)) {237return; //avoid needless changes, later logic relies on the fact that attributes have changed238}239switch (key) {240case SUMO_ATTR_ID:241GNEChange_Attribute::changeAttribute(this, key, value, undoList);242break;243default:244setCommonAttribute(key, value, undoList);245break;246}247}248249250bool251GNERouteDistribution::isValid(SumoXMLAttr key, const std::string& value) {252switch (key) {253case SUMO_ATTR_ID:254return isValidDemandElementID(NamespaceIDs::routes, value);255default:256return isCommonAttributeValid(key, value);257}258}259260261std::string262GNERouteDistribution::getPopUpID() const {263return getTagStr();264}265266267std::string268GNERouteDistribution::getHierarchyName() const {269return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;270}271272// ===========================================================================273// private274// ===========================================================================275276void277GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {278switch (key) {279case SUMO_ATTR_ID:280setDemandElementID(value);281break;282default:283setCommonAttribute(key, value);284break;285}286}287288/****************************************************************************/289290291