Path: blob/main/src/netedit/elements/additional/GNEContainerStop.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 GNEContainerStop.cpp14/// @author Pablo Alvarez Lopez15/// @date Jun 201616///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/gui/div/GLHelper.h>24#include <utils/options/OptionsCont.h>25#include <utils/vehicle/SUMORouteHandler.h>2627#include "GNEContainerStop.h"2829// ===========================================================================30// method definitions31// ===========================================================================3233GNEContainerStop::GNEContainerStop(GNENet* net) :34GNEStoppingPlace(net, SUMO_TAG_CONTAINER_STOP) {35}363738GNEContainerStop::GNEContainerStop(const std::string& id, GNENet* net, const std::string& filename, GNELane* lane, const double startPos, const double endPos,39const std::string& name, const std::vector<std::string>& lines, const int containerCapacity, const double parkingLength,40const RGBColor& color, const bool friendlyPosition, const double angle, const Parameterised::Map& parameters) :41GNEStoppingPlace(id, net, filename, SUMO_TAG_CONTAINER_STOP, lane, startPos, endPos, name, friendlyPosition, color, angle, parameters),42myLines(lines),43myContainerCapacity(containerCapacity),44myParkingLength(parkingLength) {45// update centering boundary without updating grid46updateCenteringBoundary(false);47}484950GNEContainerStop::~GNEContainerStop() {}515253void54GNEContainerStop::writeAdditional(OutputDevice& device) const {55device.openTag(getTagProperty()->getTag());56// write common attributes57writeStoppingPlaceAttributes(device);58// write specific attributes59if (getAttribute(SUMO_ATTR_LINES) != myTagProperty->getDefaultStringValue(SUMO_ATTR_LINES)) {60device.writeAttr(SUMO_ATTR_LINES, toString(myLines));61}62if (myContainerCapacity != myTagProperty->getDefaultIntValue(SUMO_ATTR_CONTAINER_CAPACITY)) {63device.writeAttr(SUMO_ATTR_CONTAINER_CAPACITY, myContainerCapacity);64}65if (myParkingLength != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_PARKING_LENGTH)) {66device.writeAttr(SUMO_ATTR_PARKING_LENGTH, myParkingLength);67}68// write all access69for (const auto& access : getChildAdditionals()) {70access->writeAdditional(device);71}72// write parameters (Always after children to avoid problems with additionals.xsd)73writeParams(device);74device.closeTag();75}767778void79GNEContainerStop::updateGeometry() {80// Get value of option "lefthand"81const double offsetSign = OptionsCont::getOptions().getBool("lefthand") ? -1 : 1;82// Update common geometry of stopping place83setStoppingPlaceGeometry(getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) / 2);84// Obtain a copy of the shape85PositionVector tmpShape = myAdditionalGeometry.getShape();86// move entire shape and update87tmpShape.move2side(2 * offsetSign);88myAdditionalGeometry.updateGeometry(tmpShape);89// Move shape to side90tmpShape.move2side(myNet->getViewNet()->getVisualisationSettings().stoppingPlaceSettings.stoppingPlaceSignOffset * offsetSign);91// Get position of the sign92mySymbolPosition = tmpShape.getLineCenter();93}949596void97GNEContainerStop::drawGL(const GUIVisualizationSettings& s) const {98// first check if additional has to be drawn99if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {100// Obtain exaggeration of the draw101const double containerStopExaggeration = getExaggeration(s);102// check if draw moving geometry points103const bool movingGeometryPoints = drawMovingGeometryPoints(false);104// get detail level105const auto d = s.getDetailLevel(containerStopExaggeration);106// draw geometry only if we'rent in drawForObjectUnderCursor mode107if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {108// declare colors109RGBColor baseColor, signColor;110// set colors111if (mySpecialColor) {112baseColor = *mySpecialColor;113signColor = baseColor.changedBrightness(-32);114} else if (drawUsingSelectColor()) {115baseColor = s.colorSettings.selectedAdditionalColor;116signColor = baseColor.changedBrightness(-32);117} else if (myColor != RGBColor::INVISIBLE) {118baseColor = myColor;119signColor = s.colorSettings.containerStopColorSign;120} else {121baseColor = s.colorSettings.containerStopColor;122signColor = s.colorSettings.containerStopColorSign;123}124// draw parent and child lines125drawParentChildLines(s, s.additionalSettings.connectionColor);126// Add a layer matrix127GLHelper::pushMatrix();128// translate to front129drawInLayer(GLO_CONTAINER_STOP);130// set base color131GLHelper::setColor(baseColor);132// Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration133GUIGeometry::drawGeometry(d, myAdditionalGeometry, s.stoppingPlaceSettings.containerStopWidth * MIN2(1.0, containerStopExaggeration));134// draw lines135drawLines(d, myLines, baseColor);136// draw sign137drawSign(s, d, containerStopExaggeration, baseColor, signColor, "C");138// draw geometry points139if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {140drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);141}142if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {143drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);144}145// pop layer matrix146GLHelper::popMatrix();147// draw lock icon148GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), containerStopExaggeration);149// Draw additional ID150drawAdditionalID(s);151// draw additional name152drawAdditionalName(s);153// draw dotted contours154if (movingGeometryPoints) {155myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,1561, s.dottedContourSettings.segmentWidthSmall);157} else {158myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);159mySymbolContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidthSmall, true);160}161}162// draw demand element children163drawDemandElementChildren(s);164// calculate contours165calculateStoppingPlaceContour(s, d, s.stoppingPlaceSettings.containerStopWidth, containerStopExaggeration, movingGeometryPoints);166}167}168169170std::string171GNEContainerStop::getAttribute(SumoXMLAttr key) const {172switch (key) {173174case SUMO_ATTR_LINES:175return joinToString(myLines, " ");176case SUMO_ATTR_CONTAINER_CAPACITY:177return toString(myContainerCapacity);178case SUMO_ATTR_PARKING_LENGTH:179return toString(myParkingLength);180default:181return getStoppingPlaceAttribute(this, key);182}183}184185186double187GNEContainerStop::getAttributeDouble(SumoXMLAttr key) const {188return getStoppingPlaceAttributeDouble(key);189}190191192void193GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {194switch (key) {195case SUMO_ATTR_LINES:196case SUMO_ATTR_CONTAINER_CAPACITY:197case SUMO_ATTR_PARKING_LENGTH:198GNEChange_Attribute::changeAttribute(this, key, value, undoList);199break;200default:201setStoppingPlaceAttribute(key, value, undoList);202break;203}204}205206207bool208GNEContainerStop::isValid(SumoXMLAttr key, const std::string& value) {209switch (key) {210case SUMO_ATTR_LINES:211return true;212case SUMO_ATTR_CONTAINER_CAPACITY:213return canParse<int>(value) && (parse<int>(value) >= 0);214case SUMO_ATTR_PARKING_LENGTH:215return canParse<double>(value) && (parse<double>(value) >= 0);216default:217return isStoppingPlaceValid(key, value);218}219}220221// ===========================================================================222// private223// ===========================================================================224225void226GNEContainerStop::setAttribute(SumoXMLAttr key, const std::string& value) {227switch (key) {228case SUMO_ATTR_LINES:229myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);230break;231case SUMO_ATTR_CONTAINER_CAPACITY:232myContainerCapacity = GNEAttributeCarrier::parse<int>(value);233break;234case SUMO_ATTR_PARKING_LENGTH:235if (value.empty()) {236myParkingLength = myTagProperty->getDefaultDoubleValue(key);237} else {238myParkingLength = GNEAttributeCarrier::parse<double>(value);239}240break;241default:242setStoppingPlaceAttribute(this, key, value);243break;244}245}246247248/****************************************************************************/249250251