Path: blob/main/src/netedit/elements/additional/GNEInstantInductionLoopDetector.cpp
193716 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 GNEInstantInductionLoopDetector.cpp14/// @author Pablo Alvarez Lopez15/// @date Jun 201816///17//18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/elements/moving/GNEMoveElementLaneSingle.h>23#include <netedit/GNENet.h>24#include <netedit/GNETagProperties.h>25#include <utils/gui/div/GLHelper.h>2627#include "GNEInstantInductionLoopDetector.h"2829// ===========================================================================30// member method definitions31// ===========================================================================3233GNEInstantInductionLoopDetector::GNEInstantInductionLoopDetector(GNENet* net) :34GNEDetector(net, SUMO_TAG_INSTANT_INDUCTION_LOOP),35myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,36GNEMoveElementLaneSingle::PositionType::SINGLE)) {37}383940GNEInstantInductionLoopDetector::GNEInstantInductionLoopDetector(const std::string& id, GNENet* net, FileBucket* fileBucket, GNELane* lane,41const double pos, const std::string& outputFilename, const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges,42const std::string& detectPersons, const std::string& name, const bool friendlyPos, const Parameterised::Map& parameters) :43GNEDetector(id, net, fileBucket, SUMO_TAG_INSTANT_INDUCTION_LOOP, 0, outputFilename,44vehicleTypes, nextEdges, detectPersons, name, parameters),45myPosOverLane(pos),46myFriendlyPos(friendlyPos),47myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,48GNEMoveElementLaneSingle::PositionType::SINGLE)) {49// set parents50setParent<GNELane*>(lane);51// update centering boundary without updating grid52updateCenteringBoundary(false);53}545556GNEInstantInductionLoopDetector::~GNEInstantInductionLoopDetector() {57delete myMoveElementLaneSingle;58}596061GNEMoveElement*62GNEInstantInductionLoopDetector::getMoveElement() const {63return myMoveElementLaneSingle;64}656667Parameterised*68GNEInstantInductionLoopDetector::getParameters() {69return this;70}717273void74GNEInstantInductionLoopDetector::writeAdditional(OutputDevice& device) const {75device.openTag(getTagProperty()->getTag());76// write common additional attributes77writeAdditionalAttributes(device);78// write move attributes79myMoveElementLaneSingle->writeMoveAttributes(device);80// write common detector parameters81writeDetectorValues(device);82// write parameters (Always after children to avoid problems with additionals.xsd)83writeParams(device);84device.closeTag();85}868788bool89GNEInstantInductionLoopDetector::isAdditionalValid() const {90// only movement problems91return myMoveElementLaneSingle->isMoveElementValid();92}939495std::string96GNEInstantInductionLoopDetector::getAdditionalProblem() const {97// only movement problems98return myMoveElementLaneSingle->getMovingProblem();99}100101102void103GNEInstantInductionLoopDetector::fixAdditionalProblem() {104// only movement problems105myMoveElementLaneSingle->fixMovingProblem();106}107108109void110GNEInstantInductionLoopDetector::updateGeometry() {111// update geometry112myAdditionalGeometry.updateGeometry(getParentLanes().front()->getLaneShape(), myMoveElementLaneSingle->getFixedPositionOverLane(true), myMoveElementLaneSingle->myMovingLateralOffset);113// update centering boundary without updating grid114updateCenteringBoundary(false);115}116117118void119GNEInstantInductionLoopDetector::drawGL(const GUIVisualizationSettings& s) const {120// check if additional has to be drawn121if (myNet->getViewNet()->getDataViewOptions().showAdditionals() &&122!myNet->getViewNet()->selectingDetectorsTLSMode()) {123// Obtain exaggeration of the draw124const double E1InstantExaggeration = getExaggeration(s);125// get detail level126const auto d = s.getDetailLevel(E1InstantExaggeration);127// draw geometry only if we'rent in drawForObjectUnderCursor mode128if (s.checkDrawAdditional(d, isAttributeCarrierSelected())) {129// declare colors130RGBColor mainColor, secondColor, textColor;131// set color132if (drawUsingSelectColor()) {133mainColor = s.colorSettings.selectedAdditionalColor;134secondColor = mainColor.changedBrightness(-32);135textColor = mainColor.changedBrightness(32);136} else {137mainColor = s.detectorSettings.E1InstantColor;138secondColor = RGBColor::WHITE;139textColor = RGBColor::BLACK;140}141// draw parent and child lines142drawParentChildLines(s, s.additionalSettings.connectionColor);143// push layer matrix144GLHelper::pushMatrix();145// translate to front146drawInLayer(GLO_E1DETECTOR_INSTANT);147// draw E1Instant shape148drawE1Shape(d, E1InstantExaggeration, mainColor, secondColor);149// draw E1 Logo150drawE1DetectorLogo(s, d, E1InstantExaggeration, "E1", textColor);151// pop layer matrix152GLHelper::popMatrix();153// draw lock icon154GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), myAdditionalGeometry.getShape().getCentroid(),155E1InstantExaggeration);156// Draw additional ID157drawAdditionalID(s);158// draw additional name159drawAdditionalName(s);160// draw dotted contour161myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);162}163// draw dotted contour164myAdditionalContour.calculateContourRectangleShape(s, d, this, myAdditionalGeometry.getShape().front(), 2, 1, getType(), 0, 0,165myAdditionalGeometry.getShapeRotations().front(), E1InstantExaggeration, getParentLanes().front()->getParentEdge());166}167}168169170std::string171GNEInstantInductionLoopDetector::getAttribute(SumoXMLAttr key) const {172return getDetectorAttribute(key);173}174175176double177GNEInstantInductionLoopDetector::getAttributeDouble(SumoXMLAttr key) const {178return getDetectorAttributeDouble(key);179}180181182Position183GNEInstantInductionLoopDetector::getAttributePosition(SumoXMLAttr key) const {184return getDetectorAttributePosition(key);185}186187188void189GNEInstantInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {190setDetectorAttribute(key, value, undoList);191}192193194bool195GNEInstantInductionLoopDetector::isValid(SumoXMLAttr key, const std::string& value) {196return isDetectorValid(key, value);197}198199// ===========================================================================200// private201// ===========================================================================202203void204GNEInstantInductionLoopDetector::setAttribute(SumoXMLAttr key, const std::string& value) {205switch (key) {206case SUMO_ATTR_LANE:207replaceAdditionalParentLanes(value);208break;209default:210setDetectorAttribute(key, value);211break;212}213}214215/****************************************************************************/216217218