SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NGNode.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A netgen-representation of a node
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <algorithm>
35 #include <netbuild/NBNode.h>
36 #include <netbuild/NBNodeCont.h>
37 #include <netbuild/NBEdge.h>
38 #include <netbuild/NBOwnTLDef.h>
39 #include <netbuild/NBTypeCont.h>
41 #include <netbuild/NBNetBuilder.h>
43 #include <utils/common/ToString.h>
46 #include <utils/options/Option.h>
47 #include "NGNode.h"
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  : xID(-1), yID(-1), myID(""), myAmCenter(false) {}
59 
60 
61 NGNode::NGNode(const std::string& id)
62  : xID(-1), yID(-1), myID(id), myAmCenter(false) {}
63 
64 
65 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
66  : xID(xIDa), yID(yIDa), myID(id), myAmCenter(false) {}
67 
68 
69 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
70  : xID(xIDa), yID(yIDa), myID(id), myAmCenter(amCenter) {}
71 
72 
74  NGEdgeList::iterator li;
75  while (LinkList.size() != 0) {
76  li = LinkList.begin();
77  delete(*li);
78  }
79 }
80 
81 
82 NBNode*
84  Position pos(myPosition);
86  // the center will have no logic!
87  if (myAmCenter) {
88  return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
89  }
90  NBNode* node = 0;
91  std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
92  OptionsCont::getOptions().getString("default-junction-type") : "";
93 
94  if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
96  node = new NBNode(myID, pos, type);
97 
98  // check whether it is a traffic light junction
99  if (type == NODETYPE_TRAFFIC_LIGHT) {
100  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0);
101  if (!nb.getTLLogicCont().insert(tlDef)) {
102  // actually, nothing should fail here
103  delete tlDef;
104  throw ProcessError();
105  }
106  }
107  } else {
108  // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
109  node = new NBNode(myID, pos, NODETYPE_PRIORITY_JUNCTION);
110  }
111 
112  return node;
113 }
114 
115 
116 void
118  LinkList.push_back(link);
119 }
120 
121 
122 void
124  LinkList.remove(link);
125 }
126 
127 
128 bool
129 NGNode::connected(NGNode* node) const {
130  for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); i++) {
131  if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
132  return true;
133  }
134  }
135  return false;
136 }
137 
138 
139 /****************************************************************************/
140