Control.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. * delete a given Category.
  209. *
  210. * @param cat the Category
  211. * @throws IOException
  212. */
  213. public void deleteCategory(String cat) throws IOException {
  214. categoryController.deleteCategory(cat);
  215. saveCategory();
  216. }
  217. /**
  218. * Delete an Object from a Category.
  219. *
  220. * @param cat the Category
  221. * @param obj the Object
  222. * @throws IOException
  223. */
  224. public void delObjectCategory(String cat, String obj) throws IOException {
  225. categoryController.deleteObject(cat, obj);
  226. saveCategory();
  227. }
  228. /**
  229. * deletes a selectedObject.
  230. *
  231. * @param obj Cpsobject
  232. */
  233. public void deleteSelectedObject(AbstractCpsObject obj) {
  234. objectController.deleteSelectedObject(obj);
  235. }
  236. /**
  237. * add an Object to selectedObject.
  238. *
  239. * @param obj AbstractCpsobject
  240. */
  241. public void addSelectedObject(AbstractCpsObject obj) {
  242. objectController.addSelectedObject(obj);
  243. }
  244. /* Operations for Canvas */
  245. /**
  246. * Add a new Object.
  247. *
  248. * @param object the Object
  249. */
  250. public void addObjectCanvas(AbstractCpsObject object) {
  251. canvasController.addNewObject(object);
  252. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  253. if (!(object instanceof CpsNode)) {
  254. try {
  255. autoSave();
  256. } catch (IOException e) {
  257. e.printStackTrace();
  258. }
  259. }
  260. }
  261. /**
  262. * Deletes an CpsObject on the Canvas and its connections.
  263. *
  264. * @param obj AbstractCpsObject
  265. * @param save
  266. */
  267. public void delCanvasObject(AbstractCpsObject obj, boolean save) {
  268. canvasController.deleteObjectOnCanvas(obj);
  269. calculateStateForCurrentTimeStep();
  270. if (obj instanceof CpsUpperNode)
  271. canvasController.bfsNodeCleaner((CpsUpperNode) obj);
  272. if (save)
  273. try {
  274. autoSave();
  275. } catch (IOException e) {
  276. e.printStackTrace();
  277. }
  278. }
  279. /**
  280. * Add an edge to the Canvas.
  281. *
  282. * @param edge the edge
  283. */
  284. public void addEdgeOnCanvas(CpsEdge edge) {
  285. canvasController.addEdgeOnCanvas(edge);
  286. try {
  287. autoSave();
  288. } catch (IOException e) {
  289. e.printStackTrace();
  290. }
  291. }
  292. /**
  293. * Removes an Edge from the Canvas.
  294. *
  295. * @param edge the edge to remove
  296. */
  297. public void removeEdgesOnCanvas(CpsEdge edge) {
  298. canvasController.removeEdgesOnCanvas(edge);
  299. try {
  300. autoSave();
  301. } catch (IOException e) {
  302. e.printStackTrace();
  303. }
  304. }
  305. /**
  306. * Set the selected Edge.
  307. *
  308. * @param edge that is selected
  309. */
  310. public void setSelecteEdge(CpsEdge edge) {
  311. model.setSelectedEdge(edge);
  312. }
  313. /**
  314. * Returns the ID of the selected Object 0 = no Object is selected.
  315. *
  316. * @param id the ID of the selected Object
  317. */
  318. public void setSelectedObjectID(int id) {
  319. objectController.setSelectedObjectID(id);
  320. }
  321. /* Operations for Objects and Elements */
  322. /**
  323. * Add a new Element into a Object on the Canvas.
  324. *
  325. * @param objectId the Object ID
  326. * @param ele the Name of the Element
  327. * @param amount the Amount
  328. * @param energy the Energy
  329. * @param elementId the Element ID
  330. */
  331. public void addElementCanvasObject(int objectId, String ele, int amount, float energy, int elementId) {
  332. objectController.addNewElementIntoCanvasObject(objectId, ele, amount, energy, elementId);
  333. try {
  334. autoSave();
  335. } catch (IOException e) {
  336. e.printStackTrace();
  337. }
  338. }
  339. /**
  340. * Add a new Element into a Object in Category.
  341. *
  342. * @param catName the Category
  343. * @param objName the Object
  344. * @param eleName the Element Name
  345. * @param amount the amount
  346. * @param energy the Energy
  347. */
  348. public void addElementCategoryObject(String catName, String objName, String eleName, int amount, float energy) {
  349. objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
  350. }
  351. /**
  352. * deletes a Element from a given Canvas Object.
  353. *
  354. * @param id the ID
  355. * @param elementid the Element ID
  356. */
  357. public void deleteElementCanvas(int id, int elementid) {
  358. objectController.deleteElementInCanvas(id, elementid);
  359. try {
  360. autoSave();
  361. } catch (IOException e) {
  362. e.printStackTrace();
  363. }
  364. }
  365. /* Global Operations */
  366. /**
  367. * Add a SubNetColor.
  368. *
  369. * @param c the Color
  370. */
  371. public void addSubNetColor(Color c) {
  372. globalController.addSubNetColor(c);
  373. }
  374. /**
  375. * Returns SCALE.
  376. *
  377. * @return SCALE
  378. */
  379. public int getScale() {
  380. return globalController.getScale();
  381. }
  382. /**
  383. * Changes the value of SCALE and SCALEDIV2.
  384. *
  385. * @param s Scale
  386. */
  387. public void setScale(int s) {
  388. globalController.setScale(s);
  389. }
  390. /**
  391. * Returns SCALE Divided by 2.
  392. *
  393. * @return SCALE Divided by 2
  394. */
  395. public int getScaleDiv2() {
  396. return globalController.getScaleDiv2();
  397. }
  398. /**
  399. * sets the current Iteration.
  400. *
  401. * @param curit the current Iteration
  402. */
  403. public void setCurIteration(int curit) {
  404. globalController.setCurIteration(curit);
  405. }
  406. /**
  407. * Writes the current State of the Modelling into a JSON File which can be
  408. * loaded.
  409. *
  410. * @param path the Path
  411. * @throws IOException exception
  412. */
  413. public void saveFile(String path) throws IOException, ArchiveException {
  414. saveController.writeSave(path);
  415. }
  416. /**
  417. * Reads the the Save File and load the state into the Model.
  418. *
  419. * @param path the Path
  420. * @throws IOException exception
  421. * @throws ArchiveException
  422. */
  423. public void loadFile(String path) throws IOException, ArchiveException {
  424. loadController.readSave(path);
  425. saveCategory();
  426. autoSave();
  427. }
  428. /**
  429. * Reads the Json File from Autosave
  430. *
  431. * @param path
  432. * @throws IOException
  433. */
  434. public void loadAutoSave(String path) throws IOException {
  435. loadController.readJson(path);
  436. }
  437. public ArrayList<Integer> loadSavedWindowDimensionsIfExistent() {
  438. try {
  439. return loadController.readWindowDimensions(otherDir + dimensionsFileName);
  440. } catch (Exception e) {
  441. return new ArrayList<>();
  442. }
  443. }
  444. /**
  445. * Init the CategoryListener.
  446. *
  447. * @param catLis the CategoryListener
  448. */
  449. public void initListener(CategoryListener catLis) {
  450. categoryController.addCategoryListener(catLis);
  451. }
  452. /**
  453. * calculates the flow of the edges and the supply for objects for the
  454. * current Timestep.
  455. */
  456. public void calculateStateForCurrentTimeStep() {
  457. // simulationManager.reset();
  458. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  459. }
  460. /**
  461. * calculates the flow of the edges and the supply for objects.
  462. *
  463. * @param x current Iteration
  464. */
  465. public void calculateStateForTimeStep(int x) {
  466. // simulationManager.reset();
  467. simulationManager.calculateStateForTimeStep(x);
  468. }
  469. /**
  470. * resets the whole State of the simulation including a reset of all Edges
  471. * to the default "is working" state
  472. */
  473. public void resetSimulation() {
  474. setIsSimRunning(false);
  475. simulationManager.resetSimulation();
  476. }
  477. /**
  478. * Set the Canvas.
  479. *
  480. * @param can the Canvas
  481. */
  482. public void setCanvas(MyCanvas can) {
  483. simulationManager.setCanvas(can);
  484. }
  485. /**
  486. * make an autosave.
  487. *
  488. * @throws IOException Exception
  489. */
  490. public void autoSave() throws IOException {
  491. autoSaveController.increaseAutoSaveNr();
  492. saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
  493. if (autoSaveController.allowed()) {
  494. new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
  495. .delete();
  496. }
  497. }
  498. /**
  499. * find all old auto save files (with a file-name, that does not contain the current rand)
  500. *
  501. * @return a list of files, that are not from the current run
  502. */
  503. public ArrayList<File> filterOldAutoSaveFiles() {
  504. File[] files = new File(autosaveDir).listFiles();
  505. ArrayList<File> oldAutoSaves = new ArrayList<>();
  506. for (File file : files) {
  507. if (!file.getName().contains(String.valueOf(rand)))
  508. oldAutoSaves.add(file);
  509. }
  510. return oldAutoSaves;
  511. }
  512. /**
  513. * deletes the old autosave files
  514. */
  515. public void deleteObsoleteAutoSaveFiles() {
  516. for (File file : filterOldAutoSaveFiles()) {
  517. file.delete();
  518. }
  519. }
  520. public void saveCategory() throws IOException {
  521. saveController.writeCategory(categoryDir + "Category.json");
  522. }
  523. public void savePosAndSizeOfWindow(int x, int y, int width, int height) throws IOException, ArchiveException {
  524. saveController.writeWindowStatus(otherDir + dimensionsFileName, x, y, width, height);
  525. }
  526. /**
  527. * Returns the undo save.
  528. *
  529. * @return the undo save
  530. */
  531. public String getUndoSave() {
  532. autoSaveController.decreaseAutoSaveNr();
  533. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  534. autoSaveController.increaseAutoSaveNr();
  535. }
  536. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  537. }
  538. /**
  539. * Returns the redo save.
  540. *
  541. * @return the redo save
  542. */
  543. public String getRedoSave() {
  544. autoSaveController.increaseAutoSaveNr();
  545. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  546. autoSaveController.decreaseAutoSaveNr();
  547. // if it still does not exist, try old autosaves
  548. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  549. ArrayList<File> oldAutoSaves = filterOldAutoSaveFiles();
  550. if (oldAutoSaves.size() > 0) {
  551. return autosaveDir + oldAutoSaves.get(oldAutoSaves.size() - 1).getName();
  552. }
  553. }
  554. }
  555. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  556. }
  557. /**
  558. * Getter for Model.
  559. *
  560. * @return the Model
  561. */
  562. public Model getModel() {
  563. return model;
  564. }
  565. /**
  566. * get the Simulation Manager.
  567. *
  568. * @return the Simulation Manager
  569. */
  570. public SimulationManager getSimManager() {
  571. return simulationManager;
  572. }
  573. /**
  574. * Getter for selected CpsObject.
  575. *
  576. * @param text String the Text
  577. * @param color the color of the Text
  578. * @param p size of the Text
  579. * @param bold bold or not
  580. * @param italic italic or not
  581. * @param nl new line or not
  582. */
  583. public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
  584. consoleController.addTextToConsole(text, color, p, bold, italic, nl);
  585. }
  586. /**
  587. * Print Text on the console in black and font size 12.
  588. *
  589. * @param text String the Text
  590. */
  591. public void addTextToConsole(String text) {
  592. consoleController.addTextToConsole(text);
  593. }
  594. /**
  595. * Clears the console.
  596. */
  597. public void clearConsole() {
  598. consoleController.clearConsole();
  599. }
  600. /**
  601. * Set the timerSpeed.
  602. *
  603. * @param t interval in ms
  604. */
  605. public void setTimerSpeed(int t) {
  606. globalController.setTimerSpeed(t);
  607. }
  608. /**
  609. * Set the Canvas X Size.
  610. *
  611. * @param canvasX the cANVAS_X to set
  612. */
  613. public void setCanvasX(int canvasX) {
  614. globalController.setCanvasX(canvasX);
  615. try {
  616. autoSave();
  617. } catch (IOException e) {
  618. e.printStackTrace();
  619. }
  620. }
  621. /**
  622. * Set the Canvas Y Size.
  623. *
  624. * @param canvasY the cANVAS_Y to set
  625. */
  626. public void setCanvasY(int canvasY) {
  627. globalController.setCanvasY(canvasY);
  628. try {
  629. autoSave();
  630. } catch (IOException e) {
  631. e.printStackTrace();
  632. }
  633. }
  634. public void setMaxCapacity(float cap) {
  635. globalController.setMaxCapacity(cap);
  636. }
  637. /**
  638. * Set the Algorithm.
  639. *
  640. * @param obj the Algorithm
  641. */
  642. public void setAlgorithm(Object obj) {
  643. multiPurposeController.setAlgorithm(obj);
  644. }
  645. /**
  646. * Run the Algorithm.
  647. */
  648. public void runAlgorithm(Model model, Control controller) {
  649. if (model.getAlgorithm() != null) {
  650. ((CpsAlgorithm) model.getAlgorithm()).runAlgorithm(model, controller);
  651. }
  652. }
  653. // ========================= MANAGING TRACKED OBJECTS ====================
  654. public ArrayList<AbstractCpsObject> getTrackingObj() {
  655. return statsController.getTrackingObj();
  656. }
  657. public void setTrackingObj(ArrayList<AbstractCpsObject> objArr) {
  658. statsController.setTrackingObj(objArr);
  659. }
  660. public void addTrackingObj(AbstractCpsObject obj) {
  661. statsController.addTrackingObj(obj);
  662. try {
  663. autoSave();
  664. } catch (IOException e) {
  665. e.printStackTrace();
  666. }
  667. }
  668. public void removeTrackingObj(AbstractCpsObject obj) {
  669. statsController.removeTrackingObj(obj);
  670. try {
  671. autoSave();
  672. } catch (IOException e) {
  673. e.printStackTrace();
  674. }
  675. }
  676. // ========================== MANAGING TRACKED OBJECTS END ================
  677. /**
  678. * Controlling Nodes of Nodes
  679. */
  680. public void addUpperNode(String nodeName, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
  681. nodeController.doUpperNode(nodeName, upperNode, toGroup);
  682. try {
  683. autoSave();
  684. } catch (IOException e) {
  685. e.printStackTrace();
  686. }
  687. }
  688. public void delUpperNode(CpsUpperNode node, CpsUpperNode upperNode) {
  689. nodeController.undoUpperNode(node, upperNode);
  690. try {
  691. autoSave();
  692. } catch (IOException e) {
  693. e.printStackTrace();
  694. }
  695. }
  696. public void addObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  697. nodeController.addObjectInUpperNode(object, upperNode);
  698. try {
  699. autoSave();
  700. } catch (IOException e) {
  701. e.printStackTrace();
  702. }
  703. }
  704. public void delObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  705. nodeController.deleteObjectInUpperNode(object, upperNode);
  706. if (object instanceof CpsUpperNode)
  707. canvasController.bfsNodeCleaner((CpsUpperNode) object);
  708. try {
  709. autoSave();
  710. } catch (IOException e) {
  711. e.printStackTrace();
  712. }
  713. }
  714. public void addEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  715. nodeController.addEdge(edge, upperNode);
  716. try {
  717. autoSave();
  718. } catch (IOException e) {
  719. e.printStackTrace();
  720. }
  721. }
  722. public void delEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  723. nodeController.deleteEdge(edge, upperNode);
  724. try {
  725. autoSave();
  726. } catch (IOException e) {
  727. e.printStackTrace();
  728. }
  729. }
  730. public void connectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  731. nodeController.connectNodes(edge, upperNode);
  732. try {
  733. autoSave();
  734. } catch (IOException e) {
  735. e.printStackTrace();
  736. }
  737. }
  738. public void disconnectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  739. nodeController.disconnectNodes(edge, upperNode);
  740. try {
  741. autoSave();
  742. } catch (IOException e) {
  743. e.printStackTrace();
  744. }
  745. }
  746. /**
  747. * Get the number of HolonObjects in the given List
  748. *
  749. * @param list
  750. */
  751. public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
  752. return objectController.getNumberHolonObjects(list);
  753. }
  754. /**
  755. * Get the number of HolonObjects with the given state in the given List
  756. *
  757. * @param list
  758. * @param state
  759. */
  760. public int getNumberStateObjects(ArrayList<AbstractCpsObject> list, int state) {
  761. return objectController.getNumberStateObjects(list, state);
  762. }
  763. /**
  764. * Returns HolonBodySCALE.
  765. *
  766. * @return SCALE
  767. */
  768. public int getHolonBodyScale() {
  769. return globalController.getHolonBodyScale();
  770. }
  771. /**
  772. * Changes the value of HolonBodySCALE
  773. *
  774. * @param s HolonBodyScale
  775. */
  776. public void setHolonBodyScale(int s) {
  777. globalController.setHolonBodyScale(s);
  778. }
  779. /**
  780. * Sets the ID of the selected HolonBody
  781. *
  782. * @param i ID of the selected HolonBody
  783. */
  784. public void addSelectedHolonBody(int i) {
  785. objectController.addSelectedHolonBody(i);
  786. }
  787. /**
  788. * Copy all Selected Objects.
  789. */
  790. public void copy(CpsUpperNode upperNode) {
  791. clipboardController.copy(upperNode);
  792. }
  793. public void paste(CpsUpperNode upperNode, Point point)
  794. throws JsonParseException, UnsupportedFlavorException, IOException {
  795. clipboardController.paste(upperNode, point);
  796. try {
  797. autoSave();
  798. } catch (IOException e) {
  799. e.printStackTrace();
  800. }
  801. }
  802. public void cut(CpsUpperNode upperNode) {
  803. clipboardController.cut(upperNode);
  804. try {
  805. autoSave();
  806. } catch (IOException e) {
  807. e.printStackTrace();
  808. }
  809. }
  810. public void getObjectsInDepth() {
  811. clipboardController.getObjectsInDepth();
  812. }
  813. public float getTotalProduction(ArrayList<AbstractCpsObject> arrayList) {
  814. return holonCanvasController.getTotalProduction(arrayList);
  815. }
  816. public float getTotalConsumption(ArrayList<AbstractCpsObject> arrayList) {
  817. return holonCanvasController.getTotalConsumption(arrayList);
  818. }
  819. public int getTotalElements(ArrayList<AbstractCpsObject> arrayList) {
  820. return holonCanvasController.getTotalElements(arrayList);
  821. }
  822. public int getTotalProducers(ArrayList<AbstractCpsObject> arrayList) {
  823. return holonCanvasController.getTotalProducers(arrayList);
  824. }
  825. public int getActiveElements(ArrayList<AbstractCpsObject> arrayList) {
  826. return holonCanvasController.getActiveElements(arrayList);
  827. }
  828. /**
  829. * Set the Background Image;
  830. *
  831. * @param imagePath Image Path
  832. * @param mode Image Mode
  833. * @param width Image custom width
  834. * @param height Image custom height
  835. */
  836. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  837. canvasController.setBackgroundImage(imagePath, mode, width, height);
  838. }
  839. public void setFlexiblePane(FlexiblePane fp) {
  840. simulationManager.setFlexiblePane(fp);
  841. }
  842. public Hashtable<String, StatisticGraphPanel> getGraphTable() {
  843. return model.getGraphTable();
  844. }
  845. public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
  846. model.setGraphTable(gT);
  847. }
  848. /**
  849. * Sets if the Simulation is running
  850. */
  851. public void setIsSimRunning(boolean isRunning) {
  852. globalController.setIsSimRunning(isRunning);
  853. }
  854. /**
  855. * Sets showConsoleLog.
  856. *
  857. * @param showConsoleLog
  858. */
  859. public void setShowConsoleLog(boolean showConsoleLog) {
  860. globalController.setShowConsoleLog(showConsoleLog);
  861. }
  862. }