Accessing the presentation

At model runtime you can access the presentation that is currently shown in the model window via the function getPresentation(). Having accessed the presenation, 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 snaphot file, etc. 

The usage example: by calling the getPresentation.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 IPresentation interface).

Presentation functions

Navigation, zoom and panning

Function

Description

void setCenter(double x, double y)

Centers the animation (places the animation center in the point with the given coordinates).

Parameters:
x - X-coordinate of the center point
y - Y-coordinate of the center point

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: viewArea - the view area to show.

void zoomIn(double coefficient)

Zooms in the animation view.

Parameter: coefficient - how much to zoom in, positive number. E.g. 2.0 will result in 2x scaling compared to the current view.

void zoomOut(double coefficient)

Zooms out the animation view.

Parameter: coefficient - how much to zoom out, positive number. E.g. 2.0 will result in 0.5x scaling compared to the current view.

void setZoomAndPanningEnabled
(boolean yes)

Enables or disables zoom & panning initiated from the GUI (button. mouse, or keyboard).

Parameter: yes - if true, zoom & panning should be enabled, if false - disabled.

boolean isZoomAndPanningEnabled()

Tests if zoom & panning from the GUI is enabled.

Returns true if zoom & panning are enabled, false if not.

Experiment termination 

Function

Description

void close()

This function returns immediately and performs the following actions in a separate thread:

  • stops experiment if it is not stopped;

  • destroys the model;

  • closes experiment window (only if the model is started in the application mode).

Presentation context

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.

Saving the model state (snapshot)

The functions are available only in AnyLogic Professional. Read more about AnyLogic model snapshots here.

Function

Description

void saveSnapshot
(String fileName)

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 special callback function of listener. Notifies all listeners registered via addSnapshotEventListener(SnapshotEventListener).

Parameter: fileName - the name of the snapshot file.

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. If you need custom error processing, please use special callback function of listener.

Notifies all listeners registered via addSnapshotEventListener(SnapshotEventListener). 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: fileName - the name of the snapshot file.

void addSnapshotEventListener
(SnapshotEventListener listener)

Registers listener for snapshot events, this listener is notified about changes performed by saveSnapshot(String) and loadSnapshot(String) functions.

Does nothing if the given listener has already been added.

Parameter: listener - the listener of snapshot events

Opening web pages

Function

Description

void openWebSite
(String url)

Opens web page with the given URL in the browser.

Parameter: url - the URL to open.

Inspect windows

Function

Description

void addInspect
(double x, double y, Presentable p, String name)

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:
x - the x coordinate in the presentable object system
y - the y coordinate in the presentable object system
p - the Presentable object whose element is being inspected
name - the name of the element being inspected

void removeInspect
(Presentable p, String name)

Removes the inspect window for the given element.

Parameters:
p - the Presentable object whose element is being inspected
name - the name of the element being inspected

Message windows

Function

Description

void showMessageDialog
(String text)

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: text - the text to display