Control.java 20 KB

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