Class TLcdSimulator

java.lang.Object
com.luciad.realtime.TLcdSimulator

public class TLcdSimulator extends Object

TLcdSimulator is the class that is responsible for the timing of the simulation: it produces the correct simulation time at each simulation step. Associated with a TLcdSimulator are:

  • A simulator model
  • One or more layer factories
  • One or more views

The simulator model is responsible for providing the TLcdSimulator with the ILcdModel objects holding the domain data to be simulated, and for putting these data in the state corresponding to a given simulation time.

The layer factories are used by the TLcdSimulator to create layers for the views, for each of the different simulation models.

TLcdSimulator can be used in two different modes:

  • time factor mode (default): there is a fixed relation between real time and simulation time.
  • time step mode: the simulator will perform a simulation at successive time-steps as fast as it can.

You can choose between the two modes with the setUseTimeStep(boolean) method.

  • Field Details

  • Constructor Details

    • TLcdSimulator

      public TLcdSimulator()
      Creates a new TLcdSimulator
  • Method Details

    • addView

      public void addView(ILcdView aView)

      Adds the given view as one of the views of this simulator and properly initializes it with the necessary simulation layers.

      Currently only instances of ILcdGXYView and ILspView are accepted. Other implementations are ignored.

      Parameters:
      aView - the view to be added to the views of this simulator
    • removeView

      public void removeView(ILcdView aView)
      Removes the given view from this simulator's views
      Parameters:
      aView - the view that needs to be removed from this simulator's views
    • getSimulatorModel

      public ILcdSimulatorModel getSimulatorModel()
      Return the ILcdSimulatorModel that is simulated by this simulator.
      Returns:
      The ILcdSimulatorModel that is simulated by this simulator.
      See Also:
    • setSimulatorModel

      public void setSimulatorModel(ILcdSimulatorModel aSimulatorModel)
      Set the ILcdSimulatorModel to be simulated by this simulator. The date information associated with the simulator is replaced with the date information associated with the simulator model. The simulator's date and the simulation's begin date and end date are set to the date, begin date, and end date of the simulator model.
      Parameters:
      aSimulatorModel - The ILcdSimulatorModel to be simulated by this simulator.
      See Also:
    • getStatus

      public int getStatus()
      Returns the status of the simulator. This is one of:
      • TLcdSimulator.RUNNING
      • TLcdSimulator.STOPPED
      • TLcdSimulator.PAUSING
      • TLcdSimulator.ENDED
      Returns:
      The status of the simulator.
    • getStatusAsString

      public String getStatusAsString()
      Return the status of the simulator as a String.
      Returns:
      The status of the simulator as a String.
      See Also:
    • getMaxCPUUsage

      public int getMaxCPUUsage()
      Returns the maximum percentage of CPU to be used by the simulation.
      Returns:
      The maximum percentage of CPU to be used by the simulation.
      See Also:
    • setMaxCPUUsage

      public void setMaxCPUUsage(int aMaxCPUUsage)
      Set the maximum percentage of CPU to be used by the simulation. It shall only be considered as an indication given to this class, not a strict value to be respected. It take as assumption that the CPU is not shared with any other threads or application. This property has priority over the delayBetweenUpdateMs property, when the percentage of the CPU time for one update, compared to the current value of delayBetweenUpdateMs (i.e.: CPU_time_update * 100 / delayBetweenUpdateMs), is greater than this property value.
      Parameters:
      aMaxCPUUsage - A value between 1 and 100.
      See Also:
    • isPauseOnMousePressed

      public boolean isPauseOnMousePressed()
      Returns whether the simulation is suspended while the mouse is pressed.
      See Also:
    • setPauseOnMousePressed

      public void setPauseOnMousePressed(boolean aPauseOnMousePressed)

      Set whether to suspend the simulation when the mouse is pressed on one of the simulation views.

      When the mouse is released, the simulation will continue as if the simulation had not been paused: the simulation time will jump to catch up the time lost between the press and release of the mouse.

      By default, this feature is enabled.

      Note: This feature does not work with Lightspeed views

      Parameters:
      aPauseOnMousePressed - When true, the simulation will be suspended while the mouse is being pressed.
      See Also:
    • getTimeFactor

      public double getTimeFactor()
      Returns the time factor, this is the factor by which simulation is accelerated with respect to real time. The default value for the time factor is 1.
      Returns:
      The time factor, this is the factor by which simulation is accelerated with respect to real time.
      See Also:
    • setTimeFactor

      public void setTimeFactor(double aTimeFactor)
      Sets the time factor, this is the factor by which simulation is accelerated with respect to real time.
      Parameters:
      aTimeFactor - The time factor to be set.
      See Also:
    • isPlayInLoop

      public boolean isPlayInLoop()
      Returns whether this simulator plays the simulation in a loop.
      Returns:
      whether this simulator plays the simulation in a loop.
    • setPlayInLoop

      public void setPlayInLoop(boolean aPlayInLoop)
      Sets whether this simulator should play the simulation in a loop.
      Parameters:
      aPlayInLoop - whether the simulator should play the simulation in a loop.
    • isTimerTraceOn

      public boolean isTimerTraceOn()
      Returns true if time tracing is active, false otherwise.
      Returns:
      true if time tracing is active, false otherwise.
      See Also:
    • setTimerTraceOn

      public void setTimerTraceOn(boolean aTimerTraceOn)

      Set time tracing to aTimerTraceOn. When timer tracing is turned on, all timer related log messages are recorded.

      To see the log output, you also have to enable tracing for this class. You can do that for example by using a logging configuration file. If you're using the default Java logging this code snippet can be used as well:

      
         simulator.setTimerTraceOn( true );
      
         Logger logger = Logger.getLogger( TLcdSimulator.class.getName() );
         logger.setLevel( Level.ALL );
         ConsoleHandler handler = new ConsoleHandler();
         handler.setLevel( Level.ALL );
         logger.addHandler( handler );
       

      This property is meant for debugging purposes. As such, no property change events are fired when it changes.

      Parameters:
      aTimerTraceOn - The value to be set for time tracing.
      See Also:
    • getUpdatesPerSecond

      public int getUpdatesPerSecond()
      Returns the current update rate.
      Returns:
      The current update rate.
    • getDelayBetweenUpdateMs

      public int getDelayBetweenUpdateMs()
      Returns the minimal delay between updates in milliseconds.
      Returns:
      The minimal delay between updates in milliseconds.
      See Also:
    • setDelayBetweenUpdateMs

      public void setDelayBetweenUpdateMs(int aDelayBetweenUpdateMs)
      Set the minimal delay in milliseconds between two simulation updates. The actual delay is also controlled by the property MaxCPUUsage. This property can be used to limit the maximum frame rate. If this property is for example set to 50 milliseconds, the theoretical maximum frame rate is 1000/50 = 20. In practice it will be somewhat lower because refreshing the view takes some time as well.
      Parameters:
      aDelayBetweenUpdateMs - The delay in milliseconds between two simulation updates.
      See Also:
    • isUseTimeStep

      public boolean isUseTimeStep()
      Returns true if using time steps, false otherwise.
      Returns:
      true if using time steps, false otherwise.
      See Also:
    • setUseTimeStep

      public void setUseTimeStep(boolean aUseTimeStep)
      Set whether to use a time-step simulation. If set to true, (and if the method getTimeStep()) returns a value > 0), the simulator will not perform a simulation that has a relation with the real elapsed time. Instead it will give an animation at successive time step as fast as it can. By default, this feature is disabled
      Parameters:
      aUseTimeStep - The value to be set for time-stepping.
      See Also:
    • getTimeStep

      public long getTimeStep()
      Returns the time step in milliseconds.
      Returns:
      The time step in milliseconds.
      See Also:
    • setTimeStep

      public void setTimeStep(long aTimeStep)

      Sets the time step to use expressed in milliseconds. The default time step is 0.

      This property is only relevant when this simulator works in time-step mode.

      Parameters:
      aTimeStep - The time step in milliseconds.
      See Also:
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener l)
      Register a listener for the PropertyChange event.
      Parameters:
      l - The listener to register.
      See Also:
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener l)
      Remove a listener for the PropertyChange event.
      Parameters:
      l - The listener to remove.
      See Also:
    • currentTime

      protected long currentTime()

      Returns the difference in milliseconds between some fixed but arbitrary time, and the current wall-clock time. For example System.nanoTime()/1e6 can be used.

      Overriding this method can be useful to synchronize the simulator with an external clock, for example from an audio or a video stream.

      Returns:
      the difference in milliseconds between some fixed but arbitrary time, and the current wall-clock time.
    • getDate

      public Date getDate()
      Return the current date of the simulation. Returns a date corresponding to January 1, 1970, 00:00:00 GMT if no valid simulator model is set.
      Returns:
      The current date of the simulation or a date corresponding to January 1, 1970, 00:00:00 GMT if no valid simulator model is set.
      See Also:
    • setDate

      public void setDate(Date newDate)
      Sets the date associated with this simulator to the given date
      Parameters:
      newDate - the new date for this simulator
    • getBeginDate

      public Date getBeginDate()
      Return the begin date of the simulation. Returns a date corresponding to January 1, 1970, 00:00:00 GMT if no valid simulator model is set.
      Returns:
      The begin date of the simulation.
    • getEndDate

      public Date getEndDate()
      Return the end date of the simulation.
      Returns:
      The end date of the simulation. Returns a date corresponding to January 1, 1970, 00:00:00 GMT if no valid simulator model is set.
    • run

      public void run()
      Start the simulator
    • stop

      public void stop()
      Stop the simulator. Simulation time is reset to the start of the simulation.
    • pause

      public void pause()
      Pause the simulator
    • getGXYView

      public ILcdGXYView[] getGXYView()
      Returns an array of ILcdGXYView on which the simulation is shown.
      Returns:
      An array of ILcdGXYView on which the simulation is shown.
      See Also:
    • setGXYView

      public void setGXYView(ILcdGXYView[] aGXYView)
      Set an array of ILcdGXYView on which the simulation is shown.
      Parameters:
      aGXYView - An array of ILcdGXYView on which the simulation is shown.
      See Also:
    • getLspView

      public ILspView[] getLspView()
      Returns an array of ILspView on which the simulation is shown.
      Returns:
      An array of ILspView on which the simulation is shown.
    • setLspView

      public void setLspView(ILspView[] aLspView)
      Set an array of ILspView on which the simulation is shown.
      Parameters:
      aLspView - An array of ILspView on which the simulation is shown.
      See Also:
    • getGXYLayerFactory

      public ILcdGXYLayerFactory getGXYLayerFactory()
      Return the ILcdGXYLayerFactory to create the simulation layer(s) for the GXY views.
      Returns:
      The ILcdGXYLayerFactory to create the simulation layer(s) for the GXY views.
      See Also:
    • setGXYLayerFactory

      public void setGXYLayerFactory(ILcdGXYLayerFactory aGXYLayerFactory)
      Set the ILcdGXYLayerFactory to create the simulation layer(s) for the GXY views.
      Parameters:
      aGXYLayerFactory - The ILcdGXYLayerFactory to create the simulation layer(s) for the GXY views.
      See Also:
    • getLspLayerFactory

      public ILspLayerFactory getLspLayerFactory()
      Return the ILspLayerFactory to create the simulation layer(s) for a Lightspeed view.
      Returns:
      The ILspLayerFactory to create the simulation layer(s) for a Lightspeed view.
      See Also:
    • setLspLayerFactory

      public void setLspLayerFactory(ILspLayerFactory aLayerFactory)
      Set the ILspLayerFactory to create the simulation layer(s) for a Lightspeed view.
      Parameters:
      aLayerFactory - The ILspLayerFactory to create the simulation layer(s) for a Lightspeed view.
      See Also:
    • getLayers

      public Collection<ILcdLayer> getLayers()
      Returns a collection of all the ILcdLayer used in this simulator. The returned collection can not be modified.
      Returns:
      a collection of all the ILcdLayer used in this simulator. The returned collection can not be modified.
    • getSimulationGXYLayers

      public ILcdGXYLayer[][] getSimulationGXYLayers()
      Returns a two-dimensional array of ILcdGXYLayer. The first dimension corresponds to the different ILcdGXYView of this simulator. The second dimension corresponds to the different simulation layers per view. The simulation layers are automatically generated when an ILcdSimulatorModel along with one or multiple views is set to this simulator. Each view should have the same number of layers, one for each track model that is contained in the ILcdSimulatorModel and should have the same order as the track models array that can be obtained by calling ILcdSimulatorModel#getTrackModels(). Based on whether this simulator is configured to share layers between views (see #setUseSameGXYLayer ) a layer for a specific track model will be shared across multiple GXY views.
      Returns:
      A two-dimensional array of ILcdGXYLayer. The first dimension corresponds to the different ILcdGXYView of this simulator. The second dimension corresponds to the different simulation layers per view.
    • getSimulationLspLayers

      public ILspLayer[][] getSimulationLspLayers()
      Returns a two-dimensional array of ILspLayer. The first dimension corresponds to the different ILspView of this simulator. The second dimension corresponds to the different simulation layers per view. The simulation layers are automatically generated when an ILcdSimulatorModel along with one or multiple views is set to this simulator. Each view should have the same number of layers, one for each track model that is contained in the ILcdSimulatorModel and should have the same order as the track models array that can be obtained by calling ILcdSimulatorModel#getTrackModels().
      Returns:
      A two-dimensional array of ILspLayer. The first dimension corresponds to the different ILspView of this simulator. The second dimension corresponds to the different simulation layers per view.
    • setUseSameGXYLayer

      public void setUseSameGXYLayer(boolean aUseSameGXYLayer)
      Set whether the same simulation layer can be used in different GXY views, or each GXY view has to have its own layer.
      Parameters:
      aUseSameGXYLayer - If true a single layer is shared among all GXY simulation views, if false a separate simulation layer is created for each GXY simulation view.
      See Also:
    • isUseSameGXYLayer

      public boolean isUseSameGXYLayer()
      Returns whether the same simulation layer can be used in different GXY views, or each GXY view has to have its own layer. By default, this feature is disabled.
      Returns:
      true if a single layer is shared among all GXY simulation views, false false if a separate simulation layer is created for each GXY simulation view.
      See Also:
    • isManageNumberOfCachedBackgroundLayers

      public boolean isManageNumberOfCachedBackgroundLayers()
      Determines whether the simulator manages the number of cached background layers of the views to which it is linked. If set to true, the number of cached background layers will be set equal to the number of layers beneath the layer created by this simulator for every view this simulator creates a layer for. If set to false, the number of cached background layers will not be modified. By default, this feature is enabled.
      Returns:
      true if background layer management is enabled; false otherwise
      See Also:
    • setManageNumberOfCachedBackgroundLayers

      public void setManageNumberOfCachedBackgroundLayers(boolean aManageNumberOfCachedBackgroundLayers)
      Enables or disables number of cached background layer management.
      Parameters:
      aManageNumberOfCachedBackgroundLayers - true to enable background layer management; false to disable it
      See Also:
    • isTraceOn

      public boolean isTraceOn()
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Returns true if tracing is enabled for this class.
      Returns:
      true if tracing is enabled for this class, false otherwise.
    • setTraceOn

      public void setTraceOn(boolean aTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for this class instance. Calling this method with either true or false as argument automatically turns off tracing for all other class instances for which setTraceOn has not been called. If the argument is false then only the informative, warning and error log messages are recorded.
      Parameters:
      aTraceOn - if true then all log messages are recorded for this instance. If false, then only the informative, warning and error log messages are recorded.