Path: blob/main/src/netedit/elements/additional/GNEBusStop.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 GNEBusStop.cpp14/// @author Pablo Alvarez Lopez15/// @date Nov 201516///17// A lane area vehicles can halt at (GNE version)18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNETagProperties.h>22#include <netedit/changes/GNEChange_Attribute.h>23#include <utils/options/OptionsCont.h>24#include <utils/gui/div/GLHelper.h>2526#include "GNEBusStop.h"2728// ===========================================================================29// method definitions30// ===========================================================================3132GNEBusStop*33GNEBusStop::buildBusStop(GNENet* net) {34return new GNEBusStop(SUMO_TAG_BUS_STOP, net);35}363738GNEBusStop*39GNEBusStop::buildTrainStop(GNENet* net) {40return new GNEBusStop(SUMO_TAG_TRAIN_STOP, net);41}424344GNEBusStop*45GNEBusStop::buildBusStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane,46const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,47const int personCapacity, const double parkingLength, const RGBColor& color, const bool friendlyPosition,48const double angle, const Parameterised::Map& parameters) {49return new GNEBusStop(SUMO_TAG_BUS_STOP, id, net, filename, lane, startPos, endPos, name, lines,50personCapacity, parkingLength, color, friendlyPosition, angle, parameters);51}525354GNEBusStop*55GNEBusStop::buildTrainStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane,56const double startPos, const double endPos, const std::string& name, const std::vector<std::string>& lines,57const int personCapacity, const double parkingLength, const RGBColor& color, const bool friendlyPosition,58const double angle, const Parameterised::Map& parameters) {59return new GNEBusStop(SUMO_TAG_TRAIN_STOP, id, net, filename, lane, startPos, endPos, name, lines,60personCapacity, parkingLength, color, friendlyPosition, angle, parameters);61}626364GNEBusStop::~GNEBusStop() {}656667void68GNEBusStop::writeAdditional(OutputDevice& device) const {69device.openTag(getTagProperty()->getTag());70// write common attributes71writeStoppingPlaceAttributes(device);72// write specific attributes73if (getAttribute(SUMO_ATTR_LINES) != myTagProperty->getDefaultStringValue(SUMO_ATTR_LINES)) {74device.writeAttr(SUMO_ATTR_LINES, toString(myLines));75}76if (myPersonCapacity != myTagProperty->getDefaultIntValue(SUMO_ATTR_PERSON_CAPACITY)) {77device.writeAttr(SUMO_ATTR_PERSON_CAPACITY, myPersonCapacity);78}79if (myParkingLength != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_PARKING_LENGTH)) {80device.writeAttr(SUMO_ATTR_PARKING_LENGTH, myParkingLength);81}82// write all access83for (const auto& access : getChildAdditionals()) {84access->writeAdditional(device);85}86// write parameters (Always after children to avoid problems with additionals.xsd)87writeParams(device);88device.closeTag();89}909192void93GNEBusStop::updateGeometry() {94// Get value of option "lefthand"95double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;96// Update common geometry of stopping place97setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);98// Obtain a copy of the shape99PositionVector tmpShape = myAdditionalGeometry.getShape();100// Move shape to side101tmpShape.move2side(myNet->getViewNet()->getVisualisationSettings().stoppingPlaceSettings.stoppingPlaceSignOffset * offsetSign);102// Get position of the sign103mySymbolPosition = tmpShape.getLineCenter();104// update demand element children105for (const auto& demandElement : getChildDemandElements()) {106demandElement->updateGeometry();107}108}109110111void112GNEBusStop::drawGL(const GUIVisualizationSettings& s) const {113// check if additional has to be drawn114if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {115// Obtain exaggeration of the draw116const double busStopExaggeration = getExaggeration(s);117// check if draw moving geometry points118const bool movingGeometryPoints = drawMovingGeometryPoints(false);119// get width120const double stopWidth = (myTagProperty->getTag() == SUMO_TAG_BUS_STOP) ? s.stoppingPlaceSettings.busStopWidth : s.stoppingPlaceSettings.trainStopWidth;121// get detail level122const auto d = s.getDetailLevel(busStopExaggeration);123// draw geometry only if we'rent in drawForObjectUnderCursor mode124if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {125// declare colors126RGBColor baseColor, signColor;127// set colors128if (mySpecialColor) {129baseColor = *mySpecialColor;130signColor = baseColor.changedBrightness(-32);131} else if (drawUsingSelectColor()) {132baseColor = s.colorSettings.selectedAdditionalColor;133signColor = baseColor.changedBrightness(-32);134} else if (myColor != RGBColor::INVISIBLE) {135baseColor = myColor;136signColor = s.colorSettings.busStopColorSign;137} else if (myTagProperty->getTag() == SUMO_TAG_TRAIN_STOP) {138baseColor = s.colorSettings.trainStopColor;139signColor = s.colorSettings.trainStopColorSign;140} else {141baseColor = s.colorSettings.busStopColor;142signColor = s.colorSettings.busStopColorSign;143}144// draw parent and child lines145drawParentChildLines(s, baseColor);146// Add layer matrix147GLHelper::pushMatrix();148// translate to front149drawInLayer(GLO_BUS_STOP);150// set base color151GLHelper::setColor(baseColor);152// Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration153GUIGeometry::drawGeometry(d, myAdditionalGeometry, stopWidth * MIN2(1.0, busStopExaggeration));154// draw lines155drawLines(d, myLines, baseColor);156// draw sign157drawSign(s, d, busStopExaggeration, baseColor, signColor, (myTagProperty->getTag() == SUMO_TAG_BUS_STOP) ? "H" : "T");158// draw geometry points159if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {160drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);161}162if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {163drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);164}165// pop layer matrix166GLHelper::popMatrix();167// draw lock icon168if (myTagProperty->getTag() == SUMO_TAG_BUS_STOP) {169GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), busStopExaggeration, 0.5);170} else {171GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), busStopExaggeration, 0.25);172}173// Draw additional ID174drawAdditionalID(s);175// draw additional name176drawAdditionalName(s);177// draw dotted contours178if (movingGeometryPoints) {179myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,1801, s.dottedContourSettings.segmentWidthSmall);181} else {182myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);183mySymbolContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidthSmall, true);184}185}186// draw demand element children187drawDemandElementChildren(s);188// calculate contours189calculateStoppingPlaceContour(s, d, stopWidth, busStopExaggeration, movingGeometryPoints);190}191}192193194std::string195GNEBusStop::getAttribute(SumoXMLAttr key) const {196switch (key) {197case SUMO_ATTR_LINES:198return joinToString(myLines, " ");199case SUMO_ATTR_PERSON_CAPACITY:200return toString(myPersonCapacity);201case SUMO_ATTR_PARKING_LENGTH:202return toString(myParkingLength);203default:204return getStoppingPlaceAttribute(this, key);205}206}207208209double210GNEBusStop::getAttributeDouble(SumoXMLAttr key) const {211return getStoppingPlaceAttributeDouble(key);212}213214215void216GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {217switch (key) {218case SUMO_ATTR_LINES:219case SUMO_ATTR_PERSON_CAPACITY:220case SUMO_ATTR_PARKING_LENGTH:221GNEChange_Attribute::changeAttribute(this, key, value, undoList);222break;223default:224setStoppingPlaceAttribute(key, value, undoList);225break;226}227}228229230bool231GNEBusStop::isValid(SumoXMLAttr key, const std::string& value) {232switch (key) {233case SUMO_ATTR_LINES:234return true;235case SUMO_ATTR_PERSON_CAPACITY:236return canParse<int>(value) && (parse<int>(value) > 0 || parse<int>(value) == -1);237case SUMO_ATTR_PARKING_LENGTH:238return canParse<double>(value) && (parse<double>(value) >= 0);239default:240return isStoppingPlaceValid(key, value);241}242}243244// ===========================================================================245// private246// ===========================================================================247248void249GNEBusStop::setAttribute(SumoXMLAttr key, const std::string& value) {250switch (key) {251case SUMO_ATTR_LINES:252myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);253break;254case SUMO_ATTR_PERSON_CAPACITY:255myPersonCapacity = GNEAttributeCarrier::parse<int>(value);256break;257case SUMO_ATTR_PARKING_LENGTH:258myParkingLength = GNEAttributeCarrier::parse<double>(value);259break;260default:261setStoppingPlaceAttribute(this, key, value);262break;263}264}265266267GNEBusStop::GNEBusStop(SumoXMLTag tag, GNENet* net) :268GNEStoppingPlace(net, tag) {269}270271272GNEBusStop::GNEBusStop(SumoXMLTag tag, const std::string& id, GNENet* net, const std::string& filename,273GNELane* lane, const double startPos, const double endPos, const std::string& name,274const std::vector<std::string>& lines, const int personCapacity, const double parkingLength,275const RGBColor& color, const bool friendlyPosition, const double angle,276const Parameterised::Map& parameters) :277GNEStoppingPlace(id, net, filename, tag, lane, startPos, endPos, name, friendlyPosition, color, angle, parameters),278myLines(lines),279myPersonCapacity(personCapacity),280myParkingLength(parkingLength) {281}282283/****************************************************************************/284285286