1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GUITriggerBuilder.cpp
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Michael Behrisch
14 /// @date    Mon, 26.04.2004
15 /// @version $Id$
16 ///
17 // Builds trigger objects for guisim
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <fstream>
28 #include <guisim/GUILaneSpeedTrigger.h>
29 #include <guisim/GUINet.h>
30 #include <guisim/GUITriggeredRerouter.h>
31 #include <guisim/GUIBusStop.h>
32 #include <guisim/GUIContainerStop.h>
33 #include <guisim/GUIParkingArea.h>
34 #include <guisim/GUICalibrator.h>
35 #include <guisim/GUIChargingStation.h>
36 #include "GUITriggerBuilder.h"
37 
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
GUITriggerBuilder()43 GUITriggerBuilder::GUITriggerBuilder() {}
44 
45 
~GUITriggerBuilder()46 GUITriggerBuilder::~GUITriggerBuilder() {}
47 
48 
49 MSLaneSpeedTrigger*
buildLaneSpeedTrigger(MSNet & net,const std::string & id,const std::vector<MSLane * > & destLanes,const std::string & file)50 GUITriggerBuilder::buildLaneSpeedTrigger(MSNet& net,
51         const std::string& id, const std::vector<MSLane*>& destLanes,
52         const std::string& file) {
53     GUILaneSpeedTrigger* lst = new GUILaneSpeedTrigger(id, destLanes, file);
54     static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(lst);
55     return lst;
56 }
57 
58 
59 MSTriggeredRerouter*
buildRerouter(MSNet & net,const std::string & id,MSEdgeVector & edges,double prob,const std::string & file,bool off,SUMOTime timeThreshold,const std::string & vTypes)60 GUITriggerBuilder::buildRerouter(MSNet& net, const std::string& id,
61                                  MSEdgeVector& edges,
62                                  double prob, const std::string& file, bool off,
63                                  SUMOTime timeThreshold,
64                                  const std::string& vTypes) {
65     GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, file, off, timeThreshold, vTypes,
66             dynamic_cast<GUINet&>(net).getVisualisationSpeedUp());
67     return rr;
68 }
69 
70 
71 void
buildStoppingPlace(MSNet & net,std::string id,std::vector<std::string> lines,MSLane * lane,double frompos,double topos,const SumoXMLTag element,std::string name,int personCapacity)72 GUITriggerBuilder::buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,
73                                       double frompos, double topos, const SumoXMLTag element, std::string name, int personCapacity) {
74     if (element == SUMO_TAG_CONTAINER_STOP) {
75         //TODO: shall we also allow names for container stops? might make sense [GL March '17]
76         myCurrentStop = new GUIContainerStop(id, lines, *lane, frompos, topos, name, personCapacity);
77     } else {
78         myCurrentStop = new GUIBusStop(id, lines, *lane, frompos, topos, name, personCapacity);
79     }
80     if (!net.addStoppingPlace(element, myCurrentStop)) {
81         delete myCurrentStop;
82         myCurrentStop = nullptr;
83         throw InvalidArgument("Could not build " + toString(element) + " '" + id + "'; probably declared twice.");
84     }
85 }
86 
87 
88 void
beginParkingArea(MSNet & net,const std::string & id,const std::vector<std::string> & lines,MSLane * lane,double frompos,double topos,unsigned int capacity,double width,double length,double angle,const std::string & name,bool onRoad)89 GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
90                                     const std::vector<std::string>& lines,
91                                     MSLane* lane,
92                                     double frompos, double topos,
93                                     unsigned int capacity,
94                                     double width, double length, double angle, const std::string& name,
95                                     bool onRoad) {
96     assert(myParkingArea == 0);
97     GUIParkingArea* stop = new GUIParkingArea(id, lines, *lane, frompos, topos, capacity, width, length, angle, name, onRoad);
98     if (!net.addStoppingPlace(SUMO_TAG_PARKING_AREA, stop)) {
99         delete stop;
100         throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
101     } else {
102         myParkingArea = stop;
103     }
104 }
105 
106 
107 void
buildChargingStation(MSNet & net,const std::string & id,MSLane * lane,double frompos,double topos,const std::string & name,double chargingPower,double efficiency,bool chargeInTransit,double chargeDelay)108 GUITriggerBuilder::buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
109                                         double chargingPower, double efficiency, bool chargeInTransit, double chargeDelay) {
110     GUIChargingStation* chargingStation = new GUIChargingStation(id, *lane, frompos, topos, name, chargingPower, efficiency, chargeInTransit, chargeDelay);
111     if (!net.addStoppingPlace(SUMO_TAG_CHARGING_STATION, chargingStation)) {
112         delete chargingStation;
113         throw InvalidArgument("Could not build charging station '" + id + "'; probably declared twice.");
114     }
115     static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(chargingStation);
116 }
117 
118 
119 MSCalibrator*
buildCalibrator(MSNet & net,const std::string & id,MSEdge * edge,MSLane * lane,double pos,const std::string & file,const std::string & outfile,const SUMOTime freq,const MSRouteProbe * probe)120 GUITriggerBuilder::buildCalibrator(MSNet& net, const std::string& id,
121                                    MSEdge* edge, MSLane* lane, double pos,
122                                    const std::string& file,
123                                    const std::string& outfile,
124                                    const SUMOTime freq,
125                                    const MSRouteProbe* probe) {
126     GUICalibrator* cali = new GUICalibrator(id, edge, lane, pos, file, outfile, freq, probe);
127     static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(cali);
128     return cali;
129 }
130 
131 
132 void
endParkingArea()133 GUITriggerBuilder::endParkingArea() {
134     if (myParkingArea != nullptr) {
135         static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(static_cast<GUIParkingArea*>(myParkingArea));
136         myParkingArea = nullptr;
137     } else {
138         throw InvalidArgument("Could not end a parking area that is not opened.");
139     }
140 }
141 
142 
143 void
endStoppingPlace()144 GUITriggerBuilder::endStoppingPlace() {
145     if (myCurrentStop != nullptr) {
146         static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(dynamic_cast<GUIGlObject*>(myCurrentStop));
147         myCurrentStop = nullptr;
148     } else {
149         throw InvalidArgument("Could not end a stopping place that is not opened.");
150     }
151 }
152 
153 /****************************************************************************/
154 
155