Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIXMLShapeHandler.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// Importer for static public transport information
19/****************************************************************************/
20#include <config.h>
21
22#include <utils/geom/Position.h>
25#include <netbuild/NBEdgeCont.h>
26#include <netbuild/NBEdge.h>
27
28#include "NIXMLShapeHandler.h"
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33
35 ShapeHandler("polgyon - file", sc, GeoConvHelper::getNumLoaded() == 0 ? nullptr : & GeoConvHelper::getLoaded()),
36 myEdgeCont(ec)
37{}
38
40NIXMLShapeHandler::getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat) {
41 std::string edgeID;
42 int laneIndex;
43 NBHelpers::interpretLaneID(laneID, edgeID, laneIndex);
44 NBEdge* edge = myEdgeCont.retrieve(edgeID);
45 if (edge == 0 || laneIndex < 0 || edge->getNumLanes() <= laneIndex) {
46 WRITE_ERRORF(TL("Lane '%' to place poi '%' on is not known."), laneID, poiID);
47 return Position::INVALID;
48 }
49 if (lanePos < 0) {
50 lanePos = edge->getLength() + lanePos;
51 }
52 if ((lanePos < 0) && friendlyPos) {
53 lanePos = 0;
54 }
55 if ((lanePos > edge->getLength()) && friendlyPos) {
56 lanePos = edge->getLength();
57 }
58 if (lanePos < 0 || lanePos > edge->getLength()) {
59 WRITE_WARNINGF(TL("lane position % for poi '%' is not valid."), toString(lanePos), poiID);
60 }
61 return edge->getLanes()[laneIndex].shape.positionAtOffset(lanePos, -lanePosLat);
62}
63
64
65/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_ERRORF(...)
Definition MsgHandler.h:305
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static methods for processing the coordinates conversion for the current net
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
The representation of a single edge during network building.
Definition NBEdge.h:92
double getLength() const
Returns the computed length of the edge.
Definition NBEdge.h:589
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition NBEdge.h:726
static void interpretLaneID(const std::string &lane_id, std::string &edge_id, int &index)
parses edge-id and index from lane-id
Position getLanePos(const std::string &poiID, const std::string &laneID, double lanePos, bool friendlyPos, double lanePosLat)
get position for a given laneID (Has to be implemented in all child)
const NBEdgeCont & myEdgeCont
NIXMLShapeHandler(ShapeContainer &sc, const NBEdgeCont &ec)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:322
Storage for geometrical objects.
The XML-Handler for network loading.