package org.opentrafficsim.demo.network.xml; import java.awt.Dimension; import java.io.IOException; import java.io.Serializable; import java.net.URISyntaxException; import java.net.URL; import java.rmi.RemoteException; import javax.naming.NamingException; import javax.swing.SwingUtilities; import javax.xml.bind.JAXBException; import javax.xml.parsers.ParserConfigurationException; import org.djunits.value.vdouble.scalar.Duration; import org.djunits.value.vdouble.scalar.Time; import org.djutils.io.URLResource; import org.opentrafficsim.core.dsol.AbstractOTSModel; import org.opentrafficsim.core.dsol.OTSAnimator; import org.opentrafficsim.core.dsol.OTSModelInterface; import org.opentrafficsim.core.dsol.OTSReplication; import org.opentrafficsim.core.dsol.OTSSimulatorInterface; import org.opentrafficsim.core.gtu.GtuException; import org.opentrafficsim.core.network.NetworkException; import org.opentrafficsim.draw.core.OTSDrawingException; import org.opentrafficsim.road.network.RoadNetwork; import org.opentrafficsim.road.network.defaults.RoadNetworkDefaults; import org.opentrafficsim.road.network.factory.xml.XmlParserException; import org.opentrafficsim.road.network.factory.xml.parser.XmlNetworkLaneParser; import org.opentrafficsim.swing.gui.OTSAnimationPanel; import org.opentrafficsim.swing.gui.OTSSimulationApplication; import org.opentrafficsim.trafficcontrol.TrafficControlException; import org.xml.sax.SAXException; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.language.DSOLException; /** * New parser test. *

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

* @version $Revision$, $LastChangedDate$, by $Author$, initial version Dec 1, 2015
* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel */ public class TestXMLParserAimsun extends OTSSimulationApplication { /** */ private static final long serialVersionUID = 1L; /** * @param model OTSModelInterface; the model * @param animationPanel OTSAnimationPanel; the animation panel * @throws OTSDrawingException on drawing error */ public TestXMLParserAimsun(final OTSModelInterface model, final OTSAnimationPanel animationPanel) throws OTSDrawingException { super(model, animationPanel); } /** * 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 { OTSAnimator simulator = new OTSAnimator("TestXMLParserAimsun"); TestAimsunModel xmlModel = new TestAimsunModel(simulator); OTSReplication replication = new OTSReplication("rep", Time.ZERO, Duration.ZERO, Duration.instantiateSI(3600)); simulator.initialize(xmlModel, replication); OTSAnimationPanel animationPanel = new OTSAnimationPanel(xmlModel.getNetwork().getExtent(), new Dimension(800, 600), simulator, xmlModel, DEFAULT_COLORER, xmlModel.getNetwork()); new TestXMLParserAimsun(xmlModel, animationPanel); animationPanel.enableSimulationControlButtons(); } catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException | DSOLException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public String toString() { return "TestXMLParserAimsunNew []"; } /** * Model to test the XML parser. *

* Copyright (c) 2013-2021 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 */ static class TestAimsunModel extends AbstractOTSModel { /** */ private static final long serialVersionUID = 20141121L; /** the network. */ private RoadNetwork network = null; /** * @param simulator OTSSimulatorInterface; the simulator */ TestAimsunModel(final OTSSimulatorInterface simulator) { super(simulator); } /** {@inheritDoc} */ @Override public final void constructModel() throws SimRuntimeException { URL url = URLResource.getResource("/xml/AimsunOtsNetwork.xml"); this.network = new RoadNetwork("Aimsun network", getSimulator()); RoadNetworkDefaults.registerDefaults(this.network); try { XmlNetworkLaneParser.build(url.getPath(), this.network, true); } catch (NetworkException | ParserConfigurationException | SAXException | JAXBException | URISyntaxException | XmlParserException | GtuException | IOException | TrafficControlException exception) { exception.printStackTrace(); } } /** {@inheritDoc} */ @Override public RoadNetwork getNetwork() { return this.network; } /** {@inheritDoc} */ @Override public final String toString() { return "TestXMLParserAimsunNew [simulator=" + this.simulator + "]"; } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "TestAimsunModel"; } } }