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 : // activitygen module 5 : // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 6 : // This program and the accompanying materials are made available under the 7 : // terms of the Eclipse Public License 2.0 which is available at 8 : // https://www.eclipse.org/legal/epl-2.0/ 9 : // This Source Code may also be made available under the following Secondary 10 : // Licenses when the conditions for such availability set forth in the Eclipse 11 : // Public License 2.0 are satisfied: GNU General Public License, version 2 12 : // or later which is available at 13 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 14 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 15 : /****************************************************************************/ 16 : /// @file AGActivityTripWriter.cpp 17 : /// @author Piotr Woznica 18 : /// @author Daniel Krajzewicz 19 : /// @author Walter Bamberger 20 : /// @date July 2010 21 : /// 22 : // Class for writing Trip objects in a SUMO-route file. 23 : /****************************************************************************/ 24 : #include <config.h> 25 : 26 : #include <utils/common/RGBColor.h> 27 : #include <utils/iodevices/OutputDevice.h> 28 : #include "activities/AGTrip.h" 29 : #include "city/AGStreet.h" 30 : #include "AGActivityTripWriter.h" 31 : 32 : 33 : // =========================================================================== 34 : // method definitions 35 : // =========================================================================== 36 8 : AGActivityTripWriter::AGActivityTripWriter(OutputDevice& file) : myTripOutput(file) { 37 8 : myTripOutput.openTag(SUMO_TAG_VTYPE) 38 : .writeAttr(SUMO_ATTR_ID, "default") 39 : .writeAttr(SUMO_ATTR_VCLASS, "passenger") 40 8 : .writeAttr(SUMO_ATTR_COLOR, RGBColor::RED).closeTag(); 41 8 : myTripOutput.openTag(SUMO_TAG_VTYPE) 42 : .writeAttr(SUMO_ATTR_ID, "random") 43 : .writeAttr(SUMO_ATTR_VCLASS, "passenger") 44 8 : .writeAttr(SUMO_ATTR_COLOR, RGBColor::BLUE).closeTag(); 45 8 : myTripOutput.openTag(SUMO_TAG_VTYPE) 46 : .writeAttr(SUMO_ATTR_ID, "bus") 47 : .writeAttr(SUMO_ATTR_VCLASS, "bus") 48 8 : .writeAttr(SUMO_ATTR_COLOR, RGBColor::GREEN).closeTag(); 49 8 : myTripOutput.lf(); 50 8 : } 51 : 52 : 53 : void 54 3814 : AGActivityTripWriter::addTrip(const AGTrip& trip) { 55 3814 : int time = (trip.getDay() - 1) * 86400 + trip.getTime(); 56 : 57 3814 : myTripOutput.openTag(SUMO_TAG_TRIP) 58 3814 : .writeAttr(SUMO_ATTR_ID, trip.getVehicleName()) 59 3814 : .writeAttr(SUMO_ATTR_TYPE, trip.getType()) 60 3814 : .writeAttr(SUMO_ATTR_DEPART, time2string(TIME2STEPS(time))) 61 3814 : .writeAttr(SUMO_ATTR_DEPARTPOS, trip.getDep().getPosition()) 62 3814 : .writeAttr(SUMO_ATTR_ARRIVALPOS, trip.getArr().getPosition()) 63 3814 : .writeAttr(SUMO_ATTR_ARRIVALSPEED, 0.) 64 7628 : .writeAttr(SUMO_ATTR_FROM, trip.getDep().getStreet().getID()); 65 : 66 3814 : if (!trip.getPassed()->empty()) { 67 772 : std::ostringstream oss; 68 5268 : for (std::list<AGPosition>::const_iterator it = trip.getPassed()->begin(); it != trip.getPassed()->end(); ++it) { 69 4496 : if (it != trip.getPassed()->begin()) { 70 3724 : oss << " "; 71 : } 72 4496 : oss << it->getStreet().getID(); 73 : } 74 772 : myTripOutput.writeAttr(SUMO_ATTR_VIA, oss.str()); 75 772 : } 76 3814 : myTripOutput.writeAttr(SUMO_ATTR_TO, trip.getArr().getStreet().getID()); 77 3814 : myTripOutput.closeTag(); 78 3814 : } 79 : 80 : 81 : /****************************************************************************/