AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, UsdElement, Serializable, Cloneable
Direct Known Subclasses:
Shape3D, ShapeCAD, ShapeCanvas, ShapeControl, ShapeEmbeddedObjectIcon, ShapeInspect, ShapeModelPrimitives, ShapeScale, ShapeSVG

public abstract class Shape
extends Object
implements Locatable2D, Serializable, Cloneable, com.anylogic.engine.internal.Child, SVGElement, UsdElement, LevelElement
The base class for all graphical shapes and also for all controls.
Shapes allow direct programmatic control, i.e. you can change the properties of the shapes explicitly by calling their methods, e.g. setWidth(). Shape also has reference to the group they belong.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Field Summary

Modifier and TypeFieldDescription
static final StringUNKNOWN_NAME
This string is returned by getName() for shapes with unknown names.
The value of this constant depends on the selected Engine language locale

Fields inherited from interface com.anylogic.engine.presentation.UsdElement

ID_NOT_SET

Constructor Summary

ConstructorDescription
Shape() 

Method Summary

Modifier and TypeMethodDescription
booleancanHandleClick(boolean publicOnly)
Checks if the shape can handle mouse clicks in its current condition, namely with current public and visibility settings.
Shapeclone()
Creates and returns a copy of this shape (i.e.
abstract booleancontains(double px, double py)
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e.
voidexecuteUserAction(String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
SVGElementfindSVGElement(long svgId)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
ShapeDrawModegetDrawMode()
Returns the draw mode for this shape.
Either it is drawn in 2D animation only, or in 3D only, or both in 2D and 3D.
ShapeGroupgetGroup()
Returns the group containing this shape.
LevelgetLevel()
Returns the level containing this shape.
StringgetName()
If the shape is declared as field in a presentable object class (Agent or Experiment), e.g.
longgetOrGenerateUSDId() 
PresentablegetPresentable()
Returns the Presentable object (Agent or Experiment) where this shape belongs to, or null.
doublegetRotation()
Returns the rotation of the shape.
doublegetScaleX()
Returns the scale of the shape along x axis
doublegetScaleY()
Returns the scale of the shape along y axis
longgetSVGId()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
longgetUsdVersion() 
doublegetX()
Returns the x coordinate of the shape.
doublegetY()
Returns the y coordinate of the shape.
booleanisJava2DSwingPresentation()
Deprecated.
booleanisPublic_xjal()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
booleanisSVGPresentation()
Deprecated.
booleanisVisible()
Returns the visibility of the shape.
booleanisVisibleCurrently()
Takes into account visibility of the Level
voidonAggregatorVisibilityChanged()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
booleanonClick(double clickx, double clicky)
Should be overridden to define the shape reaction on mouse click.
voidpostSVGShapeSpecificAttributes(List<String> att, List<String> val, boolean publicOnly)
Posts general properties specific to a particular shape class.
PointrandomPointInside()
Returns the randomly chosen point inside the shape area.
This method utilises Random Number Generator of the Presentable object containing this shape.
PointrandomPointInside(Random rng)
Returns the randomly chosen point inside the shape area.
This method utilises the given Random Number Generator.
Throws error if this shape type doesn't support returning random point inside.
voidremoveSVGFromOwner(Shape oldOwner)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
final voidremoveSVGImage(List<SVGCommand> commands) 
voidresetSVGState()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
voidrestoreOwner(Object owner)
Deprecated.
voidsetChangedUsdVersion() 
voidsetLevel(Level level)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
voidsetNextChangedUsdVersion()
Used in changes during user interactive actions (that can happen during frame collecting)
voidsetPos(double x, double y)
Sets both coordinates of the shape
voidsetPos(Point p)
Sets both coordinates of the shape
voidsetPublic_xjal(boolean ispublic)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
voidsetRotation(double r)
Sets the rotation of the shape.
voidsetScale(double s)
Sets the same scale of the shape along all the axes
voidsetScale(double sx, double sy)
Sets the scales of the shape along both axes
voidsetScaleX(double sx)
Sets the scale of the shape along x axis
voidsetScaleY(double sy)
Sets the scale of the shape along y axis
voidsetVisible(boolean v)
Sets the visibility of the shape.
voidsetX(double x)
Sets the x coordinate of the shape
voidsetY(double y)
Sets the y coordinate of the shape
voidupdateDynamicProperties()
Updates dynamic properties of this shape only (without structural contents, if any) in a given context.
Method should be overridden for shapes with dynamic properties.
booleanupdateDynamicPropertiesStructural(boolean publicOnly) 
SVGElementupdateSVGProperties(List<SVGCommand> output, ShapeDrawMode drawMode, boolean publicOnly, SVGElement owner, SVGElement elbehind)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Updates SVG properties of the element that are then sent to the rendering client.

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

initializeInternal, postInitialize

Field Details

UNKNOWN_NAME

public static final String UNKNOWN_NAME
This string is returned by getName() for shapes with unknown names.
The value of this constant depends on the selected Engine language locale
See Also:
getName()Light3D.getName()

Constructor Details

Shape

public Shape()

Method Details

getDrawMode

public ShapeDrawMode getDrawMode()
Returns the draw mode for this shape.
Either it is drawn in 2D animation only, or in 3D only, or both in 2D and 3D.
Returns:
the draw mode for this shape

onAggregatorVisibilityChanged

public void onAggregatorVisibilityChanged()
Description copied from interface: AggregatableAnimationElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
onAggregatorVisibilityChanged in interface AggregatableAnimationElement

setVisible

public void setVisible(boolean v)
Sets the visibility of the shape.
Parameters:
v - visibility: true - visible, false - not

isVisibleCurrently

@AnyLogicInternalCodegenAPI
public boolean isVisibleCurrently()
Takes into account visibility of the Level

isVisible

public boolean isVisible()
Returns the visibility of the shape. Note that Level containing the element may be invisible, and this method only returns the own state of the element.
Returns:
visibility: true - visible, false - not

setX

public void setX(double x)
Sets the x coordinate of the shape
Parameters:
x - the new value of x coordinate

getX

public double getX()
Returns the x coordinate of the shape.
Specified by:
getX in interface Locatable2D
Returns:
the x coordinate of the shape

setY

public void setY(double y)
Sets the y coordinate of the shape
Parameters:
y - the new value of y coordinate

getY

public double getY()
Returns the y coordinate of the shape.
Specified by:
getY in interface Locatable2D
Returns:
the y coordinate of the shape

setPos

public void setPos(double x,
 double y)
Sets both coordinates of the shape
Parameters:
x - the new value of x coordinate
y - the new value of y coordinate

setPos

public void setPos(Point p)
Sets both coordinates of the shape
Parameters:
p - the Point object containing coordinates

getUsdVersion

public long getUsdVersion()

setChangedUsdVersion

@AnyLogicInternalAPI
public void setChangedUsdVersion()

setNextChangedUsdVersion

@AnyLogicInternalAPI
public void setNextChangedUsdVersion()
Used in changes during user interactive actions (that can happen during frame collecting)

randomPointInside

public Point randomPointInside()
Returns the randomly chosen point inside the shape area.
This method 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 such case please use randomPointInside(Random)).
Returns null if the shape has no points (e.g. polyline with no points)
Throws error if this shape type doesn't support returning random point inside.
Returns:
the randomly chosen point inside the shape area

randomPointInside

public Point randomPointInside(Random rng)
Returns the randomly chosen point inside the shape area.
This method utilises the given Random Number Generator.
Throws error if this shape type doesn't support returning random point inside.
Parameters:
rng - the random number generator.
Returns:
the randomly chosen point inside the shape area.

setRotation

public void setRotation(double r)
Sets the rotation of the shape.
Parameters:
r - the new value of rotation in radians

getRotation

public double getRotation()
Returns the rotation of the shape.
Returns:
the rotation of the shape in radians, clockwise

setScaleX

public void setScaleX(double sx)
Sets the scale of the shape along x axis
Parameters:
sx - the new value of scale along x axis, 1 = keep original size

getScaleX

public double getScaleX()
Returns the scale of the shape along x axis
Returns:
the scale of the shape along x axis, 1 = keep original size

setScaleY

public void setScaleY(double sy)
Sets the scale of the shape along y axis
Parameters:
sy - the new value of scale along y axis, 1 = keep original size

getScaleY

public double getScaleY()
Returns the scale of the shape along y axis
Returns:
the scale of the shape along y axis, 1 = keep original size

setScale

public void setScale(double sx,
 double sy)
Sets the scales of the shape along both axes
Parameters:
sx - the new value of scale along x axis, 1 = keep original size
sy - the new value of scale along y axis, 1 = keep original size

setScale

public void setScale(double s)
Sets the same scale of the shape along all the axes
Parameters:
s - the new value of scale along all the axes, 1 = keep original size

getGroup

public ShapeGroup getGroup()
Returns the group containing this shape.
Returns:
the group containing this shape

getLevel

public Level getLevel()
Returns the level containing this shape. The returned value is null for shapes in the experiments.
Specified by:
getLevel in interface HasLevel
Returns:
the level containing this shape

setLevel

@AnyLogicInternalAPI
public void setLevel(Level level)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. Please use Level.add(Shape) instead.
Specified by:
setLevel in interface LevelElement

getName

public String getName()
If the shape is declared as field in a presentable object class (Agent or Experiment), e.g. if it was drawn in the graphical editor, returns the name of the field, otherwise returns the string UNKNOWN_NAME. For replicated shapes returns the name of the field with the index of the shape in square brackets.
This method is designed to be used for debug/development purposes only. It has a very inefficient implementation
Returns:
the name of the corresponding field or UNKNOWN_NAME

getPresentable

public Presentable getPresentable()
Returns the Presentable object (Agent or Experiment) where this shape belongs to, or null.
Returns:
the Presentable that owns this shape, or null

canHandleClick

@AnyLogicLegacyAPI
public boolean canHandleClick(boolean publicOnly)
Checks if the shape can handle mouse clicks in its current condition, namely with current public and visibility settings.
Parameters:
publicOnly - if true, non public shape would not handle clicks
Returns:
true if a click can be handled, otherwise false

onClick

@AnyLogicInternalCodegenAPI
public boolean onClick(double clickx,
 double clicky)
Should be overridden to define the shape reaction on mouse click. The click coordinates are definitely within the shape bounds if this method is called. By default, does nothing and returns false.
Parameters:
clickx - the x coordinate of the click relative to the shape
clicky - the y coordinate of the click relative to the shape
Returns:
return true to indicate that this shape is a part of agent's icon and define user's interaction with icon in model runtime. Single click will display agent's inspect window, while double click will open the agent's presentation in the model window.

contains

public abstract 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)
Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container
Returns:
true if the shape contains the point with the given coordinates

updateDynamicProperties

@AnyLogicInternalCodegenAPI
public void updateDynamicProperties()
Updates dynamic properties of this shape only (without structural contents, if any) in a given context.
Method should be overridden for shapes with dynamic properties. Note that you should call super.updateDynamicProperties() at the end of overridden method
Parameters:
publicOnly - if true, the shape is only updated if it is public

updateDynamicPropertiesStructural

@AnyLogicInternalAPI
public boolean updateDynamicPropertiesStructural(boolean publicOnly)
Returns:
true if:
1. update was done (usually for visible elements, respecting public flag etc.)
AND
2. further update of structural changes is applicable

restoreOwner

@AnyLogicInternalCodegenAPI
@Deprecated
public void restoreOwner(Object owner)
Deprecated.
This method normally should not be called by user
This method restores owner of this object
The method is used in snapshot saving/loading
Specified by:
restoreOwner in interface com.anylogic.engine.internal.Child
Parameters:
owner - owner of this object, usually Agent, Experiment or ShapeGroup

clone

public Shape clone()
Creates and returns a copy of this shape (i.e. new shape instance).
The returned shape is the object of the same class
The returned copy isn't automatically added to the group this shape belongs to.
The clone is created in the context of the same experiment or agent

Note that cloning of GIS shape, controls and charts is not supported

setPublic_xjal

@AnyLogicInternalAPI
public void setPublic_xjal(boolean ispublic)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.

isPublic_xjal

@AnyLogicInternalAPI
public boolean isPublic_xjal()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.

getSVGId

@AnyLogicInternalAPI
public long getSVGId()
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
getSVGId in interface SVGElement

getOrGenerateUSDId

@AnyLogicInternalAPI
public long getOrGenerateUSDId()
Specified by:
getOrGenerateUSDId in interface UsdElement

isJava2DSwingPresentation

@AnyLogicInternalAPI
@Deprecated
public boolean isJava2DSwingPresentation()
Deprecated.
Tests if the model is running with Java 2D/Swing presentation. Returns true if yes, returns false if not or if it is not possible to determine (e.g. in early static stages of agent initialization)
Returns:
true if running Java2D/Swing, false if not or not known yet

isSVGPresentation

@AnyLogicInternalAPI
@Deprecated
public boolean isSVGPresentation()
Deprecated.
Tests if the model is running with SVG presentation. Returns true if yes, returns false if not or if it is not possible to determine (e.g. in early static stages of agent initialization)
Returns:
true if running with SVG presentation, false if not or not known yet

updateSVGProperties

@AnyLogicInternalAPI
public SVGElement updateSVGProperties(List<SVGCommand> output,
 ShapeDrawMode drawMode,
 boolean publicOnly,
 SVGElement owner,
 SVGElement elbehind)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Updates SVG properties of the element that are then sent to the rendering client. If the element is not yet in the SVG scene, generates "C" command, if it is there, but some properties are out of date, generates "U" command. If SVG drawing of this element is not needed because of public only settings, or permanently not needed, or not supported yet, returns false and does nothing.
Specified by:
updateSVGProperties in interface SVGElement
Parameters:
output - the list of commands to add to
drawMode - TODO
publicOnly - drawing context: if true, only shapes that are marked as public only are updated
owner - the SVG element that serves as a container for this element
elbehind - the SVG element behind this one, or null if none or if order is irrelevant
Returns:
the actual owner this element has been added to or null if element is not drawn (e.g. drawing of this element is not needed because of public only settings, permanently not needed or not supported - hence SVG id is not set). The actual owner may differ from the given owner when the svg element is added to a different place (e.g. GIS map).

removeSVGImage

@AnyLogicInternalAPI
public final void removeSVGImage(List<SVGCommand> commands)

resetSVGState

@AnyLogicInternalAPI
public void resetSVGState()
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
resetSVGState in interface SVGElement

postSVGShapeSpecificAttributes

@AnyLogicInternalAPI
public void postSVGShapeSpecificAttributes(List<String> att,
 List<String> val,
 boolean publicOnly)
Posts general properties specific to a particular shape class. Is triggered by SVG_DIRTY_SHAPE flag. Made public for occasional posting of additional SVG properties from outside engine (e.g. from libraries)
Parameters:
att - attribute names
val - attribute values
publicOnly - TODO

findSVGElement

@AnyLogicInternalAPI
public SVGElement findSVGElement(long svgId)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
findSVGElement in interface SVGElement

executeUserAction

@AnyLogicInternalAPI
public void executeUserAction(String value)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
executeUserAction in interface SVGElement

removeSVGFromOwner

@AnyLogicInternalAPI
public void removeSVGFromOwner(Shape oldOwner)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
removeSVGFromOwner in interface SVGElement
Parameters:
oldOwner - may be null