Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file NGNode.cpp 15 : /// @author Markus Hartinger 16 : /// @author Daniel Krajzewicz 17 : /// @author Jakob Erdmann 18 : /// @author Michael Behrisch 19 : /// @date Mar, 2003 20 : /// 21 : // A netgen-representation of a node 22 : /****************************************************************************/ 23 : #include <config.h> 24 : 25 : #include <algorithm> 26 : #include <netbuild/NBNode.h> 27 : #include <netbuild/NBNodeCont.h> 28 : #include <netbuild/NBEdge.h> 29 : #include <netbuild/NBOwnTLDef.h> 30 : #include <netbuild/NBTypeCont.h> 31 : #include <netbuild/NBTrafficLightLogicCont.h> 32 : #include <netbuild/NBNetBuilder.h> 33 : #include <utils/common/UtilExceptions.h> 34 : #include <utils/common/ToString.h> 35 : #include <utils/geom/GeoConvHelper.h> 36 : #include <utils/options/OptionsCont.h> 37 : #include <utils/options/Option.h> 38 : #include "NGNode.h" 39 : 40 : 41 : // =========================================================================== 42 : // method definitions 43 : // =========================================================================== 44 32506 : NGNode::NGNode(const std::string& id) 45 32506 : : Named(id), myXID(-1), myYID(-1), myAmCenter(false), myAmFringe(false) {} 46 : 47 : 48 2478 : NGNode::NGNode(const std::string& id, int xIDa, int yIDa) 49 2478 : : Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(false), myAmFringe(false) {} 50 : 51 : 52 17 : NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter) 53 17 : : Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(amCenter), myAmFringe(false) {} 54 : 55 : 56 70002 : NGNode::~NGNode() { 57 : NGEdgeList::iterator li; 58 35001 : while (myLinkList.size() != 0) { 59 : li = myLinkList.begin(); 60 0 : delete (*li); 61 : } 62 70002 : } 63 : 64 : 65 : NBNode* 66 5517 : NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const { 67 : Position pos(myPosition + perturb); 68 5517 : GeoConvHelper::getProcessing().x2cartesian(pos); 69 : // the center will have no logic! 70 5517 : if (myAmCenter) { 71 17 : return new NBNode(myID, pos, SumoXMLNodeType::NOJUNCTION); 72 : } 73 : NBNode* node = nullptr; 74 11000 : std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ? 75 5581 : OptionsCont::getOptions().getString("default-junction-type") : ""; 76 : 77 5500 : if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) { 78 81 : const SumoXMLNodeType type = SUMOXMLDefinitions::NodeTypes.get(typeS); 79 81 : node = new NBNode(myID, pos, type); 80 : 81 : // check whether it is a traffic light junction 82 81 : if (NBNode::isTrafficLight(type)) { 83 35 : const TrafficLightType tlType = SUMOXMLDefinitions::TrafficLightTypes.get( 84 70 : OptionsCont::getOptions().getString("tls.default-type")); 85 35 : NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, tlType); 86 35 : if (!nb.getTLLogicCont().insert(tlDef)) { 87 : // actually, nothing should fail here 88 0 : delete tlDef; 89 0 : throw ProcessError(); 90 : } 91 : } 92 : } else { 93 : // otherwise netbuild may guess SumoXMLNodeType::TRAFFIC_LIGHT without actually building one 94 5419 : node = new NBNode(myID, pos, SumoXMLNodeType::PRIORITY); 95 : } 96 5500 : if (myAmFringe) { 97 : node->setFringeType(FringeType::OUTER); 98 : } 99 : 100 : return node; 101 : } 102 : 103 : 104 : void 105 90464 : NGNode::addLink(NGEdge* link) { 106 90464 : myLinkList.push_back(link); 107 90464 : } 108 : 109 : 110 : void 111 90464 : NGNode::removeLink(NGEdge* link) { 112 90464 : myLinkList.remove(link); 113 90464 : } 114 : 115 : 116 : bool 117 427233 : NGNode::connected(const NGNode* const node, const bool withDir) const { 118 1234490 : for (NGEdge* ngEdge : myLinkList) { 119 813430 : if (ngEdge->getStartNode() == this && ngEdge->getEndNode() == node) { 120 : return true; 121 : } 122 809087 : if (!withDir && ngEdge->getEndNode() == this && ngEdge->getStartNode() == node) { 123 : return true; 124 : } 125 : } 126 : return false; 127 : } 128 : 129 : 130 : /****************************************************************************/