/**
 * This method is highly coupled to parseStop and parseCategory.
 *
 * TODO: consider refactoring.
 */
void HelperFileParser::parseFile()
{
	char temp[12];
	file >> temp;
	if (strcmp(temp, "[stop]") == 0)
	{
		parseStop();
		parseCategory();
	} else
	{
		parseCategory();
		parseStop();
	}
}
Exemplo n.º 2
0
void
RORouteHandler::addStop(const SUMOSAXAttributes& attrs) {
    if (myActivePlan) {
        myActivePlan->openTag(SUMO_TAG_STOP);
        (*myActivePlan) << attrs;
        myActivePlan->closeTag();
        myActivePlanSize++;
        return;
    }
    std::string errorSuffix;
    if (myActiveRouteID != "") {
        errorSuffix = " in route '" + myActiveRouteID + "'.";
    } else {
        errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
    }
    SUMOVehicleParameter::Stop stop;
    bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
    if (!ok) {
        return;
    }
    // try to parse the assigned bus stop
    if (stop.busstop != "") {
        const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop);
        if (busstop == 0) {
            myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix);
        } else {
            stop.lane = busstop->lane;
            stop.endPos = busstop->endPos;
            stop.startPos = busstop->startPos;
        }
    } else {
        // no, the lane and the position should be given
        stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
        if (!ok || stop.lane == "") {
            myErrorOutput->inform("A stop must be placed on a bus stop or a lane" + errorSuffix);
            return;
        }
        ROEdge* edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
        if (edge == 0) {
            myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
            return;
        }
        stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength());
        stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS);
        const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
        if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) {
            myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
            return;
        }
    }
    if (myVehicleParameter != 0) {
        myVehicleParameter->stops.push_back(stop);
    } else {
        myActiveRouteStops.push_back(stop);
    }
}
Exemplo n.º 3
0
RouteLeg* parseLine(QXmlStreamReader &reader)
{
    //qDebug() << "Parsing LINE";

    double distance;
    QTime time;
    RoutePoint *startPoint, *endPoint;
    QList<RoutePoint*> midpoints;// = QList<RoutePoint*>();

    bool startFound = false;
    bool endFound = false;

    QXmlStreamAttributes attributes(reader.attributes());
    QString code = attributes.value("code").toString();
    int type = attributes.value("type").toString().toInt();

    while (!reader.atEnd() && !(reader.name() == "LINE" && reader.tokenType() == QXmlStreamReader::EndElement))
    {
        reader.readNext();

        if (reader.name() == "LENGTH" && reader.isStartElement())
        {
            // One LENGTH element in WALK.
            parseLength(reader, time, distance);
        }
        else if (reader.name() == "STOP" && reader.isStartElement())
        {
            // Multiple STOP elements may be found. No other LEG_TYPEs are possible. All but first and last will be appended to midpoints list.
            // If first one is not found yet, don't append point to list, but store it to startPoint.
            // If first one is found but last one is not, don't append to list, but store it to endPoint.
            // Else, append endPoint to list and store new one to endPoint.
            if (!startFound)
            {
                startPoint = parseStop(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parseStop(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parseStop(reader);
            }
        }
    }

    /* Types from reittiopas:
        Transport types:
        1 Helsinki/bus
        2 Helsinki/tram
        3 Espoo internal
        4 Vantaa internal
        5 Regional traffic
        6 Metro traffic
        7 Ferry
        8 U-lines
        9 Other local traffic
        10 Long-distance traffic
        11 Express
        12 VR local traffic
        13 VR long-distance traffic
        14 All
        21 Helsinki service lines
        22 Helsinki night traffic
        23 Espoo service lines
        24 Vantaa service lines
        25 Regional night traffic
        (types 9,10,11,13,14 are not used in the data)
*/
    RouteLeg* line = NULL;
    if (type == 6)
    {
        // Metro
        line = RouteLegGenerator::createLegSub(distance, time, startPoint, endPoint, midpoints);
    }
    else if (type == 2)
    {
        // Tram
        QString symbol = parseLineSymbol(code);
        line = RouteLegGenerator::createLegTram(distance, time, startPoint, endPoint, midpoints, symbol);
    }
    else if (type == 1 || type == 3 || type == 4 || type == 5 || type == 8 || type == 21 || type == 22 || type == 23 || type == 24 || type == 25)
    {
        // Bus
        QString symbol = parseLineSymbol(code);
        line = RouteLegGenerator::createLegBus(distance, time, startPoint, endPoint, midpoints, symbol);
    }
    else if (type == 7)
    {
        // Ferry
        line = RouteLegGenerator::createLegFerry(distance, time, startPoint, endPoint, midpoints);
    }
    else if (type == 12)
    {
        // Train
        QString symbol = parseLineSymbol(code);
        symbol = symbol.mid(1,1);
        line = RouteLegGenerator::createLegTrain(distance, time, startPoint, endPoint, midpoints, symbol);
    }
    else
        qDebug() << "Type mismatch (" << type << "!!!! Returning NULL!!!!";

    //qDebug() << "LINE parsed.";

    return line;
}
Exemplo n.º 4
0
RouteLeg* parseWalk(QXmlStreamReader &reader)
{
    //qDebug() << "Parsing WALK";

    double distance;
    QTime time;
    RoutePoint *startPoint, *endPoint;
    QList<RoutePoint*> midpoints;// = QList<RoutePoint*>();

    bool startFound = false;
    bool endFound = false;

    while (!reader.atEnd() && !(reader.name() == "WALK" && reader.tokenType() == QXmlStreamReader::EndElement))
    {
        reader.readNext();

        if (reader.name() == "LENGTH" && reader.isStartElement())
        {
            // One LENGTH element in WALK.
            parseLength(reader, time, distance);
        }
        else if (reader.name() == "POINT" && reader.isStartElement())
        {
            // Multiple POINT, MAPLOC or STOP elements may be found. All but first and last will be appended to midpoints list.
            // If first one is not found yet, don't append point to list, but store it to startPoint.
            // If first one is found but last one is not, don't append to list, but store it to endPoint.
            // Else, append endPoint to list and store new one to endPoint.
            if (!startFound)
            {
                startPoint = parsePoint(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parsePoint(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parsePoint(reader);
            }
        }
        else if (reader.name() == "MAPLOC" && reader.isStartElement())
        {
            // Read comments from above. POINT
            if (!startFound)
            {
                startPoint = parseMapLoc(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parseMapLoc(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parseMapLoc(reader);
            }
        }
        else if (reader.name() == "STOP" && reader.isStartElement())
        {
            // Read comments from above. POINT
            if (!startFound)
            {
                startPoint = parseStop(reader);
                startFound = true;
            }
            else if (!endFound)
            {
                endPoint = parseStop(reader);
                endFound = true;
            }
            else
            {
                midpoints.append(endPoint);
                endPoint = parseStop(reader);
            }
        }
    }

    RouteLeg *walk = RouteLegGenerator::createLegWalk(distance, time, startPoint, endPoint, midpoints);

    //qDebug() << "WALK parsed.";

    return walk;
}
Exemplo n.º 5
0
void
RORouteHandler::addStop(const SUMOSAXAttributes& attrs) {
    if (myActiveContainerPlan != 0) {
        myActiveContainerPlan->openTag(SUMO_TAG_STOP);
        (*myActiveContainerPlan) << attrs;
        myActiveContainerPlan->closeTag();
        myActiveContainerPlanSize++;
        return;
    }
    std::string errorSuffix;
    if (myVehicleParameter != 0) {
        errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
    } else {
        errorSuffix = " in route '" + myActiveRouteID + "'.";
    }
    SUMOVehicleParameter::Stop stop;
    bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
    if (!ok) {
        return;
    }
    // try to parse the assigned bus stop
    ROEdge* edge = 0;
    if (stop.busstop != "") {
        const SUMOVehicleParameter::Stop* busstop = myNet.getStoppingPlace(stop.busstop, SUMO_TAG_BUS_STOP);
        if (busstop == 0) {
            myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix);
            return;
        }
        stop.lane = busstop->lane;
        stop.endPos = busstop->endPos;
        stop.startPos = busstop->startPos;
        edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
    } // try to parse the assigned container stop
    else if (stop.containerstop != "") {
        const SUMOVehicleParameter::Stop* containerstop = myNet.getStoppingPlace(stop.containerstop, SUMO_TAG_CONTAINER_STOP);
        if (containerstop == 0) {
            myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix);
            return;
        }
        stop.lane = containerstop->lane;
        stop.endPos = containerstop->endPos;
        stop.startPos = containerstop->startPos;
        edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
    } // try to parse the assigned parking area
    else if (stop.parkingarea != "") {
        const SUMOVehicleParameter::Stop* parkingarea = myNet.getStoppingPlace(stop.parkingarea, SUMO_TAG_PARKING_AREA);
        if (parkingarea == 0) {
            myErrorOutput->inform("Unknown parking area '" + stop.parkingarea + "'" + errorSuffix);
            return;
        }
        stop.lane = parkingarea->lane;
        stop.endPos = parkingarea->endPos;
        stop.startPos = parkingarea->startPos;
        edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
    } else {
        // no, the lane and the position should be given
        stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
        if (!ok || stop.lane == "") {
            myErrorOutput->inform("A stop must be placed on a bus stop, a container stop, a parking area or a lane" + errorSuffix);
            return;
        }
        edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
        if (edge == 0) {
            myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
            return;
        }
        stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength());
        stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS);
        const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
        const double endPosOffset = edge->isInternal() ? edge->getNormalBefore()->getLength() : 0;
        if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength() + endPosOffset, POSITION_EPS, friendlyPos)) {
            myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
            return;
        }
    }
    if (myActivePerson != 0) {
        myActivePerson->addStop(stop, edge);
    } else if (myVehicleParameter != 0) {
        myVehicleParameter->stops.push_back(stop);
    } else {
        myActiveRouteStops.push_back(stop);
    }
    if (myInsertStopEdgesAt >= 0) {
        myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
        myInsertStopEdgesAt++;
    }
}
Exemplo n.º 6
0
void SVGGradient::parseStops(xmlNodePtr parent) {
	for(xmlNodePtr node = parent->children; node; node = node->next) {
		if(!xmlStrcmp(node->name, (const xmlChar *)"stop"))
			parseStop(node);
	}
}