Model.java 26 KB

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