Control.java 22 KB

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