parser-orchestrator.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. import { label as Label } from '../../component-registry/label';
  8. import { LineModel } from "../../components/line-component/models/line-model";
  9. export class ParserOrchestrator {
  10. constructor(mapArr) {
  11. this.mapArr = mapArr;
  12. this.list = new Array();
  13. this.drawersMap = new Map();
  14. this.tools = menu.tools;
  15. }
  16. orchestrate() {
  17. for (const i in this.mapArr) this.do(this.mapArr[i]);
  18. for (const i in this.list) this.draw(this.list[i]);
  19. }
  20. do(map) {
  21. let object;
  22. switch (map.get("type")) {
  23. case ELEMENTS_CLASS.CIRCUMFERENCE:
  24. object = CircumferenceModel.do(map, this.list);
  25. break;
  26. case ELEMENTS_CLASS.INTERSECTION_POINT:
  27. object = IntersectionModel.do(map, this.list);
  28. break;
  29. case ELEMENTS_CLASS.POINT:
  30. object = PointModel.do(map, this.list);
  31. break;
  32. case ELEMENTS_CLASS.LINE_SEGMENT:
  33. object = LineSegmentModel.do(map, this.list);
  34. break;
  35. case ELEMENTS_CLASS.LINE:
  36. object = LineModel.do(map, this.list);
  37. break;
  38. default:
  39. break;
  40. }
  41. if (object == undefined) return;
  42. switch (object.elementClass) {
  43. case ELEMENTS_CLASS.CIRCUMFERENCE:
  44. Label.pushLower(object.label);
  45. case ELEMENTS_CLASS.LINE_SEGMENT:
  46. Label.pushLower(object.label);
  47. default:
  48. Label.pushUpper(object.label);
  49. }
  50. this.list.push(object);
  51. }
  52. draw(object) {
  53. if (object == undefined) return;
  54. let drawer;
  55. switch (object.elementClass) {
  56. case ELEMENTS_CLASS.CIRCUMFERENCE:
  57. drawer = this.getDrawer(ELEMENTS_CLASS.CIRCUMFERENCE)
  58. break;
  59. case ELEMENTS_CLASS.INTERSECTION_POINT:
  60. drawer = this.getDrawer(ELEMENTS_CLASS.INTERSECTION_POINT)
  61. break;
  62. case ELEMENTS_CLASS.POINT:
  63. drawer = this.getDrawer(ELEMENTS_CLASS.POINT)
  64. break;
  65. case ELEMENTS_CLASS.LINE_SEGMENT:
  66. drawer = this.getDrawer(ELEMENTS_CLASS.LINE_SEGMENT)
  67. break;
  68. case ELEMENTS_CLASS.LINE:
  69. drawer = this.getDrawer(ELEMENTS_CLASS.LINE)
  70. break;
  71. default:
  72. break;
  73. }
  74. drawer.draw({
  75. attrs: {
  76. genericObject: object
  77. }
  78. });
  79. }
  80. getDrawer(elementClass) {
  81. return this.tools.find(x => x.drawer.elementClass === elementClass).drawer;
  82. }
  83. }