Package com.anylogic.engine.presentation
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getDrawMode
- onAggregatorVisibilityChanged
- setVisible
- isVisible
- setX
- getX
- setY
- getY
- setPos
- setPos
- randomPointInside
- randomPointInside
- setRotation
- getRotation
- setScaleX
- getScaleX
- setScaleY
- getScaleY
- setScale
- setScale
- getGroup
- getLevel
- setLevel
- getName
- getPresentable
- canHandleClick
- onClick
- contains
- updateDynamicProperties
- updateDynamicPropertiesStructural
- restoreOwner
- clone
- setPublic_xjal
- isPublic_xjal
- getSVGId
- isJava2DSwingPresentation
- isSVGPresentation
- updateSVGProperties
- removeSVGImage
- resetSVGState
- postSVGShapeSpecificAttributes
- findSVGElement
- executeUserAction
- removeSVGFromOwner
- java.lang.Object
- com.anylogic.engine.presentation.Shape
- All Implemented Interfaces:
com.anylogic.engine.internal.Child
,Locatable2D
,AggregatableAnimationElement
,HasLevel
,LevelElement
,SVGElement
,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, 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.
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
Modifier and Type | Field | Description |
---|---|---|
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 |
Constructor | Description |
---|---|
Shape() |
Modifier and Type | Method | Description |
---|---|---|
boolean | canHandleClick |
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 |
Test if the shape contains the point with the given coordinates
(relative to this shape's container, i.e.
|
void | executeUserAction |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
SVGElement | findSVGElement |
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.
|
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 |
Should be overridden to define the shape reaction on mouse click.
|
void | postSVGShapeSpecificAttributes |
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 |
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 |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
final void | removeSVGImage | |
void | resetSVGState() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void | restoreOwner |
Deprecated.
|
void | setLevel |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void | setPos |
Sets both coordinates of the shape
|
void | setPos |
Sets both coordinates of the shape
|
void | setPublic_xjal |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void | setRotation |
Sets the rotation of the shape.
|
void | setScale |
Sets the same scale of the shape along all the axes
|
void | setScale |
Sets the scales of the shape along both axes
|
void | setScaleX |
Sets the scale of the shape along x axis
|
void | setScaleY |
Sets the scale of the shape along y axis
|
void | setVisible |
Sets the visibility of the shape.
|
void | setX |
Sets the x coordinate of the shape
|
void | setY |
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 | |
SVGElement | updateSVGProperties |
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. |
public static final String UNKNOWN_NAME
This string is returned by
The value of this constant depends on the selected Engine language locale
getName()
for shapes with unknown names.The value of this constant depends on the selected Engine language locale
- See Also:
-
getName()
Light3D.getName()
public Shape()
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.
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
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.
it may be removed/renamed in future.
- Specified by:
onAggregatorVisibilityChanged
in interfaceAggregatableAnimationElement
public void setVisible(boolean v)
Sets the visibility of the shape.
- Parameters:
v
- visibility:true
- visible,false
- not
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
public void setX(double x)
Sets the x coordinate of the shape
- Parameters:
x
- the new value of x coordinate
public double getX()
Returns the x coordinate of the shape.
- Specified by:
getX
in interfaceLocatable2D
- Returns:
- the x coordinate of the shape
public void setY(double y)
Sets the y coordinate of the shape
- Parameters:
y
- the new value of y coordinate
public double getY()
Returns the y coordinate of the shape.
- Specified by:
getY
in interfaceLocatable2D
- Returns:
- the y coordinate of the shape
public void setPos(double x, double y)
Sets both coordinates of the shape
- Parameters:
x
- the new value of x coordinatey
- the new value of y coordinate
public void setPos(Point p)
Sets both coordinates of the shape
- Parameters:
p
- the Point object containing coordinates
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
Returns
Throws error if this shape type doesn't support returning random point inside.
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
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.
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.
public void setRotation(double r)
Sets the rotation of the shape.
- Parameters:
r
- the new value of rotation in radians
public double getRotation()
Returns the rotation of the shape.
- Returns:
- the rotation of the shape in radians, clockwise
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
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
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
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
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 sizesy
- the new value of scale along y axis, 1 = keep original size
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
public ShapeGroup getGroup()
Returns the group containing this shape.
- Returns:
- the group containing this shape
public Level getLevel()
Returns the level containing this shape.
The returned value is
null
for shapes in the experiments.@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
it may be removed/renamed in future. Please use
Level.add(Shape)
instead.- Specified by:
setLevel
in interfaceLevelElement
public String getName()
If the shape is declared as field in a presentable object class
(
This method is designed to be used for debug/development purposes only. It has a very inefficient implementation
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
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
@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
- iftrue
, non public shape would not handle clicks- Returns:
true
if a click can be handled, otherwisefalse
@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 shapeclicky
- 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.
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 containerpy
- the y coordinate relative to this shape's container- Returns:
true
if the shape contains the point with the given coordinates
@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
Method should be overridden for shapes with dynamic properties. Note that you should call super.updateDynamicProperties() at the end of overridden method
- Parameters:
publicOnly
- iftrue
, the shape is only updated if it is public
@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
@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
This method restores owner of this object
The method is used in snapshot saving/loading
- Specified by:
restoreOwner
in interfacecom.anylogic.engine.internal.Child
- Parameters:
owner
- owner of this object, usuallyAgent
,Experiment
orShapeGroup
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
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
@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.
it may be removed/renamed in future.
@AnyLogicInternalAPI public boolean isPublic_xjal()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@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.
it may be removed/renamed in future.
- Specified by:
getSVGId
in interfaceSVGElement
@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
@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
@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.
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 interfaceSVGElement
- Parameters:
output
- the list of commands to add todrawMode
- TODOpublicOnly
- drawing context: if true, only shapes that are marked as public only are updatedowner
- the SVG element that serves as a container for this elementelbehind
- 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 givenowner
when the svg element is added to a different place (e.g. GIS map).
@AnyLogicInternalAPI public final void removeSVGImage(List<SVGCommand> commands)
@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.
it may be removed/renamed in future.
- Specified by:
resetSVGState
in interfaceSVGElement
@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 namesval
- attribute valuespublicOnly
- TODO
@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.
it may be removed/renamed in future.
- Specified by:
findSVGElement
in interfaceSVGElement
@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.
it may be removed/renamed in future.
- Specified by:
executeUserAction
in interfaceSVGElement
@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.
it may be removed/renamed in future.
- Specified by:
removeSVGFromOwner
in interfaceSVGElement
- Parameters:
oldOwner
- may benull