parser-orchestrator.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { ELEMENTS_CLASS } from "../enums/elements-class-enum";
  2. import { PointModel } from "../../components/point-component/models/point-model";
  3. import { CircumferenceModel } from "../../components/circumference-component/models/circumference-model";
  4. import { LineSegmentModel } from "../../components/line-segment-component/models/line-segment-model";
  5. import { IntersectionModel } from "../../components/intersection-component/models/intersection-model";
  6. import { menu } from "../application/menu";
  7. export class ParserOrchestrator {
  8. constructor(mapArr) {
  9. this.mapArr = mapArr;
  10. this.list = new Array();
  11. this.drawersMap = new Map();
  12. this.tools = menu.tools;
  13. }
  14. orchestrate() {
  15. for (const i in this.mapArr) this.do(this.mapArr[i]);
  16. for (const i in this.list) this.draw(this.list[i]);
  17. }
  18. do(map) {
  19. let object;
  20. switch (map.get("type")) {
  21. case ELEMENTS_CLASS.CIRCUMFERENCE:
  22. object = CircumferenceModel.do(map, this.list);
  23. break;
  24. case ELEMENTS_CLASS.INTERSECTION_POINT:
  25. object = IntersectionModel.do(map, this.list);
  26. break;
  27. case ELEMENTS_CLASS.POINT:
  28. object = PointModel.do(map, this.list);
  29. break;
  30. case ELEMENTS_CLASS.LINE_SEGMENT:
  31. object = LineSegmentModel.do(map, this.list);
  32. break;
  33. default:
  34. break;
  35. }
  36. this.list.push(object);
  37. }
  38. draw(object) {
  39. if (object == undefined) return;
  40. let drawer;
  41. switch (object.elementClass) {
  42. case ELEMENTS_CLASS.CIRCUMFERENCE:
  43. drawer = this.getDrawer(ELEMENTS_CLASS.CIRCUMFERENCE)
  44. break;
  45. case ELEMENTS_CLASS.INTERSECTION_POINT:
  46. drawer = this.getDrawer(ELEMENTS_CLASS.INTERSECTION_POINT)
  47. break;
  48. case ELEMENTS_CLASS.POINT:
  49. drawer = this.getDrawer(ELEMENTS_CLASS.POINT)
  50. break;
  51. case ELEMENTS_CLASS.LINE_SEGMENT:
  52. drawer = this.getDrawer(ELEMENTS_CLASS.LINE_SEGMENT)
  53. break;
  54. default:
  55. break;
  56. }
  57. drawer.draw({
  58. attrs: {
  59. genericObject: object
  60. }
  61. });
  62. }
  63. getDrawer(elementClass) {
  64. return this.tools.find(x => x.drawer.elementClass === elementClass).drawer;
  65. }
  66. }