SUMO - Simulation of Urban MObility
NGNode.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // A netgen-representation of a node
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #include <algorithm>
00035 #include <netbuild/NBNode.h>
00036 #include <netbuild/NBNodeCont.h>
00037 #include <netbuild/NBEdge.h>
00038 #include <netbuild/NBOwnTLDef.h>
00039 #include <netbuild/NBTypeCont.h>
00040 #include <netbuild/NBTrafficLightLogicCont.h>
00041 #include <netbuild/NBNetBuilder.h>
00042 #include <utils/common/UtilExceptions.h>
00043 #include <utils/common/ToString.h>
00044 #include <utils/geom/GeoConvHelper.h>
00045 #include <utils/options/OptionsCont.h>
00046 #include <utils/options/Option.h>
00047 #include "NGNode.h"
00048 
00049 #ifdef CHECK_MEMORY_LEAKS
00050 #include <foreign/nvwa/debug_new.h>
00051 #endif // CHECK_MEMORY_LEAKS
00052 
00053 
00054 // ===========================================================================
00055 // method definitions
00056 // ===========================================================================
00057 NGNode::NGNode()
00058     : xID(-1), yID(-1), myID(""), myAmCenter(false) {}
00059 
00060 
00061 NGNode::NGNode(const std::string& id)
00062     : xID(-1), yID(-1), myID(id), myAmCenter(false) {}
00063 
00064 
00065 NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
00066     : xID(xIDa), yID(yIDa), myID(id), myAmCenter(false) {}
00067 
00068 
00069 NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
00070     : xID(xIDa), yID(yIDa), myID(id), myAmCenter(amCenter) {}
00071 
00072 
00073 NGNode::~NGNode() {
00074     NGEdgeList::iterator li;
00075     while (LinkList.size() != 0) {
00076         li = LinkList.begin();
00077         delete(*li);
00078     }
00079 }
00080 
00081 
00082 NBNode*
00083 NGNode::buildNBNode(NBNetBuilder& nb) const {
00084     Position pos(myPosition);
00085     GeoConvHelper::getProcessing().x2cartesian(pos);
00086     // the center will have no logic!
00087     if (myAmCenter) {
00088         return new NBNode(myID, pos, NODETYPE_NOJUNCTION);
00089     }
00090     NBNode* node = 0;
00091     std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
00092                         OptionsCont::getOptions().getString("default-junction-type") : "";
00093 
00094     if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
00095         SumoXMLNodeType type = SUMOXMLDefinitions::NodeTypes.get(typeS);
00096         node = new NBNode(myID, pos, type);
00097 
00098         // check whether it is a traffic light junction
00099         if (type == NODETYPE_TRAFFIC_LIGHT) {
00100             NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node);
00101             if (!nb.getTLLogicCont().insert(tlDef)) {
00102                 // actually, nothing should fail here
00103                 delete tlDef;
00104                 throw ProcessError();
00105             }
00106         }
00107     } else {
00108         // otherwise netbuild may guess NODETYPE_TRAFFIC_LIGHT without actually building one
00109         node = new NBNode(myID, pos, NODETYPE_PRIORITY_JUNCTION);
00110     }
00111 
00112     return node;
00113 }
00114 
00115 
00116 void
00117 NGNode::addLink(NGEdge* link) {
00118     LinkList.push_back(link);
00119 }
00120 
00121 
00122 void
00123 NGNode::removeLink(NGEdge* link) {
00124     LinkList.remove(link);
00125 }
00126 
00127 
00128 bool
00129 NGNode::connected(NGNode* node) const {
00130     for (NGEdgeList::const_iterator i = LinkList.begin(); i != LinkList.end(); i++) {
00131         if (find(node->LinkList.begin(), node->LinkList.end(), *i) != node->LinkList.end()) {
00132             return true;
00133         }
00134     }
00135     return false;
00136 }
00137 
00138 
00139 /****************************************************************************/
00140 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines