LCOV - code coverage report
Current view: top level - src/netbuild - NBSign.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 21 23 91.3 %
Date: 2024-05-07 15:28:01 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2012-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    NBSign.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Michael Behrisch
      17             : /// @author  Jakob Erdmann
      18             : /// @date    Nov 2012
      19             : ///
      20             : // A class representing a street sign
      21             : /****************************************************************************/
      22             : #include <config.h>
      23             : 
      24             : #include <cassert>
      25             : #include <utils/common/RGBColor.h>
      26             : #include <utils/common/ToString.h>
      27             : #include <utils/iodevices/OutputDevice.h>
      28             : #include "NBEdge.h"
      29             : #include "NBSign.h"
      30             : 
      31             : 
      32             : // ===========================================================================
      33             : // static members
      34             : // ===========================================================================
      35             : static StringBijection<NBSign::SignType>::Entry signTypeStringsInitializer[] = {
      36             :     {"speed limit",       NBSign::SIGN_TYPE_SPEED},
      37             :     {"yield",             NBSign::SIGN_TYPE_YIELD},
      38             :     {"stop",              NBSign::SIGN_TYPE_STOP},
      39             :     {"allway_stop",       NBSign::SIGN_TYPE_ALLWAY_STOP},
      40             :     {"on ramp",           NBSign::SIGN_TYPE_ON_RAMP},
      41             :     {"priority",          NBSign::SIGN_TYPE_PRIORITY},
      42             :     {"right before left", NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT},
      43             :     {"left before right", NBSign::SIGN_TYPE_LEFT_BEFORE_RIGHT},
      44             :     {"roundabout",        NBSign::SIGN_TYPE_ROUNDABOUT},
      45             :     {"rail crossing",     NBSign::SIGN_TYPE_RAIL_CROSSING},
      46             :     {"slope",             NBSign::SIGN_TYPE_SLOPE},
      47             :     {"city limits",       NBSign::SIGN_TYPE_CITY},
      48             :     {"info",              NBSign::SIGN_TYPE_INFO},
      49             : };
      50             : 
      51             : StringBijection<NBSign::SignType> NBSign::SignTypeStrings(
      52             :     signTypeStringsInitializer, NBSign::SIGN_TYPE_INFO);
      53             : 
      54             : 
      55             : // ===========================================================================
      56             : // member method definitions
      57             : // ===========================================================================
      58             : 
      59           8 : NBSign::NBSign(SignType type, double offset, const std::string label) :
      60           8 :     myType(type),
      61           8 :     myOffset(offset),
      62           8 :     myLabel(label) {
      63           8 : }
      64             : 
      65             : 
      66          16 : NBSign::~NBSign() {}
      67             : 
      68             : 
      69             : void
      70           8 : NBSign::writeAsPOI(OutputDevice& into, const NBEdge* edge) const {
      71             :     PositionVector shp = edge->getLanes()[0].shape;
      72             :     try {
      73           8 :         shp.move2side(3);
      74           0 :     } catch (InvalidArgument&) {
      75             :         // we do not write anything, maybe we should
      76           0 :     }
      77           8 :     Position pos = shp.positionAtOffset(myOffset);
      78           8 :     into.openTag(SUMO_TAG_POI);
      79          16 :     into.writeAttr(SUMO_ATTR_ID, edge->getID() + "." + toString(myOffset));
      80           8 :     into.writeAttr(SUMO_ATTR_TYPE, SignTypeStrings.getString(myType));
      81           8 :     switch (myType) { /// XXX @todo add default colors
      82             :         case SIGN_TYPE_SPEED:
      83             :         case SIGN_TYPE_SLOPE:
      84             :         case SIGN_TYPE_CITY:
      85             :         case SIGN_TYPE_INFO:
      86             :             into.writeAttr(SUMO_ATTR_COLOR, RGBColor::GREY);
      87             :             break;
      88             :         case SIGN_TYPE_YIELD:
      89             :         case SIGN_TYPE_STOP:
      90             :         case SIGN_TYPE_ALLWAY_STOP:
      91             :         case SIGN_TYPE_ON_RAMP:
      92             :         case SIGN_TYPE_RAIL_CROSSING:
      93             :             into.writeAttr(SUMO_ATTR_COLOR, RGBColor::RED);
      94             :             break;
      95             :         case SIGN_TYPE_PRIORITY:
      96             :             into.writeAttr(SUMO_ATTR_COLOR, RGBColor::YELLOW);
      97             :             break;
      98           4 :         case SIGN_TYPE_RIGHT_BEFORE_LEFT:
      99             :         case SIGN_TYPE_LEFT_BEFORE_RIGHT:
     100           4 :             into.writeAttr(SUMO_ATTR_COLOR, RGBColor(255, 153, 0, 255));
     101           4 :             break;
     102             :         case SIGN_TYPE_ROUNDABOUT:
     103             :             into.writeAttr(SUMO_ATTR_COLOR, RGBColor::BLUE);
     104             :             break;
     105             :     }
     106          16 :     into.writeAttr(SUMO_ATTR_X, pos.x());
     107           8 :     into.writeAttr(SUMO_ATTR_Y, pos.y());
     108           8 :     into.writeAttr(SUMO_ATTR_ANGLE, 0); // XXX use road angle?
     109             :     // @todo add image resources and default images for all signs
     110             :     //into.writeAttr(SUMO_ATTR_IMGFILE, p->getImgFile());
     111             :     //into.writeAttr(SUMO_ATTR_WIDTH, p->getWidth());
     112             :     //into.writeAttr(SUMO_ATTR_HEIGHT, p->getHeight());
     113          16 :     into.closeTag();
     114           8 : }
     115             : 
     116             : 
     117             : /****************************************************************************/

Generated by: LCOV version 1.14