123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- import { mathUtil } from "../Util/MathUtil";
- import { dataService } from "../Service/DataService";
- import { textService } from "../Service/TextService";
- export default class HistoryUtil {
- constructor() {}
- isDifferentForRoads(road1, road2) {
- if (road1.startId == road2.startId && road1.endId == road2.endId) {
- return false;
- } else {
- return true;
- }
- }
- isDifferentForPoints(point1, point2) {
- if (
- point1.x == point2.x &&
- point1.y == point2.y &&
- JSON.stringify(point1.parent) == JSON.stringify(point2.parent)
- ) {
- return false;
- } else {
- return true;
- }
- }
- isDifferentForLines(line1, line2) {
- if (
- line1.startId == line2.startId &&
- line1.endId == line2.endId &&
- line1.category == line2.category
- ) {
- return false;
- } else {
- return true;
- }
- }
- isDifferentForCircles(circle1, circle2) {
- if (
- mathUtil.equalPoint(circle1.center, circle2.center) &&
- circle1.radius == circle2.radius
- ) {
- return false;
- } else {
- return true;
- }
- }
- isDifferentForTexts(text1, text2) {
- if (
- mathUtil.equalPoint(text1.center, text2.center) &&
- text1.des == text2.des
- ) {
- return false;
- } else {
- return true;
- }
- }
- // // road2赋值给road1
- // assignRoadFromRoad(road1, road2) {
- // const roadInfo = {};
- // roadInfo.vectorId = road1.vectorId;
- // roadInfo.start = road2.startId;
- // roadInfo.end = road2.endId;
- // this.setRoadInfo(roadInfo);
- // }
- assignPointFromPoint(point1, point2) {
- const pointInfo = {};
- pointInfo.vectorId = point1.vectorId;
- pointInfo.position = { x: point2.x, y: point2.y };
- pointInfo.parent = JSON.parse(JSON.stringify(point2.parent));
- this.setPointInfo(pointInfo);
- }
- assignLineFromLine(line1, line2) {
- const lineInfo = {};
- lineInfo.vectorId = line1.vectorId;
- lineInfo.start = line2.startId;
- lineInfo.end = line2.endId;
- lineInfo.category = line2.category;
- this.setLineInfo(lineInfo);
- }
- assignCircleFromCircle(circle1, circle2) {
- const circleInfo = {};
- circleInfo.vectorId = circle1.vectorId;
- circleInfo.center = circle2.center;
- circleInfo.radius = circle2.radius;
- this.setCircleInfo(circleInfo);
- }
- assignTextFromText(text1, text2) {
- const textInfo = {};
- textInfo.vectorId = text1.vectorId;
- textInfo.des = text2.des;
- textInfo.center = JSON.parse(JSON.stringify(text2.center));
- textInfo.points2d = JSON.parse(JSON.stringify(text2.points));
- textInfo.adding = false;
- this.setTextInfo(textInfo);
- }
- getDataForPoint(point) {
- const data = {};
- data.id = point.vectorId;
- mathUtil.clonePoint(data, point);
- data.parent = JSON.parse(JSON.stringify(point.parent));
- data.type = point.geoType;
- return data;
- }
- getDataForLine(line) {
- const data = {};
- data.id = line.vectorId;
- data.start = line.startId;
- data.end = line.endId;
- data.type = line.geoType;
- return data;
- }
- getDataForCircle(circle) {
- const data = {};
- data.id = circle.vectorId;
- data.center = {};
- mathUtil.clonePoint(data.center, circle.center);
- data.radius = circle.radius;
- data.type = circle.geoType;
- return data;
- }
- getDataForText(text) {
- const data = {};
- data.id = text.vectorId;
- data.type = text.geoType;
- data.center = {};
- mathUtil.clonePoint(data.center, text.center);
- data.points = [].concat(text.points2d);
- data.des = text.des;
- return data;
- }
- // setRoadInfo(roadInfo) {
- // let road = dataService.getRoad(roadInfo.vectorId);
- // road.start = roadInfo.start;
- // road.end = roadInfo.end;
- // return road;
- // }
- setPointInfo(pointInfo) {
- let point = dataService.getPoint(pointInfo.vectorId);
- mathUtil.clonePoint(point, pointInfo.position);
- point.parent = JSON.parse(JSON.stringify(pointInfo.parent));
- return point;
- }
- setLineInfo(lineInfo) {
- let line = dataService.getLine(lineInfo.vectorId);
- line.startId = lineInfo.start;
- line.endId = lineInfo.end;
- line.category = lineInfo.category;
- return line;
- }
- setCircleInfo(circleInfo) {
- let circle = dataService.getCircle(circleInfo.vectorId);
- circle.center = circleInfo.center;
- circle.radius = circleInfo.radius;
- return circle;
- }
- setTextInfo(textInfo) {
- let text = dataService.getText(textInfo.vectorId);
- text.vectorId = textInfo.vectorId;
- text.center = JSON.parse(JSON.stringify(textInfo.center));
- text.points2d = JSON.parse(JSON.stringify(textInfo.points2d));
- text.des = textInfo.des;
- text.adding = textInfo.adding;
- }
- }
- const historyUtil = new HistoryUtil();
- export { historyUtil };
|