Eclipse SUMO - Simulation of Urban MObility
NIXMLShapeHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // Importer for static public transport information
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
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 
40 NIXMLShapeHandler::getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, 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_ERROR("Lane '" + laneID + "' to place poi '" + poiID + "' on is not known.");
47  return Position::INVALID;
48  }
49  if (lanePos < 0) {
50  lanePos = edge->getLength() + lanePos;
51  }
52  if (lanePos < 0 || lanePos > edge->getLength()) {
53  WRITE_WARNING("lane position " + toString(lanePos) + " for poi '" + poiID + "' is not valid.");
54  }
55  return edge->getLanes()[laneIndex].shape.positionAtOffset(lanePos, -lanePosLat);
56 }
57 
58 
59 
60 /****************************************************************************/
NIXMLShapeHandler::myEdgeCont
const NBEdgeCont & myEdgeCont
Definition: NIXMLShapeHandler.h:52
NBEdgeCont::retrieve
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:246
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
Position::INVALID
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:284
MsgHandler.h
NBEdgeCont.h
GeoConvHelper.h
ShapeContainer
Storage for geometrical objects.
Definition: ShapeContainer.h:49
GeoConvHelper
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:55
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NIXMLShapeHandler::NIXMLShapeHandler
NIXMLShapeHandler(ShapeContainer &sc, const NBEdgeCont &ec)
Definition: NIXMLShapeHandler.cpp:34
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
NBHelpers::interpretLaneID
static void interpretLaneID(const std::string &lane_id, std::string &edge_id, int &index)
parses edge-id and index from lane-id
Definition: NBHelpers.cpp:120
NIXMLShapeHandler::getLanePos
Position getLanePos(const std::string &poiID, const std::string &laneID, double lanePos, double lanePosLat)
get position for a given laneID (Has to be implemented in all child)
Definition: NIXMLShapeHandler.cpp:40
NBEdge::getLanes
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:656
NIXMLShapeHandler.h
NBEdge::getLength
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:545
Position.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
config.h
ShapeHandler
The XML-Handler for network loading.
Definition: ShapeHandler.h:49
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
NBEdge.h