Co-Simulation/Sumo/sumo-1.7.0/src/netload/NLHandler.cpp
// ---- the root/junction - element
the root/junction - element
the root / junction - element
void
NLHandler::openJunction(const SUMOSAXAttributes& attrs) {
    myCurrentIsBroken = false;
    bool ok = true;
    std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
    if (!ok) {
        myCurrentIsBroken = true;
        return;
    }
    PositionVector shape;
    if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
        shape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok, PositionVector());
        if (shape.size() > 2) {
            shape.closePolygon();
        }
    }
    double x = attrs.get<double>(SUMO_ATTR_X, id.c_str(), ok);
    double y = attrs.get<double>(SUMO_ATTR_Y, id.c_str(), ok);
    double z = attrs.getOpt<double>(SUMO_ATTR_Z, id.c_str(), ok, 0);
    bool typeOK = true;
    SumoXMLNodeType type = attrs.getNodeType(typeOK);
    if (!typeOK) {
        WRITE_ERROR("An unknown or invalid junction type occurred in junction '" + id + "'.");
        ok = false;
    }
    std::string key = attrs.getOpt<std::string>(SUMO_ATTR_KEY, id.c_str(), ok, "");
    std::string name = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, "");
    std::vector<MSLane*> incomingLanes;
    parseLanes(id, attrs.getStringSecure(SUMO_ATTR_INCLANES, ""), incomingLanes, ok);
    std::vector<MSLane*> internalLanes;
    if (MSGlobals::gUsingInternalLanes) {
        parseLanes(id, attrs.getStringSecure(SUMO_ATTR_INTLANES, ""), internalLanes, ok);
    }
    if (!ok) {
        myCurrentIsBroken = true;
    } else {
        try {
            myJunctionControlBuilder.openJunction(id, key, type, Position(x, y, z), shape, incomingLanes, internalLanes, name);
        } catch (InvalidArgument& e) {
            WRITE_ERROR(e.what() + std::string("\n Can not build according junction."));
            myCurrentIsBroken = true;
        }
    }
}
void NLHandler :: openJunction ( const SUMOSAXAttributes & attrs ) { myCurrentIsBroken = false ; bool ok = true ; std :: string id = attrs . get < std :: string > ( SUMO_ATTR_ID , nullptr , ok ) ; if ( ! ok ) { myCurrentIsBroken = true ; return ; } PositionVector shape ; if ( attrs . hasAttribute ( SUMO_ATTR_SHAPE ) ) { shape = attrs . getOpt < PositionVector > ( SUMO_ATTR_SHAPE , id . c_str ( ) , ok , PositionVector ( ) ) ; if ( shape . size ( ) > 2 ) { shape . closePolygon ( ) ; } } double x = attrs . get < double > ( SUMO_ATTR_X , id . c_str ( ) , ok ) ; double y = attrs . get < double > ( SUMO_ATTR_Y , id . c_str ( ) , ok ) ; double z = attrs . getOpt < double > ( SUMO_ATTR_Z , id . c_str ( ) , ok , 0 ) ; bool typeOK = true ; SumoXMLNodeType type = attrs . getNodeType ( typeOK ) ; if ( ! typeOK ) { WRITE_ERROR ( " " + id + " " ) ; ok = false ; } std :: string key = attrs . getOpt < std :: string > ( SUMO_ATTR_KEY , id . c_str ( ) , ok , " " ) ; std :: string name = attrs . getOpt < std :: string > ( SUMO_ATTR_NAME , id . c_str ( ) , ok , " " ) ; std :: vector < MSLane * > incomingLanes ; parseLanes ( id , attrs . getStringSecure ( SUMO_ATTR_INCLANES , " " ) , incomingLanes , ok ) ; std :: vector < MSLane * > internalLanes ; if ( MSGlobals :: gUsingInternalLanes ) { parseLanes ( id , attrs . getStringSecure ( SUMO_ATTR_INTLANES , " " ) , internalLanes , ok ) ; } if ( ! ok ) { myCurrentIsBroken = true ; } else { try { myJunctionControlBuilder . openJunction ( id , key , type , Position ( x , y , z ) , shape , incomingLanes , internalLanes , name ) ; } catch ( InvalidArgument & e ) { WRITE_ERROR ( e . what ( ) + std :: string ( " \n " ) ) ; myCurrentIsBroken = true ; } } }
the root/junction - element
the root / junction - element
// get the id, report an error if not given or empty... // inner junctions have no shape // incoming lanes // internal lanes