CAD Drawing

AnyLogic Professional enables users to import CAD drawings (in DXF format) into their presentations. You may need this in the case your model concerns a movement of objects (agents, pedestrians, etc.) in a certain physical space defined using a CAD drawing. Usually CAD drawings contain layouts of some buildings (hospitals, factory floors, stadiums, museums, etc.), or even some streets. 

There are two modeling approaches where CAD drawings are applied in most cases: network based modeling and pedestrian dynamics modeling.

 To add a CAD drawing
  1. Drag the  CAD Drawing element from the  Presentation palette into the graphical editor.
  2. Go to the Properties and choose CAD drawing file you want to be displayed on the presentation. Add a drawing by clicking the Browse button. This opens the Open dialog box. Browse for the file you want to add, then select it and click Open when finished. You will see the name of the selected file in the File edit box.
  3. After choosing the file, you can go to the File reading log section and view the information on reading the selected drawing file: which layers were read successfully, and which - not.
  4. Go to the Layers section. In the table you can customize the set of layers that will be visible on the drawing at runtime. To show a layer, select the check box in the corresponding row of the table.
  5. Optionally, you can change the Fill color for the drawing and Invert default colors by selecting the checkbox of the same name.

CAD drawing file added onto AnyLogic presentation will be copied to the model folder. In case you copy your model elsewhere all files will be copied as well.

Properties

General

Name – The name of the CAD shape. It is used to identify and access the shape from code.

Ignore – If selected, the CAD drawing is excluded from the model.

Visible on upper level – If selected, the shape is also visible on the upper level where this agent lives.

Lock – If selected, the shape is locked. Locked shapes do not react to mouse clicks - it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you use a shape as a background image for your animation and you want to prevent editing this shape while drawing other shapes over it.

Visible – If selected, the shape is visible on the presentation at model runtime.

File – The path to the CAD drawing file. You can choose the CAD file using the Browse button. The  button to the right allows to switch between the absolute and relative file path. After choosing the file, you can open the File reading log section of the properties and view the information on reading the selected drawing file: which layers were read successfully, and which - not.

Browse – The button allows user to browse to the required CAD drawing file. 

Fill color – Here you can choose the fill color for the drawing.

Invert default colors – Select this checkbox if you want to invert the default colors of the drawing. 

Layers

Here you can customize the set of CAD layers that will be visible on the drawing. To show a layer, select the check box in the corresponding row of the table.

Position and size

X – X-coordinate of the upper left corner of the CAD shape.

Y – Y-coordinate of the upper left corner of the CAD shape.

Width – The width of the CAD drawing shape, in pixels.

Height – The height of the CAD drawing shape, in pixels.

Advanced

On click – Code that will be called each time the user clicks on the drawing at runtime.

Use antialiasing – AnyLogic presentation supports anti-aliasing – one of the most important techniques in making graphics more smooth and pleasing to the eye. Anti-aliasing is a process of smoothing the drawing of points or lines that would otherwise appear jagged. However, note that more time is spent on rendering the presentation with the anti-aliasing set. Select the checkbox to turn on the antialiasing for this CAD drawing.

Show name – If selected, the name of the CAD shape will be displayed on the presentation diagram.

File reading log

Here you can view information on reading the selected drawing file: which layers were read successfully, and which - not (of course, this information is available only after choosing the drawing file in the File property).

Functions

Shape position

Function

Description

double getX()

Returns the X coordinate of the shape (namely, the X coordinate of its upper left corner).

double getY()

Returns the Y coordinate of the shape (namely, the Y coordinate of its upper left corner).

void setX(double x)

Sets the X coordinate of the shape.

Parameter:
x - the new value of X coordinate

void setY(double y)

Sets the Y coordinate of the shape.

Parameter:
y - the new value of Y coordinate

void setPos(double x, double y)

Sets new coordinates for the shape.

Parameters:
x - the new value of x coordinate
y - the new value of y coordinate

Shape size

Function

Description

double getWidth()

Returns the width of the shape.

double getHeight()

Returns the height of the shape.

void setWidth(double width)

Sets the width of the shape equal to width.

void setHeight(double height)

Sets the height of the shape equal to height.

Working with layers

Function

Description

String[] getLayerNames()

Returns the array of layer names in this CAD. This array  shouldn't be modified by user. 

void setVisibleLayers(String ... layerNames )

Makes the layers with given names visible and hides all other layers in this CAD. Throws an error if layer(s) with the given name isn't found. To show all the layers, please call setVisibleLayers(getLayerNames())

Parameters:
layerNames - visible layer names

void setLayerVisible
(String layerName, boolean visible)

Makes the layer with the given name visible/invisible.
Throws an error if layer with the given name isn't found.

Parameters:
layerName - the name of the layer
visible - new visibility state of the layer

boolean isLayerVisible
(String layerName)

Returns true if the layer with the given name is visible, otherwise returns false. Returns false if layer with the given name isn't found.

Parameter:
layerName - the name of the layer

Color getCustomLayerColor(String layerName)

Returns custom color of the layer's shapes, if the one is defined. Otherwise returns null. Returns null if layer with the given name isn't found.

Parameter:
layerName - the name of the layer

void setCustomLayerColor(String layerName, color)

Sets custom color for all the shapes for the given layer. The value of null indicates that layer will be drawn using its default color(s).Throws an error if layer with the given name isn't found.

Parameters:
layerName - the name of the layer
color - the value of custom layer color, or null

Background color

Function

Description

Color getBackgroundColor()

Returns the background color.

void setBackgroundColor(Color backgroundColor)

Sets the background color.

Parameter:
backgroundColor - the new background color

Image file name

Function

Description

String getImageFileName()

Returns the file name of the CAD drawing. 

Shape visibility

Function

Description

boolean isVisible()

Checks the visibility of the shape. If the shape is visible, returns true, otherwise returns false.

void setVisible(boolean v)

Sets the visibility of the shape.

Parameter:
v - visibility: if true - the shape is set to be visible, if false - not visible.

Points inside the shape

Function

Description

boolean contains(double px, double py)

Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e. in the same system with the coordinates of this shape, x and y) . Returns true if the shape contains the point with the given coordinates.

Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container

Point randomPointInside()

Returns the randomly chosen point inside the shape area.

This function utilises Random Number Generator of the Presentable object containing this shape. (Will throw an exception if the shape has been created from code and hasn't been added to any group, - in this case use randomPointInside(Random rng)).

Point randomPointInside
(java.util.Random rng)

Returns the randomly chosen point inside the shape area. This function utilises the given Random Number Generator. 

Parameter:
rng - the random number generator.


Related topics

Changing Shape's Position in Stacking Order

           API Reference: ShapeCAD Class