import { dataService } from "../Service/DataService"; import { historyUtil } from "./HistoryUtil"; import { change } from "./Change"; import { stateService } from "../Service/StateService"; 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"; import { pointService } from "../Service/PointService"; import { edgeService } from "../Service/EdgeService"; import { magnifierService } from "../Service/MagnifierService"; import { crossPointService } from "../Service/CrossPointService"; import { curveRoadPointService } from "../Service/CurveRoadPointService"; import { curveEdgeService } from "../Service/CurveEdgeService"; import { curveRoadService } from "../Service/CurveRoadService"; import { curvePointService } from "../Service/CurvePointService"; import Settings from "../Settings"; export default class History { constructor(layer) { this.layer = layer; } init() { change.saveCurrentInfo(); } save() { const flag = change.operate(); if (!flag) { return; } historyService.addHistoryRecord(change.currentData); change.saveCurrentInfo(); this.setState(); const historyState = historyService.getHistoryState(); this.layer.uiControl.graphicStateUI.canRevoke = historyState.pre; this.layer.uiControl.graphicStateUI.canRecovery = historyState.next; } setState() { const state = { pre: 0, next: 0, }; const currentRecordIndex = historyService.getCurrentRecordIndex(); const records = historyService.getHistoryRecords(); if (currentRecordIndex > -1) { state.pre = 1; } if (currentRecordIndex < records.length - 1) { state.next = 1; } const lastState = historyService.getHistoryState(); if (lastState.pre != state.pre || lastState.next != state.next) { historyService.setHistoryState(state.pre, state.next); } } // 是否可以撤销 canUndo() { const state = this.setState(); if (state.pre == 0) { return false; } else { return true; } } // 是否可以恢复 canRedo() { const state = this.setState(); if (state.next == 0) { return false; } else { return true; } } // 撤销 handleUndo() { this.goPreState(); } // 恢复 handleRedo() { this.goNextState(); } // 撤销 goPreState() { this.layer.exit(); const item = historyService.getHistoryRecord(); if (item) { stateService.clear(); item.type = "pre"; this.goPreForPoints(item.points); this.goPreForLines(item.lines); this.goPreForCurvePoints(item.curvePoints); this.goPreForCurveLines(item.curveLines); this.goPreForCircles(item.circles); this.goPreForTexts(item.texts); this.goPreForMagnifiers(item.magnifiers); this.goPreForSVGs(item.svgs); this.goPreForRoadPoints(item.roadPoints); this.goPreForRoadEdges(item.roadEdges); this.goPreForRoads(item.roads); this.goPreForCurveRoadPoints(item.curveRoadPoints); this.goPreForCurveRoadEdges(item.curveRoadEdges); this.goPreForCurveRoads(item.curveRoads); this.goPreForCrossPoints(item.crossPoints); this.goPreForSettings(item.settings); historyService.undoHistoryRecord(); change.saveCurrentInfo(); this.setState(); } else { console.error("goPreState超出范围!"); } } goPreForPoints(itemForPoints) { for (let i = 0; i < itemForPoints.length; ++i) { const item = itemForPoints[i]; if (item.handle == HistoryEvents.AddPoint) { dataService.deletePoint(item.point.id); } else if (item.handle == HistoryEvents.DeletePoint) { let point = pointService.create(item.point, item.point.id); point.setCategory(item.point.category); point.setLinkedBasePointId(item.point.linkedBasePointId); point.setLocationMode(item.point.locationMode); point.linkedTextId = item.point.linkedTextId; point.parent = JSON.parse(JSON.stringify(item.point.parent)); } else if (item.handle == HistoryEvents.ModifyPoint) { const prePoint = item.prePoint; let currentPoint = dataService.getPoint(item.curPoint.id); historyUtil.assignPointFromPoint(currentPoint, prePoint); } } } 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.createByPointId( 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); } } } goPreForCurvePoints(itemForCurvePoints) { for (let i = 0; i < itemForCurvePoints.length; ++i) { const item = itemForCurvePoints[i]; if (item.handle == HistoryEvents.AddCurvePoint) { dataService.deleteCurvePoint(item.curvePoint.id); } else if (item.handle == HistoryEvents.DeleteCurvePoint) { let curvePoint = curvePointService.create( item.curvePoint, item.curvePoint.id ); curvePoint.setIndex(item.index); curvePoint.setPointParent(item.curvePoint.parent); } else if (item.handle == HistoryEvents.ModifyCurvePoint) { const preCurvePoint = item.preCurvePoint; let currentCurvePoint = dataService.getCurvePoint( item.curCurvePoint.id ); historyUtil.assignCurvePointFromCurvePoint( currentCurvePoint, preCurvePoint ); } } } goPreForCurveLines(itemForCurveLines) { for (let i = 0; i < itemForCurveLines.length; ++i) { const item = itemForCurveLines[i]; if (item.handle == HistoryEvents.AddCurveLine) { dataService.deleteCurveLine(item.curveLine.id); } else if (item.handle == HistoryEvents.DeleteCurveLine) { const preCurveLine = item.curveLine; let newCurveLine = lineService.createCurveLineByPointIds( preCurveLine.points, preCurveLine.id ); historyUtil.assignCurveLineFromCurveLine(newCurveLine, preCurveLine); } else if (item.handle == HistoryEvents.ModifyCurveLine) { const preCurveLine = item.preCurveLine; let currentCurveLine = dataService.getCurveLine(item.curCurveLine.id); historyUtil.assignCurveLineFromCurveLine( currentCurveLine, preCurveLine ); } } } 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 = circleService.create( preCircle.center, preCircle.radius || preCircle.radiusX, preCircle.id ); 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); } } } goPreForTexts(itemForTexts) { for (let i = 0; i < itemForTexts.length; ++i) { const item = itemForTexts[i]; if (item.handle == HistoryEvents.AddText) { dataService.deleteText(item.text.id); } else if (item.handle == HistoryEvents.DeleteText) { 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; let currentText = dataService.getText(item.curText.id); historyUtil.assignTextFromText(currentText, preText); } } } goPreForMagnifiers(itemForMagnifiers) { for (let i = 0; i < itemForMagnifiers.length; ++i) { const item = itemForMagnifiers[i]; if (item.handle == HistoryEvents.AddMagnifier) { dataService.deleteMagnifier(item.magnifier.id); } else if (item.handle == HistoryEvents.DeleteMagnifier) { let newMagnifier = magnifierService.create( item.magnifier.position, item.magnifier.id ); historyUtil.assignMagnifierFromMagnifier(newMagnifier, item.magnifier); } else if (item.handle == HistoryEvents.ModifyMagnifier) { const preMagnifier = item.preMagnifier; let currentMagnifier = dataService.getMagnifier(item.curMagnifier.id); historyUtil.assignMagnifierFromMagnifier( currentMagnifier, preMagnifier ); } } } 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.type, 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); } } } goPreForRoadPoints(itemForRoadPoints) { for (let i = 0; i < itemForRoadPoints.length; ++i) { const item = itemForRoadPoints[i]; if (item.handle == HistoryEvents.AddRoadPoint) { dataService.deleteRoadPoint1(item.roadPoint.id); } else if (item.handle == HistoryEvents.DeleteRoadPoint) { let newRoadPoint = roadPointService.create( item.roadPoint.position, item.roadPoint.id ); historyUtil.assignRoadPointFromRoadPoint(newRoadPoint, item.roadPoint); } else if (item.handle == HistoryEvents.ModifyRoadPoint) { const preRoadPoint = item.preRoadPoint; let currentRoadPoint = dataService.getRoadPoint(item.curRoadPoint.id); historyUtil.assignRoadPointFromRoadPoint( currentRoadPoint, preRoadPoint ); } } } goPreForRoadEdges(itemForRoadEdges) { for (let i = 0; i < itemForRoadEdges.length; ++i) { const item = itemForRoadEdges[i]; if (item.handle == HistoryEvents.AddRoadEdge) { dataService.deleteRoadEdge(item.roadEdge.id); } else if (item.handle == HistoryEvents.DeleteRoadEdge) { let newRoadEdge = edgeService.create( item.roadEdge.start, item.roadEdge.end, item.roadEdge.id, item.roadEdge.parent ); historyUtil.assignRoadEdgeFromRoadEdge(newRoadEdge, item.roadEdge); } else if (item.handle == HistoryEvents.ModifyRoadEdge) { const preRoadEdge = item.preRoadEdge; let currentRoadEdge = dataService.getRoadEdge(item.curRoadEdge.id); historyUtil.assignRoadEdgeFromRoadEdge(currentRoadEdge, preRoadEdge); } } } 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) { let newRoad = roadService.createOnlyRoad( item.road.startId, item.road.endId, item.road.id ); historyUtil.assignRoadFromRoad(newRoad, item.road); } else if (item.handle == HistoryEvents.ModifyRoad) { const preRoad = item.preRoad; let currentRoad = dataService.getRoad(item.curRoad.id); historyUtil.assignRoadFromRoad(currentRoad, preRoad); } } } goPreForCurveRoadPoints(itemForCurveRoadPoints) { for (let i = 0; i < itemForCurveRoadPoints.length; ++i) { const item = itemForCurveRoadPoints[i]; if (item.handle == HistoryEvents.AddCurveRoadPoint) { dataService.deleteCurveRoadPoint(item.curveRoadPoint.id); } else if (item.handle == HistoryEvents.DeleteCurveRoadPoint) { let newCurveRoadPoint = curveRoadPointService.create( item.curveRoadPoint.position, item.curveRoadPoint.id ); historyUtil.assignCurveRoadPointFromCurveRoadPoint( newCurveRoadPoint, item.curveRoadPoint ); } else if (item.handle == HistoryEvents.ModifyCurveRoadPoint) { const preCurveRoadPoint = item.preCurveRoadPoint; let currentCurveRoadPoint = dataService.getCurveRoadPoint( item.curCurveRoadPoint.id ); historyUtil.assignCurveRoadPointFromCurveRoadPoint( currentCurveRoadPoint, preCurveRoadPoint ); } } } goPreForCurveRoadEdges(itemForCurveRoadEdges) { for (let i = 0; i < itemForCurveRoadEdges.length; ++i) { const item = itemForCurveRoadEdges[i]; if (item.handle == HistoryEvents.AddCurveRoadEdge) { dataService.deleteCurveRoadEdge(item.curveRoadEdge.id); } else if (item.handle == HistoryEvents.DeleteCurveRoadEdge) { let newCurveRoadEdge = curveEdgeService.create( item.curveRoadEdge.start, item.curveRoadEdge.end, item.curveRoadEdge.id, item.curveRoadEdge.parent ); historyUtil.assignCurveRoadEdgeFromCurveRoadEdge( newCurveRoadEdge, item.curveRoadEdge ); } else if (item.handle == HistoryEvents.ModifyCurveRoadEdge) { const preCurveRoadEdge = item.preCurveRoadEdge; let currentCurveRoadEdge = dataService.getCurveRoadEdge( item.curCurveRoadEdge.id ); historyUtil.assignCurveRoadEdgeFromCurveRoadEdge( currentCurveRoadEdge, preCurveRoadEdge ); } } } goPreForCurveRoads(itemForCurveRoads) { for (let i = 0; i < itemForCurveRoads.length; ++i) { const item = itemForCurveRoads[i]; if (item.handle == HistoryEvents.AddCurveRoad) { dataService.deleteCurveRoad(item.curveRoad.id); } else if (item.handle == HistoryEvents.DeleteCurveRoad) { let newCurveRoad = curveRoadService.createOnlyCurveRoad( item.curveRoad.startId, item.curveRoad.endId, item.curveRoad.id ); historyUtil.assignCurveRoadFromCurveRoad(newCurveRoad, item.curveRoad); } else if (item.handle == HistoryEvents.ModifyCurveRoad) { const preCurveRoad = item.preCurveRoad; let currentCurveRoad = dataService.getCurveRoad(item.curCurveRoad.id); historyUtil.assignCurveRoadFromCurveRoad( currentCurveRoad, preCurveRoad ); } } } goPreForCrossPoints(itemForCrossPoints) { for (let i = 0; i < itemForCrossPoints.length; ++i) { const item = itemForCrossPoints[i]; if (item.handle == HistoryEvents.AddCrossPoint) { dataService.deleteCrossPoint1(item.crossPoint.id); } else if (item.handle == HistoryEvents.DeleteCrossPoint) { let newCrossPoint = crossPointService.create( item.crossPoint.position, item.crossPoint.id ); historyUtil.assignCrossPointFromCrossPoint( newCrossPoint, item.crossPoint ); } else if (item.handle == HistoryEvents.ModifyCrossPoint) { const preCrossPoint = item.preCrossPoint; let currentCrossPoint = dataService.getCrossPoint3( item.curCrossPoint.id ); historyUtil.assignCrossPointFromCrossPoint( currentCrossPoint, preCrossPoint ); } } } goPreForSettings(itemForSettings) { if ( itemForSettings && itemForSettings.handle == HistoryEvents.ModifySettings ) { const preSettings = itemForSettings.preSettings; historyUtil.assignSettingsFromSettings(Settings, preSettings); this.layer.updateForLocation(); } } goNextForPoints(itemForPoints) { for (let i = 0; i < itemForPoints.length; ++i) { const item = itemForPoints[i]; if (item.handle == HistoryEvents.AddPoint) { let newPoint = pointService.create(item.point, item.point.id); newPoint.setCategory(item.point.category); newPoint.setLinkedBasePointId(item.point.linkedBasePointId); newPoint.setLocationMode(item.point.locationMode); historyUtil.assignPointFromPoint(newPoint, item.point); } else if (item.handle == HistoryEvents.DeletePoint) { dataService.deletePoint(item.point.id); } else if (item.handle == HistoryEvents.ModifyPoint) { const currentPoint = item.curPoint; let prePoint = dataService.getPoint(item.curPoint.id); historyUtil.assignPointFromPoint(prePoint, currentPoint); } } } 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.createByPointId( 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); } } } goNextForCurvePoints(itemForCurvePoints) { for (let i = 0; i < itemForCurvePoints.length; ++i) { const item = itemForCurvePoints[i]; if (item.handle == HistoryEvents.AddCurvePoint) { let newCurvePoint = curvePointService.create( item.curvePoint, item.curvePoint.id ); historyUtil.assignCurvePointFromCurvePoint( newCurvePoint, item.curvePoint ); } else if (item.handle == HistoryEvents.DeleteCurvePoint) { dataService.deleteCurvePoint(item.curvePoint.id); } else if (item.handle == HistoryEvents.ModifyCurvePoint) { const currentCurvePoint = item.curCurvePoint; let preCurvePoint = dataService.getCurvePoint(item.curCurvePoint.id); historyUtil.assignCurvePointFromCurvePoint( preCurvePoint, currentCurvePoint ); } } } goNextForCurveLines(itemForCurveLines) { for (let i = 0; i < itemForCurveLines.length; ++i) { const item = itemForCurveLines[i]; if (item.handle == HistoryEvents.AddCurveLine) { const preCurveLine = item.curveLine; let newCurveLine = lineService.createCurveLineByPointIds( preCurveLine.points, preCurveLine.id ); historyUtil.assignCurveLineFromCurveLine(newCurveLine, preCurveLine); } else if (item.handle == HistoryEvents.DeleteCurveLine) { dataService.deleteCurveLine(item.curveLine.id); } else if (item.handle == HistoryEvents.ModifyCurveLine) { const currentCurveLine = item.curCurveLine; let preCurveLine = dataService.getCurveLine(item.preCurveLine.id); historyUtil.assignCurveLineFromCurveLine( preCurveLine, currentCurveLine ); } } } 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.radiusX, preCircle.id ); 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); } } } goNextForTexts(itemForTexts) { for (let i = 0; i < itemForTexts.length; ++i) { const item = itemForTexts[i]; if (item.handle == HistoryEvents.AddText) { 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); } else if (item.handle == HistoryEvents.ModifyText) { const currentText = item.curText; let preText = dataService.getText(item.curText.id); historyUtil.assignTextFromText(preText, currentText); } } } goNextForMagnifiers(itemForMagnifiers) { for (let i = 0; i < itemForMagnifiers.length; ++i) { const item = itemForMagnifiers[i]; if (item.handle == HistoryEvents.AddMagnifier) { let vMagnifier = magnifierService.create( item.magnifier.position, item.magnifier.id ); historyUtil.assignMagnifierFromMagnifier(vMagnifier, item.magnifier); } else if (item.handle == HistoryEvents.DeleteMagnifier) { dataService.deleteMagnifier(item.magnifier.id); } else if (item.handle == HistoryEvents.ModifyMagnifier) { const currentMagnifier = item.curMagnifier; let preMagnifier = dataService.getMagnifier(item.curMagnifier.id); historyUtil.assignMagnifierFromMagnifier( preMagnifier, currentMagnifier ); } } } 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.type, 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.preSVG.id); historyUtil.assignSVGFromSVG(preSVG, currentSVG); } } } goNextForRoadPoints(itemForRoadPoints) { for (let i = 0; i < itemForRoadPoints.length; ++i) { const item = itemForRoadPoints[i]; if (item.handle == HistoryEvents.AddRoadPoint) { let vRoadPoint = roadPointService.create( item.roadPoint.position, item.roadPoint.id ); historyUtil.assignRoadPointFromRoadPoint(vRoadPoint, item.roadPoint); } else if (item.handle == HistoryEvents.DeleteRoadPoint) { dataService.deleteRoadPoint1(item.roadPoint.id); } else if (item.handle == HistoryEvents.ModifyRoadPoint) { const currentRoadPoint = item.curRoadPoint; let preRoadPoint = dataService.getRoadPoint(item.curRoadPoint.id); historyUtil.assignRoadPointFromRoadPoint( preRoadPoint, currentRoadPoint ); } } } goNextForRoadEdges(itemForRoadEdges) { for (let i = 0; i < itemForRoadEdges.length; ++i) { const item = itemForRoadEdges[i]; if (item.handle == HistoryEvents.AddRoadEdge) { let vRoadEdge = edgeService.create( item.roadEdge.start, item.roadEdge.end, item.roadEdge.id, item.roadEdge.parent ); historyUtil.assignRoadEdgeFromRoadEdge(vRoadEdge, item.roadEdge); } else if (item.handle == HistoryEvents.DeleteRoadEdge) { dataService.deleteRoadEdge(item.roadEdge.id); } else if (item.handle == HistoryEvents.ModifyRoadEdge) { const currentRoadEdge = item.curRoadEdge; let preRoadEdge = dataService.getRoadEdge(item.curRoadEdge.id); historyUtil.assignRoadEdgeFromRoadEdge(preRoadEdge, currentRoadEdge); } } } goNextForRoads(itemForRoads) { for (let i = 0; i < itemForRoads.length; ++i) { const item = itemForRoads[i]; if (item.handle == HistoryEvents.AddRoad) { let vRoad = roadService.createOnlyRoad( item.road.startId, item.road.endId, item.road.id ); historyUtil.assignRoadFromRoad(vRoad, item.road); } 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.curRoad.id); historyUtil.assignRoadFromRoad(preRoad, currentRoad); } } } goNextForCurveRoadPoints(itemForCurveRoadPoints) { for (let i = 0; i < itemForCurveRoadPoints.length; ++i) { const item = itemForCurveRoadPoints[i]; if (item.handle == HistoryEvents.AddCurveRoadPoint) { let vCurveRoadPoint = curveRoadPointService.create( item.curveRoadPoint.position, item.curveRoadPoint.id ); historyUtil.assignCurveRoadPointFromCurveRoadPoint( vCurveRoadPoint, item.curveRoadPoint ); } else if (item.handle == HistoryEvents.DeleteCurveRoadPoint) { dataService.deleteCurveRoadPoint(item.curveRoadPoint.id); } else if (item.handle == HistoryEvents.ModifyCurveRoadPoint) { const currentCurveRoadPoint = item.curCurveRoadPoint; let preCurveRoadPoint = dataService.getCurveRoadPoint( item.curCurveRoadPoint.id ); historyUtil.assignCurveRoadPointFromCurveRoadPoint( preCurveRoadPoint, currentCurveRoadPoint ); } } } goNextForCurveRoadEdges(itemForCurveRoadEdges) { for (let i = 0; i < itemForCurveRoadEdges.length; ++i) { const item = itemForCurveRoadEdges[i]; if (item.handle == HistoryEvents.AddCurveRoadEdge) { let vCurveRoadEdge = curveEdgeService.create( item.curveRoadEdge.start, item.curveRoadEdge.end, item.curveRoadEdge.id, item.curveRoadEdge.parent, item.curveRoadEdge.points ); historyUtil.assignCurveRoadEdgeFromCurveRoadEdge( vCurveRoadEdge, item.curveRoadEdge ); } else if (item.handle == HistoryEvents.DeleteCurveRoadEdge) { dataService.deleteCurveRoadEdge(item.curveRoadEdge.id); } else if (item.handle == HistoryEvents.ModifyCurveRoadEdge) { const currentRoadEdge = item.curCurveRoadEdge; let preRoadEdge = dataService.getCurveRoadEdge( item.curCurveRoadEdge.id ); historyUtil.assignCurveRoadEdgeFromCurveRoadEdge( preRoadEdge, currentRoadEdge ); } } } goNextForCurveRoads(itemForCurveRoads) { for (let i = 0; i < itemForCurveRoads.length; ++i) { const item = itemForCurveRoads[i]; if (item.handle == HistoryEvents.AddCurveRoad) { let vCurveRoad = curveRoadService.createOnlyCurveRoad( item.curveRoad.startId, item.curveRoad.endId, item.curveRoad.id ); historyUtil.assignCurveRoadFromCurveRoad(vCurveRoad, item.curveRoad); } else if (item.handle == HistoryEvents.DeleteCurveRoad) { dataService.deleteCurveRoad(item.curveRoad.id); } else if (item.handle == HistoryEvents.ModifyCurveRoad) { const currentCurveRoad = item.curCurveRoad; let preCurveRoad = dataService.getCurveRoad(item.curCurveRoad.id); historyUtil.assignCurveRoadFromCurveRoad( preCurveRoad, currentCurveRoad ); } } } goNextForCrossPoints(itemForCrossPoints) { for (let i = 0; i < itemForCrossPoints.length; ++i) { const item = itemForCrossPoints[i]; if (item.handle == HistoryEvents.AddCrossPoint) { let vCrossPoint = crossPointService.create( item.crossPoint.position, item.crossPoint.id ); historyUtil.assignCrossPointFromCrossPoint( vCrossPoint, item.crossPoint ); } else if (item.handle == HistoryEvents.DeleteCrossPoint) { dataService.deleteCrossPoint1(item.crossPoint.id); } else if (item.handle == HistoryEvents.ModifyCrossPoint) { const currentCrossPoint = item.curCrossPoint; let preCrossPoint = dataService.getCrossPoint3(item.curCrossPoint.id); historyUtil.assignCrossPointFromCrossPoint( preCrossPoint, currentCrossPoint ); } } } goNextForSettings(itemForSettings) { if ( itemForSettings && itemForSettings.handle == HistoryEvents.ModifySettings ) { const currentSettings = itemForSettings.curSettings; historyUtil.assignSettingsFromSettings(Settings, currentSettings); this.layer.updateForLocation(); } } // 恢复 goNextState() { this.layer.exit(); historyService.redoHistoryRecord(); const item = historyService.getHistoryRecord(); if (item) { stateService.clear(); this.goNextForPoints(item.points); this.goNextForLines(item.lines); this.goNextForCurvePoints(item.curvePoints); this.goNextForCurveLines(item.curveLines); this.goNextForCircles(item.circles); this.goNextForTexts(item.texts); this.goNextForMagnifiers(item.magnifiers); this.goNextForSVGs(item.svgs); this.goNextForRoadPoints(item.roadPoints); this.goNextForRoadEdges(item.roadEdges); this.goNextForRoads(item.roads); this.goNextForCurveRoadPoints(item.curveRoadPoints); this.goNextForCurveRoadEdges(item.curveRoadEdges); this.goNextForCurveRoads(item.curveRoads); this.goNextForCrossPoints(item.crossPoints); this.goNextForSettings(item.settings); change.saveCurrentInfo(); this.setState(); } else { historyService.undoHistoryRecord(); console.error("goNextState超出范围!"); } } }