package holeg.model; import java.util.Optional; import com.google.gson.annotations.Expose; import holeg.ui.model.IdCounter; import holeg.ui.model.IdCounter.CounterType; import holeg.utility.math.vector.Vec2i; /** * The abstract class "CpsObject" represents any possible object in the system * (except Edges). The representation of any object contains following * variables: see description of variables * * @author Gruppe14 * */ public abstract class AbstractCanvasObject { /* Type of the Object. */ @Expose String objName; /* Name given by the user. */ @Expose String name; /* ID of the Obj. */ @Expose private int id; /* Path of the image for the Obj. */ @Expose String image; /* Position with a X and Y value */ @Expose Vec2i position = new Vec2i(0,0); //TODO(Tom2022-01-11): Saving should be removed @Expose String sav; private Optional groupNode = Optional.empty(); /** * Constructor for a CpsObejct with an unique ID. * * @param objName * of the Object */ public AbstractCanvasObject(String objName) { setName(objName); this.id = IdCounter.nextId(CounterType.Object); } public void setGroupNode(GroupNode groupNode) { this.groupNode = Optional.of(groupNode); } public Optional getGroupNode() { return groupNode; } /** * Constructor for a new CpsObject with an unique ID (This constructor * correspond to the interaction between the Categories and Canvas)--> * actually the "new" Object is a copy. * * @param obj * Object to be copied */ public AbstractCanvasObject(AbstractCanvasObject obj) { setName(obj.getName()); setImage(obj.getImage()); this.id = IdCounter.nextId(CounterType.Object); } public abstract void initForReflection(); /** * Getter for the user-defined name (no unique). * * @return String */ public String getName() { return name; } /** * Set the name. * * @param name * String */ public void setName(String name) { this.name = name; } /** * Get the path of the image for the selected Object. * * @return String */ public String getImage() { return image; } /** * Set the path of the image. * * @param image * the Image to set */ public void setImage(String image) { this.image = image; } public int getId() { return id; } /** * Set the position of the Object in the canvas. * * @param x * X-Coord * @param y * Y-Coord */ public void setPosition(int x, int y) { setPosition(new Vec2i(x, y)); } /** * Get the actual position of the Object. * * @return Position Position of this Object */ public Vec2i getPosition() { return position; } /** * Set the position of the Object in the canvas. * * @param pos Coordinates */ public void setPosition(Vec2i pos) { this.position = pos; } /** * For save purpose. * * @return the stored */ public String getSav() { return sav; } /** * For save purpose. * * @param sav * the stored to set */ //TODO(Tom2021-12-1): Remove SAV public void setSav(String sav) { this.sav = sav; } }