CpsUpperNode.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package classes;
  2. import com.google.gson.annotations.Expose;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. public class CpsUpperNode extends AbstractCpsObject {
  6. private ArrayList<AbstractCpsObject> nodes;
  7. private ArrayList<CpsEdge> nodeEdges;
  8. private ArrayList<CpsEdge> oldEdges;
  9. private HashMap<Integer, Integer> nodesIdx;
  10. @Expose
  11. private int leftBorder;
  12. @Expose
  13. private String imgPath = "";
  14. @Expose
  15. private int backgroundMode = 0;
  16. @Expose
  17. private int backgroundWidth = 0;
  18. @Expose
  19. private int backgroundHeight = 0;
  20. public CpsUpperNode(String nodeName) {
  21. super(nodeName);
  22. this.setConnections(new ArrayList<>());
  23. this.setImage("/Images/upper_node.png");
  24. this.setSav("CVS");
  25. this.setId(IdCounter.nextId());
  26. this.setNodes(new ArrayList<>());
  27. this.setNodeEdges(new ArrayList<>());
  28. this.setOldEdges(new ArrayList<>());
  29. this.setNodesIdx(new HashMap<>());
  30. }
  31. /**
  32. * @return the nodes
  33. */
  34. public ArrayList<AbstractCpsObject> getNodes() {
  35. return nodes;
  36. }
  37. /**
  38. * @param nodes
  39. * the nodes to set
  40. */
  41. public void setNodes(ArrayList<AbstractCpsObject> nodes) {
  42. this.nodes = nodes;
  43. }
  44. /**
  45. * @return the nodeEdges
  46. */
  47. public ArrayList<CpsEdge> getNodeEdges() {
  48. return nodeEdges;
  49. }
  50. /**
  51. * @param nodeEdges
  52. * the nodeEdges to set
  53. */
  54. public void setNodeEdges(ArrayList<CpsEdge> nodeEdges) {
  55. this.nodeEdges = nodeEdges;
  56. }
  57. /**
  58. * @return the oldEdges
  59. */
  60. public ArrayList<CpsEdge> getOldEdges() {
  61. return oldEdges;
  62. }
  63. /**
  64. * @param oldEdges
  65. * the oldEdges to set
  66. */
  67. public void setOldEdges(ArrayList<CpsEdge> oldEdges) {
  68. this.oldEdges = oldEdges;
  69. }
  70. /**
  71. * @return the nodesIdx
  72. */
  73. public HashMap<Integer, Integer> getNodesIdx() {
  74. return nodesIdx;
  75. }
  76. /**
  77. * @param nodesIdx
  78. * the nodesIdx to set
  79. */
  80. public void setNodesIdx(HashMap<Integer, Integer> nodesIdx) {
  81. this.nodesIdx = nodesIdx;
  82. }
  83. public ArrayList<HolonObject> getNumHolonObj() {
  84. ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
  85. for (AbstractCpsObject temp : getNodes()) {
  86. if (temp instanceof HolonObject) {
  87. onlyHolonObj.add((HolonObject) temp);
  88. }
  89. }
  90. return onlyHolonObj;
  91. }
  92. public ArrayList<HolonSwitch> getNumSwitches() {
  93. ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
  94. for (AbstractCpsObject temp : getNodes()) {
  95. if (temp instanceof HolonSwitch) {
  96. onlySwitsches.add((HolonSwitch) temp);
  97. }
  98. }
  99. return onlySwitsches;
  100. }
  101. public ArrayList<CpsUpperNode> getNumUpperNodes() {
  102. ArrayList<CpsUpperNode> onlyUpperNodes = new ArrayList<CpsUpperNode>();
  103. for (AbstractCpsObject temp : getNodes()) {
  104. if (temp instanceof CpsUpperNode) {
  105. onlyUpperNodes.add((CpsUpperNode) temp);
  106. }
  107. }
  108. return onlyUpperNodes;
  109. }
  110. public AbstractCpsObject searchObj(int ID) {
  111. AbstractCpsObject result = null;
  112. for (AbstractCpsObject obj : getNodes()) {
  113. if (obj.getId() == ID) {
  114. result = obj;
  115. break;
  116. }
  117. }
  118. return result;
  119. }
  120. /**
  121. * Set the Background Image;
  122. *
  123. * @param imagePath
  124. * Image Path
  125. * @param mode
  126. * Image Mode
  127. * @param width
  128. * Image custom width
  129. * @param height
  130. * Image custom height
  131. */
  132. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  133. imgPath = imagePath;
  134. backgroundMode = mode;
  135. backgroundWidth = width;
  136. backgroundHeight = height;
  137. }
  138. /**
  139. * Get the Background Image Path.
  140. *
  141. * @return imgPath Path of the Image
  142. */
  143. public String getImagePath() {
  144. return imgPath;
  145. }
  146. /**
  147. * Get the Background mode.
  148. *
  149. * @return mode the mode
  150. */
  151. public int getBackgroundMode() {
  152. return backgroundMode;
  153. }
  154. /**
  155. * Get the Background image Width.
  156. *
  157. * @return mode the width of the Image
  158. */
  159. public int getImageWidht() {
  160. return backgroundWidth;
  161. }
  162. /**
  163. * Get the Background image Height.
  164. *
  165. * @return mode the mode
  166. */
  167. public int getImageHeight() {
  168. return backgroundHeight;
  169. }
  170. /**
  171. * @return the leftBorder
  172. */
  173. public int getLeftBorder() {
  174. return leftBorder;
  175. }
  176. /**
  177. * @param leftBorder the leftBorder to set
  178. */
  179. public void setLeftBorder(int leftBorder) {
  180. this.leftBorder = leftBorder;
  181. }
  182. }