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

public abstract class Shape
extends java.lang.Object
implements Locatable2D, java.io.Serializable, java.lang.Cloneable, com.anylogic.engine.internal.Child, SVGElement, 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

Fields 
static java.lang.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
Modifier and Type Field Description

Constructor Summary

Constructors 
Shape()  
Constructor Description

Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
boolean canHandleClick​(boolean publicOnly)
Checks if the shape can handle mouse clicks in its current condition, namely with current public and visibility settings.
Shape clone()
Creates and returns a copy of this shape (i.e.
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.
void executeUserAction​(java.lang.String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
SVGElement findSVGElement​(long svgId)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
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.
ShapeGroup getGroup()
Returns the group containing this shape.
Level getLevel()
Returns the level containing this shape.
java.lang.String getName()
If the shape is declared as field in a presentable object class (Agent or Experiment), e.g.
Presentable getPresentable()
Returns the Presentable object (Agent or Experiment) where this shape belongs to, or null.
double getRotation()
Returns the rotation of the shape.
double getScaleX()
Returns the scale of the shape along x axis
double getScaleY()
Returns the scale of the shape along y axis
long getSVGId()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
double getX()
Returns the x coordinate of the shape.
double getY()
Returns the y coordinate of the shape.
boolean isJava2DSwingPresentation()
Deprecated.
boolean isPublic_xjal()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
boolean isSVGPresentation()
Deprecated.
boolean isVisible()
Returns the visibility of the shape.
void onAggregatorVisibilityChanged()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
boolean onClick​(double clickx, double clicky)
Should be overridden to define the shape reaction on mouse click.
void postSVGShapeSpecificAttributes​(java.util.List<java.lang.String> att, java.util.List<java.lang.String> val, boolean publicOnly)
Posts general properties specific to a particular shape class.
Point randomPointInside()
Returns the randomly chosen point inside the shape area.
This method utilises Random Number Generator of the Presentable object containing this shape.
Point randomPointInside​(java.util.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.
void removeSVGFromOwner​(Shape oldOwner)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
void removeSVGImage​(java.util.List<SVGCommand> commands)  
void resetSVGState()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
void restoreOwner​(java.lang.Object owner)
Deprecated.
void setLevel​(Level level)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
void setPos​(double x, double y)
Sets both coordinates of the shape
void setPos​(Point p)
Sets both coordinates of the shape
void setPublic_xjal​(boolean ispublic)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
void setRotation​(double r)
Sets the rotation of the shape.
void setScale​(double s)
Sets the same scale of the shape along all the axes
void setScale​(double sx, double sy)
Sets the scales of the shape along both axes
void setScaleX​(double sx)
Sets the scale of the shape along x axis
void setScaleY​(double sy)
Sets the scale of the shape along y axis
void setVisible​(boolean v)
Sets the visibility of the shape.
void setX​(double x)
Sets the x coordinate of the shape
void setY​(double y)
Sets the y coordinate of the shape
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.
boolean updateDynamicPropertiesStructural​(boolean publicOnly)  
SVGElement updateSVGProperties​(java.util.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.
Modifier and Type Method Description

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 Detail

UNKNOWN_NAME

public static final java.lang.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 Detail

Shape

public Shape()

Method Detail

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

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

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​(java.util.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 java.lang.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​(java.lang.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

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​(java.util.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​(java.util.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​(java.util.List<java.lang.String> att,
                                           java.util.List<java.lang.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​(java.lang.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
How can we improve this article?