Model.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. package ui.model;
  2. import java.awt.Color;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.HashSet;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import java.util.Set;
  9. import java.util.stream.Collectors;
  10. import com.google.gson.Gson;
  11. import com.google.gson.GsonBuilder;
  12. import TypeAdapter.AbstractCpsObjectAdapter;
  13. import TypeAdapter.ColorAdapter;
  14. import TypeAdapter.PairAdapter;
  15. import TypeAdapter.PositionAdapter;
  16. import classes.AbstractCanvasObject;
  17. import classes.Category;
  18. import classes.Edge;
  19. import classes.GroupNode;
  20. import classes.HolonElement;
  21. import classes.HolonObject;
  22. import classes.HolonSwitch;
  23. import classes.Node;
  24. import classes.Pair;
  25. import interfaces.ObjectListener;
  26. import utility.Vector2Int;
  27. /**
  28. * The Class Model is the class where everything is saved. All changes made to
  29. * the Data is managed via a controller.
  30. *
  31. * @author Gruppe14
  32. */
  33. public class Model {
  34. private static final int GRAPH_ITERATIONS = 100;
  35. // Global Variables
  36. private static int sCALE = 50; // Picture Scale
  37. private static int sCALEdIV2 = sCALE / 2;
  38. public String[] colNames = {"Field", "Information"};
  39. // Canvas Attributes
  40. private String imgPath = "";
  41. private int backgroundMode = 0;
  42. private int backgroundWidth = 0;
  43. private int backgroundHeight = 0;
  44. private int canvasX = 3000;
  45. private int canvasY = 3000;
  46. private int curIteration = 0;
  47. private HolonElement selectedHolonElement;
  48. private Edge selectedEdge;
  49. private Set<AbstractCanvasObject> selectedObjects = new HashSet<>();
  50. private Set<AbstractCanvasObject> clipboardObjects = new HashSet<>();
  51. private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
  52. // Capacity for Edge
  53. private float maxCapacity;
  54. // Iteration Speed
  55. private int timerSpeed = 1000;
  56. private int selectedID = 0;
  57. // number of the current autosave
  58. private int autoSaveNr = -1;
  59. // number of max simultaneous autosaves
  60. private int numberOfSaves = 35;
  61. /** whether the supplyBars should be shown or not */
  62. private boolean showSupplyBars = true;
  63. /** the amount of iterations */
  64. private int iterations=100;
  65. /**
  66. * All implemented FairnessModels:<br>
  67. * {@link FairnessModel#MininumDemandFirst}<br>
  68. * {@link FairnessModel#AllEqual}
  69. */
  70. public enum FairnessModel{
  71. /**
  72. * One Element of each HolonObject will be powered first, starting with the
  73. * smallest Demand. If ale HolonObjects have an active Element, the
  74. * simulation will try to fully supply as many HolonObjects as possible.
  75. */
  76. MininumDemandFirst,
  77. /**
  78. * All HolonObjects will receive the same amount of energy.
  79. */
  80. AllEqual
  81. }
  82. /** the Fairness model in use */
  83. private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;
  84. /*
  85. * Array of all categories in the model. It is set by default with the
  86. * categories ENERGY, BUILDINGS and COMPONENTS
  87. */
  88. private ArrayList<Category> categories;
  89. /*
  90. * Array of all CpsObjects in our canvas. It is set by default as an empty
  91. * list.
  92. */
  93. private ArrayList<AbstractCanvasObject> objectsOnCanvas;
  94. private HashMap<String, Integer> cgIdx;
  95. private HashMap<Integer, Integer> cvsObjIdx;
  96. /*
  97. * Array of all CpsObjects in our canvas. It is set by default as an empty
  98. * list.
  99. */
  100. private ArrayList<Edge> edgesOnCanvas;
  101. private ArrayList<HolonObject> holonObjectsOnCanvas = new ArrayList<HolonObject>();
  102. private ArrayList<Node> nodesOnCanvas= new ArrayList<Node>();
  103. private ArrayList<HolonSwitch> switchsOnCanvas= new ArrayList<HolonSwitch>();
  104. private List<ObjectListener> objectListeners;
  105. private HashMap<Integer, GroupNode> hashcodeMap = new HashMap<>();
  106. private Gson gson;
  107. /**
  108. * Constructor for the model. It initializes the categories and
  109. * objectsOnCanvas by default values. Listeners are also initialized by
  110. * default values.
  111. */
  112. public Model() {
  113. setCategories(new ArrayList<>());
  114. setObjectsOnCanvas(new ArrayList<>());
  115. setEdgesOnCanvas(new ArrayList<>());
  116. setObjectListeners(new LinkedList<>());
  117. setCgIdx(new HashMap<>());
  118. setCvsObjIdx(new HashMap<>());
  119. setEleToDelete(new HashMap<>());
  120. initGson();
  121. }
  122. /**
  123. * Returns all Categories.
  124. *
  125. * @return the categories
  126. */
  127. public ArrayList<Category> getCategories() {
  128. return categories;
  129. }
  130. /**
  131. * Sets all Categories.
  132. *
  133. * @param categories the categories to set
  134. */
  135. public void setCategories(ArrayList<Category> categories) {
  136. this.categories = categories;
  137. }
  138. /**
  139. * Transform the Arraylist of categories into a string of all objectName
  140. * with a separation (',') between each name.
  141. *
  142. * @return String of all names separeted by ','
  143. */
  144. public String toStringCat() {
  145. String text = "";
  146. for (int i = 0; i < categories.size(); i++) {
  147. if (text.equals("")) {
  148. text = categories.get(i).getName();
  149. } else {
  150. text = text + ", " + categories.get(i).getName();
  151. }
  152. }
  153. return text;
  154. }
  155. /**
  156. * Returns all Objects on the Canvas.
  157. *
  158. * @return the objectsOnCanvas
  159. */
  160. public ArrayList<AbstractCanvasObject> getObjectsOnCanvas() {
  161. return objectsOnCanvas;
  162. }
  163. /**
  164. * Sets all Objects on the Canvas.
  165. *
  166. * @param objectsOnCanvas the objectsOnCanvas to set
  167. */
  168. public void setObjectsOnCanvas(ArrayList<AbstractCanvasObject> objectsOnCanvas) {
  169. this.objectsOnCanvas = objectsOnCanvas;
  170. }
  171. /**
  172. * Get all Edges on the Canvas.
  173. *
  174. * @return the edgesOnCanvas
  175. */
  176. public ArrayList<Edge> getEdgesOnCanvas() {
  177. return edgesOnCanvas;
  178. }
  179. /**
  180. * Sets the edges on the Canvas.
  181. *
  182. * @param arrayList the edgesOnCanvas to set
  183. */
  184. public void setEdgesOnCanvas(ArrayList<Edge> arrayList) {
  185. this.edgesOnCanvas = arrayList;
  186. }
  187. /**
  188. * Adds an Edge to The Canvas.
  189. *
  190. * @param edge the edgesOnCanvas to add
  191. */
  192. public void addEdgeOnCanvas(Edge edge) {
  193. this.edgesOnCanvas.add(edge);
  194. }
  195. /**
  196. * Remove an edge from the Canvas.
  197. *
  198. * @param edge the edge to remove
  199. */
  200. public void removeEdgesOnCanvas(Edge edge) {
  201. this.edgesOnCanvas.remove(edge);
  202. }
  203. /**
  204. * Returns the ObjectListener.
  205. *
  206. * @return the objectListeners
  207. */
  208. public List<ObjectListener> getObjectListeners() {
  209. return objectListeners;
  210. }
  211. /**
  212. * Sets the ObjectListener.
  213. *
  214. * @param linkedList the objectListeners to set
  215. */
  216. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  217. this.objectListeners = linkedList;
  218. }
  219. /**
  220. * Returns all selected Objects on the Canvas.
  221. *
  222. * @return The selected Objects
  223. */
  224. public Set<AbstractCanvasObject> getSelectedObjects() {
  225. return selectedObjects;
  226. }
  227. /**
  228. * Returns all selected Objects on the Canvas.
  229. *
  230. * @return The selected Objects
  231. */
  232. public void setSelectedCpsObjects(Set<AbstractCanvasObject> arr) {
  233. this.selectedObjects = arr;
  234. }
  235. /**
  236. * Returns the Selected Holon Element.
  237. *
  238. * @return selected Holon Element
  239. */
  240. public HolonElement getSelectedHolonElement() {
  241. return selectedHolonElement;
  242. }
  243. /**
  244. * Sets the Selecte HolonElement.
  245. *
  246. * @param selectedHolonElement that is Selected
  247. */
  248. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  249. this.selectedHolonElement = selectedHolonElement;
  250. }
  251. /**
  252. * Returns the sCale (Scale for the Images).
  253. *
  254. * @return sCALE
  255. */
  256. public int getScale() {
  257. return sCALE;
  258. }
  259. /**
  260. * Sets the Image Scale.
  261. *
  262. * @param scale for the image
  263. */
  264. public void setScale(int scale) {
  265. sCALE = scale;
  266. if ((sCALE & 1) == 0)
  267. sCALEdIV2 = sCALE / 2;
  268. else
  269. sCALEdIV2 = (sCALE + 1) / 2;
  270. }
  271. /**
  272. * Returns sCALEdIV2 (The Scale divided by 2).
  273. *
  274. * @return sCALEdIV2
  275. */
  276. public int getScaleDiv2() {
  277. return sCALEdIV2;
  278. }
  279. /**
  280. * Returns the maximum ITERATIONS.
  281. *
  282. * @return ITERATIONS
  283. */
  284. public int getMaxIterations() {
  285. return iterations;
  286. }
  287. /**
  288. * Returns cURiTERATION.
  289. *
  290. * @return cURiTERATION
  291. */
  292. public int getCurrentIteration() {
  293. return curIteration;
  294. }
  295. /**
  296. * sets the current Iteration.
  297. *
  298. * @param curIT the current Iteration
  299. */
  300. public void setCurIteration(int curIT) {
  301. this.curIteration = curIT;
  302. }
  303. /**
  304. * Returns the selected Edge.
  305. *
  306. * @return selectedEdge
  307. */
  308. public Edge getSelectedEdge() {
  309. return selectedEdge;
  310. }
  311. /**
  312. * Set the selected Edge.
  313. *
  314. * @param edge that is selected
  315. */
  316. public void setSelectedEdge(Edge edge) {
  317. this.selectedEdge = edge;
  318. }
  319. /**
  320. * Returns the Categorie Index.
  321. *
  322. * @return the cgIdx
  323. */
  324. public HashMap<String, Integer> getCgIdx() {
  325. return cgIdx;
  326. }
  327. /**
  328. * Sets the Categorie Index.
  329. *
  330. * @param cgIdx the cgIdx to set
  331. */
  332. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  333. this.cgIdx = cgIdx;
  334. }
  335. /**
  336. * Returns the CanvasObject Index.
  337. *
  338. * @return the cvsObjIdx
  339. */
  340. public HashMap<Integer, Integer> getCvsObjIdx() {
  341. return cvsObjIdx;
  342. }
  343. /**
  344. * Sets the CanvasObject Index.
  345. *
  346. * @param cvsObjIdx the cvsObjIdx to set
  347. */
  348. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  349. this.cvsObjIdx = cvsObjIdx;
  350. }
  351. /**
  352. * Returns the auto save Number.
  353. *
  354. * @return the auto save Number
  355. */
  356. public int getAutoSaveNr() {
  357. return autoSaveNr;
  358. }
  359. /**
  360. * Sets the auto save Number.
  361. *
  362. * @param autoSaveNr the auto save number
  363. */
  364. public void setAutoSaveNr(int autoSaveNr) {
  365. this.autoSaveNr = autoSaveNr;
  366. }
  367. /**
  368. * Returns the Number of Saves.
  369. *
  370. * @return the numberOfSaves
  371. */
  372. public int getNumberOfSaves() {
  373. return numberOfSaves;
  374. }
  375. /**
  376. * Set the Number of Saves.
  377. *
  378. * @param numberOfSaves the numberOfSaves to set
  379. */
  380. public void setNumberOfSaves(int numberOfSaves) {
  381. this.numberOfSaves = numberOfSaves;
  382. }
  383. /**
  384. * Returns all Objects in the Clipboard.
  385. *
  386. * @return Objects in the Clipboard
  387. */
  388. public Set<AbstractCanvasObject> getClipboradObjects() {
  389. return clipboardObjects;
  390. }
  391. /**
  392. * Sets the ClipboardObjects.
  393. *
  394. * @param c Array of Objects
  395. */
  396. public void setClipboradObjects(Set<AbstractCanvasObject> c) {
  397. this.clipboardObjects = c;
  398. }
  399. /**
  400. * @return the maxCapacity
  401. */
  402. public float getMaxCapacity() {
  403. return maxCapacity;
  404. }
  405. /**
  406. * @param maxCapacity the maxCapacity to set
  407. */
  408. public void setMaxCapacity(float maxCapacity) {
  409. this.maxCapacity = maxCapacity;
  410. }
  411. /**
  412. * get the Interval in ms between each Iteration.
  413. *
  414. * @return timerSpeed speed for the Iterations
  415. */
  416. public int getTimerSpeed() {
  417. return this.timerSpeed;
  418. }
  419. /**
  420. * Sets the Interval in ms between each Iteration.
  421. *
  422. * @param t speed for the Iterations
  423. */
  424. public void setTimerSpeed(int t) {
  425. this.timerSpeed = t;
  426. }
  427. /**
  428. * Get Canvas X Size.
  429. *
  430. * @return the cANVAS_X
  431. */
  432. public int getCanvasX() {
  433. return canvasX;
  434. }
  435. /**
  436. * Set Canvas X Size.
  437. *
  438. * @param canvasX the cANVAS_X to set
  439. */
  440. public void setCanvasX(int canvasX) {
  441. this.canvasX = canvasX;
  442. }
  443. /**
  444. * get Canvas Y size.
  445. *
  446. * @return the cANVAS_Y
  447. */
  448. public int getCanvasY() {
  449. return canvasY;
  450. }
  451. /**
  452. * Set Canvas Y size.
  453. *
  454. * @param canvasY the cANVAS_Y to set
  455. */
  456. public void setCanvasY(int canvasY) {
  457. this.canvasY = canvasY;
  458. }
  459. public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
  460. return this.eleToDelete;
  461. }
  462. //TODO eleToDelete is this necessary
  463. public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
  464. this.eleToDelete = theHash;
  465. }
  466. public List<HolonElement> getAllHolonElemnts() {
  467. return getAllHolonObjectsOnCanvas().stream().flatMap(hO -> hO.getElements().stream()).collect(Collectors.toList());
  468. }
  469. public ArrayList<HolonObject> getAllHolonObjectsOnCanvas(){
  470. ArrayList<HolonObject> objectToReturn = new ArrayList<HolonObject>();
  471. getAllHolonObjectsRecursive(objectToReturn, getObjectsOnCanvas());
  472. return objectToReturn;
  473. }
  474. private void getAllHolonObjectsRecursive(ArrayList<HolonObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
  475. for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
  476. if(aCps instanceof HolonObject) {
  477. addObjectsToThisList.add((HolonObject) aCps);
  478. }else if(aCps instanceof GroupNode){
  479. getAllHolonObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
  480. }
  481. }
  482. }
  483. public ArrayList<AbstractCanvasObject> getAllAbstractObjectsOnCanvas(){
  484. ArrayList<AbstractCanvasObject> objectToReturn = new ArrayList<AbstractCanvasObject>();
  485. getAllAsbtractObjectsRecursive(objectToReturn, getObjectsOnCanvas());
  486. return objectToReturn;
  487. }
  488. private void getAllAsbtractObjectsRecursive(ArrayList<AbstractCanvasObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
  489. for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
  490. if(aCps instanceof GroupNode){
  491. getAllAsbtractObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
  492. }
  493. else{
  494. addObjectsToThisList.add(aCps);
  495. }
  496. }
  497. }
  498. /**
  499. * get all Switches
  500. */
  501. public ArrayList<HolonSwitch> getAllSwitches() {
  502. ArrayList<HolonSwitch> switches = new ArrayList<>();
  503. for (AbstractCanvasObject obj : getObjectsOnCanvas()) {
  504. if (obj instanceof HolonSwitch) {
  505. switches.add((HolonSwitch) obj);
  506. } else if (obj instanceof GroupNode) {
  507. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  508. }
  509. }
  510. return switches;
  511. }
  512. /**
  513. * get the Amount of Switches help function
  514. *
  515. * @param objects objects
  516. * @param switches List of switches
  517. */
  518. private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCanvasObject> objects,
  519. ArrayList<HolonSwitch> switches) {
  520. for (AbstractCanvasObject obj : objects) {
  521. if (obj instanceof HolonSwitch) {
  522. switches.add((HolonSwitch) obj);
  523. } else if (obj instanceof GroupNode) {
  524. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  525. }
  526. }
  527. return switches;
  528. }
  529. /**
  530. * Returns the Path for the background Image of the Canvas.
  531. *
  532. * @return imgPath the Path
  533. */
  534. public String getCanvasImagePath() {
  535. return imgPath;
  536. }
  537. /**
  538. * Set the Path for the background Image of the Canvas.
  539. *
  540. * @param path the Path
  541. */
  542. public void setCanvasImagePath(String path) {
  543. imgPath = path;
  544. }
  545. /**
  546. * Returns the mode for the background Image of the Canvas.
  547. * <p>
  548. * 0 take size of the Image 1 stretch the Image 2 Custom Image size
  549. *
  550. * @return backgroundMode the mode
  551. */
  552. public int getCanvasImageMode() {
  553. return backgroundMode;
  554. }
  555. /**
  556. * Set the mode for the background Image of the Canvas.
  557. * <p>
  558. * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
  559. *
  560. * @param mode the backgroundMode
  561. */
  562. public void setCanvasImageMode(int mode) {
  563. backgroundMode = mode;
  564. }
  565. /**
  566. * Returns the Custom width of the background Image of the Canvas.
  567. *
  568. * @return backgroundWidth the Width
  569. */
  570. public int getCanvasImageWidth() {
  571. return backgroundWidth;
  572. }
  573. /**
  574. * Set the Custom width of the background Image of the Canvas.
  575. *
  576. * @param width the Width
  577. */
  578. public void setCanvasImageWidth(int width) {
  579. backgroundWidth = width;
  580. }
  581. /**
  582. * Returns the Custom height of the background Image of the Canvas.
  583. *
  584. * @return backgroundHeight the height
  585. */
  586. public int getCanvasImageHeight() {
  587. return backgroundHeight;
  588. }
  589. /**
  590. * Set the Custom height of the background Image of the Canvas.
  591. *
  592. * @param height the height
  593. */
  594. public void setCanvasImageHeight(int height) {
  595. backgroundHeight = height;
  596. }
  597. /**
  598. * @return true if SupplyBars should be shown
  599. */
  600. public boolean getShowSupplyBars() {
  601. return showSupplyBars;
  602. }
  603. /**
  604. * @param showSupplyBars true if the SupplyBars should be shown
  605. */
  606. public void setShowSupplyBars(boolean showSupplyBars) {
  607. this.showSupplyBars = showSupplyBars;
  608. }
  609. /**
  610. * @param iterations the number of steps for this simulation
  611. */
  612. public void setIterations(int iterations){
  613. this.iterations=iterations;
  614. }
  615. /**
  616. * @return the fairnessModel
  617. */
  618. public FairnessModel getFairnessModel() {
  619. return fairnessModel;
  620. }
  621. /**
  622. * @param fairnessModel the fairnessModel to set
  623. */
  624. public void setFairnessModel(FairnessModel fairnessModel) {
  625. this.fairnessModel = fairnessModel;
  626. }
  627. public int getGraphIterations(){
  628. return GRAPH_ITERATIONS;
  629. }
  630. /**
  631. * Initialize the Gson with wanted parameters
  632. */
  633. private void initGson() {
  634. GsonBuilder builder = new GsonBuilder();
  635. builder.serializeNulls();
  636. builder.excludeFieldsWithoutExposeAnnotation();
  637. builder.setPrettyPrinting();
  638. builder.registerTypeAdapter(AbstractCanvasObject.class, new AbstractCpsObjectAdapter());
  639. builder.registerTypeAdapter(Vector2Int.class, new PositionAdapter());
  640. builder.registerTypeAdapter(Color.class, new ColorAdapter());
  641. builder.registerTypeAdapter(Pair.class, new PairAdapter());
  642. // use the builder and make a instance of the Gson
  643. this.setGson(builder.create());
  644. }
  645. /**
  646. * @return the gson
  647. */
  648. public Gson getGson() {
  649. return gson;
  650. }
  651. /**
  652. * @param gson the gson to set
  653. */
  654. public void setGson(Gson gson) {
  655. this.gson = gson;
  656. }
  657. /**
  658. * @return the hashcodeMap
  659. */
  660. public HashMap<Integer, GroupNode> getHashcodeMap() {
  661. return hashcodeMap;
  662. }
  663. /**
  664. * @param hashcodeMap the hashcodeMap to set
  665. */
  666. public void setHashcodeMap(HashMap<Integer, GroupNode> hashcodeMap) {
  667. this.hashcodeMap = hashcodeMap;
  668. }
  669. public ArrayList<HolonSwitch> getSwitchsOnCanvas() {
  670. return switchsOnCanvas;
  671. }
  672. public void setSwitchsOnCanvas(ArrayList<HolonSwitch> switchsOnCanvas) {
  673. this.switchsOnCanvas = switchsOnCanvas;
  674. }
  675. public ArrayList<Node> getNodesOnCanvas() {
  676. return nodesOnCanvas;
  677. }
  678. public void setNodesOnCanvas(ArrayList<Node> nodesOnCanvas) {
  679. this.nodesOnCanvas = nodesOnCanvas;
  680. }
  681. public ArrayList<HolonObject> getHolonObjectsOnCanvas() {
  682. return holonObjectsOnCanvas;
  683. }
  684. public void setHolonObjectsOnCanvas(ArrayList<HolonObject> holonObjectsOnCanvas) {
  685. this.holonObjectsOnCanvas = holonObjectsOnCanvas;
  686. }
  687. public void defineLists() {
  688. switchsOnCanvas.clear();
  689. nodesOnCanvas.clear();
  690. holonObjectsOnCanvas.clear();
  691. for(AbstractCanvasObject aCps : this.objectsOnCanvas) {
  692. if(aCps instanceof HolonObject)holonObjectsOnCanvas.add((HolonObject) aCps);
  693. else if(aCps instanceof Node)nodesOnCanvas.add((Node) aCps);
  694. else if(aCps instanceof HolonSwitch)switchsOnCanvas.add((HolonSwitch) aCps);
  695. }
  696. }
  697. }