LCOV - code coverage report
Current view: top level - src/guinetload - GUITriggerBuilder.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 48 56 85.7 %
Date: 2024-05-05 15:31:14 Functions: 11 12 91.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    GUITriggerBuilder.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @author  Johannes Rummel
      19             : /// @date    Mon, 26.04.2004
      20             : ///
      21             : // Builds trigger objects for guisim
      22             : /****************************************************************************/
      23             : #include <config.h>
      24             : 
      25             : #include <string>
      26             : #include <fstream>
      27             : #include <utils/common/RGBColor.h>
      28             : #include <guisim/GUILaneSpeedTrigger.h>
      29             : #include <guisim/GUINet.h>
      30             : #include <guisim/GUITriggeredRerouter.h>
      31             : #include <guisim/GUIBusStop.h>
      32             : #include <guisim/GUIParkingArea.h>
      33             : #include <guisim/GUICalibrator.h>
      34             : #include <guisim/GUIChargingStation.h>
      35             : #include <guisim/GUIOverheadWire.h>
      36             : #include "GUITriggerBuilder.h"
      37             : 
      38             : 
      39             : 
      40             : // ===========================================================================
      41             : // method definitions
      42             : // ===========================================================================
      43        7228 : GUITriggerBuilder::GUITriggerBuilder() {}
      44             : 
      45             : 
      46        7228 : GUITriggerBuilder::~GUITriggerBuilder() {}
      47             : 
      48             : 
      49             : MSLaneSpeedTrigger*
      50          97 : GUITriggerBuilder::buildLaneSpeedTrigger(MSNet& net,
      51             :         const std::string& id, const std::vector<MSLane*>& destLanes,
      52             :         const std::string& file) {
      53          97 :     GUILaneSpeedTrigger* lst = new GUILaneSpeedTrigger(id, destLanes, file);
      54          97 :     static_cast<GUINet&>(net).registerRenderedObject(lst);
      55          97 :     return lst;
      56             : }
      57             : 
      58             : 
      59             : MSTriggeredRerouter*
      60         648 : GUITriggerBuilder::buildRerouter(MSNet& net, const std::string& id,
      61             :                                  MSEdgeVector& edges, double prob, bool off, bool optional,
      62             :                                  SUMOTime timeThreshold, const std::string& vTypes, const Position& pos) {
      63             :     GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, off, optional, timeThreshold, vTypes, pos,
      64         648 :             dynamic_cast<GUINet&>(net).getVisualisationSpeedUp());
      65         648 :     return rr;
      66             : }
      67             : 
      68             : 
      69             : void
      70        1595 : GUITriggerBuilder::buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,
      71             :                                       double frompos, double topos, const SumoXMLTag element, std::string name,
      72             :                                       int personCapacity, double parkingLength, RGBColor& color) {
      73        1595 :     myCurrentStop = new GUIBusStop(id, element, lines, *lane, frompos, topos, name, personCapacity, parkingLength, color);
      74        1595 :     if (!net.addStoppingPlace(element, myCurrentStop)) {
      75           3 :         delete myCurrentStop;
      76           3 :         myCurrentStop = nullptr;
      77           6 :         throw InvalidArgument("Could not build " + toString(element) + " '" + id + "'; probably declared twice.");
      78             :     }
      79        1592 : }
      80             : 
      81             : 
      82             : void
      83         671 : GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
      84             :                                     const std::vector<std::string>& lines,
      85             :                                     const std::vector<std::string>& badges,
      86             :                                     MSLane* lane,
      87             :                                     double frompos, double topos,
      88             :                                     unsigned int capacity,
      89             :                                     double width, double length, double angle, const std::string& name,
      90             :                                     bool onRoad,
      91             :                                     const std::string& departPos,
      92             :                                     bool lefthand) {
      93             :     assert(myParkingArea == 0);
      94         671 :     GUIParkingArea* stop = new GUIParkingArea(id, lines, badges, *lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand);
      95         671 :     if (!net.addStoppingPlace(SUMO_TAG_PARKING_AREA, stop)) {
      96           0 :         delete stop;
      97           0 :         throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
      98             :     } else {
      99         671 :         myParkingArea = stop;
     100             :     }
     101         671 : }
     102             : 
     103             : 
     104             : void
     105         165 : GUITriggerBuilder::buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos,
     106             :                                         const std::string& name, double chargingPower, double efficiency, bool chargeInTransit,
     107             :                                         SUMOTime chargeDelay, std::string chargeType, SUMOTime waitingTime, MSParkingArea* parkingArea) {
     108         165 :     GUIChargingStation* chargingStation = (parkingArea == nullptr) ? new GUIChargingStation(id, *lane, frompos, topos, name, chargingPower, efficiency,
     109         165 :                                           chargeInTransit, chargeDelay, chargeType, waitingTime) : new GUIChargingStation(id, parkingArea, name, chargingPower, efficiency,
     110           0 :                                                   chargeInTransit, chargeDelay, chargeType, waitingTime);
     111         165 :     if (!net.addStoppingPlace(SUMO_TAG_CHARGING_STATION, chargingStation)) {
     112           0 :         delete chargingStation;
     113           0 :         throw InvalidArgument("Could not build charging station '" + id + "'; probably declared twice.");
     114             :     }
     115         165 :     myCurrentStop = chargingStation;
     116         165 :     static_cast<GUINet&>(net).registerRenderedObject(chargingStation);
     117         165 : }
     118             : 
     119             : 
     120             : void
     121          12 : GUITriggerBuilder::buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos,
     122             :         bool voltageSource) {
     123          12 :     GUIOverheadWire* overheadWire = new GUIOverheadWire(id, *lane, frompos, topos, voltageSource);
     124          12 :     if (!net.addStoppingPlace(SUMO_TAG_OVERHEAD_WIRE_SEGMENT, overheadWire)) {
     125           0 :         delete overheadWire;
     126           0 :         throw InvalidArgument("Could not build overheadWireSegment '" + id + "'; probably declared twice.");
     127             :     }
     128          12 :     static_cast<GUINet&>(net).registerRenderedObject(overheadWire);
     129          12 : }
     130             : 
     131             : void
     132           1 : GUITriggerBuilder::buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end) {
     133           1 :     GUIOverheadWireClamp* overheadWireClamp = new GUIOverheadWireClamp(id, *lane_start, *lane_end);
     134           1 :     static_cast<GUINet&>(net).registerRenderedObject(overheadWireClamp);
     135           1 : }
     136             : 
     137             : 
     138             : void
     139         671 : GUITriggerBuilder::endParkingArea() {
     140         671 :     if (myParkingArea != nullptr) {
     141         671 :         static_cast<GUINet*>(MSNet::getInstance())->registerRenderedObject(static_cast<GUIParkingArea*>(myParkingArea));
     142         671 :         myParkingArea = nullptr;
     143             :     } else {
     144           0 :         throw InvalidArgument("Could not end a parking area that is not opened.");
     145             :     }
     146         671 : }
     147             : 
     148             : 
     149             : void
     150        1760 : GUITriggerBuilder::endStoppingPlace() {
     151        1760 :     if (myCurrentStop != nullptr) {
     152        1757 :         static_cast<GUINet*>(MSNet::getInstance())->registerRenderedObject(dynamic_cast<GUIGlObject*>(myCurrentStop));
     153        1757 :         myCurrentStop = nullptr;
     154             :     } else {
     155           6 :         throw InvalidArgument("Could not end a stopping place that is not opened.");
     156             :     }
     157        1757 : }
     158             : 
     159             : 
     160             : /****************************************************************************/

Generated by: LCOV version 1.14