View Javadoc
1   package org.opentrafficsim.web.animation;
2   
3   import org.opentrafficsim.core.gtu.Gtu;
4   import org.opentrafficsim.core.gtu.GtuGenerator.GtuGeneratorPosition;
5   import org.opentrafficsim.core.network.Node;
6   import org.opentrafficsim.core.network.Link;
7   import org.opentrafficsim.draw.gtu.DefaultCarAnimation;
8   import org.opentrafficsim.draw.network.LinkAnimation;
9   import org.opentrafficsim.draw.network.NodeAnimation;
10  import org.opentrafficsim.draw.road.BusStopAnimation;
11  import org.opentrafficsim.draw.road.DetectorAnimation;
12  import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation;
13  import org.opentrafficsim.draw.road.LaneAnimation;
14  import org.opentrafficsim.draw.road.TrafficLightAnimation;
15  import org.opentrafficsim.road.network.lane.Lane;
16  import org.opentrafficsim.road.network.lane.Shoulder;
17  import org.opentrafficsim.road.network.lane.Stripe;
18  import org.opentrafficsim.road.network.lane.conflict.Conflict;
19  import org.opentrafficsim.road.network.lane.object.BusStop;
20  import org.opentrafficsim.road.network.lane.object.detector.Detector;
21  import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight;
22  
23  import nl.tudelft.simulation.dsol.animation.Locatable;
24  import nl.tudelft.simulation.dsol.web.animation.d2.HtmlAnimationPanel;
25  
26  /**
27   * Set the default animation toggles for the HTML animation panel.
28   * <p>
29   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
31   * </p>
32   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
33   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
34   * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
35   */
36  public final class WebAnimationToggles
37  {
38      /**
39       * Do not instantiate this class.
40       */
41      private WebAnimationToggles()
42      {
43          // static class.
44      }
45  
46      /**
47       * Set all commonly used animation on, and create the toggles on the left hand side.
48       * @param panel HTMLAnimationPanel; the Animation panel to add the toggle to.
49       */
50      public static void setTextAnimationTogglesFull(final HtmlAnimationPanel panel)
51      {
52          panel.addToggleAnimationButtonText("Node", NodeAnimation.ElevatedNode.class, "Show/hide nodes", true);
53          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node Ids", false);
54          panel.addToggleAnimationButtonText("Link", Link.class, "Show/hide links", true);
55          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false);
56          panel.addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true);
57          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", false);
58          panel.addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
59          panel.addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true);
60          panel.addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true);
61          panel.addToggleAnimationButtonText("GTU", Gtu.class, "Show/hide GTUs", true);
62          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false);
63          panel.addToggleAnimationButtonText("Detector", Detector.class, "Show/hide detector", true);
64          panel.addToggleAnimationButtonText("DetectorId", DetectorAnimation.Text.class, "Show/hide detector Ids", false);
65          panel.addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true);
66          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide traffic light Ids", false);
67          panel.addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false);
68          panel.addToggleAnimationButtonText("Generator", GtuGeneratorPosition.class, "Show/hide generators", false);
69          panel.addToggleAnimationButtonText("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class,
70                  "Show/hide generator queues", false);
71          panel.addToggleAnimationButtonText("Bus", BusStop.class, "Show/hide bus stops", false);
72          panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop Ids", false);
73      }
74  
75      /**
76       * Set the most common animation on, and create the toggles on the left hand side.
77       * @param panel HTMLAnimationPanel; the Animation panel to add the toggle to.
78       */
79      public static void setTextAnimationTogglesStandard(final HtmlAnimationPanel panel)
80      {
81          panel.addToggleAnimationButtonText("Node", NodeAnimation.ElevatedNode.class, "Show/hide nodes", false);
82          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node Ids", false);
83          panel.addToggleAnimationButtonText("Link", Link.class, "Show/hide links", false);
84          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false);
85          panel.addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true);
86          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", false);
87          panel.addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
88          panel.addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true);
89          panel.addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true);
90          panel.addToggleAnimationButtonText("GTU", Gtu.class, "Show/hide GTUs", true);
91          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false);
92          panel.addToggleAnimationButtonText("Detector", Detector.class, "Show/hide detector", false);
93          panel.addToggleAnimationButtonText("DetectorId", DetectorAnimation.Text.class, "Show/hide detector Ids", false);
94          panel.addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true);
95          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide traffic light Ids", false);
96          panel.addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false);
97          panel.addToggleAnimationButtonText("Generator", GtuGeneratorPosition.class, "Show/hide generators", false);
98          panel.addToggleAnimationButtonText("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class,
99                  "Show/hide generator queues", false);
100         panel.addToggleAnimationButtonText("Bus", BusStop.class, "Show/hide bus stops", false);
101         panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop Ids", false);
102     }
103 
104     /**
105      * Set a class to be shown in the animation to true.
106      * @param panel OtsAnimationPanel; the HTMLAnimationPanel where the animation of a class has to be switched off
107      * @param locatableClass Class&lt;? extends Locatable&gt;; the class for which the animation has to be shown.
108      */
109     public final static void showAnimationClass(final HtmlAnimationPanel panel, final Class<? extends Locatable> locatableClass)
110     {
111         panel.showClass(locatableClass);
112     }
113 
114     /**
115      * Set a class to be shown in the animation to false.
116      * @param panel HTMLAnimationPanel; the HTMLAnimationPanel where the animation of a class has to be switched off
117      * @param locatableClass Class&lt;? extends Locatable&gt;; the class for which the animation has to be shown.
118      */
119     public final static void hideAnimationClass(final HtmlAnimationPanel panel, final Class<? extends Locatable> locatableClass)
120     {
121         panel.hideClass(locatableClass);
122     }
123 
124     /**
125      * Set all commonly used animation on, and create the toggles on the left hand side.
126      * @param panel HTMLAnimationPanel; the HTMLAnimationPanel where classes are shown or not.
127      */
128     public static void showAnimationFull(final HtmlAnimationPanel panel)
129     {
130         showAnimationClass(panel, Node.class);
131         hideAnimationClass(panel, NodeAnimation.Text.class);
132         showAnimationClass(panel, Link.class);
133         hideAnimationClass(panel, LinkAnimation.Text.class);
134         showAnimationClass(panel, Lane.class);
135         hideAnimationClass(panel, LaneAnimation.Text.class);
136         hideAnimationClass(panel, LaneAnimation.CenterLine.class);
137         showAnimationClass(panel, Stripe.class);
138         showAnimationClass(panel, Shoulder.class);
139         showAnimationClass(panel, Gtu.class);
140         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
141         showAnimationClass(panel, Detector.class);
142         hideAnimationClass(panel, DetectorAnimation.Text.class);
143         showAnimationClass(panel, TrafficLight.class);
144         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
145         showAnimationClass(panel, Conflict.class);
146         showAnimationClass(panel, GtuGeneratorPosition.class);
147         hideAnimationClass(panel, GtuGeneratorPositionAnimation.Queue.class);
148         showAnimationClass(panel, BusStop.class);
149         hideAnimationClass(panel, BusStopAnimation.Text.class);
150     }
151 
152     /**
153      * Set the most common animation on, and create the toggles on the left hand side.
154      * @param panel OtsAnimationPanel; the WrappableAnimation.
155      */
156     public static void showAnimationStandard(final HtmlAnimationPanel panel)
157     {
158         hideAnimationClass(panel, Node.class);
159         hideAnimationClass(panel, NodeAnimation.Text.class);
160         hideAnimationClass(panel, Link.class);
161         hideAnimationClass(panel, LinkAnimation.Text.class);
162         showAnimationClass(panel, Lane.class);
163         hideAnimationClass(panel, LaneAnimation.Text.class);
164         hideAnimationClass(panel, LaneAnimation.CenterLine.class);
165         showAnimationClass(panel, Stripe.class);
166         showAnimationClass(panel, Shoulder.class);
167         showAnimationClass(panel, Gtu.class);
168         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
169         hideAnimationClass(panel, Detector.class);
170         hideAnimationClass(panel, DetectorAnimation.Text.class);
171         showAnimationClass(panel, TrafficLight.class);
172         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
173         hideAnimationClass(panel, Conflict.class);
174         hideAnimationClass(panel, GtuGeneratorPosition.class);
175         hideAnimationClass(panel, GtuGeneratorPositionAnimation.Queue.class);
176         hideAnimationClass(panel, BusStop.class);
177         hideAnimationClass(panel, BusStopAnimation.Text.class);
178     }
179 
180 }