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

            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         4702 : GUIMEInductLoop::MyWrapper::getExaggeration(const GUIVisualizationSettings& s) const {
      80         4702 :     return s.addSize.getExaggeration(s, this);
      81              : }
      82              : 
      83              : 
      84              : Boundary
      85         4882 : GUIMEInductLoop::MyWrapper::getCenteringBoundary() const {
      86              :     Boundary b(myBoundary);
      87         4882 :     b.grow(20);
      88         4882 :     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         4702 : GUIMEInductLoop::MyWrapper::drawGL(const GUIVisualizationSettings& s) const {
     126         4702 :     GLHelper::pushName(getGlID());
     127         4702 :     glPolygonOffset(0, -2);
     128         4702 :     double width = (double) 2.0 * s.scale;
     129         4702 :     glLineWidth(1.0);
     130         4702 :     const double exaggeration = getExaggeration(s);
     131              :     // shape
     132         4702 :     glColor3d(1, 1, 0);
     133         4702 :     GLHelper::pushMatrix();
     134         4702 :     glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
     135         4702 :     glRotated(myFGRotation, 0, 0, 1);
     136         4702 :     glScaled(exaggeration, exaggeration, exaggeration);
     137         4702 :     glBegin(GL_QUADS);
     138         4702 :     glVertex2d(0 - 1.0, 2);
     139         4702 :     glVertex2d(-1.0, -2);
     140         4702 :     glVertex2d(1.0, -2);
     141         4702 :     glVertex2d(1.0, 2);
     142         4702 :     glEnd();
     143         4702 :     glBegin(GL_LINES);
     144              :     // without the subtracted offsets, lines are partially longer
     145              :     //  than the boxes
     146         4702 :     glVertex2d(0, 2 - .1);
     147         4702 :     glVertex2d(0, -2 + .1);
     148         4702 :     glEnd();
     149              : 
     150              :     // outline
     151         4702 :     if (width * exaggeration > 1) {
     152         2842 :         glColor3d(1, 1, 1);
     153         2842 :         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     154         2842 :         glBegin(GL_QUADS);
     155         2842 :         glVertex2d(0 - 1.0, 2);
     156         2842 :         glVertex2d(-1.0, -2);
     157         2842 :         glVertex2d(1.0, -2);
     158         2842 :         glVertex2d(1.0, 2);
     159         2842 :         glEnd();
     160         2842 :         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     161              :     }
     162              : 
     163              :     // position indicator
     164         4702 :     if (width * exaggeration > 1) {
     165         2842 :         glRotated(90, 0, 0, -1);
     166         2842 :         glColor3d(1, 1, 1);
     167         2842 :         glBegin(GL_LINES);
     168         2842 :         glVertex2d(0, 1.7);
     169         2842 :         glVertex2d(0, -1.7);
     170         2842 :         glEnd();
     171              :     }
     172         4702 :     GLHelper::popMatrix();
     173         4702 :     drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
     174         4702 :     GLHelper::popName();
     175         4702 : }
     176              : 
     177              : 
     178              : GUIMEInductLoop&
     179            0 : GUIMEInductLoop::MyWrapper::getLoop() {
     180            0 :     return myDetector;
     181              : }
     182              : 
     183              : 
     184              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1