import { ELEMENTS_CLASS } from "../enums/elements-class-enum"; import { PointModel } from "../../components/point-component/models/point-model"; import { CircumferenceModel } from "../../components/circumference-component/models/circumference-model"; import { LineSegmentModel } from "../../components/line-segment-component/models/line-segment-model"; import { IntersectionModel } from "../../components/intersection-component/models/intersection-model"; import { menu } from "../application/menu"; export class ParserOrchestrator { constructor(mapArr) { this.mapArr = mapArr; this.list = new Array(); this.drawersMap = new Map(); this.tools = menu.tools; } orchestrate() { for (const i in this.mapArr) this.do(this.mapArr[i]); for (const i in this.list) this.draw(this.list[i]); } do(map) { let object; switch (map.get("type")) { case ELEMENTS_CLASS.CIRCUMFERENCE: object = CircumferenceModel.do(map, this.list); break; case ELEMENTS_CLASS.INTERSECTION_POINT: object = IntersectionModel.do(map, this.list); break; case ELEMENTS_CLASS.POINT: object = PointModel.do(map, this.list); break; case ELEMENTS_CLASS.LINE_SEGMENT: object = LineSegmentModel.do(map, this.list); break; default: break; } this.list.push(object); } draw(object) { if (object == undefined) return; let drawer; switch (object.elementClass) { case ELEMENTS_CLASS.CIRCUMFERENCE: drawer = this.getDrawer(ELEMENTS_CLASS.CIRCUMFERENCE) break; case ELEMENTS_CLASS.INTERSECTION_POINT: drawer = this.getDrawer(ELEMENTS_CLASS.INTERSECTION_POINT) break; case ELEMENTS_CLASS.POINT: drawer = this.getDrawer(ELEMENTS_CLASS.POINT) break; case ELEMENTS_CLASS.LINE_SEGMENT: drawer = this.getDrawer(ELEMENTS_CLASS.LINE_SEGMENT) break; default: break; } drawer.draw({ attrs: { genericObject: object } }); } getDrawer(elementClass) { return this.tools.find(x => x.drawer.elementClass === elementClass).drawer; } }