package org.opentrafficsim.swing.script; import java.awt.Dimension; import java.io.Serializable; import java.rmi.RemoteException; import java.text.SimpleDateFormat; import java.util.Date; import org.djunits.value.vdouble.scalar.Duration; import org.djunits.value.vdouble.scalar.Time; import org.djutils.cli.Checkable; import org.djutils.cli.CliException; import org.djutils.cli.CliUtil; import org.djutils.event.EventInterface; import org.djutils.event.EventListenerInterface; import org.djutils.exceptions.Throw; import org.djutils.exceptions.Try; import org.djutils.reflection.ClassUtil; import org.opentrafficsim.core.animation.gtu.colorer.GtuColorer; import org.opentrafficsim.core.dsol.AbstractOTSModel; import org.opentrafficsim.core.dsol.OTSAnimator; import org.opentrafficsim.core.dsol.OTSReplication; import org.opentrafficsim.core.dsol.OTSSimulator; import org.opentrafficsim.core.dsol.OTSSimulatorInterface; import org.opentrafficsim.core.network.Network; import org.opentrafficsim.draw.core.OTSDrawingException; import org.opentrafficsim.draw.factory.DefaultAnimationFactory; import org.opentrafficsim.road.network.RoadNetwork; import org.opentrafficsim.swing.gui.AnimationToggles; import org.opentrafficsim.swing.gui.OTSAnimationPanel; import org.opentrafficsim.swing.gui.OTSSimulationApplication; import org.opentrafficsim.swing.gui.OTSSwingApplication; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.experiment.ReplicationInterface; import nl.tudelft.simulation.dsol.experiment.StreamInformation; import picocli.CommandLine.Command; import picocli.CommandLine.Option; /** * Template for simulation script. This class allows the user to run a single visualized simulation, or to batch-run the same * model. Parameters can be given through the command-line using djutils-ext. Fields can be added to sub-classes using the * {@code @Options} and similar annotations. Default values of the properties in this abstract class can be overwritten by the * sub-class using {@code CliUtil.changeDefaultValue()}. *
* 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.
*
* 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 9 apr. 2018
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
private class ScriptModel extends AbstractOTSModel
{
/** */
private static final long serialVersionUID = 20180409L;
/**
* @param simulator OTSSimulatorInterface; the simulator
*/
@SuppressWarnings("synthetic-access")
ScriptModel(final OTSSimulatorInterface simulator)
{
super(simulator);
AbstractSimulationScript.this.simulator = simulator;
}
/** {@inheritDoc} */
@SuppressWarnings("synthetic-access")
@Override
public void constructModel() throws SimRuntimeException
{
AbstractSimulationScript.this.network =
Try.assign(() -> AbstractSimulationScript.this.setupSimulation(AbstractSimulationScript.this.simulator,
getStreamInformation()), RuntimeException.class, "Exception while setting up simulation.");
try
{
AbstractSimulationScript.this.simulator.addListener(AbstractSimulationScript.this,
ReplicationInterface.END_REPLICATION_EVENT);
}
catch (RemoteException exception)
{
throw new SimRuntimeException(exception);
}
}
/** {@inheritDoc} */
@SuppressWarnings("synthetic-access")
@Override
public OTSSimulatorInterface getSimulator()
{
return AbstractSimulationScript.this.simulator;
}
/** {@inheritDoc} */
@SuppressWarnings("synthetic-access")
@Override
public RoadNetwork getNetwork()
{
return AbstractSimulationScript.this.network;
}
/** {@inheritDoc} */
@SuppressWarnings("synthetic-access")
@Override
public String getShortName()
{
return AbstractSimulationScript.this.name;
}
/** {@inheritDoc} */
@SuppressWarnings("synthetic-access")
@Override
public String getDescription()
{
return AbstractSimulationScript.this.description;
}
/** {@inheritDoc} */
@Override
public Serializable getSourceId()
{
return getShortName();
}
}
}