package org.opentrafficsim.road.test; import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D.Double; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import javax.naming.NamingException; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.xml.parsers.ParserConfigurationException; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import nl.tudelft.simulation.language.io.URLResource; import org.djunits.unit.TimeUnit; import org.djunits.value.vdouble.scalar.DoubleScalar; import org.djunits.value.vdouble.scalar.Time; import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface; import org.opentrafficsim.core.dsol.OTSModelInterface; import org.opentrafficsim.core.dsol.OTSSimTimeDouble; import org.opentrafficsim.core.geometry.OTSGeometryException; import org.opentrafficsim.core.gtu.GTUException; import org.opentrafficsim.core.gtu.animation.GTUColorer; import org.opentrafficsim.core.network.NetworkException; import org.opentrafficsim.road.network.factory.xml.XmlNetworkLaneParser; import org.opentrafficsim.simulationengine.AbstractWrappableAnimation; import org.opentrafficsim.simulationengine.OTSSimulationException; import org.opentrafficsim.simulationengine.properties.AbstractProperty; import org.xml.sax.SAXException; /** *

* Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $, * initial version Oct 17, 2014
* @author Alexander Verbraeck */ public class TestLaneDirections extends AbstractWrappableAnimation { /** * Main program. * @param args String[]; the command line arguments (not used) * @throws SimRuntimeException should never happen */ public static void main(final String[] args) throws SimRuntimeException { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { TestLaneDirections xmlModel = new TestLaneDirections(); // 1 hour simulation run for testing xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND), new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList>(), null, true); } catch (SimRuntimeException | NamingException | OTSSimulationException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public final String shortName() { return "TestXMLModel"; } /** {@inheritDoc} */ @Override public final String description() { return "TestXMLModel"; } /** {@inheritDoc} */ @Override public final void stopTimersThreads() { super.stopTimersThreads(); } /** {@inheritDoc} */ @Override protected final JPanel makeCharts() { return null; } /** {@inheritDoc} */ @Override protected final OTSModelInterface makeModel(final GTUColorer colorer) { return new TestXMLModel(); } /** {@inheritDoc} */ @Override protected final Double makeAnimationRectangle() { return new Rectangle2D.Double(-50, 0, 400, 200); } /** * Model to test the XML parser. *

* Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.
* All rights reserved. BSD-style license. See OpenTrafficSim * License. *

* $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $, * initial version un 27, 2015
* @author Alexander Verbraeck * @author Peter Knoppers */ class TestXMLModel implements OTSModelInterface { /** */ private static final long serialVersionUID = 20141121L; /** The simulator. */ private OTSDEVSSimulatorInterface simulator; /** {@inheritDoc} */ @Override public final void constructModel( final SimulatorInterface, DoubleScalar.Rel, OTSSimTimeDouble> pSimulator) throws SimRuntimeException { this.simulator = (OTSDEVSSimulatorInterface) pSimulator; URL url = URLResource.getResource("/lanedirection.xml"); XmlNetworkLaneParser nlp = new XmlNetworkLaneParser(this.simulator); try { nlp.build(url); } catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } } /** {@inheritDoc} */ @Override public SimulatorInterface, DoubleScalar.Rel, OTSSimTimeDouble> getSimulator() { return this.simulator; } } }