Path: blob/main/src/netedit/elements/additional/GNEParkingAreaReroute.cpp
169684 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 GNEParkingAreaReroute.cpp14/// @author Jakob Erdmann15/// @date May 201816///17//18/****************************************************************************/19#include <config.h>2021#include <netedit/GNENet.h>22#include <netedit/GNEUndoList.h>23#include <netedit/changes/GNEChange_Attribute.h>2425#include "GNEParkingAreaReroute.h"2627// ===========================================================================28// member method definitions29// ===========================================================================3031GNEParkingAreaReroute::GNEParkingAreaReroute(GNENet* net):32GNEAdditional("", net, "", SUMO_TAG_PARKING_AREA_REROUTE, "") {33}343536GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea,37const double probability, const bool visible):38GNEAdditional(rerouterIntervalParent, SUMO_TAG_PARKING_AREA_REROUTE, ""),39myProbability(probability),40myVisible(visible) {41// set parents42setParents<GNEAdditional*>({rerouterIntervalParent, newParkingArea});43// update boundary of rerouter parent44rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);45}464748GNEParkingAreaReroute::~GNEParkingAreaReroute() {}495051void52GNEParkingAreaReroute::writeAdditional(OutputDevice& device) const {53device.openTag(SUMO_TAG_PARKING_AREA_REROUTE);54device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_PARKING));55if (myProbability != 1.0) {56device.writeAttr(SUMO_ATTR_PROB, myProbability);57}58if (myVisible) {59device.writeAttr(SUMO_ATTR_VISIBLE, true);60}61device.closeTag();62}636465bool66GNEParkingAreaReroute::isAdditionalValid() const {67return true;68}697071std::string72GNEParkingAreaReroute::getAdditionalProblem() const {73return "";74}757677void78GNEParkingAreaReroute::fixAdditionalProblem() {79// nothing to fix80}818283bool84GNEParkingAreaReroute::checkDrawMoveContour() const {85return false;86}878889GNEMoveOperation*90GNEParkingAreaReroute::getMoveOperation() {91// GNEParkingAreaReroutes cannot be moved92return nullptr;93}949596void97GNEParkingAreaReroute::updateGeometry() {98// update centering boundary (needed for centering)99updateCenteringBoundary(false);100}101102103Position104GNEParkingAreaReroute::getPositionInView() const {105// get rerouter parent position106Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();107// set position depending of indexes108signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);109// return signPosition110return signPosition;111}112113114void115GNEParkingAreaReroute::updateCenteringBoundary(const bool /*updateGrid*/) {116// nothing to update117}118119120void121GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {122// geometry of this element cannot be splitted123}124125126std::string127GNEParkingAreaReroute::getParentName() const {128return getParentAdditionals().at(0)->getID();129}130131132void133GNEParkingAreaReroute::drawGL(const GUIVisualizationSettings& s) const {134// draw route prob reroute as listed attribute135drawListedAdditional(s, getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView(),1361, getParentAdditionals().front()->getDrawPositionIndex(),137RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_PARKINGAREAREROUTE,138getAttribute(SUMO_ATTR_PARKING) + ": " + getAttribute(SUMO_ATTR_PROB));139}140141142std::string143GNEParkingAreaReroute::getAttribute(SumoXMLAttr key) const {144switch (key) {145case SUMO_ATTR_ID:146return getMicrosimID();147case SUMO_ATTR_PARKING:148return getParentAdditionals().at(1)->getID();149case SUMO_ATTR_PROB:150return toString(myProbability);151case SUMO_ATTR_VISIBLE:152return toString(myVisible);153case GNE_ATTR_PARENT:154return toString(getParentAdditionals().at(0)->getID());155default:156return getCommonAttribute(this, key);157}158}159160161double162GNEParkingAreaReroute::getAttributeDouble(SumoXMLAttr key) const {163throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");164}165166167const Parameterised::Map&168GNEParkingAreaReroute::getACParametersMap() const {169return getParametersMap();170}171172173void174GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {175if (value == getAttribute(key)) {176return; //avoid needless changes, later logic relies on the fact that attributes have changed177}178switch (key) {179case SUMO_ATTR_ID:180case SUMO_ATTR_PARKING:181case SUMO_ATTR_PROB:182case SUMO_ATTR_VISIBLE:183GNEChange_Attribute::changeAttribute(this, key, value, undoList);184break;185default:186setCommonAttribute(key, value, undoList);187break;188}189}190191192bool193GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {194switch (key) {195case SUMO_ATTR_ID:196return isValidAdditionalID(value);197case SUMO_ATTR_PARKING:198return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);199case SUMO_ATTR_PROB:200return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;201case SUMO_ATTR_VISIBLE:202return canParse<bool>(value);203default:204return isCommonValid(key, value);205}206}207208209std::string210GNEParkingAreaReroute::getPopUpID() const {211return getTagStr();212}213214215std::string216GNEParkingAreaReroute::getHierarchyName() const {217return getTagStr() + ": " + getParentAdditionals().at(1)->getID();218}219220// ===========================================================================221// private222// ===========================================================================223224void225GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {226switch (key) {227case SUMO_ATTR_ID:228// update microsimID229setAdditionalID(value);230break;231case SUMO_ATTR_PARKING:232replaceAdditionalParent(SUMO_TAG_PARKING_AREA, value, 1);233break;234case SUMO_ATTR_PROB:235myProbability = parse<double>(value);236break;237case SUMO_ATTR_VISIBLE:238myVisible = parse<bool>(value);239break;240default:241setCommonAttribute(this, key, value);242break;243}244}245246247void248GNEParkingAreaReroute::setMoveShape(const GNEMoveResult& /*moveResult*/) {249// nothing to do250}251252253void254GNEParkingAreaReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {255// nothing to do256}257258259/****************************************************************************/260261262