package org.opentrafficsim.swing.gui; import java.rmi.RemoteException; import org.djunits.unit.util.UNITS; import org.djutils.draw.bounds.Bounds2d; import org.opentrafficsim.core.animation.gtu.colorer.DefaultSwitchableGtuColorer; import org.opentrafficsim.core.dsol.OTSModelInterface; import org.opentrafficsim.core.gtu.Gtu; import org.opentrafficsim.core.network.Link; import org.opentrafficsim.draw.core.OTSDrawingException; import org.opentrafficsim.draw.factory.DefaultAnimationFactory; import org.opentrafficsim.draw.gtu.DefaultCarAnimation; import org.opentrafficsim.draw.gtu.GtuGeneratorQueueAnimation; import org.opentrafficsim.draw.network.LinkAnimation; import org.opentrafficsim.draw.network.NodeAnimation; import org.opentrafficsim.draw.road.LaneAnimation; import org.opentrafficsim.draw.road.SensorAnimation; import org.opentrafficsim.draw.road.TrafficLightAnimation; import org.opentrafficsim.road.network.lane.Lane; import org.opentrafficsim.road.network.lane.Shoulder; import org.opentrafficsim.road.network.lane.Stripe; import org.opentrafficsim.road.network.lane.conflict.Conflict; import org.opentrafficsim.road.network.lane.object.sensor.Sensor; import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight; import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel; import nl.tudelft.simulation.dsol.swing.gui.animation.DSOLAnimationApplication; import nl.tudelft.simulation.dsol.swing.gui.animation.DSOLAnimationTab; import nl.tudelft.simulation.language.DSOLException; /** * OTSAnimationApplication.java. *

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

* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel * @param model type */ public class OTSAnimationApplication extends DSOLAnimationApplication implements UNITS { /** */ private static final long serialVersionUID = 1L; /** */ private final DSOLPanel animationPanel; /** */ private final T model; /** * @param title String; the window title * @param panel DSOLPanel; animation panel * @param model T; model * @throws OTSDrawingException on animation error * @throws DSOLException x * @throws IllegalArgumentException x * @throws RemoteException x */ public OTSAnimationApplication(final String title, final DSOLPanel panel, final T model) throws OTSDrawingException, RemoteException, IllegalArgumentException, DSOLException { super(panel, title, DSOLAnimationTab.createAutoPanTab(new Bounds2d(-100, 100, -100, 100), model.getSimulator())); this.animationPanel = panel; this.model = model; animateNetwork(); setAnimationToggles(); addTabs(); setAppearance(getAppearance()); // update appearance of added objects } /** * Creates the animation objects. This method is overridable. The default uses {@code DefaultAnimationFactory}. * @throws OTSDrawingException on animation error */ protected void animateNetwork() throws OTSDrawingException { DefaultAnimationFactory.animateNetwork(getModel().getNetwork(), getModel().getNetwork().getSimulator(), new DefaultSwitchableGtuColorer()); } /** * Set animation toggles. This method is overridable. The default sets standard text toggles. */ protected void setAnimationToggles() { setTextAnimationTogglesStandard(getAnimationPanel()); } /** * Set the most common animation on, and create the toggles on the left hand side. * @param panel DSOLPanel; the WrappableAnimation. */ public void setTextAnimationTogglesStandard(final DSOLPanel panel) { getAnimationTab().addToggleAnimationButtonText("Node", NodeAnimation.ElevatedNode.class, "Show/hide nodes", false); getAnimationTab().addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node Ids", false); getAnimationTab().addToggleAnimationButtonText("Link", Link.class, "Show/hide links", false); getAnimationTab().addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false); getAnimationTab().addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true); getAnimationTab().addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", false); getAnimationTab().addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false); getAnimationTab().addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true); getAnimationTab().addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true); getAnimationTab().addToggleAnimationButtonText("GTU", Gtu.class, "Show/hide GTUs", true); getAnimationTab().addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false); getAnimationTab().addToggleAnimationButtonText("Sensor", Sensor.class, "Show/hide sensors", false); getAnimationTab().addToggleAnimationButtonText("SensorId", SensorAnimation.Text.class, "Show/hide sensors Ids", false); getAnimationTab().addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true); getAnimationTab().addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide sensors Ids", false); getAnimationTab().addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false); getAnimationTab().addToggleAnimationButtonText("Generator", GtuGeneratorQueueAnimation.class, "Show/hide generators", false); } /** * Adds tabs. This method is overridable. The default does nothing. */ protected void addTabs() { // } /** * Returns the animation panel. * @return OTSAnimationPanel; animation panel */ public DSOLPanel getAnimationPanel() { return this.animationPanel; } /** * @return model */ public T getModel() { return this.model; } }