src/app/core/parser/parser-orchestrator.js
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";
import { label as Label } from '../../component-registry/label';
import { LineModel } from "../../components/line-component/models/line-model";
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;
case ELEMENTS_CLASS.LINE:
object = LineModel.do(map, this.list);
break;
default:
break;
}
if (object == undefined) return;
switch (object.elementClass) {
case ELEMENTS_CLASS.CIRCUMFERENCE:
Label.pushLower(object.label);
case ELEMENTS_CLASS.LINE_SEGMENT:
Label.pushLower(object.label);
default:
Label.pushUpper(object.label);
}
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;
case ELEMENTS_CLASS.LINE:
drawer = this.getDrawer(ELEMENTS_CLASS.LINE)
break;
default:
break;
}
drawer.draw({
attrs: {
genericObject: object
}
});
}
getDrawer(elementClass) {
return this.tools.find(x => x.drawer.elementClass === elementClass).drawer;
}
}