At model runtime you can access the presentation that is currently shown in the model window via the function getExperimentHost(). Having accessed the presentation, you can do a number of things with it: zoom it in/out, navigate to the presentation's center or to some view area, show an inspect window for a specific model element, save the model state in a snapshot file, etc.
The usage example: by calling the getExperimentHost().zoomIn(2); function you zoom in the presentation two times.
In this article we list all the functions provided by AnyLogic presentation (that implements the AnyLogic's IExperimentHost interface).
Function |
Description |
void setCenter(double x, double y) |
Centers the animation (places the animation center in the point with the given coordinates).
Parameters: |
void navigateHome() |
Navigates the presentation to "home location", i.e. moves the presentation coordinate origin (0,0) to the top left corner of the window, and sets zoom to match the initial frame. |
void navigateTo(ViewArea viewArea) |
Shows the given view area in the model animation panel.
Parameter: |
void zoomIn(double coefficient) |
Zooms in the animation view.
Parameter: |
void zoomOut(double coefficient) |
Zooms out the animation view.
Parameter: |
void setZoomAndPanningEnabled(boolean yes) |
Enables or disables zoom & panning initiated from the GUI (button. mouse, or keyboard).
Parameter: |
boolean isZoomAndPanningEnabled() |
Tests if zoom & panning from the GUI is enabled. Returns true if zoom & panning are enabled, false if not. |
Function |
Description |
Experiment getExperiment() |
Returns the experiment. |
Function |
Description |
void close() |
This function returns immediately and performs the following actions in a separate thread:
|
Function |
Description |
Presentable getPresentable() |
Returns the object currently displayed by the model animation. |
void setPresentable(Presentable p) |
Sets the presentable object to be displayed by the model animation. Should be called when a different object should be displayed or when the current (active) object is destroyed. |
Function |
Description |
void setDeveloperPanelEnabled(boolean yes) |
Enables or disables the developer panel.
Parameter: |
void setDeveloperPanelVisibleOnStart(boolean yes) |
Shows the developer panel (if enabled) when the model window is shown.
Parameter: |
Function |
Description |
void setRunControlEnabled(boolean runControlEnabled) |
Enables or disables Run, Pause, and Stop buttons on the model window control panel. If the buttons are disabled, the Disabled by model designer tooltip is shown.
Parameter: |
boolean isRunControlEnabled() |
Tests if Run, Pause, and Stop buttons on the model window control panel are enabled.
If the function returns
true, the buttons are enabled. If the function returns
false, they are disabled. |
void setSpeedControlEnabled(boolean speedControlEnabled) |
Enables or disables the model execution speed buttons on the model window control panel. If the buttons are disabled, the Disabled by model designer tooltip is shown.
Parameter: |
boolean isSpeedControlEnabled() |
Tests if the model execution speed buttons on the model window control panel are enabled. If the function returns
true, the buttons are enabled. If the function returns
false, they are disabled. |
The functions are available only in AnyLogic Professional. Read more about AnyLogic model snapshots here.
Function |
Description |
void saveSnapshot |
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running. On any error throws nothing. If you need custom error processing, please use another function notation (see below). Parameter: fileName - the name of the snapshot file. |
void saveSnapshot(String fileName,
|
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running.
Parameters: Usage example. If the snapshot was successfully saved, we print the "Saved!" text to the console. In case of an error, we print the "Error!" text and the error stack trace to the console. getExperimentHost().saveSnapshot( "file.als", () -> traceln("Saved!"), e -> { traceln("Error!"); e.printStackTrace(); } ); |
void loadSnapshot |
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot. On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running. If you need custom error processing, please use another function notation (see below). When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment, and agents), therefore, it is recommended not to keep references to model objects after this function call.
Parameter: |
void loadSnapshot(String fileName,
|
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot. On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running. When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment, and agents), therefore, it is recommended not to keep references to model objects after this function call. Parameters: Usage example. If the snapshot was successfully loaded, we print the "Loaded!" text to the console, set the window to display the top-level agent's presentation and launch the model. In case of an error, we print the "Error!" text and the error stack trace to the console. getExperimentHost().loadSnapshot( "file.als", () -> { traceln("Loaded!"); getExperimentHost().setPresentable( getExperiment().getEngine().getRoot() ); getExperiment().run(); }, e -> { traceln("Error!"); e.printStackTrace(); }
); |
Function |
Description |
void openWebSite (String url) |
Opens web page with the given URL in the browser. |
Function |
Description |
void addInspect |
Creates an inspect window at a particular location for an element of a Presentable object. If there is another inspect with the same Presentable and same element name, it is brought to front and a new inspect is not created. The initial size of the window is adjusted to fit the initial contents.
Parameters: |
void removeInspect |
Removes the inspect window for the given element.
Parameters: |
Function |
Description |
void showMessageDialog |
Shows a standard message dialog box with the given text. The function usually returns immediately and does not wait for the dialog to be closed (except the cases when the function is called from UI thread).
Parameter: |