Path: blob/main/src/netedit/elements/network/GNEInternalLane.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 GNEInternalLane.cpp14/// @author Jakob Erdmann15/// @date June 201116///17// A class for visualizing Inner Lanes (used when editing traffic lights)18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/frames/network/GNETLSEditorFrame.h>22#include <utils/gui/div/GLHelper.h>23#include <utils/gui/div/GUIParameterTableWindow.h>24#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>2526#include "GNEInternalLane.h"2728// ===========================================================================29// FOX callback mapping30// ===========================================================================3132FXIMPLEMENT(GNEInternalLane, FXDelegator, 0, 0)3334// ===========================================================================35// static member definitions36// ===========================================================================3738StringBijection<FXuint>::Entry GNEInternalLane::linkStateNamesValues[] = {39{ "Green-Major", LINKSTATE_TL_GREEN_MAJOR },40{ "Green-Minor", LINKSTATE_TL_GREEN_MINOR },41//{ "Yellow-Major", LINKSTATE_TL_YELLOW_MAJOR }, (should not be used)42{ "Yellow", LINKSTATE_TL_YELLOW_MINOR },43{ "Red", LINKSTATE_TL_RED },44{ "Red-Yellow", LINKSTATE_TL_REDYELLOW },45{ "Stop", LINKSTATE_STOP },46{ "Off", LINKSTATE_TL_OFF_NOSIGNAL },47{ "Off-Blinking", LINKSTATE_TL_OFF_BLINKING },48};4950const StringBijection<FXuint> GNEInternalLane::LinkStateNames(51GNEInternalLane::linkStateNamesValues, LINKSTATE_TL_OFF_BLINKING);5253// ===========================================================================54// method definitions55// ===========================================================================5657GNEInternalLane::GNEInternalLane(GNETLSEditorFrame* editor, GNEJunction* junctionParent,58const std::string& id, const PositionVector& shape, int tlIndex, LinkState state) :59GNENetworkElement(junctionParent->getNet(), id, GNE_TAG_INTERNAL_LANE),60myJunctionParent(junctionParent),61myState(state),62myStateTarget(myState),63myEditor(editor),64myTlIndex(tlIndex),65myPopup(nullptr) {66// calculate internal lane geometry67myInternalLaneGeometry.updateGeometry(shape);68// update centering boundary without updating grid69updateCenteringBoundary(false);70// vinculate this internal lane with their junction parent71myJunctionParent->addInternalLane(this);72}737475GNEInternalLane::GNEInternalLane() :76GNENetworkElement(nullptr, "dummyInternalLane", GNE_TAG_INTERNAL_LANE),77myJunctionParent(nullptr),78myState(0),79myEditor(0),80myTlIndex(0),81myPopup(nullptr) {82}838485GNEInternalLane::~GNEInternalLane() {86// remove this internal lane from junction parent87myJunctionParent->removeInternalLane(this);88}899091GNEMoveElement*92GNEInternalLane::getMoveElement() const {93return nullptr;94}959697Parameterised*98GNEInternalLane::getParameters() {99return nullptr;100}101102103const Parameterised*104GNEInternalLane::getParameters() const {105return nullptr;106}107108109void110GNEInternalLane::updateGeometry() {111// nothing to update112}113114115Position116GNEInternalLane::getPositionInView() const {117return myJunctionParent->getPositionInView();118}119120121bool122GNEInternalLane::checkDrawFromContour() const {123return false;124}125126127bool128GNEInternalLane::checkDrawToContour() const {129return false;130}131132133bool134GNEInternalLane::checkDrawRelatedContour() const {135// check opened popup136if (myNet->getViewNet()->getPopup()) {137return myNet->getViewNet()->getPopup()->getGLObject() == this;138}139return false;140}141142143bool144GNEInternalLane::checkDrawOverContour() const {145return myNet->getViewNet()->getViewObjectsSelector().getGUIGlObjectFront() == this;146}147148149bool150GNEInternalLane::checkDrawDeleteContour() const {151return false;152}153154155bool156GNEInternalLane::checkDrawDeleteContourSmall() const {157return false;158}159160161bool162GNEInternalLane::checkDrawSelectContour() const {163return false;164}165166167bool168GNEInternalLane::checkDrawMoveContour() const {169return false;170}171172173long174GNEInternalLane::onDefault(FXObject* obj, FXSelector sel, void* data) {175if (myEditor != nullptr) {176FXuint before = myState;177myStateTarget.handle(obj, sel, data);178if (myState != before) {179myEditor->handleChange(this);180}181// let GUISUMOAbstractView know about clicks so that the popup is properly destroyed182if (FXSELTYPE(sel) == SEL_COMMAND) {183if (myPopup != nullptr) {184myPopup->getParentView()->destroyPopup();185myPopup = nullptr;186}187}188}189return 1;190}191192193void194GNEInternalLane::drawGL(const GUIVisualizationSettings& s) const {195// only draw if we're not selecting E1 detectors in TLS Mode196if (!myNet->getViewNet()->selectingDetectorsTLSMode()) {197// get detail level198const auto d = s.getDetailLevel(1);199// draw geometry only if we'rent in drawForObjectUnderCursor mode200if (!s.drawForViewObjectsHandler) {201// get link state color202const auto linkStateColor = colorForLinksState(myState);203// push layer matrix204GLHelper::pushMatrix();205// translate to front206myJunctionParent->drawInLayer(GLO_TLLOGIC);207// move front again208glTranslated(0, 0, 0.5);209// set color210GLHelper::setColor(linkStateColor);211// draw geometry212GUIGeometry::drawGeometry(d, myInternalLaneGeometry,213s.connectionSettings.connectionWidth);214// pop layer matrix215GLHelper::popMatrix();216// draw dotted contour217myNetworkElementContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);218}219// calculate contour220myNetworkElementContour.calculateContourExtrudedShape(s, d, this, myInternalLaneGeometry.getShape(), getType(),221s.connectionSettings.connectionWidth, 1, true, true, 0, nullptr, myJunctionParent);222}223}224225226void227GNEInternalLane::deleteGLObject() {228// Internal lanes cannot be removed229}230231232void233GNEInternalLane::updateGLObject() {234updateGeometry();235}236237238void239GNEInternalLane::setLinkState(LinkState state) {240myState = state;241myOrigState = state;242}243244245LinkState246GNEInternalLane::getLinkState() const {247return (LinkState)myState;248}249250251int252GNEInternalLane::getTLIndex() const {253return myTlIndex;254}255256257GUIGLObjectPopupMenu*258GNEInternalLane::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {259myPopup = new GUIGLObjectPopupMenu(app, parent, this);260buildPopupHeader(myPopup, app);261if ((myEditor != nullptr) && (myEditor->getViewNet()->getEditModes().isCurrentSupermodeNetwork())) {262const std::vector<std::string> names = LinkStateNames.getStrings();263for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {264FXuint state = LinkStateNames.get(*it);265std::string origHint = ((LinkState)state == myOrigState ? " (original)" : "");266FXMenuRadio* mc = new FXMenuRadio(myPopup, (*it + origHint).c_str(), this, FXDataTarget::ID_OPTION + state);267mc->setSelBackColor(MFXUtils::getFXColor(colorForLinksState(state)));268mc->setBackColor(MFXUtils::getFXColor(colorForLinksState(state)));269}270}271return myPopup;272}273274275GUIParameterTableWindow*276GNEInternalLane::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {277// internal lanes don't have attributes278GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);279// close building280ret->closeBuilding();281return ret;282}283284285Boundary286GNEInternalLane::getCenteringBoundary() const {287return myNetworkElementContour.getContourBoundary();288}289290291void292GNEInternalLane::updateCenteringBoundary(const bool /*updateGrid*/) {293// nothing to update294}295296297RGBColor298GNEInternalLane::colorForLinksState(FXuint state) {299try {300return GUIVisualizationSettings::getLinkColor((LinkState)state);301} catch (ProcessError&) {302WRITE_WARNINGF(TL("invalid link state='%'"), toString(state));303return RGBColor::BLACK;304}305}306307308std::string309GNEInternalLane::getAttribute(SumoXMLAttr key) const {310return getCommonAttribute(key);311}312313314double315GNEInternalLane::getAttributeDouble(SumoXMLAttr key) const {316return getCommonAttributeDouble(key);317}318319320Position321GNEInternalLane::getAttributePosition(SumoXMLAttr key) const {322return getCommonAttributePosition(key);323}324325326PositionVector327GNEInternalLane::getAttributePositionVector(SumoXMLAttr key) const {328return getCommonAttributePositionVector(key);329}330331332void333GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {334setCommonAttribute(key, value, undoList);335}336337338bool339GNEInternalLane::isValid(SumoXMLAttr key, const std::string& value) {340return isCommonAttributeValid(key, value);341}342343344void345GNEInternalLane::setAttribute(SumoXMLAttr key, const std::string& value) {346setCommonAttribute(key, value);347}348349/****************************************************************************/350351352