Control.java 23 KB

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