Control.java 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. package ui.controller;
  2. import api.CpsAlgorithm;
  3. import classes.*;
  4. import com.google.gson.JsonParseException;
  5. import interfaces.CategoryListener;
  6. import org.apache.commons.compress.archivers.ArchiveException;
  7. import ui.model.Model;
  8. import ui.view.FlexiblePane;
  9. import ui.view.MyCanvas;
  10. import ui.view.StatisticGraphPanel;
  11. import java.awt.*;
  12. import java.awt.datatransfer.UnsupportedFlavorException;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.util.ArrayList;
  16. import java.util.Hashtable;
  17. /**
  18. * The Class represents the controller in the model, controller view Pattern.
  19. *
  20. * @author Gruppe14
  21. */
  22. public class Control {
  23. private final ConsoleController consoleController;
  24. private final MultiPurposeController multiPurposeController;
  25. private final CategoryController categoryController;
  26. private final ObjectController objectController;
  27. private final CanvasController canvasController;
  28. private final GlobalController globalController;
  29. private final SaveController saveController;
  30. private final LoadController loadController;
  31. private final AutoSaveController autoSaveController;
  32. private final StatsController statsController;
  33. private final NodeController nodeController;
  34. private final ClipboardController clipboardController;
  35. private final HolonCanvasController holonCanvasController;
  36. private Model model;
  37. private SimulationManager simulationManager;
  38. private String autosaveDir = "";
  39. private String categoryDir = "";
  40. private String otherDir = "";
  41. private String dimensionsFileName = "dimensions";
  42. private int rand;
  43. /**
  44. * Constructor.
  45. *
  46. * @param model the Model
  47. */
  48. public Control(Model model) {
  49. this.model = model;
  50. this.multiPurposeController = new MultiPurposeController(model);
  51. this.categoryController = new CategoryController(model, multiPurposeController);
  52. this.objectController = new ObjectController(model, multiPurposeController);
  53. this.canvasController = new CanvasController(model, multiPurposeController);
  54. this.globalController = new GlobalController(model);
  55. this.saveController = new SaveController(model);
  56. this.nodeController = new NodeController(model, canvasController, multiPurposeController);
  57. this.loadController = new LoadController(model, categoryController, canvasController, objectController,
  58. nodeController, multiPurposeController);
  59. this.simulationManager = new SimulationManager(model);
  60. this.autoSaveController = new AutoSaveController(model);
  61. this.consoleController = new ConsoleController(model);
  62. this.statsController = new StatsController(model);
  63. this.clipboardController = new ClipboardController(model, saveController, loadController, canvasController,
  64. objectController, nodeController, multiPurposeController);
  65. this.holonCanvasController = new HolonCanvasController(model);
  66. autosaveDir = System.getProperty("user.home") + "/.config/HolonGUI/Autosave/";
  67. categoryDir = System.getProperty("user.home") + "/.config/HolonGUI/Category/";
  68. otherDir = System.getProperty("user.home") + "/.config/HolonGUI/Other/";
  69. File autoSave = new File(autosaveDir);
  70. File category = new File(categoryDir);
  71. File other = new File(otherDir);
  72. // deleteDirectory(dest);
  73. autoSave.mkdirs();
  74. category.mkdirs();
  75. other.mkdirs();
  76. createAutoRandom();
  77. try {
  78. autoSave();
  79. } catch (IOException e) {
  80. e.printStackTrace();
  81. }
  82. }
  83. /**
  84. * Generate random number, so that every instance of the program has unique
  85. * save files
  86. */
  87. private void createAutoRandom() {
  88. rand = (int) (Math.random() * 1000);
  89. while (new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  90. rand = (int) Math.random() * 1000;
  91. }
  92. }
  93. /**
  94. * Delete a Directory.
  95. *
  96. * @param path to delete
  97. */
  98. public void deleteDirectory(File path) {
  99. if (path.exists()) {
  100. File[] files = path.listFiles();
  101. for (File file : files) {
  102. if (file.isDirectory()) {
  103. deleteDirectory(file);
  104. } else {
  105. if (file.getName().contains("" + rand))
  106. file.delete();
  107. }
  108. }
  109. // path.delete();
  110. }
  111. }
  112. /* Operations for searching */
  113. /**
  114. * Search for Object by ID.
  115. *
  116. * @param id the id of the Object
  117. * @return the CpsObject
  118. */
  119. public AbstractCpsObject searchByID(int id) {
  120. return multiPurposeController.searchByID(id);
  121. }
  122. /**
  123. * Search for Object by ID in upperNode
  124. *
  125. * @param id the id of the Object
  126. * @return the CpsObject
  127. */
  128. public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
  129. return multiPurposeController.searchByIDUpperNode(id, upperNode);
  130. }
  131. public AbstractCpsObject searchTracked(int id) {
  132. return multiPurposeController.searchByID(id);
  133. }
  134. /**
  135. * Search for Object in a Category.
  136. *
  137. * @param category name of the Category
  138. * @param object Name of the Object
  139. * @return The Object
  140. */
  141. public AbstractCpsObject searchCategoryObject(String category, String object) {
  142. return multiPurposeController.searchCatObj(multiPurposeController.searchCat(category), object);
  143. }
  144. /**
  145. * search for category.
  146. *
  147. * @param cat name of the Category
  148. * @return the Category
  149. */
  150. public Category searchCategory(String cat) {
  151. return multiPurposeController.searchCat(cat);
  152. }
  153. /* Operations for Categories and Objects */
  154. /**
  155. * init default category and objects.
  156. *
  157. * @throws IOException
  158. */
  159. public void resetCategorys() throws IOException {
  160. categoryController.initCategories();
  161. objectController.initHolonElements();
  162. saveCategory();
  163. }
  164. /**
  165. * Adds New Category into Model.
  166. *
  167. * @param cat name of the new Category
  168. * @throws IOException
  169. */
  170. public void addCategory(String cat) throws IOException {
  171. categoryController.addNewCategory(cat);
  172. saveCategory();
  173. }
  174. /**
  175. * Add new Holon Object to a Category.
  176. *
  177. * @param cat Category
  178. * @param obj New Object Name
  179. * @param ele Array of Elements
  180. * @param img the image Path
  181. * @throws IOException
  182. */
  183. public void addObject(Category cat, String obj, ArrayList<HolonElement> ele, String img) throws IOException {
  184. categoryController.addNewHolonObject(cat, obj, ele, img);
  185. saveCategory();
  186. }
  187. /**
  188. * Add new Holon Transformer to a Category.
  189. *
  190. * @param cat Category
  191. * @param obj New Object Name
  192. */
  193. public void addTransformer(Category cat, String obj) {
  194. categoryController.addNewHolonTransformer(cat, obj, "/Images/transformer-1.png");
  195. }
  196. /**
  197. * Add new Holon Switch to a Category.
  198. *
  199. * @param cat Category
  200. * @param obj New Object Name
  201. * @throws IOException
  202. */
  203. public void addSwitch(Category cat, String obj) throws IOException {
  204. categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-on.png");
  205. saveCategory();
  206. }
  207. /**
  208. * Add new HolonBattery to a Category
  209. * @param cat
  210. * @param obj
  211. * @throws IOException
  212. */
  213. public void addBattery(Category cat, String obj) throws IOException {
  214. categoryController.addNewHolonBattery(cat, obj, "/Images/battery.png");
  215. saveCategory();
  216. }
  217. /**
  218. * delete a given Category.
  219. *
  220. * @param cat the Category
  221. * @throws IOException
  222. */
  223. public void deleteCategory(String cat) throws IOException {
  224. categoryController.deleteCategory(cat);
  225. saveCategory();
  226. }
  227. /**
  228. * Delete an Object from a Category.
  229. *
  230. * @param cat the Category
  231. * @param obj the Object
  232. * @throws IOException
  233. */
  234. public void delObjectCategory(String cat, String obj) throws IOException {
  235. categoryController.deleteObject(cat, obj);
  236. saveCategory();
  237. }
  238. /**
  239. * deletes a selectedObject.
  240. *
  241. * @param obj Cpsobject
  242. */
  243. public void deleteSelectedObject(AbstractCpsObject obj) {
  244. objectController.deleteSelectedObject(obj);
  245. }
  246. /**
  247. * add an Object to selectedObject.
  248. *
  249. * @param obj AbstractCpsobject
  250. */
  251. public void addSelectedObject(AbstractCpsObject obj) {
  252. objectController.addSelectedObject(obj);
  253. }
  254. /* Operations for Canvas */
  255. /**
  256. * Add a new Object.
  257. *
  258. * @param object the Object
  259. */
  260. public void addObjectCanvas(AbstractCpsObject object) {
  261. canvasController.addNewObject(object);
  262. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  263. if (!(object instanceof CpsNode)) {
  264. try {
  265. autoSave();
  266. } catch (IOException e) {
  267. e.printStackTrace();
  268. }
  269. }
  270. }
  271. /**
  272. * Deletes an CpsObject on the Canvas and its connections.
  273. *
  274. * @param obj AbstractCpsObject
  275. * @param save
  276. */
  277. public void delCanvasObject(AbstractCpsObject obj, boolean save) {
  278. canvasController.deleteObjectOnCanvas(obj);
  279. calculateStateForCurrentTimeStep();
  280. if (obj instanceof CpsUpperNode)
  281. canvasController.bfsNodeCleaner((CpsUpperNode) obj);
  282. if (save)
  283. try {
  284. autoSave();
  285. } catch (IOException e) {
  286. e.printStackTrace();
  287. }
  288. }
  289. /**
  290. * Add an edge to the Canvas.
  291. *
  292. * @param edge the edge
  293. */
  294. public void addEdgeOnCanvas(CpsEdge edge) {
  295. canvasController.addEdgeOnCanvas(edge);
  296. try {
  297. autoSave();
  298. } catch (IOException e) {
  299. e.printStackTrace();
  300. }
  301. }
  302. /**
  303. * Removes an Edge from the Canvas.
  304. *
  305. * @param edge the edge to remove
  306. */
  307. public void removeEdgesOnCanvas(CpsEdge edge) {
  308. canvasController.removeEdgesOnCanvas(edge);
  309. try {
  310. autoSave();
  311. } catch (IOException e) {
  312. e.printStackTrace();
  313. }
  314. }
  315. /**
  316. * Set the selected Edge.
  317. *
  318. * @param edge that is selected
  319. */
  320. public void setSelecteEdge(CpsEdge edge) {
  321. model.setSelectedEdge(edge);
  322. }
  323. /**
  324. * Returns the ID of the selected Object 0 = no Object is selected.
  325. *
  326. * @param id the ID of the selected Object
  327. */
  328. public void setSelectedObjectID(int id) {
  329. objectController.setSelectedObjectID(id);
  330. }
  331. /* Operations for Objects and Elements */
  332. /**
  333. * Add a new Element into a Object on the Canvas.
  334. *
  335. * @param objectId the Object ID
  336. * @param ele the Name of the Element
  337. * @param amount the Amount
  338. * @param energy the Energy
  339. * @param elementId the Element ID
  340. */
  341. public void addElementCanvasObject(int objectId, String ele, int amount, float energy, int elementId) {
  342. objectController.addNewElementIntoCanvasObject(objectId, ele, amount, energy, elementId);
  343. try {
  344. autoSave();
  345. } catch (IOException e) {
  346. e.printStackTrace();
  347. }
  348. }
  349. /**
  350. * Add a new Element into a Object in Category.
  351. *
  352. * @param catName the Category
  353. * @param objName the Object
  354. * @param eleName the Element Name
  355. * @param amount the amount
  356. * @param energy the Energy
  357. */
  358. public void addElementCategoryObject(String catName, String objName, String eleName, int amount, float energy) {
  359. objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
  360. }
  361. /**
  362. * deletes a Element from a given Canvas Object.
  363. *
  364. * @param id the ID
  365. * @param elementid the Element ID
  366. */
  367. public void deleteElementCanvas(int id, int elementid) {
  368. objectController.deleteElementInCanvas(id, elementid);
  369. try {
  370. autoSave();
  371. } catch (IOException e) {
  372. e.printStackTrace();
  373. }
  374. }
  375. /* Global Operations */
  376. /**
  377. * Add a SubNetColor.
  378. *
  379. * @param c the Color
  380. */
  381. public void addSubNetColor(Color c) {
  382. globalController.addSubNetColor(c);
  383. }
  384. /**
  385. * Returns SCALE.
  386. *
  387. * @return SCALE
  388. */
  389. public int getScale() {
  390. return globalController.getScale();
  391. }
  392. /**
  393. * Changes the value of SCALE and SCALEDIV2.
  394. *
  395. * @param s Scale
  396. */
  397. public void setScale(int s) {
  398. globalController.setScale(s);
  399. }
  400. /**
  401. * Returns SCALE Divided by 2.
  402. *
  403. * @return SCALE Divided by 2
  404. */
  405. public int getScaleDiv2() {
  406. return globalController.getScaleDiv2();
  407. }
  408. /**
  409. * sets the current Iteration.
  410. *
  411. * @param curit the current Iteration
  412. */
  413. public void setCurIteration(int curit) {
  414. globalController.setCurIteration(curit);
  415. }
  416. /**
  417. * Writes the current State of the Modelling into a JSON File which can be
  418. * loaded.
  419. *
  420. * @param path the Path
  421. * @throws IOException exception
  422. */
  423. public void saveFile(String path) throws IOException, ArchiveException {
  424. saveController.writeSave(path);
  425. }
  426. /**
  427. * Reads the the Save File and load the state into the Model.
  428. *
  429. * @param path the Path
  430. * @throws IOException exception
  431. * @throws ArchiveException
  432. */
  433. public void loadFile(String path) throws IOException, ArchiveException {
  434. loadController.readSave(path);
  435. saveCategory();
  436. autoSave();
  437. }
  438. /**
  439. * Reads the Json File from Autosave
  440. *
  441. * @param path
  442. * @throws IOException
  443. */
  444. public void loadAutoSave(String path) throws IOException {
  445. loadController.readJson(path);
  446. }
  447. public ArrayList<Integer> loadSavedWindowDimensionsIfExistent() {
  448. try {
  449. return loadController.readWindowDimensions(otherDir + dimensionsFileName);
  450. } catch (Exception e) {
  451. return new ArrayList<>();
  452. }
  453. }
  454. /**
  455. * Init the CategoryListener.
  456. *
  457. * @param catLis the CategoryListener
  458. */
  459. public void initListener(CategoryListener catLis) {
  460. categoryController.addCategoryListener(catLis);
  461. }
  462. /**
  463. * calculates the flow of the edges and the supply for objects for the
  464. * current Timestep.
  465. */
  466. public void calculateStateForCurrentTimeStep() {
  467. // simulationManager.reset();
  468. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  469. }
  470. /**
  471. * calculates the flow of the edges and the supply for objects.
  472. *
  473. * @param x current Iteration
  474. */
  475. public void calculateStateForTimeStep(int x) {
  476. // simulationManager.reset();
  477. simulationManager.calculateStateForTimeStep(x);
  478. }
  479. /**
  480. * resets the whole State of the simulation including a reset of all Edges
  481. * to the default "is working" state
  482. */
  483. public void resetSimulation() {
  484. setIsSimRunning(false);
  485. simulationManager.resetSimulation();
  486. }
  487. /**
  488. * Set the Canvas.
  489. *
  490. * @param can the Canvas
  491. */
  492. public void setCanvas(MyCanvas can) {
  493. simulationManager.setCanvas(can);
  494. }
  495. /**
  496. * make an autosave.
  497. *
  498. * @throws IOException Exception
  499. */
  500. public void autoSave() throws IOException {
  501. autoSaveController.increaseAutoSaveNr();
  502. saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
  503. if (autoSaveController.allowed()) {
  504. new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
  505. .delete();
  506. }
  507. }
  508. /**
  509. * find all old auto save files (with a file-name, that does not contain the current rand)
  510. *
  511. * @return a list of files, that are not from the current run
  512. */
  513. public ArrayList<File> filterOldAutoSaveFiles() {
  514. File[] files = new File(autosaveDir).listFiles();
  515. ArrayList<File> oldAutoSaves = new ArrayList<>();
  516. for (File file : files) {
  517. if (!file.getName().contains(String.valueOf(rand)))
  518. oldAutoSaves.add(file);
  519. }
  520. return oldAutoSaves;
  521. }
  522. /**
  523. * deletes the old autosave files
  524. */
  525. public void deleteObsoleteAutoSaveFiles() {
  526. for (File file : filterOldAutoSaveFiles()) {
  527. file.delete();
  528. }
  529. }
  530. public void saveCategory() throws IOException {
  531. saveController.writeCategory(categoryDir + "Category.json");
  532. }
  533. public void savePosAndSizeOfWindow(int x, int y, int width, int height) throws IOException, ArchiveException {
  534. saveController.writeWindowStatus(otherDir + dimensionsFileName, x, y, width, height);
  535. }
  536. /**
  537. * Returns the undo save.
  538. *
  539. * @return the undo save
  540. */
  541. public String getUndoSave() {
  542. autoSaveController.decreaseAutoSaveNr();
  543. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  544. autoSaveController.increaseAutoSaveNr();
  545. }
  546. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  547. }
  548. /**
  549. * Returns the redo save.
  550. *
  551. * @return the redo save
  552. */
  553. public String getRedoSave() {
  554. autoSaveController.increaseAutoSaveNr();
  555. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  556. autoSaveController.decreaseAutoSaveNr();
  557. // if it still does not exist, try old autosaves
  558. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  559. ArrayList<File> oldAutoSaves = filterOldAutoSaveFiles();
  560. if (oldAutoSaves.size() > 0) {
  561. return autosaveDir + oldAutoSaves.get(oldAutoSaves.size() - 1).getName();
  562. }
  563. }
  564. }
  565. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  566. }
  567. /**
  568. * Getter for Model.
  569. *
  570. * @return the Model
  571. */
  572. public Model getModel() {
  573. return model;
  574. }
  575. /**
  576. * get the Simulation Manager.
  577. *
  578. * @return the Simulation Manager
  579. */
  580. public SimulationManager getSimManager() {
  581. return simulationManager;
  582. }
  583. /**
  584. * Getter for selected CpsObject.
  585. *
  586. * @param text String the Text
  587. * @param color the color of the Text
  588. * @param p size of the Text
  589. * @param bold bold or not
  590. * @param italic italic or not
  591. * @param nl new line or not
  592. */
  593. public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
  594. consoleController.addTextToConsole(text, color, p, bold, italic, nl);
  595. }
  596. /**
  597. * Print Text on the console in black and font size 12.
  598. *
  599. * @param text String the Text
  600. */
  601. public void addTextToConsole(String text) {
  602. consoleController.addTextToConsole(text);
  603. }
  604. /**
  605. * Clears the console.
  606. */
  607. public void clearConsole() {
  608. consoleController.clearConsole();
  609. }
  610. /**
  611. * Set the timerSpeed.
  612. *
  613. * @param t interval in ms
  614. */
  615. public void setTimerSpeed(int t) {
  616. globalController.setTimerSpeed(t);
  617. }
  618. /**
  619. * Set the Canvas X Size.
  620. *
  621. * @param canvasX the cANVAS_X to set
  622. */
  623. public void setCanvasX(int canvasX) {
  624. globalController.setCanvasX(canvasX);
  625. try {
  626. autoSave();
  627. } catch (IOException e) {
  628. e.printStackTrace();
  629. }
  630. }
  631. /**
  632. * Set the Canvas Y Size.
  633. *
  634. * @param canvasY the cANVAS_Y to set
  635. */
  636. public void setCanvasY(int canvasY) {
  637. globalController.setCanvasY(canvasY);
  638. try {
  639. autoSave();
  640. } catch (IOException e) {
  641. e.printStackTrace();
  642. }
  643. }
  644. public void setMaxCapacity(float cap) {
  645. globalController.setMaxCapacity(cap);
  646. }
  647. /**
  648. * Set the Algorithm.
  649. *
  650. * @param obj the Algorithm
  651. */
  652. public void setAlgorithm(Object obj) {
  653. multiPurposeController.setAlgorithm(obj);
  654. }
  655. /**
  656. * Run the Algorithm.
  657. */
  658. public void runAlgorithm(Model model, Control controller) {
  659. if (model.getAlgorithm() != null) {
  660. ((CpsAlgorithm) model.getAlgorithm()).runAlgorithm(model, controller);
  661. }
  662. }
  663. // ========================= MANAGING TRACKED OBJECTS ====================
  664. public ArrayList<AbstractCpsObject> getTrackingObj() {
  665. return statsController.getTrackingObj();
  666. }
  667. public void setTrackingObj(ArrayList<AbstractCpsObject> objArr) {
  668. statsController.setTrackingObj(objArr);
  669. }
  670. public void addTrackingObj(AbstractCpsObject obj) {
  671. statsController.addTrackingObj(obj);
  672. try {
  673. autoSave();
  674. } catch (IOException e) {
  675. e.printStackTrace();
  676. }
  677. }
  678. public void removeTrackingObj(AbstractCpsObject obj) {
  679. statsController.removeTrackingObj(obj);
  680. try {
  681. autoSave();
  682. } catch (IOException e) {
  683. e.printStackTrace();
  684. }
  685. }
  686. // ========================== MANAGING TRACKED OBJECTS END ================
  687. /**
  688. * Controlling Nodes of Nodes
  689. */
  690. public void addUpperNode(String nodeName, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
  691. nodeController.doUpperNode(nodeName, upperNode, toGroup);
  692. try {
  693. autoSave();
  694. } catch (IOException e) {
  695. e.printStackTrace();
  696. }
  697. }
  698. public void delUpperNode(CpsUpperNode node, CpsUpperNode upperNode) {
  699. nodeController.undoUpperNode(node, upperNode);
  700. try {
  701. autoSave();
  702. } catch (IOException e) {
  703. e.printStackTrace();
  704. }
  705. }
  706. public void addObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  707. nodeController.addObjectInUpperNode(object, upperNode);
  708. try {
  709. autoSave();
  710. } catch (IOException e) {
  711. e.printStackTrace();
  712. }
  713. }
  714. public void delObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  715. nodeController.deleteObjectInUpperNode(object, upperNode);
  716. if (object instanceof CpsUpperNode)
  717. canvasController.bfsNodeCleaner((CpsUpperNode) object);
  718. try {
  719. autoSave();
  720. } catch (IOException e) {
  721. e.printStackTrace();
  722. }
  723. }
  724. public void addEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  725. nodeController.addEdge(edge, upperNode);
  726. try {
  727. autoSave();
  728. } catch (IOException e) {
  729. e.printStackTrace();
  730. }
  731. }
  732. public void delEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  733. nodeController.deleteEdge(edge, upperNode);
  734. try {
  735. autoSave();
  736. } catch (IOException e) {
  737. e.printStackTrace();
  738. }
  739. }
  740. public void connectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  741. nodeController.connectNodes(edge, upperNode);
  742. try {
  743. autoSave();
  744. } catch (IOException e) {
  745. e.printStackTrace();
  746. }
  747. }
  748. public void disconnectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  749. nodeController.disconnectNodes(edge, upperNode);
  750. try {
  751. autoSave();
  752. } catch (IOException e) {
  753. e.printStackTrace();
  754. }
  755. }
  756. /**
  757. * Get the number of HolonObjects in the given List
  758. *
  759. * @param list
  760. */
  761. public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
  762. return objectController.getNumberHolonObjects(list);
  763. }
  764. /**
  765. * Get the number of HolonObjects with the given state in the given List
  766. *
  767. * @param list
  768. * @param state
  769. */
  770. public int getNumberStateObjects(ArrayList<AbstractCpsObject> list, int state) {
  771. return objectController.getNumberStateObjects(list, state);
  772. }
  773. /**
  774. * Returns HolonBodySCALE.
  775. *
  776. * @return SCALE
  777. */
  778. public int getHolonBodyScale() {
  779. return globalController.getHolonBodyScale();
  780. }
  781. /**
  782. * Changes the value of HolonBodySCALE
  783. *
  784. * @param s HolonBodyScale
  785. */
  786. public void setHolonBodyScale(int s) {
  787. globalController.setHolonBodyScale(s);
  788. }
  789. /**
  790. * Sets the ID of the selected HolonBody
  791. *
  792. * @param i ID of the selected HolonBody
  793. */
  794. public void addSelectedHolonBody(int i) {
  795. objectController.addSelectedHolonBody(i);
  796. }
  797. /**
  798. * Copy all Selected Objects.
  799. */
  800. public void copy(CpsUpperNode upperNode) {
  801. clipboardController.copy(upperNode);
  802. }
  803. public void paste(CpsUpperNode upperNode, Point point)
  804. throws JsonParseException, UnsupportedFlavorException, IOException {
  805. clipboardController.paste(upperNode, point);
  806. try {
  807. autoSave();
  808. } catch (IOException e) {
  809. e.printStackTrace();
  810. }
  811. }
  812. public void cut(CpsUpperNode upperNode) {
  813. clipboardController.cut(upperNode);
  814. try {
  815. autoSave();
  816. } catch (IOException e) {
  817. e.printStackTrace();
  818. }
  819. }
  820. public void getObjectsInDepth() {
  821. clipboardController.getObjectsInDepth();
  822. }
  823. public float getTotalProduction(ArrayList<AbstractCpsObject> arrayList) {
  824. return holonCanvasController.getTotalProduction(arrayList);
  825. }
  826. public float getTotalConsumption(ArrayList<AbstractCpsObject> arrayList) {
  827. return holonCanvasController.getTotalConsumption(arrayList);
  828. }
  829. public int getTotalElements(ArrayList<AbstractCpsObject> arrayList) {
  830. return holonCanvasController.getTotalElements(arrayList);
  831. }
  832. public int getTotalProducers(ArrayList<AbstractCpsObject> arrayList) {
  833. return holonCanvasController.getTotalProducers(arrayList);
  834. }
  835. public int getActiveElements(ArrayList<AbstractCpsObject> arrayList) {
  836. return holonCanvasController.getActiveElements(arrayList);
  837. }
  838. /**
  839. * Set the Background Image;
  840. *
  841. * @param imagePath Image Path
  842. * @param mode Image Mode
  843. * @param width Image custom width
  844. * @param height Image custom height
  845. */
  846. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  847. canvasController.setBackgroundImage(imagePath, mode, width, height);
  848. }
  849. public void setFlexiblePane(FlexiblePane fp) {
  850. simulationManager.setFlexiblePane(fp);
  851. }
  852. public Hashtable<String, StatisticGraphPanel> getGraphTable() {
  853. return model.getGraphTable();
  854. }
  855. public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
  856. model.setGraphTable(gT);
  857. }
  858. /**
  859. * Sets if the Simulation is running
  860. */
  861. public void setIsSimRunning(boolean isRunning) {
  862. globalController.setIsSimRunning(isRunning);
  863. }
  864. /**
  865. * Sets showConsoleLog.
  866. *
  867. * @param showConsoleLog
  868. */
  869. public void setShowConsoleLog(boolean showConsoleLog) {
  870. globalController.setShowConsoleLog(showConsoleLog);
  871. }
  872. /**
  873. * Sets show
  874. * @param showSupplyBars wether the bars should be shown
  875. */
  876. public void setShowSupplyBars(boolean showSupplyBars) {
  877. globalController.setShowSupplyBars(showSupplyBars);
  878. }
  879. /**
  880. * Sets fairness Model
  881. * @param fairnessModel that should be used.
  882. */
  883. public void setFairnessModel(short fairnessModel) {
  884. globalController.setFairnessModel(fairnessModel);
  885. }
  886. }