Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netgen/NGNode.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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 NGNode.cpp
15
/// @author Markus Hartinger
16
/// @author Daniel Krajzewicz
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @date Mar, 2003
20
///
21
// A netgen-representation of a node
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <algorithm>
26
#include <netbuild/NBNode.h>
27
#include <netbuild/NBNodeCont.h>
28
#include <netbuild/NBEdge.h>
29
#include <netbuild/NBOwnTLDef.h>
30
#include <netbuild/NBTypeCont.h>
31
#include <netbuild/NBTrafficLightLogicCont.h>
32
#include <netbuild/NBNetBuilder.h>
33
#include <utils/common/UtilExceptions.h>
34
#include <utils/common/ToString.h>
35
#include <utils/geom/GeoConvHelper.h>
36
#include <utils/options/OptionsCont.h>
37
#include <utils/options/Option.h>
38
#include "NGNode.h"
39
40
41
// ===========================================================================
42
// method definitions
43
// ===========================================================================
44
NGNode::NGNode(const std::string& id)
45
: Named(id), myXID(-1), myYID(-1), myAmCenter(false), myAmFringe(false) {}
46
47
48
NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
49
: Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(false), myAmFringe(false) {}
50
51
52
NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
53
: Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(amCenter), myAmFringe(false) {}
54
55
56
NGNode::~NGNode() {
57
NGEdgeList::iterator li;
58
while (myLinkList.size() != 0) {
59
li = myLinkList.begin();
60
delete (*li);
61
}
62
}
63
64
65
NBNode*
66
NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const {
67
Position pos(myPosition + perturb);
68
GeoConvHelper::getProcessing().x2cartesian(pos);
69
// the center will have no logic!
70
if (myAmCenter) {
71
return new NBNode(myID, pos, SumoXMLNodeType::NOJUNCTION);
72
}
73
NBNode* node = nullptr;
74
std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
75
OptionsCont::getOptions().getString("default-junction-type") : "";
76
77
if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
78
const SumoXMLNodeType type = SUMOXMLDefinitions::NodeTypes.get(typeS);
79
node = new NBNode(myID, pos, type);
80
81
// check whether it is a traffic light junction
82
if (NBNode::isTrafficLight(type)) {
83
const TrafficLightType tlType = SUMOXMLDefinitions::TrafficLightTypes.get(
84
OptionsCont::getOptions().getString("tls.default-type"));
85
NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, tlType);
86
if (!nb.getTLLogicCont().insert(tlDef)) {
87
// actually, nothing should fail here
88
delete tlDef;
89
throw ProcessError();
90
}
91
}
92
} else {
93
// otherwise netbuild may guess SumoXMLNodeType::TRAFFIC_LIGHT without actually building one
94
node = new NBNode(myID, pos, SumoXMLNodeType::PRIORITY);
95
}
96
if (myAmFringe) {
97
node->setFringeType(FringeType::OUTER);
98
}
99
100
return node;
101
}
102
103
104
void
105
NGNode::addLink(NGEdge* link) {
106
myLinkList.push_back(link);
107
}
108
109
110
void
111
NGNode::removeLink(NGEdge* link) {
112
myLinkList.remove(link);
113
}
114
115
116
bool
117
NGNode::connected(const NGNode* const node, const bool withDir) const {
118
for (NGEdge* ngEdge : myLinkList) {
119
if (ngEdge->getStartNode() == this && ngEdge->getEndNode() == node) {
120
return true;
121
}
122
if (!withDir && ngEdge->getEndNode() == this && ngEdge->getStartNode() == node) {
123
return true;
124
}
125
}
126
return false;
127
}
128
129
130
/****************************************************************************/
131
132