Example #1
0
unsigned int
NIVissimConnection::buildEdgeConnections(NBEdgeCont &ec) {
    unsigned int unsetConnections = 0;
    // try to determine the connected edges
    NBEdge *fromEdge = 0;
    NBEdge *toEdge = 0;
    NIVissimEdge *vissimFrom = NIVissimEdge::dictionary(getFromEdgeID());
    if (vissimFrom->wasWithinAJunction()) {
        // this edge was not built, try to get one that approaches it
        vissimFrom = vissimFrom->getBestIncoming();
        if (vissimFrom!=0) {
            fromEdge = ec.retrievePossiblySplitted(toString(vissimFrom->getID()), toString(getFromEdgeID()), true);
        }
    } else {
        // this edge was built, try to get the proper part
        fromEdge = ec.retrievePossiblySplitted(toString(getFromEdgeID()), toString(getToEdgeID()), true);
    }
    NIVissimEdge *vissimTo = NIVissimEdge::dictionary(getToEdgeID());
    if (vissimTo->wasWithinAJunction()) {
        vissimTo = vissimTo->getBestOutgoing();
        if (vissimTo!=0) {
            toEdge = ec.retrievePossiblySplitted(toString(vissimTo->getID()), toString(getToEdgeID()), true);
        }
    } else {
        toEdge = ec.retrievePossiblySplitted(toString(getToEdgeID()), toString(getFromEdgeID()), false);
    }

    // try to get the edges the current connection connects
    /*
    NBEdge *fromEdge = ec.retrievePossiblySplitted(toString(getFromEdgeID()), toString(getToEdgeID()), true);
    NBEdge *toEdge = ec.retrievePossiblySplitted(toString(getToEdgeID()), toString(getFromEdgeID()), false);
    */
    if (fromEdge==0||toEdge==0) {
        WRITE_WARNING("Could not build connection between '" + toString(getFromEdgeID())+ "' and '" + toString(getToEdgeID())+ "'.");
        return 1; // !!! actually not 1
    }
    recheckLanes(fromEdge, toEdge);
    const IntVector &fromLanes = getFromLanes();
    const IntVector &toLanes = getToLanes();
    if (fromLanes.size()!=toLanes.size()) {
        MsgHandler::getWarningInstance()->inform("Lane sizes differ for connection '" + toString(getID()) + "'.");
    } else {
        for (unsigned int index=0; index<fromLanes.size(); ++index) {
            if (fromEdge->getNoLanes()<=static_cast<unsigned int>(fromLanes[index])) {
                MsgHandler::getWarningInstance()->inform("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
                ++unsetConnections;
            } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::L2L_VALIDATED)) {
                MsgHandler::getWarningInstance()->inform("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
                ++unsetConnections;
            }
        }
    }
    return unsetConnections;
}
Example #2
0
bool
NIVissimTL::NIVissimTLSignal::addTo(NBEdgeCont &ec, NBLoadedTLDef *tl) const {
    NIVissimConnection *c = NIVissimConnection::dictionary(myEdgeID);
    NBConnectionVector assignedConnections;
    if (c==0) {
        // What to do if on an edge? -> close all outgoing connections
        NBEdge *edge = ec.retrievePossiblySplitted(toString<int>(myEdgeID), myPosition);
        if (edge==0) {
            MsgHandler::getWarningInstance()->inform("Could not set tls signal at edge '" + toString(myEdgeID) + "' - the edge was not built.");
            return false;
        }
        // Check whether it is already known, which edges are approached
        //  by which lanes
        // check whether to use the original lanes only
        if (edge->lanesWereAssigned()) {
            std::vector<NBEdge::Connection> connections = edge->getConnectionsFromLane(myLane-1);
            for (std::vector<NBEdge::Connection>::iterator i=connections.begin(); i!=connections.end(); i++) {
                const NBEdge::Connection &conn = *i;
                assert(myLane-1<(int)edge->getNoLanes());
                assignedConnections.push_back(NBConnection(edge, myLane-1, conn.toEdge, conn.toLane));
            }
        } else {
            WRITE_WARNING("Edge : Lanes were not assigned(!)");
            for (unsigned int j=0; j<edge->getNoLanes(); j++) {
                std::vector<NBEdge::Connection> connections = edge->getConnectionsFromLane(j);
                for (std::vector<NBEdge::Connection>::iterator i=connections.begin(); i!=connections.end(); i++) {
                    const NBEdge::Connection &conn = *i;
                    assignedConnections.push_back(NBConnection(edge, j, conn.toEdge, conn.toLane));
                }
            }
        }
    } else {
        // get the edges
        NBEdge *tmpFrom = ec.retrievePossiblySplitted(
                              toString<int>(c->getFromEdgeID()),
                              toString<int>(c->getToEdgeID()),
                              true);
        NBEdge *tmpTo = ec.retrievePossiblySplitted(
                            toString<int>(c->getToEdgeID()),
                            toString<int>(c->getFromEdgeID()),
                            false);
        // check whether the edges are known
        if (tmpFrom!=0&&tmpTo!=0) {
            // add connections this signal is responsible for
            assignedConnections.push_back(NBConnection(tmpFrom, -1, tmpTo, -1));
        } else {
            return false;
            // !!! one of the edges could not be build
        }
    }
    // add to the group
    assert(myGroupIDs.size()!=0);
    if (myGroupIDs.size()==1) {
        return tl->addToSignalGroup(toString<int>(*(myGroupIDs.begin())),
                                    assignedConnections);
    } else {
        // !!!
        return tl->addToSignalGroup(toString<int>(*(myGroupIDs.begin())),
                                    assignedConnections);
    }
    return true;
}