Control.java 26 KB

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