#include <config.h>
#include <algorithm>
#include <netbuild/NBNode.h>
#include <netbuild/NBNodeCont.h>
#include <netbuild/NBEdge.h>
#include <netbuild/NBOwnTLDef.h>
#include <netbuild/NBTypeCont.h>
#include <netbuild/NBTrafficLightLogicCont.h>
#include <netbuild/NBNetBuilder.h>
#include <utils/common/UtilExceptions.h>
#include <utils/common/ToString.h>
#include <utils/geom/GeoConvHelper.h>
#include <utils/options/OptionsCont.h>
#include <utils/options/Option.h>
#include "NGNode.h"
NGNode::NGNode(const std::string& id)
: Named(id), myXID(-1), myYID(-1), myAmCenter(false), myAmFringe(false) {}
NGNode::NGNode(const std::string& id, int xIDa, int yIDa)
: Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(false), myAmFringe(false) {}
NGNode::NGNode(const std::string& id, int xIDa, int yIDa, bool amCenter)
: Named(id), myXID(xIDa), myYID(yIDa), myAmCenter(amCenter), myAmFringe(false) {}
NGNode::~NGNode() {
NGEdgeList::iterator li;
while (myLinkList.size() != 0) {
li = myLinkList.begin();
delete (*li);
}
}
NBNode*
NGNode::buildNBNode(NBNetBuilder& nb, const Position& perturb) const {
Position pos(myPosition + perturb);
GeoConvHelper::getProcessing().x2cartesian(pos);
if (myAmCenter) {
return new NBNode(myID, pos, SumoXMLNodeType::NOJUNCTION);
}
NBNode* node = nullptr;
std::string typeS = OptionsCont::getOptions().isSet("default-junction-type") ?
OptionsCont::getOptions().getString("default-junction-type") : "";
if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) {
const SumoXMLNodeType type = SUMOXMLDefinitions::NodeTypes.get(typeS);
node = new NBNode(myID, pos, type);
if (NBNode::isTrafficLight(type)) {
const TrafficLightType tlType = SUMOXMLDefinitions::TrafficLightTypes.get(
OptionsCont::getOptions().getString("tls.default-type"));
NBTrafficLightDefinition* tlDef = new NBOwnTLDef(myID, node, 0, tlType);
if (!nb.getTLLogicCont().insert(tlDef)) {
delete tlDef;
throw ProcessError();
}
}
} else {
node = new NBNode(myID, pos, SumoXMLNodeType::PRIORITY);
}
if (myAmFringe) {
node->setFringeType(FringeType::OUTER);
}
return node;
}
void
NGNode::addLink(NGEdge* link) {
myLinkList.push_back(link);
}
void
NGNode::removeLink(NGEdge* link) {
myLinkList.remove(link);
}
bool
NGNode::connected(const NGNode* const node, const bool withDir) const {
for (NGEdge* ngEdge : myLinkList) {
if (ngEdge->getStartNode() == this && ngEdge->getEndNode() == node) {
return true;
}
if (!withDir && ngEdge->getEndNode() == this && ngEdge->getStartNode() == node) {
return true;
}
}
return false;
}