us.ihmc.scs2.definition.yoGraphic.YoGraphicPolygon2DDefinition Maven / Gradle / Ivy
package us.ihmc.scs2.definition.yoGraphic;
import java.util.List;
import java.util.Objects;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import us.ihmc.scs2.definition.yoComposite.YoTuple2DDefinition;
/**
* A {@code YoGraphicPolygon2DDefinition} is a template for creating 2D polygon and which components
* can be backed by {@code YoVariable}s.
*
*
* A 2D yoGraphic is rendered in the overhead plotter panel and it can be back by
* {@code YoVariable}s allowing it to move and change at runtime.
*
*
* The {@code YoGraphicLine2DDefinition} is to be passed before initialization of a session (either
* before starting a simulation or when creating a yoVariable server), such that the SCS GUI can use
* the definitions and create the actual graphics.
*
*
* See {@link YoGraphicDefinitionFactory} for factory methods simplifying the creation of yoGraphic
* definitions.
*
*
* @author Sylvain Bertrand
*/
@XmlRootElement(name = "YoGraphicPolygon2D")
public class YoGraphicPolygon2DDefinition extends YoGraphic2DDefinition
{
/** The list of vertices for the polygon. */
private List vertices;
/** The number of vertices to use in the list {@link #vertices} or {@code null} to use all. */
private String numberOfVertices;
/**
* Creates a new yoGraphic definition for rendering a line.
*
* Its components need to be initialized. See {@link YoGraphicDefinitionFactory} for factories to
* facilitate creation.
*
*/
public YoGraphicPolygon2DDefinition()
{
registerListField("vertices", this::getVertices, this::setVertices, "v", Object::toString, YoTuple2DDefinition::parse);
registerStringField("numberOfVertices", this::getNumberOfVertices, this::setNumberOfVertices);
}
/**
* Sets the vertices for the polygon.
*
* @param vertices the vertices for the polygon.
*/
@XmlElement
public void setVertices(List vertices)
{
this.vertices = vertices;
}
/**
* Sets the number of vertices to use in the list of vertices.
*
* Using this method allows to back the number of vertices with a {@code YoVariable} by giving the
* variable name/fullname.
*
*
* @param numberOfVertices the number of vertices to use.
*/
@XmlElement
public void setNumberOfVertices(String numberOfVertices)
{
this.numberOfVertices = numberOfVertices;
}
public List getVertices()
{
return vertices;
}
public String getNumberOfVertices()
{
return numberOfVertices;
}
@Override
public boolean equals(Object object)
{
if (object == this)
{
return true;
}
else if (!super.equals(object))
{
return false;
}
else if (object instanceof YoGraphicPolygon2DDefinition other)
{
if (!Objects.equals(vertices, other.vertices))
return false;
if (!Objects.equals(numberOfVertices, other.numberOfVertices))
return false;
return true;
}
else
{
return false;
}
}
@Override
public String toString(int indent)
{
String out = "%s [name=%s, visible=%b, fillColor=%s, strokeColor=%s, strokeWidth=%s, vertices=%s, numberOfVertices=%s]";
return out.formatted(getClass().getSimpleName(),
name,
visible,
fillColor,
strokeColor,
strokeWidth,
indentedListString(indent, true, vertices, Object::toString),
numberOfVertices);
}
}