History.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. import { dataService } from "../Service/DataService";
  2. import { historyUtil } from "./HistoryUtil";
  3. import { change } from "./Change";
  4. import { stateService } from "../Service/StateService";
  5. import HistoryEvents from "../enum/HistoryEvents";
  6. import { historyService } from "../Service/HistoryService";
  7. import { textService } from "../Service/TextService";
  8. import { roadService } from "../Service/RoadService";
  9. import { svgService } from "../Service/SVGService";
  10. import { roadPointService } from "../Service/RoadPointService";
  11. import { lineService } from "../Service/LineService";
  12. import { circleService } from "../Service/CircleService";
  13. import { pointService } from "../Service/PointService";
  14. import { edgeService } from "../Service/EdgeService";
  15. import { magnifierService } from "../Service/MagnifierService";
  16. import { crossPointService } from "../Service/CrossPointService";
  17. import { curveRoadPointService } from "../Service/CurveRoadPointService";
  18. import { curveEdgeService } from "../Service/CurveEdgeService";
  19. import { curveRoadService } from "../Service/CurveRoadService";
  20. import { curvePointService } from "../Service/CurvePointService";
  21. import Settings from "../Settings";
  22. export default class History {
  23. constructor(layer) {
  24. this.layer = layer;
  25. }
  26. init() {
  27. change.saveCurrentInfo();
  28. }
  29. save() {
  30. const flag = change.operate();
  31. if (!flag) {
  32. return;
  33. }
  34. historyService.addHistoryRecord(change.currentData);
  35. change.saveCurrentInfo();
  36. this.setState();
  37. const historyState = historyService.getHistoryState();
  38. this.layer.uiControl.graphicStateUI.canRevoke = historyState.pre;
  39. this.layer.uiControl.graphicStateUI.canRecovery = historyState.next;
  40. }
  41. setState() {
  42. const state = {
  43. pre: 0,
  44. next: 0,
  45. };
  46. const currentRecordIndex = historyService.getCurrentRecordIndex();
  47. const records = historyService.getHistoryRecords();
  48. if (currentRecordIndex > -1) {
  49. state.pre = 1;
  50. }
  51. if (currentRecordIndex < records.length - 1) {
  52. state.next = 1;
  53. }
  54. const lastState = historyService.getHistoryState();
  55. if (lastState.pre != state.pre || lastState.next != state.next) {
  56. historyService.setHistoryState(state.pre, state.next);
  57. }
  58. }
  59. // 是否可以撤销
  60. canUndo() {
  61. const state = this.setState();
  62. if (state.pre == 0) {
  63. return false;
  64. } else {
  65. return true;
  66. }
  67. }
  68. // 是否可以恢复
  69. canRedo() {
  70. const state = this.setState();
  71. if (state.next == 0) {
  72. return false;
  73. } else {
  74. return true;
  75. }
  76. }
  77. // 撤销
  78. handleUndo() {
  79. this.goPreState();
  80. }
  81. // 恢复
  82. handleRedo() {
  83. this.goNextState();
  84. }
  85. // 撤销
  86. goPreState() {
  87. this.layer.exit();
  88. const item = historyService.getHistoryRecord();
  89. if (item) {
  90. stateService.clear();
  91. item.type = "pre";
  92. this.goPreForPoints(item.points);
  93. this.goPreForLines(item.lines);
  94. this.goPreForCurvePoints(item.curvePoints);
  95. this.goPreForCurveLines(item.curveLines);
  96. this.goPreForCircles(item.circles);
  97. this.goPreForTexts(item.texts);
  98. this.goPreForMagnifiers(item.magnifiers);
  99. this.goPreForSVGs(item.svgs);
  100. this.goPreForRoadPoints(item.roadPoints);
  101. this.goPreForRoadEdges(item.roadEdges);
  102. this.goPreForRoads(item.roads);
  103. this.goPreForCurveRoadPoints(item.curveRoadPoints);
  104. this.goPreForCurveRoadEdges(item.curveRoadEdges);
  105. this.goPreForCurveRoads(item.curveRoads);
  106. this.goPreForCrossPoints(item.crossPoints);
  107. this.goPreForSettings(item.settings);
  108. historyService.undoHistoryRecord();
  109. change.saveCurrentInfo();
  110. this.setState();
  111. } else {
  112. console.error("goPreState超出范围!");
  113. }
  114. }
  115. goPreForPoints(itemForPoints) {
  116. for (let i = 0; i < itemForPoints.length; ++i) {
  117. const item = itemForPoints[i];
  118. if (item.handle == HistoryEvents.AddPoint) {
  119. dataService.deletePoint(item.point.id);
  120. } else if (item.handle == HistoryEvents.DeletePoint) {
  121. let point = pointService.create(item.point, item.point.id);
  122. point.setCategory(item.point.category);
  123. point.setLinkedBasePointId(item.point.linkedBasePointId);
  124. point.setLocationMode(item.point.locationMode);
  125. point.linkedTextId = item.point.linkedTextId;
  126. point.parent = JSON.parse(JSON.stringify(item.point.parent));
  127. } else if (item.handle == HistoryEvents.ModifyPoint) {
  128. const prePoint = item.prePoint;
  129. let currentPoint = dataService.getPoint(item.curPoint.id);
  130. historyUtil.assignPointFromPoint(currentPoint, prePoint);
  131. }
  132. }
  133. }
  134. goPreForLines(itemForLines) {
  135. for (let i = 0; i < itemForLines.length; ++i) {
  136. const item = itemForLines[i];
  137. if (item.handle == HistoryEvents.AddLine) {
  138. dataService.deleteLine(item.line.id);
  139. } else if (item.handle == HistoryEvents.DeleteLine) {
  140. const preLine = item.line;
  141. let newLine = lineService.createByPointId(
  142. preLine.start,
  143. preLine.end,
  144. preLine.category,
  145. preLine.id
  146. );
  147. historyUtil.assignLineFromLine(newLine, preLine);
  148. } else if (item.handle == HistoryEvents.ModifyLine) {
  149. const preLine = item.preLine;
  150. let currentLine = dataService.getLine(item.curLine.id);
  151. historyUtil.assignLineFromLine(currentLine, preLine);
  152. }
  153. }
  154. }
  155. goPreForCurvePoints(itemForCurvePoints) {
  156. for (let i = 0; i < itemForCurvePoints.length; ++i) {
  157. const item = itemForCurvePoints[i];
  158. if (item.handle == HistoryEvents.AddCurvePoint) {
  159. dataService.deleteCurvePoint(item.curvePoint.id);
  160. } else if (item.handle == HistoryEvents.DeleteCurvePoint) {
  161. let curvePoint = curvePointService.create(
  162. item.curvePoint,
  163. item.curvePoint.id
  164. );
  165. curvePoint.setIndex(item.index);
  166. curvePoint.setPointParent(item.curvePoint.parent);
  167. } else if (item.handle == HistoryEvents.ModifyCurvePoint) {
  168. const preCurvePoint = item.preCurvePoint;
  169. let currentCurvePoint = dataService.getCurvePoint(
  170. item.curCurvePoint.id
  171. );
  172. historyUtil.assignCurvePointFromCurvePoint(
  173. currentCurvePoint,
  174. preCurvePoint
  175. );
  176. }
  177. }
  178. }
  179. goPreForCurveLines(itemForCurveLines) {
  180. for (let i = 0; i < itemForCurveLines.length; ++i) {
  181. const item = itemForCurveLines[i];
  182. if (item.handle == HistoryEvents.AddCurveLine) {
  183. dataService.deleteCurveLine(item.curveLine.id);
  184. } else if (item.handle == HistoryEvents.DeleteCurveLine) {
  185. const preCurveLine = item.curveLine;
  186. let newCurveLine = lineService.createCurveLineByPointIds(
  187. preCurveLine.points,
  188. preCurveLine.id
  189. );
  190. historyUtil.assignCurveLineFromCurveLine(newCurveLine, preCurveLine);
  191. } else if (item.handle == HistoryEvents.ModifyCurveLine) {
  192. const preCurveLine = item.preCurveLine;
  193. let currentCurveLine = dataService.getCurveLine(item.curCurveLine.id);
  194. historyUtil.assignCurveLineFromCurveLine(
  195. currentCurveLine,
  196. preCurveLine
  197. );
  198. }
  199. }
  200. }
  201. goPreForCircles(itemForCircles) {
  202. for (let i = 0; i < itemForCircles.length; ++i) {
  203. const item = itemForCircles[i];
  204. if (item.handle == HistoryEvents.AddCircle) {
  205. dataService.deleteCircle(item.circle.id);
  206. } else if (item.handle == HistoryEvents.DeleteCircle) {
  207. const preCircle = item.circle;
  208. let newCircle = circleService.create(
  209. preCircle.center,
  210. preCircle.radius || preCircle.radiusX,
  211. preCircle.id
  212. );
  213. historyUtil.assignCircleFromCircle(newCircle, preCircle);
  214. } else if (item.handle == HistoryEvents.ModifyCircle) {
  215. const preCircle = item.preCircle;
  216. let currentCircle = dataService.getCircle(item.curCircle.id);
  217. historyUtil.assignCircleFromCircle(currentCircle, preCircle);
  218. }
  219. }
  220. }
  221. goPreForTexts(itemForTexts) {
  222. for (let i = 0; i < itemForTexts.length; ++i) {
  223. const item = itemForTexts[i];
  224. if (item.handle == HistoryEvents.AddText) {
  225. dataService.deleteText(item.text.id);
  226. } else if (item.handle == HistoryEvents.DeleteText) {
  227. let newText = textService.create(item.text.center, item.text.id);
  228. historyUtil.assignTextFromText(newText, item.text);
  229. } else if (item.handle == HistoryEvents.ModifyText) {
  230. const preText = item.preText;
  231. let currentText = dataService.getText(item.curText.id);
  232. historyUtil.assignTextFromText(currentText, preText);
  233. }
  234. }
  235. }
  236. goPreForMagnifiers(itemForMagnifiers) {
  237. for (let i = 0; i < itemForMagnifiers.length; ++i) {
  238. const item = itemForMagnifiers[i];
  239. if (item.handle == HistoryEvents.AddMagnifier) {
  240. dataService.deleteMagnifier(item.magnifier.id);
  241. } else if (item.handle == HistoryEvents.DeleteMagnifier) {
  242. let newMagnifier = magnifierService.create(
  243. item.magnifier.position,
  244. item.magnifier.id
  245. );
  246. historyUtil.assignMagnifierFromMagnifier(newMagnifier, item.magnifier);
  247. } else if (item.handle == HistoryEvents.ModifyMagnifier) {
  248. const preMagnifier = item.preMagnifier;
  249. let currentMagnifier = dataService.getMagnifier(item.curMagnifier.id);
  250. historyUtil.assignMagnifierFromMagnifier(
  251. currentMagnifier,
  252. preMagnifier
  253. );
  254. }
  255. }
  256. }
  257. goPreForSVGs(itemForSVGs) {
  258. for (let i = 0; i < itemForSVGs.length; ++i) {
  259. const item = itemForSVGs[i];
  260. if (item.handle == HistoryEvents.AddSVG) {
  261. dataService.deleteSVG(item.svg.id);
  262. } else if (item.handle == HistoryEvents.DeleteSVG) {
  263. let newSVG = svgService.create(
  264. item.svg.center,
  265. item.svg.type,
  266. item.svg.id
  267. );
  268. historyUtil.assignSVGFromSVG(newSVG, item.svg);
  269. } else if (item.handle == HistoryEvents.ModifySVG) {
  270. const preSVG = item.preSVG;
  271. let currentSVG = dataService.getSVG(item.curSVG.id);
  272. historyUtil.assignSVGFromSVG(currentSVG, preSVG);
  273. }
  274. }
  275. }
  276. goPreForRoadPoints(itemForRoadPoints) {
  277. for (let i = 0; i < itemForRoadPoints.length; ++i) {
  278. const item = itemForRoadPoints[i];
  279. if (item.handle == HistoryEvents.AddRoadPoint) {
  280. dataService.deleteRoadPoint1(item.roadPoint.id);
  281. } else if (item.handle == HistoryEvents.DeleteRoadPoint) {
  282. let newRoadPoint = roadPointService.create(
  283. item.roadPoint.position,
  284. item.roadPoint.id
  285. );
  286. historyUtil.assignRoadPointFromRoadPoint(newRoadPoint, item.roadPoint);
  287. } else if (item.handle == HistoryEvents.ModifyRoadPoint) {
  288. const preRoadPoint = item.preRoadPoint;
  289. let currentRoadPoint = dataService.getRoadPoint(item.curRoadPoint.id);
  290. historyUtil.assignRoadPointFromRoadPoint(
  291. currentRoadPoint,
  292. preRoadPoint
  293. );
  294. }
  295. }
  296. }
  297. goPreForRoadEdges(itemForRoadEdges) {
  298. for (let i = 0; i < itemForRoadEdges.length; ++i) {
  299. const item = itemForRoadEdges[i];
  300. if (item.handle == HistoryEvents.AddRoadEdge) {
  301. dataService.deleteRoadEdge(item.roadEdge.id);
  302. } else if (item.handle == HistoryEvents.DeleteRoadEdge) {
  303. let newRoadEdge = edgeService.create(
  304. item.roadEdge.start,
  305. item.roadEdge.end,
  306. item.roadEdge.id,
  307. item.roadEdge.parent
  308. );
  309. historyUtil.assignRoadEdgeFromRoadEdge(newRoadEdge, item.roadEdge);
  310. } else if (item.handle == HistoryEvents.ModifyRoadEdge) {
  311. const preRoadEdge = item.preRoadEdge;
  312. let currentRoadEdge = dataService.getRoadEdge(item.curRoadEdge.id);
  313. historyUtil.assignRoadEdgeFromRoadEdge(currentRoadEdge, preRoadEdge);
  314. }
  315. }
  316. }
  317. goPreForRoads(itemForRoads) {
  318. for (let i = 0; i < itemForRoads.length; ++i) {
  319. const item = itemForRoads[i];
  320. if (item.handle == HistoryEvents.AddRoad) {
  321. dataService.deleteRoad(item.road.id);
  322. } else if (item.handle == HistoryEvents.DeleteRoad) {
  323. let newRoad = roadService.createOnlyRoad(
  324. item.road.startId,
  325. item.road.endId,
  326. item.road.id
  327. );
  328. historyUtil.assignRoadFromRoad(newRoad, item.road);
  329. } else if (item.handle == HistoryEvents.ModifyRoad) {
  330. const preRoad = item.preRoad;
  331. let currentRoad = dataService.getRoad(item.curRoad.id);
  332. historyUtil.assignRoadFromRoad(currentRoad, preRoad);
  333. }
  334. }
  335. }
  336. goPreForCurveRoadPoints(itemForCurveRoadPoints) {
  337. for (let i = 0; i < itemForCurveRoadPoints.length; ++i) {
  338. const item = itemForCurveRoadPoints[i];
  339. if (item.handle == HistoryEvents.AddCurveRoadPoint) {
  340. dataService.deleteCurveRoadPoint(item.curveRoadPoint.id);
  341. } else if (item.handle == HistoryEvents.DeleteCurveRoadPoint) {
  342. let newCurveRoadPoint = curveRoadPointService.create(
  343. item.curveRoadPoint.position,
  344. item.curveRoadPoint.id
  345. );
  346. historyUtil.assignCurveRoadPointFromCurveRoadPoint(
  347. newCurveRoadPoint,
  348. item.curveRoadPoint
  349. );
  350. } else if (item.handle == HistoryEvents.ModifyCurveRoadPoint) {
  351. const preCurveRoadPoint = item.preCurveRoadPoint;
  352. let currentCurveRoadPoint = dataService.getCurveRoadPoint(
  353. item.curCurveRoadPoint.id
  354. );
  355. historyUtil.assignCurveRoadPointFromCurveRoadPoint(
  356. currentCurveRoadPoint,
  357. preCurveRoadPoint
  358. );
  359. }
  360. }
  361. }
  362. goPreForCurveRoadEdges(itemForCurveRoadEdges) {
  363. for (let i = 0; i < itemForCurveRoadEdges.length; ++i) {
  364. const item = itemForCurveRoadEdges[i];
  365. if (item.handle == HistoryEvents.AddCurveRoadEdge) {
  366. dataService.deleteCurveRoadEdge(item.curveRoadEdge.id);
  367. } else if (item.handle == HistoryEvents.DeleteCurveRoadEdge) {
  368. let newCurveRoadEdge = curveEdgeService.create(
  369. item.curveRoadEdge.start,
  370. item.curveRoadEdge.end,
  371. item.curveRoadEdge.id,
  372. item.curveRoadEdge.parent
  373. );
  374. historyUtil.assignCurveRoadEdgeFromCurveRoadEdge(
  375. newCurveRoadEdge,
  376. item.curveRoadEdge
  377. );
  378. } else if (item.handle == HistoryEvents.ModifyCurveRoadEdge) {
  379. const preCurveRoadEdge = item.preCurveRoadEdge;
  380. let currentCurveRoadEdge = dataService.getCurveRoadEdge(
  381. item.curCurveRoadEdge.id
  382. );
  383. historyUtil.assignCurveRoadEdgeFromCurveRoadEdge(
  384. currentCurveRoadEdge,
  385. preCurveRoadEdge
  386. );
  387. }
  388. }
  389. }
  390. goPreForCurveRoads(itemForCurveRoads) {
  391. for (let i = 0; i < itemForCurveRoads.length; ++i) {
  392. const item = itemForCurveRoads[i];
  393. if (item.handle == HistoryEvents.AddCurveRoad) {
  394. dataService.deleteCurveRoad(item.curveRoad.id);
  395. } else if (item.handle == HistoryEvents.DeleteCurveRoad) {
  396. let newCurveRoad = curveRoadService.createOnlyCurveRoad(
  397. item.curveRoad.startId,
  398. item.curveRoad.endId,
  399. item.curveRoad.id
  400. );
  401. historyUtil.assignCurveRoadFromCurveRoad(newCurveRoad, item.curveRoad);
  402. } else if (item.handle == HistoryEvents.ModifyCurveRoad) {
  403. const preCurveRoad = item.preCurveRoad;
  404. let currentCurveRoad = dataService.getCurveRoad(item.curCurveRoad.id);
  405. historyUtil.assignCurveRoadFromCurveRoad(
  406. currentCurveRoad,
  407. preCurveRoad
  408. );
  409. }
  410. }
  411. }
  412. goPreForCrossPoints(itemForCrossPoints) {
  413. for (let i = 0; i < itemForCrossPoints.length; ++i) {
  414. const item = itemForCrossPoints[i];
  415. if (item.handle == HistoryEvents.AddCrossPoint) {
  416. dataService.deleteCrossPoint1(item.crossPoint.id);
  417. } else if (item.handle == HistoryEvents.DeleteCrossPoint) {
  418. let newCrossPoint = crossPointService.create(
  419. item.crossPoint.position,
  420. item.crossPoint.id
  421. );
  422. historyUtil.assignCrossPointFromCrossPoint(
  423. newCrossPoint,
  424. item.crossPoint
  425. );
  426. } else if (item.handle == HistoryEvents.ModifyCrossPoint) {
  427. const preCrossPoint = item.preCrossPoint;
  428. let currentCrossPoint = dataService.getCrossPoint3(
  429. item.curCrossPoint.id
  430. );
  431. historyUtil.assignCrossPointFromCrossPoint(
  432. currentCrossPoint,
  433. preCrossPoint
  434. );
  435. }
  436. }
  437. }
  438. goPreForSettings(itemForSettings) {
  439. if (
  440. itemForSettings &&
  441. itemForSettings.handle == HistoryEvents.ModifySettings
  442. ) {
  443. const preSettings = itemForSettings.preSettings;
  444. historyUtil.assignSettingsFromSettings(Settings, preSettings);
  445. this.layer.updateForLocation();
  446. }
  447. }
  448. goNextForPoints(itemForPoints) {
  449. for (let i = 0; i < itemForPoints.length; ++i) {
  450. const item = itemForPoints[i];
  451. if (item.handle == HistoryEvents.AddPoint) {
  452. let newPoint = pointService.create(item.point, item.point.id);
  453. newPoint.setCategory(item.point.category);
  454. newPoint.setLinkedBasePointId(item.point.linkedBasePointId);
  455. newPoint.setLocationMode(item.point.locationMode);
  456. historyUtil.assignPointFromPoint(newPoint, item.point);
  457. } else if (item.handle == HistoryEvents.DeletePoint) {
  458. dataService.deletePoint(item.point.id);
  459. } else if (item.handle == HistoryEvents.ModifyPoint) {
  460. const currentPoint = item.curPoint;
  461. let prePoint = dataService.getPoint(item.curPoint.id);
  462. historyUtil.assignPointFromPoint(prePoint, currentPoint);
  463. }
  464. }
  465. }
  466. goNextForLines(itemForLines) {
  467. for (let i = 0; i < itemForLines.length; ++i) {
  468. const item = itemForLines[i];
  469. if (item.handle == HistoryEvents.AddLine) {
  470. const preLine = item.line;
  471. let newLine = lineService.createByPointId(
  472. preLine.start,
  473. preLine.end,
  474. preLine.category,
  475. preLine.id
  476. );
  477. historyUtil.assignLineFromLine(newLine, preLine);
  478. } else if (item.handle == HistoryEvents.DeleteLine) {
  479. dataService.deleteLine(item.line.id);
  480. } else if (item.handle == HistoryEvents.ModifyLine) {
  481. const currentLine = item.curLine;
  482. let preLine = dataService.getLine(item.preLine.id);
  483. historyUtil.assignLineFromLine(preLine, currentLine);
  484. }
  485. }
  486. }
  487. goNextForCurvePoints(itemForCurvePoints) {
  488. for (let i = 0; i < itemForCurvePoints.length; ++i) {
  489. const item = itemForCurvePoints[i];
  490. if (item.handle == HistoryEvents.AddCurvePoint) {
  491. let newCurvePoint = curvePointService.create(
  492. item.curvePoint,
  493. item.curvePoint.id
  494. );
  495. historyUtil.assignCurvePointFromCurvePoint(
  496. newCurvePoint,
  497. item.curvePoint
  498. );
  499. } else if (item.handle == HistoryEvents.DeleteCurvePoint) {
  500. dataService.deleteCurvePoint(item.curvePoint.id);
  501. } else if (item.handle == HistoryEvents.ModifyCurvePoint) {
  502. const currentCurvePoint = item.curCurvePoint;
  503. let preCurvePoint = dataService.getCurvePoint(item.curCurvePoint.id);
  504. historyUtil.assignCurvePointFromCurvePoint(
  505. preCurvePoint,
  506. currentCurvePoint
  507. );
  508. }
  509. }
  510. }
  511. goNextForCurveLines(itemForCurveLines) {
  512. for (let i = 0; i < itemForCurveLines.length; ++i) {
  513. const item = itemForCurveLines[i];
  514. if (item.handle == HistoryEvents.AddCurveLine) {
  515. const preCurveLine = item.curveLine;
  516. let newCurveLine = lineService.createCurveLineByPointIds(
  517. preCurveLine.points,
  518. preCurveLine.id
  519. );
  520. historyUtil.assignCurveLineFromCurveLine(newCurveLine, preCurveLine);
  521. } else if (item.handle == HistoryEvents.DeleteCurveLine) {
  522. dataService.deleteCurveLine(item.curveLine.id);
  523. } else if (item.handle == HistoryEvents.ModifyCurveLine) {
  524. const currentCurveLine = item.curCurveLine;
  525. let preCurveLine = dataService.getCurveLine(item.preCurveLine.id);
  526. historyUtil.assignCurveLineFromCurveLine(
  527. preCurveLine,
  528. currentCurveLine
  529. );
  530. }
  531. }
  532. }
  533. goNextForCircles(itemForCircles) {
  534. for (let i = 0; i < itemForCircles.length; ++i) {
  535. const item = itemForCircles[i];
  536. if (item.handle == HistoryEvents.AddCircle) {
  537. const preCircle = item.circle;
  538. let newCircle = circleService.create(
  539. preCircle.center,
  540. preCircle.radius || preCircle.radiusX,
  541. preCircle.id
  542. );
  543. historyUtil.assignCircleFromCircle(newCircle, preCircle);
  544. } else if (item.handle == HistoryEvents.DeleteCircle) {
  545. dataService.deleteCircle(item.circle.id);
  546. } else if (item.handle == HistoryEvents.ModifyCircle) {
  547. const currentCircle = item.curCircle;
  548. let preCircle = dataService.getCircle(item.preCircle.id);
  549. historyUtil.assignCircleFromCircle(preCircle, currentCircle);
  550. }
  551. }
  552. }
  553. goNextForTexts(itemForTexts) {
  554. for (let i = 0; i < itemForTexts.length; ++i) {
  555. const item = itemForTexts[i];
  556. if (item.handle == HistoryEvents.AddText) {
  557. let vText = textService.create(item.text.center, item.text.id);
  558. historyUtil.assignTextFromText(vText, item.text);
  559. } else if (item.handle == HistoryEvents.DeleteText) {
  560. dataService.deleteText(item.text.id);
  561. } else if (item.handle == HistoryEvents.ModifyText) {
  562. const currentText = item.curText;
  563. let preText = dataService.getText(item.curText.id);
  564. historyUtil.assignTextFromText(preText, currentText);
  565. }
  566. }
  567. }
  568. goNextForMagnifiers(itemForMagnifiers) {
  569. for (let i = 0; i < itemForMagnifiers.length; ++i) {
  570. const item = itemForMagnifiers[i];
  571. if (item.handle == HistoryEvents.AddMagnifier) {
  572. let vMagnifier = magnifierService.create(
  573. item.magnifier.position,
  574. item.magnifier.id
  575. );
  576. historyUtil.assignMagnifierFromMagnifier(vMagnifier, item.magnifier);
  577. } else if (item.handle == HistoryEvents.DeleteMagnifier) {
  578. dataService.deleteMagnifier(item.magnifier.id);
  579. } else if (item.handle == HistoryEvents.ModifyMagnifier) {
  580. const currentMagnifier = item.curMagnifier;
  581. let preMagnifier = dataService.getMagnifier(item.curMagnifier.id);
  582. historyUtil.assignMagnifierFromMagnifier(
  583. preMagnifier,
  584. currentMagnifier
  585. );
  586. }
  587. }
  588. }
  589. goNextForSVGs(itemForSVGs) {
  590. for (let i = 0; i < itemForSVGs.length; ++i) {
  591. const item = itemForSVGs[i];
  592. if (item.handle == HistoryEvents.AddSVG) {
  593. let vSVG = svgService.create(
  594. item.svg.center,
  595. item.svg.type,
  596. item.svg.id
  597. );
  598. historyUtil.assignSVGFromSVG(vSVG, item.svg);
  599. } else if (item.handle == HistoryEvents.DeleteSVG) {
  600. dataService.deleteSVG(item.svg.id);
  601. } else if (item.handle == HistoryEvents.ModifySVG) {
  602. const currentSVG = item.curSVG;
  603. let preSVG = dataService.getSVG(item.preSVG.id);
  604. historyUtil.assignSVGFromSVG(preSVG, currentSVG);
  605. }
  606. }
  607. }
  608. goNextForRoadPoints(itemForRoadPoints) {
  609. for (let i = 0; i < itemForRoadPoints.length; ++i) {
  610. const item = itemForRoadPoints[i];
  611. if (item.handle == HistoryEvents.AddRoadPoint) {
  612. let vRoadPoint = roadPointService.create(
  613. item.roadPoint.position,
  614. item.roadPoint.id
  615. );
  616. historyUtil.assignRoadPointFromRoadPoint(vRoadPoint, item.roadPoint);
  617. } else if (item.handle == HistoryEvents.DeleteRoadPoint) {
  618. dataService.deleteRoadPoint1(item.roadPoint.id);
  619. } else if (item.handle == HistoryEvents.ModifyRoadPoint) {
  620. const currentRoadPoint = item.curRoadPoint;
  621. let preRoadPoint = dataService.getRoadPoint(item.curRoadPoint.id);
  622. historyUtil.assignRoadPointFromRoadPoint(
  623. preRoadPoint,
  624. currentRoadPoint
  625. );
  626. }
  627. }
  628. }
  629. goNextForRoadEdges(itemForRoadEdges) {
  630. for (let i = 0; i < itemForRoadEdges.length; ++i) {
  631. const item = itemForRoadEdges[i];
  632. if (item.handle == HistoryEvents.AddRoadEdge) {
  633. let vRoadEdge = edgeService.create(
  634. item.roadEdge.start,
  635. item.roadEdge.end,
  636. item.roadEdge.id,
  637. item.roadEdge.parent
  638. );
  639. historyUtil.assignRoadEdgeFromRoadEdge(vRoadEdge, item.roadEdge);
  640. } else if (item.handle == HistoryEvents.DeleteRoadEdge) {
  641. dataService.deleteRoadEdge(item.roadEdge.id);
  642. } else if (item.handle == HistoryEvents.ModifyRoadEdge) {
  643. const currentRoadEdge = item.curRoadEdge;
  644. let preRoadEdge = dataService.getRoadEdge(item.curRoadEdge.id);
  645. historyUtil.assignRoadEdgeFromRoadEdge(preRoadEdge, currentRoadEdge);
  646. }
  647. }
  648. }
  649. goNextForRoads(itemForRoads) {
  650. for (let i = 0; i < itemForRoads.length; ++i) {
  651. const item = itemForRoads[i];
  652. if (item.handle == HistoryEvents.AddRoad) {
  653. let vRoad = roadService.createOnlyRoad(
  654. item.road.startId,
  655. item.road.endId,
  656. item.road.id
  657. );
  658. historyUtil.assignRoadFromRoad(vRoad, item.road);
  659. } else if (item.handle == HistoryEvents.DeleteRoad) {
  660. dataService.deleteRoad(item.road.id);
  661. } else if (item.handle == HistoryEvents.ModifyRoad) {
  662. const currentRoad = item.curRoad;
  663. let preRoad = dataService.getRoad(item.curRoad.id);
  664. historyUtil.assignRoadFromRoad(preRoad, currentRoad);
  665. }
  666. }
  667. }
  668. goNextForCurveRoadPoints(itemForCurveRoadPoints) {
  669. for (let i = 0; i < itemForCurveRoadPoints.length; ++i) {
  670. const item = itemForCurveRoadPoints[i];
  671. if (item.handle == HistoryEvents.AddCurveRoadPoint) {
  672. let vCurveRoadPoint = curveRoadPointService.create(
  673. item.curveRoadPoint.position,
  674. item.curveRoadPoint.id
  675. );
  676. historyUtil.assignCurveRoadPointFromCurveRoadPoint(
  677. vCurveRoadPoint,
  678. item.curveRoadPoint
  679. );
  680. } else if (item.handle == HistoryEvents.DeleteCurveRoadPoint) {
  681. dataService.deleteCurveRoadPoint(item.curveRoadPoint.id);
  682. } else if (item.handle == HistoryEvents.ModifyCurveRoadPoint) {
  683. const currentCurveRoadPoint = item.curCurveRoadPoint;
  684. let preCurveRoadPoint = dataService.getCurveRoadPoint(
  685. item.curCurveRoadPoint.id
  686. );
  687. historyUtil.assignCurveRoadPointFromCurveRoadPoint(
  688. preCurveRoadPoint,
  689. currentCurveRoadPoint
  690. );
  691. }
  692. }
  693. }
  694. goNextForCurveRoadEdges(itemForCurveRoadEdges) {
  695. for (let i = 0; i < itemForCurveRoadEdges.length; ++i) {
  696. const item = itemForCurveRoadEdges[i];
  697. if (item.handle == HistoryEvents.AddCurveRoadEdge) {
  698. let vCurveRoadEdge = curveEdgeService.create(
  699. item.curveRoadEdge.start,
  700. item.curveRoadEdge.end,
  701. item.curveRoadEdge.id,
  702. item.curveRoadEdge.parent,
  703. item.curveRoadEdge.points
  704. );
  705. historyUtil.assignCurveRoadEdgeFromCurveRoadEdge(
  706. vCurveRoadEdge,
  707. item.curveRoadEdge
  708. );
  709. } else if (item.handle == HistoryEvents.DeleteCurveRoadEdge) {
  710. dataService.deleteCurveRoadEdge(item.curveRoadEdge.id);
  711. } else if (item.handle == HistoryEvents.ModifyCurveRoadEdge) {
  712. const currentRoadEdge = item.curCurveRoadEdge;
  713. let preRoadEdge = dataService.getCurveRoadEdge(
  714. item.curCurveRoadEdge.id
  715. );
  716. historyUtil.assignCurveRoadEdgeFromCurveRoadEdge(
  717. preRoadEdge,
  718. currentRoadEdge
  719. );
  720. }
  721. }
  722. }
  723. goNextForCurveRoads(itemForCurveRoads) {
  724. for (let i = 0; i < itemForCurveRoads.length; ++i) {
  725. const item = itemForCurveRoads[i];
  726. if (item.handle == HistoryEvents.AddCurveRoad) {
  727. let vCurveRoad = curveRoadService.createOnlyCurveRoad(
  728. item.curveRoad.startId,
  729. item.curveRoad.endId,
  730. item.curveRoad.id
  731. );
  732. historyUtil.assignCurveRoadFromCurveRoad(vCurveRoad, item.curveRoad);
  733. } else if (item.handle == HistoryEvents.DeleteCurveRoad) {
  734. dataService.deleteCurveRoad(item.curveRoad.id);
  735. } else if (item.handle == HistoryEvents.ModifyCurveRoad) {
  736. const currentCurveRoad = item.curCurveRoad;
  737. let preCurveRoad = dataService.getCurveRoad(item.curCurveRoad.id);
  738. historyUtil.assignCurveRoadFromCurveRoad(
  739. preCurveRoad,
  740. currentCurveRoad
  741. );
  742. }
  743. }
  744. }
  745. goNextForCrossPoints(itemForCrossPoints) {
  746. for (let i = 0; i < itemForCrossPoints.length; ++i) {
  747. const item = itemForCrossPoints[i];
  748. if (item.handle == HistoryEvents.AddCrossPoint) {
  749. let vCrossPoint = crossPointService.create(
  750. item.crossPoint.position,
  751. item.crossPoint.id
  752. );
  753. historyUtil.assignCrossPointFromCrossPoint(
  754. vCrossPoint,
  755. item.crossPoint
  756. );
  757. } else if (item.handle == HistoryEvents.DeleteCrossPoint) {
  758. dataService.deleteCrossPoint1(item.crossPoint.id);
  759. } else if (item.handle == HistoryEvents.ModifyCrossPoint) {
  760. const currentCrossPoint = item.curCrossPoint;
  761. let preCrossPoint = dataService.getCrossPoint3(item.curCrossPoint.id);
  762. historyUtil.assignCrossPointFromCrossPoint(
  763. preCrossPoint,
  764. currentCrossPoint
  765. );
  766. }
  767. }
  768. }
  769. goNextForSettings(itemForSettings) {
  770. if (
  771. itemForSettings &&
  772. itemForSettings.handle == HistoryEvents.ModifySettings
  773. ) {
  774. const currentSettings = itemForSettings.curSettings;
  775. historyUtil.assignSettingsFromSettings(Settings, currentSettings);
  776. this.layer.updateForLocation();
  777. }
  778. }
  779. // 恢复
  780. goNextState() {
  781. this.layer.exit();
  782. historyService.redoHistoryRecord();
  783. const item = historyService.getHistoryRecord();
  784. if (item) {
  785. stateService.clear();
  786. this.goNextForPoints(item.points);
  787. this.goNextForLines(item.lines);
  788. this.goNextForCurvePoints(item.curvePoints);
  789. this.goNextForCurveLines(item.curveLines);
  790. this.goNextForCircles(item.circles);
  791. this.goNextForTexts(item.texts);
  792. this.goNextForMagnifiers(item.magnifiers);
  793. this.goNextForSVGs(item.svgs);
  794. this.goNextForRoadPoints(item.roadPoints);
  795. this.goNextForRoadEdges(item.roadEdges);
  796. this.goNextForRoads(item.roads);
  797. this.goNextForCurveRoadPoints(item.curveRoadPoints);
  798. this.goNextForCurveRoadEdges(item.curveRoadEdges);
  799. this.goNextForCurveRoads(item.curveRoads);
  800. this.goNextForCrossPoints(item.crossPoints);
  801. this.goNextForSettings(item.settings);
  802. change.saveCurrentInfo();
  803. this.setState();
  804. } else {
  805. historyService.undoHistoryRecord();
  806. console.error("goNextState超出范围!");
  807. }
  808. }
  809. }