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