Control.java 22 KB

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