LCOV - code coverage report
Current view: top level - src/guisim - GUIJunctionWrapper.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 54.4 % 136 74
Test Date: 2024-11-22 15:46:21 Functions: 63.6 % 11 7

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    GUIJunctionWrapper.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Laura Bieker
      19              : /// @author  Andreas Gaubatz
      20              : /// @date    Mon, 1 Jul 2003
      21              : ///
      22              : // }
      23              : /****************************************************************************/
      24              : #include <config.h>
      25              : 
      26              : #include <string>
      27              : #include <utility>
      28              : #include <microsim/MSLane.h>
      29              : #include <microsim/MSEdge.h>
      30              : #include <microsim/MSJunction.h>
      31              : #include <utils/geom/Position.h>
      32              : #include <utils/geom/GeomHelper.h>
      33              : #include <microsim/MSNet.h>
      34              : #include <microsim/MSInternalJunction.h>
      35              : #include <microsim/traffic_lights/MSTrafficLightLogic.h>
      36              : #include <microsim/traffic_lights/MSTLLogicControl.h>
      37              : #include <gui/GUIApplicationWindow.h>
      38              : #include <gui/GUIGlobals.h>
      39              : #include <utils/gui/windows/GUIAppEnum.h>
      40              : #include <utils/gui/windows/GUISUMOAbstractView.h>
      41              : #include "GUIJunctionWrapper.h"
      42              : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
      43              : #include <utils/gui/div/GUIGlobalSelection.h>
      44              : #include <utils/gui/div/GUIParameterTableWindow.h>
      45              : #include <utils/gui/div/GLHelper.h>
      46              : #include <utils/gui/globjects/GLIncludes.h>
      47              : 
      48              : #include <osgview/GUIOSGHeader.h>
      49              : 
      50              : // ===========================================================================
      51              : // method definitions
      52              : // ===========================================================================
      53        86486 : GUIJunctionWrapper::GUIJunctionWrapper(MSJunction& junction, const std::string& tllID):
      54              :     GUIGlObject(GLO_JUNCTION, junction.getID(), GUIIconSubSys::getIcon(GUIIcon::JUNCTION)),
      55        86486 :     myJunction(junction),
      56       172972 :     myTesselation(junction.getID(), "", RGBColor::MAGENTA, junction.getShape(), false, true, 0),
      57        86486 :     myExaggeration(1),
      58       172972 :     myTLLID(tllID) {
      59        86486 :     if (myJunction.getShape().size() == 0) {
      60        24586 :         Position pos = myJunction.getPosition();
      61        24586 :         myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
      62              :     } else {
      63        61900 :         myBoundary = myJunction.getShape().getBoxBoundary();
      64              :     }
      65        86486 :     myMaxSize = MAX2(myBoundary.getWidth(), myBoundary.getHeight());
      66        86486 :     myIsInternal = myJunction.getType() == SumoXMLNodeType::INTERNAL;
      67        86486 :     myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
      68        86486 :     myAmRailway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
      69        86486 :     myAmAirway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
      70       260222 :     for (auto it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end() && (myAmWaterway || myAmRailway); ++it) {
      71       173736 :         if (!(*it)->isInternal()) {
      72        58941 :             if (!isWaterway((*it)->getPermissions())) {
      73        58903 :                 myAmWaterway = false;
      74              :             }
      75        58941 :             if (!isRailway((*it)->getPermissions())) {
      76        53620 :                 myAmRailway = false;
      77              :             }
      78        58941 :             if (!isAirway((*it)->getPermissions())) {
      79        58941 :                 myAmAirway = false;
      80              :             }
      81              :         }
      82              :     }
      83       100045 :     for (auto it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end() && (myAmWaterway || myAmRailway); ++it) {
      84        13559 :         if (!(*it)->isInternal()) {
      85         9375 :             if (!isWaterway((*it)->getPermissions())) {
      86         9342 :                 myAmWaterway = false;
      87              :             }
      88         9375 :             if (!isRailway((*it)->getPermissions())) {
      89         4114 :                 myAmRailway = false;
      90              :             }
      91         9375 :             if (!isAirway((*it)->getPermissions())) {
      92         9375 :                 myAmAirway = false;
      93              :             }
      94              :         }
      95              :     }
      96        86486 :     myTesselation.getShapeRef().closePolygon();
      97        86486 : }
      98              : 
      99              : 
     100       259011 : GUIJunctionWrapper::~GUIJunctionWrapper() {}
     101              : 
     102              : 
     103              : GUIGLObjectPopupMenu*
     104            0 : GUIJunctionWrapper::getPopUpMenu(GUIMainWindow& app,
     105              :                                  GUISUMOAbstractView& parent) {
     106            0 :     GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
     107            0 :     buildPopupHeader(ret, app);
     108            0 :     buildCenterPopupEntry(ret);
     109            0 :     buildNameCopyPopupEntry(ret);
     110            0 :     buildSelectionPopupEntry(ret);
     111            0 :     buildShowParamsPopupEntry(ret);
     112            0 :     buildPositionCopyEntry(ret, app);
     113            0 :     return ret;
     114              : }
     115              : 
     116              : 
     117              : GUIParameterTableWindow*
     118            0 : GUIJunctionWrapper::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
     119            0 :     GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
     120              :     // add items
     121            0 :     ret->mkItem(TL("type"), false, toString(myJunction.getType()));
     122            0 :     ret->mkItem(TL("name"), false, myJunction.getName());
     123              :     // close building
     124            0 :     ret->closeBuilding(&myJunction);
     125            0 :     return ret;
     126              : }
     127              : 
     128              : 
     129              : double
     130      5571018 : GUIJunctionWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
     131      5571018 :     return s.junctionSize.getExaggeration(s, this, 4);
     132              : }
     133              : 
     134              : 
     135              : Boundary
     136            0 : GUIJunctionWrapper::getCenteringBoundary() const {
     137              :     Boundary b = myBoundary;
     138            0 :     b.grow(1);
     139            0 :     return b;
     140            0 : }
     141              : 
     142              : const std::string
     143            0 : GUIJunctionWrapper::getOptionalName() const {
     144            0 :     return myJunction.getName();
     145              : }
     146              : 
     147              : void
     148      7632722 : GUIJunctionWrapper::drawGL(const GUIVisualizationSettings& s) const {
     149      7632722 :     const bool s2 = s.secondaryShape;
     150      7632722 :     if (!myIsInternal && s.drawJunctionShape && !s2) {
     151              :         // check whether it is not too small
     152      5571018 :         const double exaggeration = getExaggeration(s);
     153      5571018 :         if (s.scale * exaggeration >= s.junctionSize.minSize) {
     154      1269130 :             GLHelper::pushMatrix();
     155      1269130 :             GLHelper::pushName(getGlID());
     156      1269130 :             const double colorValue = getColorValue(s, s.junctionColorer.getActive());
     157      1269130 :             const RGBColor color = s.junctionColorer.getScheme().getColor(colorValue);
     158      1269130 :             GLHelper::setColor(color);
     159              : 
     160              :             // recognize full transparency and simply don't draw
     161      1269130 :             if (color.alpha() != 0) {
     162      1257222 :                 if ((exaggeration > 1 || myExaggeration > 1) && exaggeration != myExaggeration) {
     163            0 :                     myExaggeration = exaggeration;
     164            0 :                     myTesselation.setShape(myJunction.getShape());
     165            0 :                     myTesselation.getShapeRef().closePolygon();
     166            0 :                     myTesselation.getShapeRef().scaleRelative(exaggeration);
     167              :                     myTesselation.myTesselation.clear();
     168              :                 }
     169      1257222 :                 glTranslated(0, 0, getType());
     170      1257222 :                 if (s.scale * myMaxSize < 40.) {
     171      1011311 :                     GLHelper::drawFilledPoly(myTesselation.getShape(), true);
     172              :                 } else {
     173       245911 :                     myTesselation.drawTesselation(myTesselation.getShape());
     174              :                 }
     175              :                 // make small junctions more visible when coloring by type
     176      1257222 :                 if (myJunction.getType() == SumoXMLNodeType::RAIL_SIGNAL && s.junctionColorer.getActive() == 2) {
     177            0 :                     glTranslated(myJunction.getPosition(s2).x(), myJunction.getPosition(s2).y(), getType() + 0.05);
     178            0 :                     GLHelper::drawFilledCircle(2 * exaggeration, 12);
     179              :                 }
     180              :             }
     181      1269130 :             GLHelper::popName();
     182      1269130 :             GLHelper::popMatrix();
     183      1269126 :             if (s.geometryIndices.show(this)) {
     184            0 :                 GLHelper::debugVertices(myJunction.getShape(), s.geometryIndices, s.scale);
     185              :             }
     186              :         }
     187              :     }
     188      7632718 :     if (myIsInternal) {
     189      2061704 :         drawName(myJunction.getPosition(s2), s.scale, s.internalJunctionName, s.angle);
     190              :     } else {
     191      5571014 :         drawName(myJunction.getPosition(s2), s.scale, s.junctionID, s.angle);
     192      5571014 :         if (s.junctionName.show(this) && myJunction.getName() != "") {
     193            0 :             GLHelper::drawTextSettings(s.junctionName, myJunction.getName(), myJunction.getPosition(s2), s.scale, s.angle);
     194              :         }
     195      5571014 :         if ((s.tlsPhaseIndex.show(this) || s.tlsPhaseName.show(this)) && myTLLID != "") {
     196            0 :             const MSTrafficLightLogic* active = MSNet::getInstance()->getTLSControl().getActive(myTLLID);
     197            0 :             if (s.tlsPhaseIndex.show(this)) {
     198            0 :                 const int index = active->getCurrentPhaseIndex();
     199            0 :                 GLHelper::drawTextSettings(s.tlsPhaseIndex, toString(index), myJunction.getPosition(s2), s.scale, s.angle);
     200              :             }
     201            0 :             if (s.tlsPhaseName.show(this)) {
     202            0 :                 const std::string& name = active->getCurrentPhaseDef().getName();
     203            0 :                 if (name != "") {
     204            0 :                     const Position offset = (s.tlsPhaseIndex.show(this) ?
     205            0 :                                              Position(0, 0.8 * s.tlsPhaseIndex.scaledSize(s.scale)).rotateAround2D(DEG2RAD(-s.angle), Position(0, 0))
     206            0 :                                              : Position(0, 0));
     207            0 :                     GLHelper::drawTextSettings(s.tlsPhaseName, name, myJunction.getPosition(s2) - offset, s.scale, s.angle);
     208              :                 }
     209              :             }
     210              :         }
     211              :     }
     212      7632718 : }
     213              : 
     214              : 
     215              : double
     216      1355012 : GUIJunctionWrapper::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
     217      1355012 :     switch (activeScheme) {
     218      1355012 :         case 0:
     219      1355012 :             if (myAmWaterway) {
     220              :                 return 1;
     221      1354678 :             } else if (myAmRailway && MSNet::getInstance()->hasInternalLinks()) {
     222              :                 return 2;
     223      1341635 :             } else if (myAmAirway) {
     224              :                 return 3;
     225              :             } else {
     226              :                 return 0;
     227              :             }
     228            0 :         case 1:
     229            0 :             return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
     230            0 :         case 2:
     231            0 :             switch (myJunction.getType()) {
     232              :                 case SumoXMLNodeType::TRAFFIC_LIGHT:
     233              :                     return 0;
     234              :                 case SumoXMLNodeType::TRAFFIC_LIGHT_NOJUNCTION:
     235              :                     return 1;
     236              :                 case SumoXMLNodeType::PRIORITY:
     237              :                     return 2;
     238              :                 case SumoXMLNodeType::PRIORITY_STOP:
     239              :                     return 3;
     240              :                 case SumoXMLNodeType::RIGHT_BEFORE_LEFT:
     241              :                     return 4;
     242            0 :                 case SumoXMLNodeType::ALLWAY_STOP:
     243            0 :                     return 5;
     244            0 :                 case SumoXMLNodeType::DISTRICT:
     245            0 :                     return 6;
     246            0 :                 case SumoXMLNodeType::NOJUNCTION:
     247            0 :                     return 7;
     248              :                 case SumoXMLNodeType::DEAD_END:
     249              :                 case SumoXMLNodeType::DEAD_END_DEPRECATED:
     250              :                     return 8;
     251              :                 case SumoXMLNodeType::UNKNOWN:
     252              :                 case SumoXMLNodeType::INTERNAL:
     253              :                     assert(false);
     254              :                     return 8;
     255            0 :                 case SumoXMLNodeType::RAIL_SIGNAL:
     256            0 :                     return 9;
     257            0 :                 case SumoXMLNodeType::ZIPPER:
     258            0 :                     return 10;
     259            0 :                 case SumoXMLNodeType::TRAFFIC_LIGHT_RIGHT_ON_RED:
     260            0 :                     return 11;
     261            0 :                 case SumoXMLNodeType::RAIL_CROSSING:
     262            0 :                     return 12;
     263            0 :                 case SumoXMLNodeType::LEFT_BEFORE_RIGHT:
     264            0 :                     return 13;
     265              :                 default:
     266              :                     assert(false);
     267              :                     return 0;
     268              :             }
     269            0 :         case 3:
     270            0 :             return myJunction.getPosition().z();
     271              :         default:
     272              :             assert(false);
     273              :             return 0;
     274              :     }
     275              : }
     276              : 
     277              : #ifdef HAVE_OSG
     278              : void
     279        85882 : GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
     280        85882 :     const double colorValue = getColorValue(s, s.junctionColorer.getActive());
     281        85882 :     const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
     282        85882 :     osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
     283        85882 :     (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
     284        85882 :     myGeom->setColorArray(colors);
     285        85882 : }
     286              : #endif
     287              : 
     288              : 
     289              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1