LCOV - code coverage report
Current view: top level - src/mesogui - GUIMEInductLoop.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 63 72 87.5 %
Date: 2024-05-02 15:31:40 Functions: 10 12 83.3 %

          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    GUIMEInductLoop.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @date    Thu, 21.07.2005
      17             : ///
      18             : // The gui-version of the MEInductLoop
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : 
      23             : #include <utils/gui/globjects/GLIncludes.h>
      24             : #include <utils/gui/globjects/GUIGlObject.h>
      25             : #include <utils/geom/PositionVector.h>
      26             : #include <guisim/GUILane.h>
      27             : #include <utils/gui/div/GLHelper.h>
      28             : #include <utils/gui/div/GUIParameterTableWindow.h>
      29             : #include <microsim/logging/FuncBinding_IntParam.h>
      30             : #include <microsim/logging/FunctionBinding.h>
      31             : #include <mesosim/MEInductLoop.h>
      32             : #include <mesosim/MESegment.h>
      33             : #include "GUIMEInductLoop.h"
      34             : 
      35             : 
      36             : // ===========================================================================
      37             : // method definitions
      38             : // ===========================================================================
      39             : /* -------------------------------------------------------------------------
      40             :  * GUIMEInductLoop-methods
      41             :  * ----------------------------------------------------------------------- */
      42         182 : GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
      43             :                                  double position,
      44             :                                  const std::string name, const std::string& vTypes,
      45             :                                  const std::string& nextEdges,
      46             :                                  int detectPersons,
      47         182 :                                  bool /*show*/):
      48         182 :     MEInductLoop(id, s, position, name, vTypes, nextEdges, detectPersons)
      49         181 : {}
      50             : 
      51             : 
      52         362 : GUIMEInductLoop::~GUIMEInductLoop() {}
      53             : 
      54             : 
      55             : GUIDetectorWrapper*
      56         180 : GUIMEInductLoop::buildDetectorGUIRepresentation() {
      57         180 :     return new MyWrapper(*this, myPosition);
      58             : }
      59             : 
      60             : // -----------------------------------------------------------------------
      61             : // GUIMEInductLoop::MyWrapper-methods
      62             : // -----------------------------------------------------------------------
      63             : 
      64         180 : GUIMEInductLoop::MyWrapper::MyWrapper(GUIMEInductLoop& detector, double pos)
      65             :     : GUIDetectorWrapper(GLO_E1DETECTOR_ME, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E1)),
      66         180 :       myDetector(detector), myPosition(pos) {
      67         180 :     const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
      68         180 :     myFGPosition = lane->geometryPositionAtOffset(pos);
      69         180 :     myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
      70         180 :     myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
      71         180 :     myFGRotation = -lane->getShape().rotationDegreeAtOffset(pos);
      72         180 : }
      73             : 
      74             : 
      75         360 : GUIMEInductLoop::MyWrapper::~MyWrapper() {}
      76             : 
      77             : 
      78             : double
      79        5553 : GUIMEInductLoop::MyWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
      80        5553 :     return s.addSize.getExaggeration(s, this);
      81             : }
      82             : 
      83             : 
      84             : Boundary
      85        5733 : GUIMEInductLoop::MyWrapper::getCenteringBoundary() const {
      86             :     Boundary b(myBoundary);
      87        5733 :     b.grow(20);
      88        5733 :     return b;
      89           0 : }
      90             : 
      91             : 
      92             : 
      93             : GUIParameterTableWindow*
      94           0 : GUIMEInductLoop::MyWrapper::getParameterWindow(GUIMainWindow& app,
      95             :         GUISUMOAbstractView& /* parent */) {
      96           0 :     GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
      97             :     // add items
      98             :     /*
      99             :     ret->mkItem("flow [veh/h]", true,
     100             :         new FuncBinding_IntParam<GUIMEInductLoop, double>(
     101             :             &(getLoop()), &GUIMEInductLoop::getFlow, 1));
     102             :     ret->mkItem("mean speed [m/s]", true,
     103             :         new FuncBinding_IntParam<GUIMEInductLoop, double>(
     104             :             &(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
     105             :     ret->mkItem("occupancy [%]", true,
     106             :         new FuncBinding_IntParam<GUIMEInductLoop, double>(
     107             :             &(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
     108             :     ret->mkItem("mean vehicle length [m]", true,
     109             :         new FuncBinding_IntParam<GUIMEInductLoop, double>(
     110             :             &(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
     111             :     ret->mkItem("empty time [s]", true,
     112             :         new FunctionBinding<GUIMEInductLoop, double>(
     113             :             &(getLoop()), &GUIMEInductLoop::getTimeSinceLastDetection));
     114             :             */
     115             :     //
     116           0 :     ret->mkItem("position [m]", false, myPosition);
     117           0 :     ret->mkItem("lane", false, myDetector.mySegment->getID());
     118             :     // close building
     119           0 :     ret->closeBuilding();
     120           0 :     return ret;
     121             : }
     122             : 
     123             : 
     124             : void
     125        5553 : GUIMEInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
     126        5553 :     GLHelper::pushName(getGlID());
     127        5553 :     glPolygonOffset(0, -2);
     128        5553 :     double width = (double) 2.0 * s.scale;
     129        5553 :     glLineWidth(1.0);
     130        5553 :     const double exaggeration = getExaggeration(s);
     131             :     // shape
     132        5553 :     glColor3d(1, 1, 0);
     133        5553 :     GLHelper::pushMatrix();
     134        5553 :     glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
     135        5553 :     glRotated(myFGRotation, 0, 0, 1);
     136        5553 :     glScaled(exaggeration, exaggeration, exaggeration);
     137        5553 :     glBegin(GL_QUADS);
     138        5553 :     glVertex2d(0 - 1.0, 2);
     139        5553 :     glVertex2d(-1.0, -2);
     140        5553 :     glVertex2d(1.0, -2);
     141        5553 :     glVertex2d(1.0, 2);
     142        5553 :     glEnd();
     143        5553 :     glBegin(GL_LINES);
     144             :     // without the subtracted offsets, lines are partially longer
     145             :     //  than the boxes
     146        5553 :     glVertex2d(0, 2 - .1);
     147        5553 :     glVertex2d(0, -2 + .1);
     148        5553 :     glEnd();
     149             : 
     150             :     // outline
     151        5553 :     if (width * exaggeration > 1) {
     152        3419 :         glColor3d(1, 1, 1);
     153        3419 :         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     154        3419 :         glBegin(GL_QUADS);
     155        3419 :         glVertex2d(0 - 1.0, 2);
     156        3419 :         glVertex2d(-1.0, -2);
     157        3419 :         glVertex2d(1.0, -2);
     158        3419 :         glVertex2d(1.0, 2);
     159        3419 :         glEnd();
     160        3419 :         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     161             :     }
     162             : 
     163             :     // position indicator
     164        5553 :     if (width * exaggeration > 1) {
     165        3419 :         glRotated(90, 0, 0, -1);
     166        3419 :         glColor3d(1, 1, 1);
     167        3419 :         glBegin(GL_LINES);
     168        3419 :         glVertex2d(0, 1.7);
     169        3419 :         glVertex2d(0, -1.7);
     170        3419 :         glEnd();
     171             :     }
     172        5553 :     GLHelper::popMatrix();
     173        5553 :     drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
     174        5553 :     GLHelper::popName();
     175        5553 : }
     176             : 
     177             : 
     178             : GUIMEInductLoop&
     179           0 : GUIMEInductLoop::MyWrapper::getLoop() {
     180           0 :     return myDetector;
     181             : }
     182             : 
     183             : 
     184             : /****************************************************************************/

Generated by: LCOV version 1.14