Path: blob/main/src/netedit/elements/additional/GNEInductionLoopDetector.cpp
193811 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEInductionLoopDetector.cpp14/// @author Pablo Alvarez Lopez15/// @date Nov 201516///17//18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/elements/moving/GNEMoveElementLaneSingle.h>23#include <netedit/frames/network/GNETLSEditorFrame.h>24#include <netedit/GNENet.h>25#include <netedit/GNETagProperties.h>26#include <netedit/GNEViewParent.h>27#include <utils/gui/div/GLHelper.h>28#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>2930#include "GNEInductionLoopDetector.h"3132// ===========================================================================33// member method definitions34// ===========================================================================3536GNEInductionLoopDetector::GNEInductionLoopDetector(GNENet* net) :37GNEDetector(net, SUMO_TAG_INDUCTION_LOOP),38myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,39GNEMoveElementLaneSingle::PositionType::SINGLE)) {40}414243GNEInductionLoopDetector::GNEInductionLoopDetector(const std::string& id, GNENet* net, FileBucket* fileBucket, GNELane* lane,44const double pos, const SUMOTime freq, const std::string& outputFilename, const std::vector<std::string>& vehicleTypes,45const std::vector<std::string>& nextEdges, const std::string& detectPersons, const std::string& name, const bool friendlyPos,46const Parameterised::Map& parameters) :47GNEDetector(id, net, fileBucket, SUMO_TAG_INDUCTION_LOOP, freq, outputFilename, vehicleTypes, nextEdges,48detectPersons, name, parameters),49myPosOverLane(pos),50myFriendlyPos(friendlyPos),51myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,52GNEMoveElementLaneSingle::PositionType::SINGLE)) {53// set parents54setParent<GNELane*>(lane);55// update centering boundary without updating grid56updateCenteringBoundary(false);57}585960GNEInductionLoopDetector::~GNEInductionLoopDetector() {61delete myMoveElementLaneSingle;62}636465GNEMoveElement*66GNEInductionLoopDetector::getMoveElement() const {67return myMoveElementLaneSingle;68}697071Parameterised*72GNEInductionLoopDetector::getParameters() {73return this;74}757677void78GNEInductionLoopDetector::writeAdditional(OutputDevice& device) const {79device.openTag(getTagProperty()->getTag());80// write common additional attributes81writeAdditionalAttributes(device);82// write move attributes83myMoveElementLaneSingle->writeMoveAttributes(device);84// write detector attributes85writeDetectorValues(device);86// write parameters (Always after children to avoid problems with additionals.xsd)87writeParams(device);88device.closeTag();89}909192bool93GNEInductionLoopDetector::isAdditionalValid() const {94// only movement problems95return myMoveElementLaneSingle->isMoveElementValid();96}979899std::string100GNEInductionLoopDetector::getAdditionalProblem() const {101// only movement problems102return myMoveElementLaneSingle->getMovingProblem();103}104105106void107GNEInductionLoopDetector::fixAdditionalProblem() {108// only movement problems109myMoveElementLaneSingle->fixMovingProblem();110}111112113void114GNEInductionLoopDetector::updateGeometry() {115// update geometry116myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), myMoveElementLaneSingle->getFixedPositionOverLane(true), myMoveElementLaneSingle->myMovingLateralOffset);117// update centering boundary without updating grid118updateCenteringBoundary(false);119}120121122bool123GNEInductionLoopDetector::checkDrawRelatedContour() const {124// get TLS Attributes125const auto& TLSAttributes = myNet->getViewParent()->getTLSEditorFrame()->getTLSAttributes();126// check detectors127if (myNet->getViewNet()->selectingDetectorsTLSMode() &&128(TLSAttributes->getE1Detectors().count(getParentLanes().front()->getID()) > 0) &&129(TLSAttributes->getE1Detectors().at(getParentLanes().front()->getID()) == getID())) {130return true;131}132// check opened popup133if (myNet->getViewNet()->getPopup()) {134return myNet->getViewNet()->getPopup()->getGLObject() == this;135}136return false;137}138139140void141GNEInductionLoopDetector::drawGL(const GUIVisualizationSettings& s) const {142// first check if additional has to be drawn143if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {144// Obtain exaggeration of the draw145const double E1Exaggeration = getExaggeration(s);146// get detail level147const auto d = s.getDetailLevel(E1Exaggeration);148// draw geometry only if we'rent in drawForObjectUnderCursor mode149if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {150// declare colors151RGBColor mainColor, secondColor, textColor;152// set color153if (drawUsingSelectColor()) {154mainColor = s.colorSettings.selectedAdditionalColor;155secondColor = mainColor.changedBrightness(-32);156textColor = mainColor.changedBrightness(32);157} else {158mainColor = s.detectorSettings.E1Color;159secondColor = RGBColor::WHITE;160textColor = RGBColor::BLACK;161}162// draw parent and child lines163drawParentChildLines(s, s.additionalSettings.connectionColor);164// push layer matrix165GLHelper::pushMatrix();166// translate to front167drawInLayer(GLO_E1DETECTOR);168// draw E1 shape169drawE1Shape(d, E1Exaggeration, mainColor, secondColor);170// draw E1 Logo171drawE1DetectorLogo(s, d, E1Exaggeration, "E1", textColor);172// pop layer matrix173GLHelper::popMatrix();174// draw lock icon175GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(), E1Exaggeration);176// Draw additional ID177drawAdditionalID(s);178// draw additional name179drawAdditionalName(s);180// draw dotted contour181myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);182}183// calculate contour rectangle184myAdditionalContour.calculateContourRectangleShape(s, d, this, myAdditionalGeometry.getShape().front(), 2, 1, getType(), 0, 0,185myAdditionalGeometry.getShapeRotations().front(), E1Exaggeration, getParentLanes().front()->getParentEdge());186}187}188189190std::string191GNEInductionLoopDetector::getAttribute(SumoXMLAttr key) const {192return getDetectorAttribute(key);193}194195196double197GNEInductionLoopDetector::getAttributeDouble(SumoXMLAttr key) const {198return getDetectorAttributeDouble(key);199}200201202Position203GNEInductionLoopDetector::getAttributePosition(SumoXMLAttr key) const {204return getDetectorAttributePosition(key);205}206207208void209GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {210setDetectorAttribute(key, value, undoList);211}212213214bool215GNEInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {216return isDetectorValid(key, value);217}218219// ===========================================================================220// private221// ===========================================================================222223void224GNEInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value) {225switch (key) {226case SUMO_ATTR_LANE:227replaceAdditionalParentLanes(value);228break;229default:230setDetectorAttribute(key, value);231break;232}233}234235/****************************************************************************/236237238