AbstractCanvasObject.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package holeg.model;
  2. import java.util.Optional;
  3. import com.google.gson.annotations.Expose;
  4. import holeg.ui.model.IdCounter;
  5. import holeg.ui.model.IdCounter.CounterType;
  6. import holeg.utility.math.vector.Vec2i;
  7. /**
  8. * The abstract class "CpsObject" represents any possible object in the system
  9. * (except Edges). The representation of any object contains following
  10. * variables: see description of variables
  11. *
  12. * @author Gruppe14
  13. *
  14. */
  15. public abstract class AbstractCanvasObject {
  16. /* Type of the Object. */
  17. @Expose
  18. String objName;
  19. /* Name given by the user. */
  20. @Expose
  21. String name;
  22. /* ID of the Obj. */
  23. @Expose
  24. private int id;
  25. /* Path of the image for the Obj. */
  26. @Expose
  27. String image;
  28. /* Position with a X and Y value */
  29. @Expose
  30. Vec2i position = new Vec2i(0,0);
  31. //TODO(Tom2022-01-11): Saving should be removed
  32. @Expose
  33. String sav;
  34. private Optional<GroupNode> groupNode = Optional.empty();
  35. /**
  36. * Constructor for a CpsObejct with an unique ID.
  37. *
  38. * @param objName
  39. * of the Object
  40. */
  41. public AbstractCanvasObject(String objName) {
  42. setName(objName);
  43. this.id = IdCounter.nextId(CounterType.Object);
  44. }
  45. public void setGroupNode(GroupNode groupNode) {
  46. this.groupNode = Optional.of(groupNode);
  47. }
  48. public Optional<GroupNode> getGroupNode() {
  49. return groupNode;
  50. }
  51. /**
  52. * Constructor for a new CpsObject with an unique ID (This constructor
  53. * correspond to the interaction between the Categories and Canvas)-->
  54. * actually the "new" Object is a copy.
  55. *
  56. * @param obj
  57. * Object to be copied
  58. */
  59. public AbstractCanvasObject(AbstractCanvasObject obj) {
  60. setName(obj.getName());
  61. setImage(obj.getImage());
  62. this.id = IdCounter.nextId(CounterType.Object);
  63. }
  64. public abstract void initForReflection();
  65. /**
  66. * Getter for the user-defined name (no unique).
  67. *
  68. * @return String
  69. */
  70. public String getName() {
  71. return name;
  72. }
  73. /**
  74. * Set the name.
  75. *
  76. * @param name
  77. * String
  78. */
  79. public void setName(String name) {
  80. this.name = name;
  81. }
  82. /**
  83. * Get the path of the image for the selected Object.
  84. *
  85. * @return String
  86. */
  87. public String getImage() {
  88. return image;
  89. }
  90. /**
  91. * Set the path of the image.
  92. *
  93. * @param image
  94. * the Image to set
  95. */
  96. public void setImage(String image) {
  97. this.image = image;
  98. }
  99. public int getId() {
  100. return id;
  101. }
  102. /**
  103. * Set the position of the Object in the canvas.
  104. *
  105. * @param x
  106. * X-Coord
  107. * @param y
  108. * Y-Coord
  109. */
  110. public void setPosition(int x, int y) {
  111. setPosition(new Vec2i(x, y));
  112. }
  113. /**
  114. * Get the actual position of the Object.
  115. *
  116. * @return Position Position of this Object
  117. */
  118. public Vec2i getPosition() {
  119. return position;
  120. }
  121. /**
  122. * Set the position of the Object in the canvas.
  123. *
  124. * @param pos Coordinates
  125. */
  126. public void setPosition(Vec2i pos) {
  127. this.position = pos;
  128. }
  129. /**
  130. * For save purpose.
  131. *
  132. * @return the stored
  133. */
  134. public String getSav() {
  135. return sav;
  136. }
  137. /**
  138. * For save purpose.
  139. *
  140. * @param sav
  141. * the stored to set
  142. */
  143. //TODO(Tom2021-12-1): Remove SAV
  144. public void setSav(String sav) {
  145. this.sav = sav;
  146. }
  147. }