SUMO - Simulation of Urban MObility

NGNode.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A netgen-representation of a node
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
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 // method definitions
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     Position pos(myPosition);
00081     GeoConvHelper::getDefaultInstance().x2cartesian(pos);
00082     // the center will have no logic!
00083     if (myAmCenter) {
00084         return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
00085     }
00086     NBNode* node = 0;
00087     std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
00088                         OptionsCont::getOptions().getString("default-junction-type") : "";
00089 
00090     if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
00091         SumoXMLNodeType type = SUMOXMLDefinitions::NodeTypes.get(typeS);
00092         node = new NBNode(myID, pos, type);
00093 
00094         // check whether it is a traffic light junction
00095         if (type == NODETYPE_TRAFFIC_LIGHT) {
00096             NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node);
00097             if (!nb.getTLLogicCont().insert(tlDef)) {
00098                 // actually, nothing should fail here
00099                 delete tlDef;
00100                 throw ProcessError();
00101             }
00102         }
00103     } else {
00104         // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
00105         node = new NBNode(myID, pos, NODETYPE_PRIORITY_JUNCTION);
00106     }
00107 
00108     return node;
00109 }
00110 
00111 
00112 void
00113 NGNode::addLink(NGEdge* link) throw() {
00114     LinkList.push_back(link);
00115 }
00116 
00117 
00118 void
00119 NGNode::removeLink(NGEdge* link) throw() {
00120     LinkList.remove(link);
00121 }
00122 
00123 
00124 bool
00125 NGNode::connected(NGNode* node) const throw() {
00126     for (NGEdgeList::const_iterator i=LinkList.begin(); i!=LinkList.end(); i++) {
00127         if (find(node->LinkList.begin(), node->LinkList.end(), *i)!=node->LinkList.end()) {
00128             return true;
00129         }
00130     }
00131     return false;
00132 }
00133 
00134 
00135 /****************************************************************************/
00136 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines