Model.java 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. package ui.model;
  2. import TypeAdapter.AbstractCpsObjectAdapter;
  3. import TypeAdapter.ColorAdapter;
  4. import TypeAdapter.PairAdapter;
  5. import TypeAdapter.PositionAdapter;
  6. import classes.*;
  7. import com.google.gson.Gson;
  8. import com.google.gson.GsonBuilder;
  9. import com.google.gson.JsonObject;
  10. import interfaces.CategoryListener;
  11. import interfaces.GraphListener;
  12. import interfaces.ObjectListener;
  13. import ui.view.*;
  14. import javax.swing.*;
  15. import java.awt.*;
  16. import java.util.*;
  17. import java.util.List;
  18. /**
  19. * The Class Model is the class where everything is saved. All changes made to
  20. * the Data is managed via a controller.
  21. *
  22. * @author Gruppe14
  23. */
  24. public class Model {
  25. private static final int GRAPH_ITERATIONS = 100;
  26. // Global Variables
  27. private static int sCALE = 50; // Picture Scale
  28. private static int sCALEdIV2 = sCALE / 2;
  29. private static int holonBodysCALE = 100; // Picture Scale
  30. public String[] colNames = {"Field", "Information"};
  31. // Canvas Attributes
  32. private String imgPath = "";
  33. private int backgroundMode = 0;
  34. private int backgroundWidth = 0;
  35. private int backgroundHeight = 0;
  36. private int canvasX = 3000;
  37. private int canvasY = 3000;
  38. private int curIteration = 0;
  39. private LinkedList<Color> subNetColors = new LinkedList<>();
  40. // ID of the Selected Object
  41. private AbstractCanvasObject selectedCpsObject = null;
  42. private HolonElement selectedHolonElement;
  43. private Edge selectedEdge;
  44. private ArrayList<AbstractCanvasObject> selectedObjects = new ArrayList<>();
  45. private ArrayList<AbstractCanvasObject> clipboardObjects = new ArrayList<>();
  46. private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
  47. // Capacity for Edge
  48. private float maxCapacity;
  49. // Table for HolonElements --> all cells are editable
  50. private JTable tableHolonElement;
  51. /** Table for the properties of HolonObjects, Edges etc */
  52. private JTable propertyTable;
  53. private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
  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 simulation is running and has not been reseted
  62. private boolean isSimRunning = false;
  63. // whether the console log of the program should be displayed
  64. private boolean showConsoleLog = true;
  65. // whether the console log of the program should be displayed
  66. private boolean useFlexibleDevices = true;
  67. /** whether the supplyBars should be shown or not */
  68. private boolean showSupplyBars = true;
  69. //TODO:
  70. private int iterations=100;
  71. /**
  72. * All implemented FairnessModels:<br>
  73. * {@link FairnessModel#MininumDemandFirst}<br>
  74. * {@link FairnessModel#AllEqual}
  75. */
  76. public enum FairnessModel{
  77. /**
  78. * One Element of each HolonObject will be powered first, starting with the
  79. * smallest Demand. If ale HolonObjects have an active Element, the
  80. * simulation will try to fully supply as many HolonObjects as possible.
  81. */
  82. MininumDemandFirst,
  83. /**
  84. * All HolonObjects will receive the same amount of energy.
  85. */
  86. AllEqual
  87. }
  88. /** the Fairness model in use */
  89. private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;
  90. /*
  91. * Array of all categories in the model. It is set by default with the
  92. * categories ENERGY, BUILDINGS and COMPONENTS
  93. */
  94. private ArrayList<Category> categories;
  95. /*
  96. * Array of all HolonObj and HolonSwitches, that should be tracked through
  97. * out the statistics tab
  98. */
  99. private ArrayList<AbstractCanvasObject> trackedObjects;
  100. /*
  101. * Array of all CpsObjects in our canvas. It is set by default as an empty
  102. * list.
  103. */
  104. private ArrayList<AbstractCanvasObject> objectsOnCanvas;
  105. private HashMap<String, Integer> cgIdx;
  106. private HashMap<Integer, Integer> cvsObjIdx;
  107. /*
  108. * Array of all CpsObjects in our canvas. It is set by default as an empty
  109. * list.
  110. */
  111. private ArrayList<Edge> edgesOnCanvas;
  112. private ArrayList<HolonObject> holonObjectsOnCanvas = new ArrayList<HolonObject>();
  113. private ArrayList<Node> nodesOnCanvas= new ArrayList<Node>();
  114. private ArrayList<HolonSwitch> switchsOnCanvas= new ArrayList<HolonSwitch>();
  115. /*
  116. * Array for all Listeners
  117. */
  118. private List<CategoryListener> categoryListeners;
  119. private List<ObjectListener> objectListeners;
  120. private PropertyTable tableModelHolonElementMulti;
  121. private PropertyTable tableModelHolonElementSingle;
  122. private DefaulTable tableModelProperties;
  123. /*
  124. * Object that runs the Algorithm
  125. */
  126. private Object algorithm = null;
  127. private int selectedHolonBody;
  128. // Statistic Graph Data
  129. private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<>();
  130. private HashMap<Integer, GroupNode> hashcodeMap = new HashMap<>();
  131. private ArrayList<JsonObject> statisticData = new ArrayList<>();
  132. private Gson gson;
  133. private StatisticPanel statPanel;
  134. /**
  135. * Constructor for the model. It initializes the categories and
  136. * objectsOnCanvas by default values. Listeners are also initialized by
  137. * default values.
  138. */
  139. public Model() {
  140. setCategories(new ArrayList<>());
  141. setObjectsOnCanvas(new ArrayList<>());
  142. setEdgesOnCanvas(new ArrayList<>());
  143. setCategoryListeners(new LinkedList<>());
  144. setObjectListeners(new LinkedList<>());
  145. setCgIdx(new HashMap<>());
  146. setCvsObjIdx(new HashMap<>());
  147. setClipboradObjects(new ArrayList<>());
  148. setTrackingObj(new ArrayList<>());
  149. setEleToDelete(new HashMap<>());
  150. setSingleTable(new PropertyTable());
  151. setMultiTable(new PropertyTable());
  152. setPropertyTable(new DefaulTable(1000, colNames.length));
  153. getPropertyTable().setColumnIdentifiers(colNames);
  154. setTableHolonElement(new JTable());
  155. initGson();
  156. }
  157. /**
  158. * Returns all Categories.
  159. *
  160. * @return the categories
  161. */
  162. public ArrayList<Category> getCategories() {
  163. return categories;
  164. }
  165. /**
  166. * Sets all Categories.
  167. *
  168. * @param categories the categories to set
  169. */
  170. public void setCategories(ArrayList<Category> categories) {
  171. this.categories = categories;
  172. }
  173. /**
  174. * Transform the Arraylist of categories into a string of all objectName
  175. * with a separation (',') between each name.
  176. *
  177. * @return String of all names separeted by ','
  178. */
  179. public String toStringCat() {
  180. String text = "";
  181. for (int i = 0; i < categories.size(); i++) {
  182. if (text.equals("")) {
  183. text = categories.get(i).getName();
  184. } else {
  185. text = text + ", " + categories.get(i).getName();
  186. }
  187. }
  188. return text;
  189. }
  190. /**
  191. * Returns all Objects on the Canvas.
  192. *
  193. * @return the objectsOnCanvas
  194. */
  195. public ArrayList<AbstractCanvasObject> getObjectsOnCanvas() {
  196. return objectsOnCanvas;
  197. }
  198. /**
  199. * Sets all Objects on the Canvas.
  200. *
  201. * @param objectsOnCanvas the objectsOnCanvas to set
  202. */
  203. public void setObjectsOnCanvas(ArrayList<AbstractCanvasObject> objectsOnCanvas) {
  204. this.objectsOnCanvas = objectsOnCanvas;
  205. }
  206. /**
  207. * Get all Edges on the Canvas.
  208. *
  209. * @return the edgesOnCanvas
  210. */
  211. public ArrayList<Edge> getEdgesOnCanvas() {
  212. return edgesOnCanvas;
  213. }
  214. /**
  215. * Sets the edges on the Canvas.
  216. *
  217. * @param arrayList the edgesOnCanvas to set
  218. */
  219. public void setEdgesOnCanvas(ArrayList<Edge> arrayList) {
  220. this.edgesOnCanvas = arrayList;
  221. }
  222. /**
  223. * Adds an Edge to The Canvas.
  224. *
  225. * @param edge the edgesOnCanvas to add
  226. */
  227. public void addEdgeOnCanvas(Edge edge) {
  228. this.edgesOnCanvas.add(edge);
  229. }
  230. /**
  231. * Remove an edge from the Canvas.
  232. *
  233. * @param edge the edge to remove
  234. */
  235. public void removeEdgesOnCanvas(Edge edge) {
  236. this.edgesOnCanvas.remove(edge);
  237. }
  238. /**
  239. * Returns the ObjectListener.
  240. *
  241. * @return the objectListeners
  242. */
  243. public List<ObjectListener> getObjectListeners() {
  244. return objectListeners;
  245. }
  246. /**
  247. * Sets the ObjectListener.
  248. *
  249. * @param linkedList the objectListeners to set
  250. */
  251. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  252. this.objectListeners = linkedList;
  253. }
  254. /**
  255. * Returns the CategorieListener.
  256. *
  257. * @return the categoryListeners
  258. */
  259. public List<CategoryListener> getCategoryListeners() {
  260. return categoryListeners;
  261. }
  262. /**
  263. * Sets the CategorieListener.
  264. *
  265. * @param linkedList the categoryListeners to set
  266. */
  267. public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
  268. this.categoryListeners = linkedList;
  269. }
  270. /**
  271. * Returns the ID of the selected Object 0 = no Object is selected.
  272. *
  273. * @return ID
  274. */
  275. public int getSelectedObjectID() {
  276. return selectedID;
  277. }
  278. /**
  279. * Set the ID of the selected Object 0 = no Object is selected.
  280. *
  281. * @param id the ID
  282. */
  283. public void setSelectedObjectID(int id) {
  284. this.selectedID = id;
  285. }
  286. /**
  287. * Returns the Selected Cps Object.
  288. *
  289. * @return selected Cps Object
  290. */
  291. public AbstractCanvasObject getSelectedCpsObject() {
  292. return selectedCpsObject;
  293. }
  294. /**
  295. * Set the Selected Objecs.
  296. *
  297. * @param selectedCpsObject Objects that are selected
  298. */
  299. public void setSelectedCpsObject(AbstractCanvasObject selectedCpsObject) {
  300. this.selectedCpsObject = selectedCpsObject;
  301. }
  302. /**
  303. * Returns all selected Objects on the Canvas.
  304. *
  305. * @return The selected Objects
  306. */
  307. public ArrayList<AbstractCanvasObject> getSelectedCpsObjects() {
  308. return selectedObjects;
  309. }
  310. /**
  311. * Returns all selected Objects on the Canvas.
  312. *
  313. * @return The selected Objects
  314. */
  315. public void setSelectedCpsObjects(ArrayList<AbstractCanvasObject> arr) {
  316. this.selectedObjects = arr;
  317. }
  318. /**
  319. * Returns the Selected Holon Element.
  320. *
  321. * @return selected Holon Element
  322. */
  323. public HolonElement getSelectedHolonElement() {
  324. return selectedHolonElement;
  325. }
  326. /**
  327. * Sets the Selecte HolonElement.
  328. *
  329. * @param selectedHolonElement that is Selected
  330. */
  331. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  332. this.selectedHolonElement = selectedHolonElement;
  333. }
  334. /**
  335. * Returns the sCale (Scale for the Images).
  336. *
  337. * @return sCALE
  338. */
  339. public int getScale() {
  340. return sCALE;
  341. }
  342. /**
  343. * Sets the Image Scale.
  344. *
  345. * @param scale for the image
  346. */
  347. public void setScale(int scale) {
  348. sCALE = scale;
  349. if ((sCALE & 1) == 0)
  350. sCALEdIV2 = sCALE / 2;
  351. else
  352. sCALEdIV2 = (sCALE + 1) / 2;
  353. }
  354. /**
  355. * Returns sCALEdIV2 (The Scale divided by 2).
  356. *
  357. * @return sCALEdIV2
  358. */
  359. public int getScaleDiv2() {
  360. return sCALEdIV2;
  361. }
  362. /**
  363. * Returns ITERATIONS.
  364. *
  365. * @return ITERATIONS
  366. */
  367. public int getIterations() {
  368. return iterations;
  369. }
  370. private void notifyGraphListeners() {
  371. for (GraphListener gl : graphListeners) {
  372. gl.repaintTree();
  373. }
  374. }
  375. /**
  376. * Returns cURiTERATION.
  377. *
  378. * @return cURiTERATION
  379. */
  380. public int getCurIteration() {
  381. return curIteration;
  382. }
  383. /**
  384. * sets the current Iteration.
  385. *
  386. * @param curIT the current Iteration
  387. */
  388. public void setCurIteration(int curIT) {
  389. this.curIteration = curIT;
  390. notifyGraphListeners();
  391. }
  392. /**
  393. * Returns the selected Edge.
  394. *
  395. * @return selectedEdge
  396. */
  397. public Edge getSelectedEdge() {
  398. return selectedEdge;
  399. }
  400. /**
  401. * Set the selected Edge.
  402. *
  403. * @param edge that is selected
  404. */
  405. public void setSelectedEdge(Edge edge) {
  406. this.selectedEdge = edge;
  407. }
  408. /**
  409. * Returns the Categorie Index.
  410. *
  411. * @return the cgIdx
  412. */
  413. public HashMap<String, Integer> getCgIdx() {
  414. return cgIdx;
  415. }
  416. /**
  417. * Sets the Categorie Index.
  418. *
  419. * @param cgIdx the cgIdx to set
  420. */
  421. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  422. this.cgIdx = cgIdx;
  423. }
  424. /**
  425. * Returns the CanvasObject Index.
  426. *
  427. * @return the cvsObjIdx
  428. */
  429. public HashMap<Integer, Integer> getCvsObjIdx() {
  430. return cvsObjIdx;
  431. }
  432. /**
  433. * Sets the CanvasObject Index.
  434. *
  435. * @param cvsObjIdx the cvsObjIdx to set
  436. */
  437. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  438. this.cvsObjIdx = cvsObjIdx;
  439. }
  440. /**
  441. * Returns the auto save Number.
  442. *
  443. * @return the auto save Number
  444. */
  445. public int getAutoSaveNr() {
  446. return autoSaveNr;
  447. }
  448. /**
  449. * Sets the auto save Number.
  450. *
  451. * @param autoSaveNr the auto save number
  452. */
  453. public void setAutoSaveNr(int autoSaveNr) {
  454. this.autoSaveNr = autoSaveNr;
  455. }
  456. /**
  457. * Returns the Number of Saves.
  458. *
  459. * @return the numberOfSaves
  460. */
  461. public int getNumberOfSaves() {
  462. return numberOfSaves;
  463. }
  464. /**
  465. * Set the Number of Saves.
  466. *
  467. * @param numberOfSaves the numberOfSaves to set
  468. */
  469. public void setNumberOfSaves(int numberOfSaves) {
  470. this.numberOfSaves = numberOfSaves;
  471. }
  472. /**
  473. * Returns all Objects in the Clipboard.
  474. *
  475. * @return Objects in the Clipboard
  476. */
  477. public ArrayList<AbstractCanvasObject> getClipboradObjects() {
  478. return clipboardObjects;
  479. }
  480. /**
  481. * Sets the ClipboardObjects.
  482. *
  483. * @param c Array of Objects
  484. */
  485. public void setClipboradObjects(ArrayList<AbstractCanvasObject> c) {
  486. this.clipboardObjects = c;
  487. }
  488. /**
  489. * @return the maxCapacity
  490. */
  491. public float getMaxCapacity() {
  492. return maxCapacity;
  493. }
  494. /**
  495. * @param maxCapacity the maxCapacity to set
  496. */
  497. public void setMaxCapacity(float maxCapacity) {
  498. this.maxCapacity = maxCapacity;
  499. }
  500. /**
  501. * get the Interval in ms between each Iteration.
  502. *
  503. * @return timerSpeed speed for the Iterations
  504. */
  505. public int getTimerSpeed() {
  506. return this.timerSpeed;
  507. }
  508. /**
  509. * Sets the Interval in ms between each Iteration.
  510. *
  511. * @param t speed for the Iterations
  512. */
  513. public void setTimerSpeed(int t) {
  514. this.timerSpeed = t;
  515. }
  516. /**
  517. * Get Canvas X Size.
  518. *
  519. * @return the cANVAS_X
  520. */
  521. public int getCanvasX() {
  522. return canvasX;
  523. }
  524. /**
  525. * Set Canvas X Size.
  526. *
  527. * @param canvasX the cANVAS_X to set
  528. */
  529. public void setCanvasX(int canvasX) {
  530. this.canvasX = canvasX;
  531. }
  532. /**
  533. * get Canvas Y size.
  534. *
  535. * @return the cANVAS_Y
  536. */
  537. public int getCanvasY() {
  538. return canvasY;
  539. }
  540. /**
  541. * Set Canvas Y size.
  542. *
  543. * @param canvasY the cANVAS_Y to set
  544. */
  545. public void setCanvasY(int canvasY) {
  546. this.canvasY = canvasY;
  547. }
  548. /**
  549. * get the Algorithm.
  550. *
  551. * @return the Algorithm
  552. */
  553. public Object getAlgorithm() {
  554. return algorithm;
  555. }
  556. /**
  557. * Set the Algorithm.
  558. *
  559. * @param obj the Algorithm
  560. */
  561. public void setAlgorithm(Object obj) {
  562. this.algorithm = null;
  563. this.algorithm = obj;
  564. }
  565. /**
  566. * Add a SubNetColor.
  567. *
  568. * @param c the Color
  569. */
  570. public void addSubNetColor(Color c) {
  571. this.subNetColors.add(c);
  572. }
  573. /**
  574. * Get the SubNetColors.
  575. *
  576. * @return SubNetColors
  577. */
  578. public LinkedList<Color> getSubNetColors() {
  579. return this.subNetColors;
  580. }
  581. public ArrayList<AbstractCanvasObject> getTrackingObj() {
  582. return trackedObjects;
  583. }
  584. public void setTrackingObj(ArrayList<AbstractCanvasObject> toTrack) {
  585. trackedObjects = toTrack;
  586. }
  587. public void addGraphListener(GraphListener gl) {
  588. graphListeners.add(gl);
  589. }
  590. public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
  591. return this.eleToDelete;
  592. }
  593. public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
  594. this.eleToDelete = theHash;
  595. }
  596. public PropertyTable getSingleTable() {
  597. return this.tableModelHolonElementSingle;
  598. }
  599. public void setSingleTable(PropertyTable pt) {
  600. this.tableModelHolonElementSingle = pt;
  601. }
  602. public PropertyTable getMultiTable() {
  603. return this.tableModelHolonElementMulti;
  604. }
  605. public void setMultiTable(PropertyTable pt) {
  606. this.tableModelHolonElementMulti = pt;
  607. }
  608. public void addObjectsToGraphListeners() {
  609. for (GraphListener gl : graphListeners) {
  610. gl.addTrackedObject(trackedObjects);
  611. gl.repaintTree();
  612. }
  613. }
  614. public DefaulTable getPropertyTable() {
  615. return this.tableModelProperties;
  616. }
  617. public void setPropertyTable(DefaulTable pt) {
  618. this.tableModelProperties = pt;
  619. }
  620. public JTable getTableHolonElement() {
  621. return tableHolonElement;
  622. }
  623. public void setTableHolonElement(JTable tableHolonElement) {
  624. this.tableHolonElement = tableHolonElement;
  625. }
  626. /**
  627. * @return the tableProperties
  628. */
  629. public JTable getTableProperties() {
  630. return propertyTable;
  631. }
  632. /**
  633. * @return the tableProperties
  634. */
  635. public void setTableProperties(JTable propertyTable) {
  636. this.propertyTable = propertyTable;
  637. }
  638. /**
  639. * Returns the sCale (Scale for the Images).
  640. *
  641. * @return sCALE
  642. */
  643. public int getHolonBodyScale() {
  644. return holonBodysCALE;
  645. }
  646. /**
  647. * Sets the HolonBody Scale.
  648. *
  649. * @param scale for the HolonBody
  650. */
  651. public void setHolonBodyScale(int scale) {
  652. holonBodysCALE = scale;
  653. }
  654. /**
  655. * Returns the ID of the selected HolonBody
  656. *
  657. * @return selectedHolonBody
  658. */
  659. public int getSelectedHolonBody() {
  660. return selectedHolonBody;
  661. }
  662. /**
  663. * Sets the ID of the selected HolonBody
  664. *
  665. * @param i int
  666. */
  667. public void setSelectedHolonBody(int i) {
  668. selectedHolonBody = i;
  669. }
  670. public ArrayList<HolonObject> getAllHolonObjectsOnCanvas(){
  671. ArrayList<HolonObject> objectToReturn = new ArrayList<HolonObject>();
  672. getAllHolonObjectsRecursive(objectToReturn, getObjectsOnCanvas());
  673. return objectToReturn;
  674. }
  675. private void getAllHolonObjectsRecursive(ArrayList<HolonObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
  676. for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
  677. if(aCps instanceof HolonObject) {
  678. addObjectsToThisList.add((HolonObject) aCps);
  679. }else if(aCps instanceof GroupNode){
  680. getAllHolonObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
  681. }
  682. }
  683. }
  684. /**
  685. * get all Switches
  686. */
  687. public ArrayList<HolonSwitch> getAllSwitches() {
  688. ArrayList<HolonSwitch> switches = new ArrayList<>();
  689. for (AbstractCanvasObject obj : getObjectsOnCanvas()) {
  690. if (obj instanceof HolonSwitch) {
  691. switches.add((HolonSwitch) obj);
  692. } else if (obj instanceof GroupNode) {
  693. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  694. }
  695. }
  696. return switches;
  697. }
  698. /**
  699. * get the Amount of Switches help function
  700. *
  701. * @param objects objects
  702. * @param switches List of switches
  703. */
  704. private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCanvasObject> objects,
  705. ArrayList<HolonSwitch> switches) {
  706. for (AbstractCanvasObject obj : objects) {
  707. if (obj instanceof HolonSwitch) {
  708. switches.add((HolonSwitch) obj);
  709. } else if (obj instanceof GroupNode) {
  710. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  711. }
  712. }
  713. return switches;
  714. }
  715. /**
  716. * Returns the Path for the background Image of the Canvas.
  717. *
  718. * @return imgPath the Path
  719. */
  720. public String getCanvasImagePath() {
  721. return imgPath;
  722. }
  723. /**
  724. * Set the Path for the background Image of the Canvas.
  725. *
  726. * @param path the Path
  727. */
  728. public void setCanvasImagePath(String path) {
  729. imgPath = path;
  730. }
  731. /**
  732. * Returns the mode for the background Image of the Canvas.
  733. * <p>
  734. * 0 take size of the Image 1 stretch the Image 2 Custom Image size
  735. *
  736. * @return backgroundMode the mode
  737. */
  738. public int getCanvasImageMode() {
  739. return backgroundMode;
  740. }
  741. /**
  742. * Set the mode for the background Image of the Canvas.
  743. * <p>
  744. * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
  745. *
  746. * @param mode the backgroundMode
  747. */
  748. public void setCanvasImageMode(int mode) {
  749. backgroundMode = mode;
  750. }
  751. /**
  752. * Returns the Custom width of the background Image of the Canvas.
  753. *
  754. * @return backgroundWidth the Width
  755. */
  756. public int getCanvasImageWidth() {
  757. return backgroundWidth;
  758. }
  759. /**
  760. * Set the Custom width of the background Image of the Canvas.
  761. *
  762. * @param width the Width
  763. */
  764. public void setCanvasImageWidth(int width) {
  765. backgroundWidth = width;
  766. }
  767. /**
  768. * Returns the Custom height of the background Image of the Canvas.
  769. *
  770. * @return backgroundHeight the height
  771. */
  772. public int getCanvasImageHeight() {
  773. return backgroundHeight;
  774. }
  775. /**
  776. * Set the Custom height of the background Image of the Canvas.
  777. *
  778. * @param height the height
  779. */
  780. public void setCanvasImageHeight(int height) {
  781. backgroundHeight = height;
  782. }
  783. /**
  784. * Returns the graphtable for Statistic Graphs.
  785. */
  786. public Hashtable<String, StatisticGraphPanel> getGraphTable() {
  787. return statisticGraphTable;
  788. }
  789. /**
  790. * Set the graphtable for Statistic Graphs
  791. */
  792. public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
  793. statisticGraphTable = gT;
  794. }
  795. /**
  796. * Returns if the Simulation is running.
  797. */
  798. public boolean getIsSimRunning() {
  799. return isSimRunning;
  800. }
  801. /**
  802. * Sets isSimRunning.
  803. *
  804. * @param isRunning
  805. */
  806. public void setIsSimRunning(boolean isRunning) {
  807. isSimRunning = isRunning;
  808. }
  809. /**
  810. * @return the statisticData
  811. */
  812. public ArrayList<JsonObject> getStatisticData() {
  813. return statisticData;
  814. }
  815. /**
  816. * @param statisticData the statisticData to set
  817. */
  818. public void setStatisticData(ArrayList<JsonObject> statisticData) {
  819. this.statisticData = statisticData;
  820. }
  821. /**
  822. * Returns showConsoleLog.
  823. */
  824. public boolean getShowConsoleLog() {
  825. return this.showConsoleLog;
  826. }
  827. /**
  828. * Sets showConsoleLog.
  829. *
  830. * @param showConsoleLog
  831. */
  832. public void setShowConsoleLog(boolean showConsoleLog) {
  833. this.showConsoleLog = showConsoleLog;
  834. }
  835. public boolean useFlexibleDevices() {
  836. return this.useFlexibleDevices;
  837. }
  838. public void setUseFlexibleDevices(boolean useFlexibleDevices) {
  839. this.useFlexibleDevices = useFlexibleDevices;
  840. }
  841. /**
  842. * @return true if SupplyBars should be shown
  843. */
  844. public boolean getShowSupplyBars() {
  845. return showSupplyBars;
  846. }
  847. /**
  848. * @param showSupplyBars true if the SupplyBars should be shown
  849. */
  850. public void setShowSupplyBars(boolean showSupplyBars) {
  851. this.showSupplyBars = showSupplyBars;
  852. }
  853. /**
  854. * @param iterations the number of steps for this simulation
  855. */
  856. public void setIterations(int iterations){
  857. this.iterations=iterations;
  858. }
  859. /**
  860. * @return the fairnessModel
  861. */
  862. public FairnessModel getFairnessModel() {
  863. return fairnessModel;
  864. }
  865. /**
  866. * @param fairnessModel the fairnessModel to set
  867. */
  868. public void setFairnessModel(FairnessModel fairnessModel) {
  869. this.fairnessModel = fairnessModel;
  870. }
  871. public int getGraphIterations(){
  872. return GRAPH_ITERATIONS;
  873. }
  874. /**
  875. * Initialize the Gson with wanted parameters
  876. */
  877. private void initGson() {
  878. GsonBuilder builder = new GsonBuilder();
  879. builder.serializeNulls();
  880. builder.excludeFieldsWithoutExposeAnnotation();
  881. builder.setPrettyPrinting();
  882. builder.registerTypeAdapter(AbstractCanvasObject.class, new AbstractCpsObjectAdapter());
  883. builder.registerTypeAdapter(Position.class, new PositionAdapter());
  884. builder.registerTypeAdapter(Color.class, new ColorAdapter());
  885. builder.registerTypeAdapter(Pair.class, new PairAdapter());
  886. // use the builder and make a instance of the Gson
  887. this.setGson(builder.create());
  888. }
  889. /**
  890. * @return the gson
  891. */
  892. public Gson getGson() {
  893. return gson;
  894. }
  895. /**
  896. * @param gson the gson to set
  897. */
  898. public void setGson(Gson gson) {
  899. this.gson = gson;
  900. }
  901. public StatisticPanel getStatPanel() {
  902. return statPanel;
  903. }
  904. public void setStatPanel(StatisticPanel sP) {
  905. statPanel = sP;
  906. }
  907. /**
  908. * @return the hashcodeMap
  909. */
  910. public HashMap<Integer, GroupNode> getHashcodeMap() {
  911. return hashcodeMap;
  912. }
  913. /**
  914. * @param hashcodeMap the hashcodeMap to set
  915. */
  916. public void setHashcodeMap(HashMap<Integer, GroupNode> hashcodeMap) {
  917. this.hashcodeMap = hashcodeMap;
  918. }
  919. public ArrayList<HolonSwitch> getSwitchsOnCanvas() {
  920. return switchsOnCanvas;
  921. }
  922. public void setSwitchsOnCanvas(ArrayList<HolonSwitch> switchsOnCanvas) {
  923. this.switchsOnCanvas = switchsOnCanvas;
  924. }
  925. public ArrayList<Node> getNodesOnCanvas() {
  926. return nodesOnCanvas;
  927. }
  928. public void setNodesOnCanvas(ArrayList<Node> nodesOnCanvas) {
  929. this.nodesOnCanvas = nodesOnCanvas;
  930. }
  931. public ArrayList<HolonObject> getHolonObjectsOnCanvas() {
  932. return holonObjectsOnCanvas;
  933. }
  934. public void setHolonObjectsOnCanvas(ArrayList<HolonObject> holonObjectsOnCanvas) {
  935. this.holonObjectsOnCanvas = holonObjectsOnCanvas;
  936. }
  937. public void defineLists() {
  938. switchsOnCanvas.clear();
  939. nodesOnCanvas.clear();
  940. holonObjectsOnCanvas.clear();
  941. for(AbstractCanvasObject aCps : this.objectsOnCanvas) {
  942. if(aCps instanceof HolonObject)holonObjectsOnCanvas.add((HolonObject) aCps);
  943. else if(aCps instanceof Node)nodesOnCanvas.add((Node) aCps);
  944. else if(aCps instanceof HolonSwitch)switchsOnCanvas.add((HolonSwitch) aCps);
  945. }
  946. }
  947. }