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 GUIE3Collector.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Jan 2004
19 : ///
20 : // The gui-version of a MSE3Collector
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include "GUIE3Collector.h"
25 : #include "GUIEdge.h"
26 : #include <utils/common/MsgHandler.h>
27 : #include <utils/gui/div/GUIParameterTableWindow.h>
28 : #include <utils/gui/div/GLHelper.h>
29 : #include <microsim/logging/FunctionBinding.h>
30 : #include <microsim/MSLane.h>
31 : #include <utils/gui/globjects/GLIncludes.h>
32 :
33 :
34 : // ===========================================================================
35 : // method definitions
36 : // ===========================================================================
37 :
38 : // -------------------------------------------------------------------------
39 : // GUIE3Collector::MyWrapper-methods
40 : // -------------------------------------------------------------------------
41 :
42 126 : GUIE3Collector::MyWrapper::MyWrapper(GUIE3Collector& detector) :
43 : GUIDetectorWrapper(GLO_E3DETECTOR, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E3)),
44 126 : myDetector(detector) {
45 126 : const CrossSectionVector& entries = detector.getEntries();
46 126 : const CrossSectionVector& exits = detector.getExits();
47 : CrossSectionVectorConstIt i;
48 333 : for (i = entries.begin(); i != entries.end(); ++i) {
49 207 : SingleCrossingDefinition def = buildDefinition(*i);
50 207 : myBoundary.add(def.myFGPosition);
51 207 : myEntryDefinitions.push_back(def);
52 : }
53 320 : for (i = exits.begin(); i != exits.end(); ++i) {
54 194 : SingleCrossingDefinition def = buildDefinition(*i);
55 194 : myBoundary.add(def.myFGPosition);
56 194 : myExitDefinitions.push_back(def);
57 : }
58 126 : }
59 :
60 :
61 252 : GUIE3Collector::MyWrapper::~MyWrapper() {}
62 :
63 :
64 : GUIE3Collector::MyWrapper::SingleCrossingDefinition
65 401 : GUIE3Collector::MyWrapper::buildDefinition(const MSCrossSection& section) {
66 : SingleCrossingDefinition def;
67 401 : def.myFGPosition = section.myLane->geometryPositionAtOffset(section.myPosition);
68 401 : def.myFGRotation = -section.myLane->getShape().rotationDegreeAtOffset(section.myPosition);
69 401 : return def;
70 : }
71 :
72 :
73 : GUIParameterTableWindow*
74 0 : GUIE3Collector::MyWrapper::getParameterWindow(GUIMainWindow& app,
75 : GUISUMOAbstractView&) {
76 : GUIParameterTableWindow* ret =
77 0 : new GUIParameterTableWindow(app, *this);
78 : // add items
79 : // values
80 0 : ret->mkItem(TL("name"), false, myDetector.myName);
81 0 : if (myDetector.isTyped()) {
82 0 : ret->mkItem(TL("vTypes"), false, toString(myDetector.getVehicleTypes()));
83 : }
84 0 : ret->mkItem(TL("vehicles within [#]"), true,
85 0 : new FunctionBinding<MSE3Collector, int>(&myDetector, &MSE3Collector::getVehiclesWithin));
86 0 : ret->mkItem(TL("mean speed [m/s]"), true,
87 0 : new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getCurrentMeanSpeed));
88 0 : ret->mkItem(TL("haltings [#]"), true,
89 0 : new FunctionBinding<MSE3Collector, int>(&myDetector, &MSE3Collector::getCurrentHaltingNumber));
90 0 : ret->mkItem(TL("last interval mean travel time [s]"), true,
91 0 : new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getLastIntervalMeanTravelTime));
92 0 : ret->mkItem(TL("last interval mean haltings [#]"), true,
93 0 : new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getLastIntervalMeanHaltsPerVehicle));
94 0 : ret->mkItem(TL("last interval mean time loss [s]"), true,
95 0 : new FunctionBinding<MSE3Collector, double>(&myDetector, &MSE3Collector::getLastIntervalMeanTimeLoss));
96 0 : ret->mkItem(TL("last interval mean vehicle count [#]"), true,
97 0 : new FunctionBinding<MSE3Collector, int>(&myDetector, &MSE3Collector::getLastIntervalVehicleSum));
98 :
99 : // close building
100 0 : ret->closeBuilding(&myDetector);
101 0 : return ret;
102 : }
103 :
104 :
105 : void
106 12572 : GUIE3Collector::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
107 12572 : GLHelper::pushName(getGlID());
108 12572 : GLHelper::pushMatrix();
109 12572 : glTranslated(0, 0, GLO_JUNCTION + 0.4); // do not draw on top of linkRules
110 : typedef std::vector<SingleCrossingDefinition> CrossingDefinitions;
111 : CrossingDefinitions::const_iterator i;
112 12572 : GLHelper::setColor(s.detectorSettings.E3EntryColor);
113 12572 : const double exaggeration = getExaggeration(s);
114 69860 : for (i = myEntryDefinitions.begin(); i != myEntryDefinitions.end(); ++i) {
115 57288 : drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, exaggeration);
116 : }
117 12572 : GLHelper::setColor(s.detectorSettings.E3ExitColor);
118 69322 : for (i = myExitDefinitions.begin(); i != myExitDefinitions.end(); ++i) {
119 56750 : drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, exaggeration);
120 : }
121 12572 : GLHelper::popMatrix();
122 12572 : drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
123 12572 : GLHelper::popName();
124 12572 : }
125 :
126 :
127 : void
128 114038 : GUIE3Collector::MyWrapper::drawSingleCrossing(const Position& pos,
129 : double rot, double upscale) const {
130 114038 : glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
131 114038 : GLHelper::pushMatrix();
132 114038 : glTranslated(pos.x(), pos.y(), 0);
133 114038 : glRotated(rot, 0, 0, 1);
134 114038 : glScaled(upscale, upscale, 1);
135 114038 : glBegin(GL_LINES);
136 114038 : glVertex2d(1.7, 0);
137 114038 : glVertex2d(-1.7, 0);
138 114038 : glEnd();
139 114038 : glBegin(GL_QUADS);
140 114038 : glVertex2d(-1.7, .5);
141 114038 : glVertex2d(-1.7, -.5);
142 114038 : glVertex2d(1.7, -.5);
143 114038 : glVertex2d(1.7, .5);
144 114038 : glEnd();
145 : // arrows
146 114038 : glTranslated(1.5, 0, 0);
147 114038 : GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
148 114038 : GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
149 114038 : glTranslated(-3, 0, 0);
150 114038 : GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
151 114038 : GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
152 114038 : GLHelper::popMatrix();
153 114038 : }
154 :
155 :
156 : double
157 12572 : GUIE3Collector::MyWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
158 12572 : return s.addSize.getExaggeration(s, this);
159 : }
160 :
161 :
162 : Boundary
163 12698 : GUIE3Collector::MyWrapper::getCenteringBoundary() const {
164 : Boundary b(myBoundary);
165 12698 : b.grow(20);
166 12698 : return b;
167 0 : }
168 :
169 :
170 : GUIE3Collector&
171 0 : GUIE3Collector::MyWrapper::getDetector() {
172 0 : return myDetector;
173 : }
174 :
175 :
176 : /* -------------------------------------------------------------------------
177 : * GUIE3Collector-methods
178 : * ----------------------------------------------------------------------- */
179 165 : GUIE3Collector::GUIE3Collector(const std::string& id,
180 : const CrossSectionVector& entries, const CrossSectionVector& exits,
181 : double haltingSpeedThreshold,
182 : SUMOTime haltingTimeThreshold,
183 : const std::string name, const std::string& vTypes,
184 : const std::string& nextEdges,
185 : int detectPersons,
186 165 : bool openEntry, bool expectArrival):
187 165 : MSE3Collector(id, entries, exits, haltingSpeedThreshold, haltingTimeThreshold, name, vTypes, nextEdges, detectPersons, openEntry, expectArrival)
188 165 : {}
189 :
190 :
191 330 : GUIE3Collector::~GUIE3Collector() {}
192 :
193 :
194 : const CrossSectionVector&
195 126 : GUIE3Collector::getEntries() const {
196 126 : return myEntries;
197 : }
198 :
199 :
200 : const CrossSectionVector&
201 126 : GUIE3Collector::getExits() const {
202 126 : return myExits;
203 : }
204 :
205 :
206 :
207 : GUIDetectorWrapper*
208 126 : GUIE3Collector::buildDetectorGUIRepresentation() {
209 126 : return new MyWrapper(*this);
210 : }
211 :
212 :
213 : /****************************************************************************/
|