Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2003-2025 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 NGEdge.cpp
15 : /// @author Markus Hartinger
16 : /// @author Daniel Krajzewicz
17 : /// @author Michael Behrisch
18 : /// @author Jakob Erdmann
19 : /// @date Mar, 2003
20 : ///
21 : // A netgen-representation of an edge
22 : /****************************************************************************/
23 : #include <config.h>
24 :
25 : #include <algorithm>
26 : #include <utils/common/RandHelper.h>
27 : #include <netbuild/NBNode.h>
28 : #include <netbuild/NBNodeCont.h>
29 : #include <netbuild/NBEdge.h>
30 : #include <netbuild/NBOwnTLDef.h>
31 : #include <netbuild/NBTypeCont.h>
32 : #include <netbuild/NBTrafficLightLogicCont.h>
33 : #include <netbuild/NBNetBuilder.h>
34 : #include <utils/common/UtilExceptions.h>
35 : #include <utils/common/ToString.h>
36 : #include <utils/geom/GeoConvHelper.h>
37 : #include <utils/options/OptionsCont.h>
38 : #include <utils/options/Option.h>
39 : #include "NGEdge.h"
40 : #include "NGNode.h"
41 :
42 :
43 : // ===========================================================================
44 : // method definitions
45 : // ===========================================================================
46 : // ---------------------------------------------------------------------------
47 : // NGEdge-definitions
48 : // ---------------------------------------------------------------------------
49 44936 : NGEdge::NGEdge(const std::string& id, NGNode* startNode, NGNode* endNode, const std::string& reverseID) :
50 44936 : Named(id), myStartNode(startNode), myEndNode(endNode), myReverseID(reverseID == "" ? "-" + id : reverseID) {
51 44936 : myStartNode->addLink(this);
52 44936 : myEndNode->addLink(this);
53 44936 : }
54 :
55 :
56 89872 : NGEdge::~NGEdge() {
57 44936 : myStartNode->removeLink(this);
58 44936 : myEndNode->removeLink(this);
59 89872 : }
60 :
61 :
62 : NBEdge*
63 15158 : NGEdge::buildNBEdge(NBNetBuilder& nb, std::string type, const bool reversed) const {
64 15158 : const OptionsCont& oc = OptionsCont::getOptions();
65 30316 : if (oc.getBool("random-type") && nb.getTypeCont().size() > 1) {
66 24 : auto it = nb.getTypeCont().begin();
67 24 : std::advance(it, RandHelper::rand((int)nb.getTypeCont().size()));
68 24 : type = it->first;
69 : }
70 15158 : int priority = nb.getTypeCont().getEdgeTypePriority(type);
71 15790 : if (priority > 1 && oc.getBool("rand.random-priority")) {
72 584 : priority = RandHelper::rand(priority) + 1;
73 : }
74 15158 : int lanenumber = nb.getTypeCont().getEdgeTypeNumLanes(type);
75 16552 : if (lanenumber > 1 && oc.getBool("rand.random-lanenumber")) {
76 584 : lanenumber = RandHelper::rand(lanenumber) + 1;
77 : }
78 :
79 15158 : SVCPermissions permissions = nb.getTypeCont().getEdgeTypePermissions(type);
80 15158 : LaneSpreadFunction lsf = nb.getTypeCont().getEdgeTypeSpreadType(type);
81 15158 : if (isRailway(permissions) && nb.getTypeCont().getEdgeTypeIsOneWay(type)) {
82 : lsf = LaneSpreadFunction::CENTER;
83 : }
84 30316 : const double maxSegmentLength = oc.getFloat("geometry.max-segment-length");
85 15158 : NBNode* from = nb.getNodeCont().retrieve(reversed ? myEndNode->getID() : myStartNode->getID());
86 15158 : NBNode* to = nb.getNodeCont().retrieve(reversed ? myStartNode->getID() : myEndNode->getID());
87 15158 : PositionVector shape;
88 15158 : if (maxSegmentLength > 0) {
89 24 : shape.push_back(from->getPosition());
90 24 : shape.push_back(to->getPosition());
91 : // shape is already cartesian but we must use a copy because the original will be modified
92 24 : NBNetBuilder::addGeometrySegments(shape, PositionVector(shape), maxSegmentLength);
93 : }
94 : NBEdge* result = new NBEdge(
95 : reversed ? myReverseID : myID,
96 : from, to,
97 : type, nb.getTypeCont().getEdgeTypeSpeed(type), NBEdge::UNSPECIFIED_FRICTION, lanenumber,
98 60632 : priority, nb.getTypeCont().getEdgeTypeWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, lsf);
99 15158 : result->setPermissions(permissions);
100 15158 : return result;
101 15158 : }
102 :
103 :
104 : /****************************************************************************/
|