|
@@ -6,7 +6,10 @@ import HistoryEvents from "../enum/HistoryEvents";
|
|
|
import { historyService } from "../Service/HistoryService";
|
|
|
import { textService } from "../Service/TextService";
|
|
|
import { roadService } from "../Service/RoadService";
|
|
|
+import { svgService } from "../Service/SVGService";
|
|
|
import { roadPointService } from "../Service/RoadPointService";
|
|
|
+import { lineService } from "../Service/LineService";
|
|
|
+import { circleService } from "../Service/CircleService";
|
|
|
|
|
|
export default class History {
|
|
|
constructor(layer) {
|
|
@@ -25,24 +28,11 @@ export default class History {
|
|
|
historyService.addHistoryRecord(change.currentData);
|
|
|
change.saveCurrentInfo();
|
|
|
this.setState();
|
|
|
- const historyState = historyService.getHistoryState();
|
|
|
- // if (historyState.pre) {
|
|
|
- // this.layer.$xui.toolbar.recall = true;
|
|
|
- // }
|
|
|
- // this.layer.$xui.toolbar.recover = false;
|
|
|
-
|
|
|
- const points = dataService.getRoadPoints();
|
|
|
- // if (Object.keys(points).length > 0) {
|
|
|
- // this.layer.$xui.toolbar.clear = true;
|
|
|
- // this.layer.$xui.toolbar.download = true;
|
|
|
- // } else {
|
|
|
- // this.layer.$xui.toolbar.clear = false;
|
|
|
- // this.layer.$xui.toolbar.download = false;
|
|
|
- // }
|
|
|
-
|
|
|
- //给UI发送事件
|
|
|
- this.layer.emit("change");
|
|
|
- return change.currentData;
|
|
|
+ // const historyState = historyService.getHistoryState();
|
|
|
+ // const points = dataService.getRoadPoints();
|
|
|
+ // //给UI发送事件
|
|
|
+ // this.layer.emit("change");
|
|
|
+ // return change.currentData;
|
|
|
}
|
|
|
|
|
|
setState() {
|
|
@@ -101,26 +91,16 @@ export default class History {
|
|
|
goPreState() {
|
|
|
const item = historyService.getHistoryRecord();
|
|
|
if (item) {
|
|
|
- stateService.clearFocusItem();
|
|
|
- stateService.clearEventName();
|
|
|
- //this.layer.uiControl.currentUI = null;
|
|
|
+ stateService.clear();
|
|
|
item.type = "pre";
|
|
|
this.goPreForPoints(item.points);
|
|
|
- this.goPreForRoads(item.roads);
|
|
|
+ this.goPreForLines(item.lines);
|
|
|
+ this.goPreForCircles(item.circles);
|
|
|
this.goPreForTexts(item.texts);
|
|
|
-
|
|
|
+ this.goPreForSVGs(item.svgs);
|
|
|
historyService.undoHistoryRecord();
|
|
|
change.saveCurrentInfo();
|
|
|
this.setState();
|
|
|
-
|
|
|
- // const points = dataService.getRoadPoints();
|
|
|
- // if (Object.keys(points).length > 0) {
|
|
|
- // this.layer.$xui.toolbar.clear = true;
|
|
|
- // this.layer.$xui.toolbar.download = true;
|
|
|
- // } else {
|
|
|
- // this.layer.$xui.toolbar.clear = false;
|
|
|
- // this.layer.$xui.toolbar.download = false;
|
|
|
- // }
|
|
|
} else {
|
|
|
console.error("goPreState超出范围!");
|
|
|
}
|
|
@@ -130,7 +110,7 @@ export default class History {
|
|
|
for (let i = 0; i < itemForPoints.length; ++i) {
|
|
|
const item = itemForPoints[i];
|
|
|
if (item.handle == HistoryEvents.AddPoint) {
|
|
|
- historyUtil.deletePoint(item.point.id);
|
|
|
+ dataService.deletePoint(item.point.id);
|
|
|
} else if (item.handle == HistoryEvents.DeletePoint) {
|
|
|
let point = roadPointService.create(item.point, item.point.id);
|
|
|
point.parent = JSON.parse(JSON.stringify(item.point.parent));
|
|
@@ -142,23 +122,46 @@ export default class History {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- goPreForRoads(itemForRoads) {
|
|
|
- for (let i = 0; i < itemForRoads.length; ++i) {
|
|
|
- const item = itemForRoads[i];
|
|
|
- if (item.handle == HistoryEvents.AddRoad) {
|
|
|
- dataService.deleteRoad(item.road.id);
|
|
|
- } else if (item.handle == HistoryEvents.DeleteRoad) {
|
|
|
- const preRoad = item.road;
|
|
|
- let newRoad = roadService.create(
|
|
|
- preRoad.start,
|
|
|
- preRoad.end,
|
|
|
- preRoad.id
|
|
|
+ goPreForLines(itemForLines) {
|
|
|
+ for (let i = 0; i < itemForLines.length; ++i) {
|
|
|
+ const item = itemForLines[i];
|
|
|
+ if (item.handle == HistoryEvents.AddLine) {
|
|
|
+ dataService.deleteLine(item.line.id);
|
|
|
+ } else if (item.handle == HistoryEvents.DeleteLine) {
|
|
|
+ const preLine = item.line;
|
|
|
+ let newLine = lineService.create(
|
|
|
+ preLine.start,
|
|
|
+ preLine.end,
|
|
|
+ preLine.category,
|
|
|
+ preLine.id
|
|
|
+ );
|
|
|
+ historyUtil.assignLineFromLine(newLine, preLine);
|
|
|
+ } else if (item.handle == HistoryEvents.ModifyLine) {
|
|
|
+ const preLine = item.preLine;
|
|
|
+ let currentLine = dataService.getLine(item.curLine.id);
|
|
|
+ historyUtil.assignLineFromLine(currentLine, preLine);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ goPreForCircles(itemForCircles) {
|
|
|
+ for (let i = 0; i < itemForCircles.length; ++i) {
|
|
|
+ const item = itemForCircles[i];
|
|
|
+ if (item.handle == HistoryEvents.AddCircle) {
|
|
|
+ dataService.deleteCircle(item.circle.id);
|
|
|
+ } else if (item.handle == HistoryEvents.DeleteCircle) {
|
|
|
+ const preCircle = item.circle;
|
|
|
+ let newCircle = lineService.createCircle(
|
|
|
+ preCircle.start,
|
|
|
+ preCircle.end,
|
|
|
+ preCircle.category,
|
|
|
+ preCircle.id
|
|
|
);
|
|
|
- historyUtil.assignRoadFromRoad(newRoad, preRoad);
|
|
|
- } else if (item.handle == HistoryEvents.ModifyRoad) {
|
|
|
- const preRoad = item.preRoad;
|
|
|
- let currentRoad = dataService.getRoad(item.curRoad.id);
|
|
|
- historyUtil.assignRoadFromRoad(currentRoad, preRoad);
|
|
|
+ historyUtil.assignCircleFromCircle(newCircle, preCircle);
|
|
|
+ } else if (item.handle == HistoryEvents.ModifyCircle) {
|
|
|
+ const preCircle = item.preCircle;
|
|
|
+ let currentCircle = dataService.getCircle(item.curCircle.id);
|
|
|
+ historyUtil.assignCircleFromCircle(currentCircle, preCircle);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -169,7 +172,7 @@ export default class History {
|
|
|
if (item.handle == HistoryEvents.AddText) {
|
|
|
dataService.deleteText(item.text.id);
|
|
|
} else if (item.handle == HistoryEvents.DeleteText) {
|
|
|
- let newText = textService.createText(item.text.center, item.text.id);
|
|
|
+ let newText = textService.create(item.text.center, item.text.id);
|
|
|
historyUtil.assignTextFromText(newText, item.text);
|
|
|
} else if (item.handle == HistoryEvents.ModifyText) {
|
|
|
const preText = item.preText;
|
|
@@ -179,6 +182,22 @@ export default class History {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ goPreForSVGs(itemForSVGs) {
|
|
|
+ for (let i = 0; i < itemForSVGs.length; ++i) {
|
|
|
+ const item = itemForSVGs[i];
|
|
|
+ if (item.handle == HistoryEvents.AddSVG) {
|
|
|
+ dataService.deleteSVG(item.svg.id);
|
|
|
+ } else if (item.handle == HistoryEvents.DeleteSVG) {
|
|
|
+ let newSVG = svgService.create(item.svg.center, item.svg.id);
|
|
|
+ historyUtil.assignSVGFromSVG(newSVG, item.svg);
|
|
|
+ } else if (item.handle == HistoryEvents.ModifySVG) {
|
|
|
+ const preSVG = item.preSVG;
|
|
|
+ let currentSVG = dataService.getSVG(item.curSVG.id);
|
|
|
+ historyUtil.assignSVGFromSVG(currentSVG, preSVG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
goNextForPoints(itemForPoints) {
|
|
|
for (let i = 0; i < itemForPoints.length; ++i) {
|
|
|
const item = itemForPoints[i];
|
|
@@ -186,7 +205,7 @@ export default class History {
|
|
|
let newPoint = roadPointService.create(item.point, item.point.id);
|
|
|
historyUtil.assignPointFromPoint(newPoint, item.point);
|
|
|
} else if (item.handle == HistoryEvents.DeletePoint) {
|
|
|
- historyUtil.deletePoint(item.point.id);
|
|
|
+ dataService.deletePoint(item.point.id);
|
|
|
} else if (item.handle == HistoryEvents.ModifyPoint) {
|
|
|
const currentPoint = item.curPoint;
|
|
|
let prePoint = dataService.getRoadPoint(item.curPoint.id);
|
|
@@ -195,23 +214,45 @@ export default class History {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- goNextForRoads(itemForRoads) {
|
|
|
- for (let i = 0; i < itemForRoads.length; ++i) {
|
|
|
- const item = itemForRoads[i];
|
|
|
- if (item.handle == HistoryEvents.AddRoad) {
|
|
|
- const preRoad = item.road;
|
|
|
- let newRoad = roadService.create(
|
|
|
- preRoad.start,
|
|
|
- preRoad.end,
|
|
|
- preRoad.id
|
|
|
+ goNextForLines(itemForLines) {
|
|
|
+ for (let i = 0; i < itemForLines.length; ++i) {
|
|
|
+ const item = itemForLines[i];
|
|
|
+ if (item.handle == HistoryEvents.AddLine) {
|
|
|
+ const preLine = item.line;
|
|
|
+ let newLine = lineService.create(
|
|
|
+ preLine.start,
|
|
|
+ preLine.end,
|
|
|
+ preLine.category,
|
|
|
+ preLine.id
|
|
|
+ );
|
|
|
+ historyUtil.assignLineFromLine(newLine, preLine);
|
|
|
+ } else if (item.handle == HistoryEvents.DeleteLine) {
|
|
|
+ dataService.deleteLine(item.line.id);
|
|
|
+ } else if (item.handle == HistoryEvents.ModifyLine) {
|
|
|
+ const currentLine = item.curLine;
|
|
|
+ let preLine = dataService.getLine(item.preLine.id);
|
|
|
+ historyUtil.assignLineFromLine(preLine, currentLine);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ goNextForCircles(itemForCircles) {
|
|
|
+ for (let i = 0; i < itemForCircles.length; ++i) {
|
|
|
+ const item = itemForCircles[i];
|
|
|
+ if (item.handle == HistoryEvents.AddCircle) {
|
|
|
+ const preCircle = item.circle;
|
|
|
+ let newCircle = circleService.create(
|
|
|
+ preCircle.center,
|
|
|
+ preCircle.radius,
|
|
|
+ preCircle.id
|
|
|
);
|
|
|
- historyUtil.assignRoadFromRoad(newRoad, preRoad);
|
|
|
- } else if (item.handle == HistoryEvents.DeleteRoad) {
|
|
|
- dataService.deleteRoad(item.road.id);
|
|
|
- } else if (item.handle == HistoryEvents.ModifyRoad) {
|
|
|
- const currentRoad = item.curRoad;
|
|
|
- let preRoad = dataService.getRoad(item.preRoad.id);
|
|
|
- historyUtil.assignRoadFromRoad(preRoad, currentRoad);
|
|
|
+ historyUtil.assignCircleFromCircle(newCircle, preCircle);
|
|
|
+ } else if (item.handle == HistoryEvents.DeleteCircle) {
|
|
|
+ dataService.deleteCircle(item.circle.id);
|
|
|
+ } else if (item.handle == HistoryEvents.ModifyCircle) {
|
|
|
+ const currentCircle = item.curCircle;
|
|
|
+ let preCircle = dataService.getCircle(item.preCircle.id);
|
|
|
+ historyUtil.assignCircleFromCircle(preCircle, currentCircle);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -220,7 +261,7 @@ export default class History {
|
|
|
for (let i = 0; i < itemForTexts.length; ++i) {
|
|
|
const item = itemForTexts[i];
|
|
|
if (item.handle == HistoryEvents.AddText) {
|
|
|
- let vText = textService.createText(item.text.center, item.text.id);
|
|
|
+ let vText = textService.create(item.text.center, item.text.id);
|
|
|
historyUtil.assignTextFromText(vText, item.text);
|
|
|
} else if (item.handle == HistoryEvents.DeleteText) {
|
|
|
dataService.deleteText(item.text.id);
|
|
@@ -232,28 +273,36 @@ export default class History {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ goNextForSVGs(itemForSVGs) {
|
|
|
+ for (let i = 0; i < itemForSVGs.length; ++i) {
|
|
|
+ const item = itemForSVGs[i];
|
|
|
+ if (item.handle == HistoryEvents.AddSVG) {
|
|
|
+ let vSVG = svgService.create(item.svg.center, item.svg.id);
|
|
|
+ historyUtil.assignSVGFromSVG(vSVG, item.svg);
|
|
|
+ } else if (item.handle == HistoryEvents.DeleteSVG) {
|
|
|
+ dataService.deleteSVG(item.svg.id);
|
|
|
+ } else if (item.handle == HistoryEvents.ModifySVG) {
|
|
|
+ const currentSVG = item.curSVG;
|
|
|
+ let preSVG = dataService.getSVG(item.curSVG.id);
|
|
|
+ historyUtil.assignSVGFromSVG(preSVG, currentSVG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 恢复
|
|
|
goNextState() {
|
|
|
historyService.redoHistoryRecord();
|
|
|
const item = historyService.getHistoryRecord();
|
|
|
if (item) {
|
|
|
- stateService.clearFocusItem();
|
|
|
- stateService.clearEventName();
|
|
|
- //this.layer.uiControl.currentUI = null;
|
|
|
+ stateService.clear();
|
|
|
+
|
|
|
this.goNextForPoints(item.points);
|
|
|
- this.goNextForRoads(item.roads);
|
|
|
+ this.goNextForLines(item.lines);
|
|
|
+ this.goNextForCircles(item.circles);
|
|
|
this.goNextForTexts(item.texts);
|
|
|
+ this.goNextForSVGs(item.svgs);
|
|
|
change.saveCurrentInfo();
|
|
|
this.setState();
|
|
|
-
|
|
|
- // const points = dataService.getRoadPoints();
|
|
|
- // if (Object.keys(points).length > 0) {
|
|
|
- // this.layer.$xui.toolbar.clear = true;
|
|
|
- // this.layer.$xui.toolbar.download = true;
|
|
|
- // } else {
|
|
|
- // this.layer.$xui.toolbar.clear = false;
|
|
|
- // this.layer.$xui.toolbar.download = false;
|
|
|
- // }
|
|
|
} else {
|
|
|
historyService.undoHistoryRecord();
|
|
|
console.error("goNextState超出范围!");
|