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 /****************************************************************************/
10 /// @file    NGNode.cpp
11 /// @author  Markus Hartinger
12 /// @author  Daniel Krajzewicz
13 /// @author  Jakob Erdmann
14 /// @author  Michael Behrisch
15 /// @date    Mar, 2003
16 /// @version $Id$
17 ///
18 // A netgen-representation of a node
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <algorithm>
28 #include <netbuild/NBNode.h>
29 #include <netbuild/NBNodeCont.h>
30 #include <netbuild/NBEdge.h>
31 #include <netbuild/NBOwnTLDef.h>
32 #include <netbuild/NBTypeCont.h>
33 #include <netbuild/NBTrafficLightLogicCont.h>
34 #include <netbuild/NBNetBuilder.h>
35 #include <utils/common/UtilExceptions.h>
36 #include <utils/common/ToString.h>
37 #include <utils/geom/GeoConvHelper.h>
38 #include <utils/options/OptionsCont.h>
39 #include <utils/options/Option.h>
40 #include "NGNode.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
NGNode(const std::string & id)46 NGNode::NGNode(const std::string& id)
47     : Named(id), xID(-1), yID(-1), myAmCenter(false) {}
48 
49 
NGNode(const std::string & id,int xIDa,int yIDa)50 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
51     : Named(id), xID(xIDa), yID(yIDa), myAmCenter(false) {}
52 
53 
NGNode(const std::string & id,int xIDa,int yIDa,bool amCenter)54 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
55     : Named(id), xID(xIDa), yID(yIDa), myAmCenter(amCenter) {}
56 
57 
~NGNode()58 NGNode::~NGNode() {
59     NGEdgeList::iterator li;
60     while (LinkList.size() != 0) {
61         li = LinkList.begin();
62         delete (*li);
63     }
64 }
65 
66 
67 NBNode*
buildNBNode(NBNetBuilder & nb,const Position & perturb) const68 NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const {
69     Position pos(myPosition + perturb);
70     GeoConvHelper::getProcessing().x2cartesian(pos);
71     // the center will have no logic!
72     if (myAmCenter) {
73         return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
74     }
75     NBNode* node = nullptr;
76     std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
77                         OptionsCont::getOptions().getString("default-junction-type") : "";
78 
79     if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
80         SumoXMLNodeType type = SUMOXMLDefinitions::NodeTypes.get(typeS);
81         node = new NBNode(myID, pos, type);
82 
83         // check whether it is a traffic light junction
84         if (NBNode::isTrafficLight(type)) {
85             TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(
86                                         OptionsCont::getOptions().getString("tls.default-type"));
87             NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, type);
88             if (!nb.getTLLogicCont().insert(tlDef)) {
89                 // actually, nothing should fail here
90                 delete tlDef;
91                 throw ProcessError();
92             }
93         }
94     } else {
95         // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
96         node = new NBNode(myID, pos, NODETYPE_PRIORITY);
97     }
98 
99     return node;
100 }
101 
102 
103 void
addLink(NGEdge * link)104 NGNode::addLink(NGEdge* link) {
105     LinkList.push_back(link);
106 }
107 
108 
109 void
removeLink(NGEdge * link)110 NGNode::removeLink(NGEdge* link) {
111     LinkList.remove(link);
112 }
113 
114 
115 bool
connected(NGNode * node) const116 NGNode::connected(NGNode* node) const {
117     for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); ++i) {
118         if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
119             return true;
120         }
121     }
122     return false;
123 }
124 
125 
126 /****************************************************************************/
127 
128