NGNode.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <algorithm>
00031 #include <netbuild/NBNode.h>
00032 #include <netbuild/NBNodeCont.h>
00033 #include <netbuild/NBEdge.h>
00034 #include <netbuild/NBOwnTLDef.h>
00035 #include <netbuild/NBTypeCont.h>
00036 #include <netbuild/NBTrafficLightLogicCont.h>
00037 #include <netbuild/NBNetBuilder.h>
00038 #include <utils/common/UtilExceptions.h>
00039 #include <utils/common/ToString.h>
00040 #include <utils/geom/GeoConvHelper.h>
00041 #include <utils/options/OptionsCont.h>
00042 #include <utils/options/Option.h>
00043 #include "NGNode.h"
00044
00045 #ifdef CHECK_MEMORY_LEAKS
00046 #include <foreign/nvwa/debug_new.h>
00047 #endif // CHECK_MEMORY_LEAKS
00048
00049
00050
00051
00052
00053 NGNode::NGNode() throw()
00054 : xID(-1), yID(-1), myID(""), myAmCenter(false) {}
00055
00056
00057 NGNode::NGNode(const std::string &id) throw()
00058 : xID(-1), yID(-1), myID(id), myAmCenter(false) {}
00059
00060
00061 NGNode::NGNode(const std::string &id, int xIDa, int yIDa) throw()
00062 : xID(xIDa), yID(yIDa), myID(id), myAmCenter(false) {}
00063
00064
00065 NGNode::NGNode(const std::string &id, int xIDa, int yIDa, bool amCenter) throw()
00066 : xID(xIDa), yID(yIDa), myID(id), myAmCenter(amCenter) {}
00067
00068
00069 NGNode::~NGNode() throw() {
00070 NGEdgeList::iterator li;
00071 while (LinkList.size() != 0) {
00072 li = LinkList.begin();
00073 delete(*li);
00074 }
00075 }
00076
00077
00078 NBNode *
00079 NGNode::buildNBNode(NBNetBuilder &nb) const throw(ProcessError) {
00080 Position2D pos(myPosition);
00081 GeoConvHelper::x2cartesian(pos);
00082
00083 if (myAmCenter) {
00084 return new NBNode(myID, pos, NBNode::NODETYPE_NOJUNCTION);
00085 }
00086
00087
00088 std::string nodeType = OptionsCont::getOptions().isSet("default-junction-type")
00089 ? OptionsCont::getOptions().getString("default-junction-type")
00090 : "";
00091 NBNode *node = 0;
00092 if (nodeType=="") {
00093 node = new NBNode(myID, pos);
00094 } else if (nodeType=="priority") {
00095 node = new NBNode(myID, pos, NBNode::NODETYPE_PRIORITY_JUNCTION);
00096 } else if (nodeType=="right_before_left") {
00097 node = new NBNode(myID, pos, NBNode::NODETYPE_RIGHT_BEFORE_LEFT);
00098 } else if (nodeType=="traffic_light") {
00099 node = new NBNode(myID, pos, NBNode::NODETYPE_PRIORITY_JUNCTION);
00100 NBTrafficLightDefinition *tlDef = new NBOwnTLDef(myID, node);
00101 if (!nb.getTLLogicCont().insert(tlDef)) {
00102
00103 delete tlDef;
00104 throw ProcessError();
00105 }
00106 }
00107 return node;
00108 }
00109
00110
00111 void
00112 NGNode::addLink(NGEdge *link) throw() {
00113 LinkList.push_back(link);
00114 }
00115
00116
00117 void
00118 NGNode::removeLink(NGEdge *link) throw() {
00119 LinkList.remove(link);
00120 }
00121
00122
00123 bool
00124 NGNode::connected(NGNode *node) const throw() {
00125 for (NGEdgeList::const_iterator i=LinkList.begin(); i!=LinkList.end(); i++) {
00126 if (find(node->LinkList.begin(), node->LinkList.end(), *i)!=node->LinkList.end()) {
00127 return true;
00128 }
00129 }
00130 return false;
00131 }
00132
00133
00134
00135