Path: blob/main/src/netedit/frames/network/GNEProhibitionFrame.cpp
169685 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 GNEProhibitionFrame.cpp14/// @author Mirko Barthauer (Technische Universitaet Braunschweig)15/// @date May 201816///17// The Widget for editing connection prohibits18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNEViewNet.h>22#include <netedit/GNEViewParent.h>23#include <netedit/elements/network/GNEConnection.h>24#include <netedit/elements/network/GNEEdge.h>25#include <netedit/elements/network/GNEJunction.h>26#include <netedit/elements/network/GNELane.h>27#include <utils/foxtools/MFXLabelTooltip.h>28#include <utils/gui/div/GUIDesigns.h>2930#include "GNEProhibitionFrame.h"3132// ===========================================================================33// FOX callback mapping34// ===========================================================================3536FXDEFMAP(GNEProhibitionFrame::Selection) SelectionMap[] = {37FXMAPFUNC(SEL_COMMAND, MID_OK, GNEProhibitionFrame::Selection::onCmdOK),38FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNEProhibitionFrame::Selection::onCmdCancel),39FXMAPFUNC(SEL_UPDATE, MID_CANCEL, GNEProhibitionFrame::Selection::onCmdRequireConnection),40};4142// Object implementation43FXIMPLEMENT(GNEProhibitionFrame::Selection, FXVerticalFrame, SelectionMap, ARRAYNUMBER(SelectionMap))4445// ===========================================================================46// method definitions47// ===========================================================================4849// ---------------------------------------------------------------------------50// GNEProhibitionFrame::RelativeToConnection - methods51// ---------------------------------------------------------------------------5253GNEProhibitionFrame::RelativeToConnection::RelativeToConnection(GNEProhibitionFrame* prohibitionFrameParent) :54MFXGroupBoxModule(prohibitionFrameParent, TL("Selected connection")),55myProhibitionFrameParent(prohibitionFrameParent) {56// Create label for current connection description and update it57myConnDescriptionLabel = new FXLabel(getCollapsableFrame(), "", nullptr, GUIDesignLabelFrameInformation);58// update description59updateDescription();60}616263GNEProhibitionFrame::RelativeToConnection::~RelativeToConnection() {}646566void67GNEProhibitionFrame::RelativeToConnection::updateDescription() const {68// update depending of myCurrentConn69if (myProhibitionFrameParent->myCurrentConn == nullptr) {70myConnDescriptionLabel->setText(TL("No Connection selected\n"));71} else {72myConnDescriptionLabel->setText(73(TL("- Junction: ") + myProhibitionFrameParent->myCurrentConn->getEdgeFrom()->getToJunction()->getID() + "\n" +74TL("- From lane: ") + myProhibitionFrameParent->myCurrentConn->getLaneFrom()->getMicrosimID() + "\n" +75TL("- To lane: ") + myProhibitionFrameParent->myCurrentConn->getLaneTo()->getMicrosimID()).c_str());76}77}7879// ---------------------------------------------------------------------------80// GNEProhibitionFrame::ProhibitionLegend - methods81// ---------------------------------------------------------------------------8283GNEProhibitionFrame::Legend::Legend(GNEProhibitionFrame* prohibitionFrameParent) :84MFXGroupBoxModule(prohibitionFrameParent, TL("Information")),85myUndefinedColor(RGBColor::GREY),86myProhibitedColor(RGBColor(0, 179, 0)),87myProhibitingColor(RGBColor::RED),88myUnregulatedConflictColor(RGBColor::ORANGE),89myMutualConflictColor(RGBColor::CYAN) {90// Create labels for color legend91MFXLabelTooltip* legendLabel = new MFXLabelTooltip(getCollapsableFrame(),92prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),93TL("Selected"), nullptr, GUIDesignLabelFrameInformation);94legendLabel->setTipText(TL("Current selected connection"));95legendLabel->setTextColor(MFXUtils::getFXColor(RGBColor::WHITE));96legendLabel->setBackColor(MFXUtils::getFXColor(prohibitionFrameParent->myViewNet->getVisualisationSettings().colorSettings.selectedProhibitionColor));97// label for conflicts98legendLabel = new MFXLabelTooltip(getCollapsableFrame(),99prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),100TL("No conflict"), nullptr, GUIDesignLabelFrameInformation);101legendLabel->setTipText(TL("No conflict with the selected connection"));102legendLabel->setBackColor(MFXUtils::getFXColor(myUndefinedColor));103// label for yields104legendLabel = new MFXLabelTooltip(getCollapsableFrame(),105prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),106TL("Yields"), nullptr, GUIDesignLabelFrameInformation);107legendLabel->setTipText(TL("Connection yields the selected connection"));108legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitedColor));109// label for right of way110legendLabel = new MFXLabelTooltip(getCollapsableFrame(),111prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),112TL("Has right of way"), nullptr, GUIDesignLabelFrameInformation);113legendLabel->setTipText(TL("Connection has right of way with the selected connection"));114legendLabel->setBackColor(MFXUtils::getFXColor(myProhibitingColor));115// label for unregulated conflict116legendLabel = new MFXLabelTooltip(getCollapsableFrame(),117prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),118TL("Unregulated conflict"), nullptr, GUIDesignLabelFrameInformation);119legendLabel->setTipText(TL("Connection has an unregulated conflict with the selected connection"));120legendLabel->setBackColor(MFXUtils::getFXColor(myUnregulatedConflictColor));121// label for mutual conflict122legendLabel = new MFXLabelTooltip(getCollapsableFrame(),123prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),124TL("Mutual conflict"), nullptr, GUIDesignLabelFrameInformation);125legendLabel->setTipText(TL("Connection has a mutual conflict with the selected connection"));126legendLabel->setBackColor(MFXUtils::getFXColor(myMutualConflictColor));127}128129130GNEProhibitionFrame::Legend::~Legend() {}131132133const RGBColor&134GNEProhibitionFrame::Legend::getUndefinedColor() const {135return myUndefinedColor;136}137138139const RGBColor&140GNEProhibitionFrame::Legend::getProhibitedColor() const {141return myProhibitedColor;142}143144145const RGBColor&146GNEProhibitionFrame::Legend::getProhibitingColor() const {147return myProhibitingColor;148}149150151const RGBColor&152GNEProhibitionFrame::Legend::getUnregulatedConflictColor() const {153return myUnregulatedConflictColor;154}155156157const RGBColor&158GNEProhibitionFrame::Legend::getMutualConflictColor() const {159return myMutualConflictColor;160}161162// ---------------------------------------------------------------------------163// GNEProhibitionFrame::Selection - methods164// ---------------------------------------------------------------------------165166GNEProhibitionFrame::Selection::Selection(GNEProhibitionFrame* prohibitionFrameParent) :167MFXGroupBoxModule(prohibitionFrameParent, TL("Selection")),168myProhibitionFrameParent(prohibitionFrameParent) {169// Create "OK" button170mySaveButton = new MFXButtonTooltip(getCollapsableFrame(),171prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),172TL("OK"),173GUIIconSubSys::getIcon(GUIIcon::ACCEPT), this, MID_OK, GUIDesignButton);174mySaveButton->setTipText(TL("Save prohibition modifications (Enter)"));175// Create "Cancel" button176myCancelButton = new MFXButtonTooltip(getCollapsableFrame(),177prohibitionFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),178TL("Unselect connection"),179GUIIconSubSys::getIcon(GUIIcon::CANCEL), this, MID_CANCEL, GUIDesignButton);180myCancelButton->setTipText(TL("Unselect connection (Esc)"));181// Currently mySaveButton is hidden182mySaveButton->hide();183}184185186GNEProhibitionFrame::Selection::~Selection() {}187188189long190GNEProhibitionFrame::Selection::onCmdOK(FXObject*, FXSelector, void*) {191return 1;192}193194195long196GNEProhibitionFrame::Selection::onCmdCancel(FXObject*, FXSelector, void*) {197if (myProhibitionFrameParent->myCurrentConn != nullptr) {198for (const auto& conn : myProhibitionFrameParent->myConcernedConns) {199conn->setSpecialColor(nullptr);200}201myProhibitionFrameParent->myCurrentConn->setSpecialColor(nullptr);202myProhibitionFrameParent->myCurrentConn = nullptr;203myProhibitionFrameParent->myConcernedConns.clear();204myProhibitionFrameParent->myRelativeToConnection->updateDescription();205myProhibitionFrameParent->myViewNet->updateViewNet();206}207return 1;208}209210211long212GNEProhibitionFrame::Selection::onCmdRequireConnection(FXObject*, FXSelector, void*) {213if (myProhibitionFrameParent->myCurrentConn) {214mySaveButton->enable();215myCancelButton->enable();216} else {217mySaveButton->disable();218myCancelButton->disable();219}220return 1;221}222223// ---------------------------------------------------------------------------224// GNEProhibitionFrame - methods225// ---------------------------------------------------------------------------226227GNEProhibitionFrame::GNEProhibitionFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :228GNEFrame(viewParent, viewNet, TL("Prohibitions")),229myCurrentConn(nullptr) {230231// create RelativeToConnection232myRelativeToConnection = new RelativeToConnection(this);233234// create legend235myLegend = new Legend(this);236237// create Selection module238mySelectionModul = new Selection(this);239}240241242GNEProhibitionFrame::~GNEProhibitionFrame() {}243244245void246GNEProhibitionFrame::handleProhibitionClick(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {247// build prohibition248buildProhibition(viewObjects.getConnectionFront(), myViewNet->getMouseButtonKeyPressed().shiftKeyPressed(), myViewNet->getMouseButtonKeyPressed().controlKeyPressed(), true);249}250251252void253GNEProhibitionFrame::show() {254GNEFrame::show();255}256257258void259GNEProhibitionFrame::hide() {260GNEFrame::hide();261}262263264GNEProhibitionFrame::Selection*265GNEProhibitionFrame::getSelectionModul() const {266return mySelectionModul;267}268269// ---------------------------------------------------------------------------270// GNEProhibitionFrame - private methods271// ---------------------------------------------------------------------------272273void274GNEProhibitionFrame::buildProhibition(GNEConnection* conn, bool /* mayDefinitelyPass */, bool /* allowConflict */, bool /* toggle */) {275if (myCurrentConn != nullptr) {276mySelectionModul->onCmdCancel(nullptr, 0, nullptr);277}278if (conn != nullptr) {279myCurrentConn = conn;280myCurrentConn->setSpecialColor(&myViewNet->getVisualisationSettings().colorSettings.selectedProhibitionColor);281282// determine prohibition status of all other connections with respect to the selected one283GNEJunction* junction = myCurrentConn->getEdgeFrom()->getToJunction();284std::vector<GNEConnection*> connections = junction->getGNEConnections();285NBNode* node = junction->getNBNode();286NBEdge* currentConnFrom = myCurrentConn->getEdgeFrom()->getNBEdge();287288const int currentLinkIndex = node->getConnectionIndex(currentConnFrom, myCurrentConn->getNBEdgeConnection());289std::string currentFoesString = node->getFoes(currentLinkIndex);290std::string currentResponseString = node->getResponse(currentLinkIndex);291std::reverse(currentFoesString.begin(), currentFoesString.end());292std::reverse(currentResponseString.begin(), currentResponseString.end());293// iterate over all connections294for (const auto& connection : connections) {295if (connection != myCurrentConn) {296NBEdge* otherConnFrom = connection->getEdgeFrom()->getNBEdge();297const int linkIndex = node->getConnectionIndex(otherConnFrom, connection->getNBEdgeConnection());298std::string responseString = node->getResponse(linkIndex);299std::reverse(responseString.begin(), responseString.end());300// determine the prohibition status301bool foes = ((int)currentFoesString.size() > linkIndex) && (currentFoesString[linkIndex] == '1');302bool forbids = ((int)responseString.size() > currentLinkIndex) && (responseString[currentLinkIndex] == '1');303bool forbidden = ((int)currentResponseString.size() > linkIndex) && (currentResponseString[linkIndex] == '1');304// insert in myConcernedConns305myConcernedConns.insert(connection);306// change color depending of prohibition status307if (!foes) {308connection->setSpecialColor(&myLegend->getUndefinedColor());309} else {310if (forbids && forbidden) {311connection->setSpecialColor(&myLegend->getMutualConflictColor());312} else if (forbids) {313connection->setSpecialColor(&myLegend->getProhibitedColor());314} else if (forbidden) {315connection->setSpecialColor(&myLegend->getProhibitingColor());316} else {317connection->setSpecialColor(&myLegend->getUnregulatedConflictColor());318}319}320}321}322// update description323myRelativeToConnection->updateDescription();324}325}326327328/****************************************************************************/329330331