Change.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. import { dataService } from "../Service/DataService";
  2. import { roadService } from "../Service/RoadService";
  3. import { historyUtil } from "./HistoryUtil";
  4. import HistoryEvents from "../enum/HistoryEvents";
  5. import { coordinate } from "../Coordinate";
  6. import { mathUtil } from "../Util/MathUtil";
  7. import Settings from "../Settings";
  8. export default class Change {
  9. constructor() {
  10. this.lastData = {}; // 每次都是当前数据和lastData进行比较,一般在mouseDown的时候存储进来
  11. this.currentData = {}; // 当前的变化
  12. }
  13. // 保存当前记录
  14. saveCurrentInfo() {
  15. // this.lastData.roadPoints = JSON.parse(
  16. // JSON.stringify(dataService.getRoadPoints())
  17. // );
  18. //this.lastData.roads = JSON.parse(JSON.stringify(dataService.getRoads()));
  19. this.lastData.lines = JSON.parse(JSON.stringify(dataService.getLines()));
  20. this.lastData.texts = JSON.parse(JSON.stringify(dataService.getTexts()));
  21. this.lastData.points = JSON.parse(JSON.stringify(dataService.getPoints()));
  22. this.lastData.curveLines = JSON.parse(
  23. JSON.stringify(dataService.getCurveLines())
  24. );
  25. this.lastData.curvePoints = JSON.parse(
  26. JSON.stringify(dataService.getCurvePoints())
  27. );
  28. this.lastData.circles = JSON.parse(
  29. JSON.stringify(dataService.getCircles())
  30. );
  31. this.lastData.elliptics = JSON.parse(
  32. JSON.stringify(dataService.getElliptics())
  33. );
  34. this.lastData.magnifiers = JSON.parse(
  35. JSON.stringify(dataService.getMagnifiers())
  36. );
  37. this.lastData.svgs = JSON.parse(JSON.stringify(dataService.getSVGs()));
  38. this.lastData.roadPoints = JSON.parse(
  39. JSON.stringify(dataService.getRoadPoints())
  40. );
  41. this.lastData.roadEdges = JSON.parse(
  42. JSON.stringify(dataService.getRoadEdges())
  43. );
  44. this.lastData.roads = JSON.parse(JSON.stringify(dataService.getRoads()));
  45. this.lastData.curveRoadPoints = JSON.parse(
  46. JSON.stringify(dataService.getCurveRoadPoints())
  47. );
  48. this.lastData.curveRoadEdges = JSON.parse(
  49. JSON.stringify(dataService.getCurveRoadEdges())
  50. );
  51. this.lastData.curveRoads = JSON.parse(
  52. JSON.stringify(dataService.getCurveRoads())
  53. );
  54. this.lastData.crossPoints = JSON.parse(
  55. JSON.stringify(dataService.getCrossPoints())
  56. );
  57. this.lastData.settings = JSON.parse(JSON.stringify(Settings));
  58. }
  59. operate() {
  60. //
  61. this.currentData = {};
  62. // this.compareRoads();
  63. this.comparePoints();
  64. this.compareLines();
  65. this.compareCurvePoints();
  66. this.compareCurveLines();
  67. this.compareCircles();
  68. this.compareElliptics();
  69. this.compareTexts();
  70. this.compareMagnifiers();
  71. this.compareSVGs();
  72. this.compareRoadPoints();
  73. this.compareRoadEdges();
  74. this.compareRoads();
  75. this.compareCurveRoadPoints();
  76. this.compareCurveRoadEdges();
  77. this.compareCurveRoads();
  78. this.compareCrossPoints();
  79. this.compareSettings();
  80. if (
  81. this.currentData.points.length == 0 &&
  82. this.currentData.lines.length == 0 &&
  83. this.currentData.curvePoints.length == 0 &&
  84. this.currentData.curveLines.length == 0 &&
  85. this.currentData.circles.length == 0 &&
  86. this.currentData.elliptics.length == 0 &&
  87. this.currentData.texts.length == 0 &&
  88. this.currentData.magnifiers.length == 0 &&
  89. this.currentData.roadPoints.length == 0 &&
  90. this.currentData.roadEdges.length == 0 &&
  91. this.currentData.roads.length == 0 &&
  92. this.currentData.curveRoadPoints.length == 0 &&
  93. this.currentData.curveRoadEdges.length == 0 &&
  94. this.currentData.curveRoads.length == 0 &&
  95. this.currentData.crossPoints.length == 0 &&
  96. this.currentData.settings
  97. ) {
  98. this.saveCurrentInfo();
  99. return false;
  100. }
  101. this.lastData = {};
  102. // 这里不能取this.records.length-1,因为可能撤销后操作,这时候应该是覆盖,而不是往后面添加
  103. return true;
  104. }
  105. comparePoints() {
  106. const points = dataService.getPoints();
  107. this.currentData.points = [];
  108. for (const key in points) {
  109. const point = points[key];
  110. // 不存在意味着增加
  111. if (!this.lastData.points[key]) {
  112. const item = {
  113. handle: HistoryEvents.AddPoint,
  114. point: historyUtil.getDataForPoint(point),
  115. };
  116. this.currentData.points.push(item);
  117. } else {
  118. const lastPoint = this.lastData.points[key];
  119. if (!historyUtil.isDifferentForPoints(point, lastPoint)) {
  120. delete this.lastData.points[key];
  121. continue;
  122. } else {
  123. const item = {
  124. handle: HistoryEvents.ModifyPoint,
  125. prePoint: historyUtil.getDataForPoint(lastPoint),
  126. curPoint: historyUtil.getDataForPoint(point),
  127. };
  128. this.currentData.points.push(item);
  129. }
  130. }
  131. delete this.lastData.points[key];
  132. }
  133. for (const key in this.lastData.points) {
  134. const item = {
  135. handle: HistoryEvents.DeletePoint,
  136. point: historyUtil.getDataForPoint(this.lastData.points[key]),
  137. };
  138. this.currentData.points.push(item);
  139. }
  140. }
  141. compareLines() {
  142. const lines = dataService.getLines();
  143. this.currentData.lines = [];
  144. for (const key in lines) {
  145. const line = lines[key];
  146. // 不存在意味着增加
  147. if (!this.lastData.lines[key]) {
  148. const item = {
  149. handle: HistoryEvents.AddLine,
  150. line: historyUtil.getDataForLine(line),
  151. };
  152. this.currentData.lines.push(item);
  153. } else {
  154. const lastLine = this.lastData.lines[key];
  155. if (!historyUtil.isDifferentForLines(line, lastLine)) {
  156. delete this.lastData.lines[key];
  157. continue;
  158. } else {
  159. const item = {
  160. handle: HistoryEvents.ModifyLine,
  161. preLine: historyUtil.getDataForLine(lastLine),
  162. curLine: historyUtil.getDataForLine(line),
  163. };
  164. this.currentData.lines.push(item);
  165. }
  166. }
  167. delete this.lastData.lines[key];
  168. }
  169. for (const key in this.lastData.lines) {
  170. const item = {
  171. handle: HistoryEvents.DeleteLine,
  172. line: historyUtil.getDataForLine(this.lastData.lines[key]),
  173. };
  174. this.currentData.lines.push(item);
  175. }
  176. }
  177. compareCurvePoints() {
  178. const curvePoints = dataService.getCurvePoints();
  179. this.currentData.curvePoints = [];
  180. for (const key in curvePoints) {
  181. const curvePoint = curvePoints[key];
  182. // 不存在意味着增加
  183. if (!this.lastData.curvePoints[key]) {
  184. const item = {
  185. handle: HistoryEvents.AddCurvePoint,
  186. curvePoint: historyUtil.getDataForCurvePoint(curvePoint),
  187. };
  188. this.currentData.curvePoints.push(item);
  189. } else {
  190. const lastCurvePoint = this.lastData.curvePoints[key];
  191. if (
  192. !historyUtil.isDifferentForCurvePoints(curvePoint, lastCurvePoint)
  193. ) {
  194. delete this.lastData.curvePoints[key];
  195. continue;
  196. } else {
  197. const item = {
  198. handle: HistoryEvents.ModifyCurvePoint,
  199. preCurvePoint: historyUtil.getDataForCurvePoint(lastCurvePoint),
  200. curCurvePoint: historyUtil.getDataForCurvePoint(curvePoint),
  201. };
  202. this.currentData.curvePoints.push(item);
  203. }
  204. }
  205. delete this.lastData.curvePoints[key];
  206. }
  207. for (const key in this.lastData.curvePoints) {
  208. const item = {
  209. handle: HistoryEvents.DeleteCurvePoint,
  210. curvePoint: historyUtil.getDataForCurvePoint(
  211. this.lastData.curvePoints[key]
  212. ),
  213. };
  214. this.currentData.curvePoints.push(item);
  215. }
  216. }
  217. compareCurveLines() {
  218. const curveLines = dataService.getCurveLines();
  219. this.currentData.curveLines = [];
  220. for (const key in curveLines) {
  221. const curveLine = curveLines[key];
  222. // 不存在意味着增加
  223. if (!this.lastData.curveLines[key]) {
  224. const item = {
  225. handle: HistoryEvents.AddCurveLine,
  226. curveLine: historyUtil.getDataForCurveLine(curveLine),
  227. };
  228. this.currentData.curveLines.push(item);
  229. } else {
  230. const lastCurveLine = this.lastData.curveLines[key];
  231. if (!historyUtil.isDifferentForCurveLines(curveLine, lastCurveLine)) {
  232. delete this.lastData.curveLines[key];
  233. continue;
  234. } else {
  235. const item = {
  236. handle: HistoryEvents.ModifyCurveLine,
  237. preCurveLine: historyUtil.getDataForCurveLine(lastCurveLine),
  238. curCurveLine: historyUtil.getDataForCurveLine(curveLine),
  239. };
  240. this.currentData.curveLines.push(item);
  241. }
  242. }
  243. delete this.lastData.curveLines[key];
  244. }
  245. for (const key in this.lastData.curveLines) {
  246. const item = {
  247. handle: HistoryEvents.DeleteCurveLine,
  248. curveLine: historyUtil.getDataForCurveLine(
  249. this.lastData.curveLines[key]
  250. ),
  251. };
  252. this.currentData.curveLines.push(item);
  253. }
  254. }
  255. compareTexts() {
  256. this.currentData.texts = [];
  257. const texts = dataService.getTexts();
  258. for (const key in texts) {
  259. const text = texts[key];
  260. const lastText = this.lastData.texts[key];
  261. // 不存在意味着增加
  262. if (!lastText) {
  263. const item = {
  264. handle: HistoryEvents.AddText,
  265. text: historyUtil.getDataForText(text),
  266. };
  267. this.currentData.texts.push(item);
  268. } else {
  269. if (!historyUtil.isDifferentForTexts(text, lastText)) {
  270. delete this.lastData.texts[key];
  271. continue;
  272. } else {
  273. const item = {
  274. handle: HistoryEvents.ModifyText,
  275. preText: historyUtil.getDataForText(lastText),
  276. curText: historyUtil.getDataForText(text),
  277. };
  278. this.currentData.texts.push(item);
  279. }
  280. }
  281. delete this.lastData.texts[key];
  282. }
  283. for (const key in this.lastData.texts) {
  284. const item = {
  285. handle: HistoryEvents.DeleteText,
  286. text: historyUtil.getDataForText(this.lastData.texts[key]),
  287. };
  288. this.currentData.texts.push(item);
  289. }
  290. }
  291. compareCircles() {
  292. const circles = dataService.getCircles();
  293. this.currentData.circles = [];
  294. for (const key in circles) {
  295. const circle = circles[key];
  296. // 不存在意味着增加
  297. if (!this.lastData.circles[key]) {
  298. const item = {
  299. handle: HistoryEvents.AddCircle,
  300. circle: historyUtil.getDataForCircle(circle),
  301. };
  302. this.currentData.circles.push(item);
  303. } else {
  304. const lastCircle = this.lastData.circles[key];
  305. if (!historyUtil.isDifferentForCircles(circle, lastCircle)) {
  306. delete this.lastData.circles[key];
  307. continue;
  308. } else {
  309. const item = {
  310. handle: HistoryEvents.ModifyCircle,
  311. preCircle: historyUtil.getDataForCircle(lastCircle),
  312. curCircle: historyUtil.getDataForCircle(circle),
  313. };
  314. this.currentData.circles.push(item);
  315. }
  316. }
  317. delete this.lastData.circles[key];
  318. }
  319. for (const key in this.lastData.circles) {
  320. const item = {
  321. handle: HistoryEvents.DeleteCircle,
  322. circle: historyUtil.getDataForCircle(this.lastData.circles[key]),
  323. };
  324. this.currentData.circles.push(item);
  325. }
  326. }
  327. compareElliptics() {
  328. const elliptics = dataService.getElliptics();
  329. this.currentData.elliptics = [];
  330. for (const key in elliptics) {
  331. const elliptic = elliptics[key];
  332. // 不存在意味着增加
  333. if (!this.lastData.elliptics[key]) {
  334. const item = {
  335. handle: HistoryEvents.AddElliptic,
  336. elliptic: historyUtil.getDataForElliptic(elliptic),
  337. };
  338. this.currentData.elliptics.push(item);
  339. } else {
  340. const lastElliptic = this.lastData.elliptics[key];
  341. if (!historyUtil.isDifferentForElliptics(elliptic, lastElliptic)) {
  342. delete this.lastData.elliptics[key];
  343. continue;
  344. } else {
  345. const item = {
  346. handle: HistoryEvents.ModifyElliptic,
  347. preElliptic: historyUtil.getDataForElliptic(lastElliptic),
  348. curElliptic: historyUtil.getDataForElliptic(elliptic),
  349. };
  350. this.currentData.elliptics.push(item);
  351. }
  352. }
  353. delete this.lastData.elliptics[key];
  354. }
  355. for (const key in this.lastData.elliptics) {
  356. const item = {
  357. handle: HistoryEvents.DeleteElliptic,
  358. elliptic: historyUtil.getDataForElliptic(this.lastData.elliptics[key]),
  359. };
  360. this.currentData.elliptics.push(item);
  361. }
  362. }
  363. compareMagnifiers() {
  364. const magnifiers = dataService.getMagnifiers();
  365. this.currentData.magnifiers = [];
  366. for (const key in magnifiers) {
  367. const magnifier = magnifiers[key];
  368. // 不存在意味着增加
  369. if (!this.lastData.magnifiers[key]) {
  370. const item = {
  371. handle: HistoryEvents.AddMagnifier,
  372. magnifier: historyUtil.getDataForMagnifier(magnifier),
  373. };
  374. this.currentData.magnifiers.push(item);
  375. } else {
  376. const lastMagnifier = this.lastData.magnifiers[key];
  377. if (!historyUtil.isDifferentForMagnifiers(magnifier, lastMagnifier)) {
  378. delete this.lastData.magnifiers[key];
  379. continue;
  380. } else {
  381. const item = {
  382. handle: HistoryEvents.ModifyMagnifier,
  383. preMagnifier: historyUtil.getDataForMagnifier(lastMagnifier),
  384. curMagnifier: historyUtil.getDataForMagnifier(magnifier),
  385. };
  386. this.currentData.magnifiers.push(item);
  387. }
  388. }
  389. delete this.lastData.magnifiers[key];
  390. }
  391. for (const key in this.lastData.magnifiers) {
  392. const item = {
  393. handle: HistoryEvents.DeleteMagnifier,
  394. magnifier: historyUtil.getDataForMagnifier(
  395. this.lastData.magnifiers[key]
  396. ),
  397. };
  398. this.currentData.magnifiers.push(item);
  399. }
  400. }
  401. compareSVGs() {
  402. this.currentData.svgs = [];
  403. const svgs = dataService.getSVGs();
  404. for (const key in svgs) {
  405. const svg = svgs[key];
  406. const lastSVG = this.lastData.svgs[key];
  407. // 不存在意味着增加
  408. if (!lastSVG) {
  409. const item = {
  410. handle: HistoryEvents.AddSVG,
  411. svg: historyUtil.getDataForSVG(svg),
  412. };
  413. this.currentData.svgs.push(item);
  414. } else {
  415. if (!historyUtil.isDifferentForSVGs(svg, lastSVG)) {
  416. delete this.lastData.svgs[key];
  417. continue;
  418. } else {
  419. const item = {
  420. handle: HistoryEvents.ModifySVG,
  421. preSVG: historyUtil.getDataForSVG(lastSVG),
  422. curSVG: historyUtil.getDataForSVG(svg),
  423. };
  424. this.currentData.svgs.push(item);
  425. }
  426. }
  427. delete this.lastData.svgs[key];
  428. }
  429. for (const key in this.lastData.svgs) {
  430. const item = {
  431. handle: HistoryEvents.DeleteSVG,
  432. svg: historyUtil.getDataForSVG(this.lastData.svgs[key]),
  433. };
  434. this.currentData.svgs.push(item);
  435. }
  436. }
  437. compareRoadPoints() {
  438. this.currentData.roadPoints = [];
  439. const roadPoints = dataService.getRoadPoints();
  440. for (const key in roadPoints) {
  441. const roadPoint = roadPoints[key];
  442. const lastRoadPoint = this.lastData.roadPoints[key];
  443. // 不存在意味着增加
  444. if (!lastRoadPoint) {
  445. const item = {
  446. handle: HistoryEvents.AddRoadPoint,
  447. roadPoint: historyUtil.getDataForRoadPoint(roadPoint),
  448. };
  449. this.currentData.roadPoints.push(item);
  450. } else {
  451. if (!historyUtil.isDifferentForRoadPoints(roadPoint, lastRoadPoint)) {
  452. delete this.lastData.roadPoints[key];
  453. continue;
  454. } else {
  455. const item = {
  456. handle: HistoryEvents.ModifyRoadPoint,
  457. preRoadPoint: historyUtil.getDataForRoadPoint(lastRoadPoint),
  458. curRoadPoint: historyUtil.getDataForRoadPoint(roadPoint),
  459. };
  460. this.currentData.roadPoints.push(item);
  461. }
  462. }
  463. delete this.lastData.roadPoints[key];
  464. }
  465. for (const key in this.lastData.roadPoints) {
  466. const item = {
  467. handle: HistoryEvents.DeleteRoadPoint,
  468. roadPoint: historyUtil.getDataForRoadPoint(
  469. this.lastData.roadPoints[key]
  470. ),
  471. };
  472. this.currentData.roadPoints.push(item);
  473. }
  474. }
  475. compareRoadEdges() {
  476. this.currentData.roadEdges = [];
  477. const roadEdges = dataService.getRoadEdges();
  478. for (const key in roadEdges) {
  479. const roadEdge = roadEdges[key];
  480. const lastRoadEdge = this.lastData.roadEdges[key];
  481. // 不存在意味着增加
  482. if (!lastRoadEdge) {
  483. const item = {
  484. handle: HistoryEvents.AddRoadEdge,
  485. roadEdge: historyUtil.getDataForRoadEdge(roadEdge),
  486. };
  487. this.currentData.roadEdges.push(item);
  488. } else {
  489. if (!historyUtil.isDifferentForRoadEdges(roadEdge, lastRoadEdge)) {
  490. delete this.lastData.roadEdges[key];
  491. continue;
  492. } else {
  493. const item = {
  494. handle: HistoryEvents.ModifyRoadEdge,
  495. preRoadEdge: historyUtil.getDataForRoadEdge(lastRoadEdge),
  496. curRoadEdge: historyUtil.getDataForRoadEdge(roadEdge),
  497. };
  498. this.currentData.roadEdges.push(item);
  499. }
  500. }
  501. delete this.lastData.roadEdges[key];
  502. }
  503. for (const key in this.lastData.roadEdges) {
  504. const item = {
  505. handle: HistoryEvents.DeleteRoadEdge,
  506. roadEdge: historyUtil.getDataForRoadEdge(this.lastData.roadEdges[key]),
  507. };
  508. this.currentData.roadEdges.push(item);
  509. }
  510. }
  511. compareRoads() {
  512. this.currentData.roads = [];
  513. const roads = dataService.getRoads();
  514. for (const key in roads) {
  515. const road = roads[key];
  516. const lastRoad = this.lastData.roads[key];
  517. // 不存在意味着增加
  518. if (!lastRoad) {
  519. const item = {
  520. handle: HistoryEvents.AddRoad,
  521. road: historyUtil.getDataForRoad(road),
  522. };
  523. this.currentData.roads.push(item);
  524. } else {
  525. if (!historyUtil.isDifferentForRoads(road, lastRoad)) {
  526. delete this.lastData.roads[key];
  527. continue;
  528. } else {
  529. const item = {
  530. handle: HistoryEvents.ModifyRoad,
  531. preRoad: historyUtil.getDataForRoad(lastRoad),
  532. curRoad: historyUtil.getDataForRoad(road),
  533. };
  534. this.currentData.roads.push(item);
  535. }
  536. }
  537. delete this.lastData.roads[key];
  538. }
  539. for (const key in this.lastData.roads) {
  540. const item = {
  541. handle: HistoryEvents.DeleteRoad,
  542. road: historyUtil.getDataForRoad(this.lastData.roads[key]),
  543. };
  544. this.currentData.roads.push(item);
  545. }
  546. }
  547. compareCurveRoadPoints() {
  548. this.currentData.curveRoadPoints = [];
  549. const curveRoadPoints = dataService.getCurveRoadPoints();
  550. for (const key in curveRoadPoints) {
  551. const curveRoadPoint = curveRoadPoints[key];
  552. const lastCurveRoadPoint = this.lastData.curveRoadPoints[key];
  553. // 不存在意味着增加
  554. if (!lastCurveRoadPoint) {
  555. const item = {
  556. handle: HistoryEvents.AddCurveRoadPoint,
  557. curveRoadPoint: historyUtil.getDataForCurveRoadPoint(curveRoadPoint),
  558. };
  559. this.currentData.curveRoadPoints.push(item);
  560. } else {
  561. if (
  562. !historyUtil.isDifferentForCurveRoadPoints(
  563. curveRoadPoint,
  564. lastCurveRoadPoint
  565. )
  566. ) {
  567. delete this.lastData.curveRoadPoints[key];
  568. continue;
  569. } else {
  570. const item = {
  571. handle: HistoryEvents.ModifyCurveRoadPoint,
  572. preCurveRoadPoint:
  573. historyUtil.getDataForCurveRoadPoint(lastCurveRoadPoint),
  574. curCurveRoadPoint:
  575. historyUtil.getDataForCurveRoadPoint(curveRoadPoint),
  576. };
  577. this.currentData.curveRoadPoints.push(item);
  578. }
  579. }
  580. delete this.lastData.curveRoadPoints[key];
  581. }
  582. for (const key in this.lastData.curveRoadPoints) {
  583. const item = {
  584. handle: HistoryEvents.DeleteCurveRoadPoint,
  585. curveRoadPoint: historyUtil.getDataForCurveRoadPoint(
  586. this.lastData.curveRoadPoints[key]
  587. ),
  588. };
  589. this.currentData.curveRoadPoints.push(item);
  590. }
  591. }
  592. compareCurveRoads() {
  593. this.currentData.curveRoads = [];
  594. const curveRoads = dataService.getCurveRoads();
  595. for (const key in curveRoads) {
  596. const curveRoad = curveRoads[key];
  597. const lastCurveRoad = this.lastData.curveRoads[key];
  598. // 不存在意味着增加
  599. if (!lastCurveRoad) {
  600. const item = {
  601. handle: HistoryEvents.AddCurveRoad,
  602. curveRoad: historyUtil.getDataForCurveRoad(curveRoad),
  603. };
  604. this.currentData.curveRoads.push(item);
  605. } else {
  606. if (!historyUtil.isDifferentForCurveRoads(curveRoad, lastCurveRoad)) {
  607. delete this.lastData.curveRoads[key];
  608. continue;
  609. } else {
  610. const item = {
  611. handle: HistoryEvents.ModifyCurveRoad,
  612. preCurveRoad: historyUtil.getDataForCurveRoad(lastCurveRoad),
  613. curCurveRoad: historyUtil.getDataForCurveRoad(curveRoad),
  614. };
  615. this.currentData.curveRoads.push(item);
  616. }
  617. }
  618. delete this.lastData.curveRoads[key];
  619. }
  620. for (const key in this.lastData.curveRoads) {
  621. const item = {
  622. handle: HistoryEvents.DeleteCurveRoad,
  623. curveRoad: historyUtil.getDataForCurveRoad(
  624. this.lastData.curveRoads[key]
  625. ),
  626. };
  627. this.currentData.curveRoads.push(item);
  628. }
  629. }
  630. compareCurveRoadEdges() {
  631. this.currentData.curveRoadEdges = [];
  632. const curveRoadEdges = dataService.getCurveRoadEdges();
  633. for (const key in curveRoadEdges) {
  634. const curveRoadEdge = curveRoadEdges[key];
  635. const lastCurveRoadEdge = this.lastData.curveRoadEdges[key];
  636. // 不存在意味着增加
  637. if (!lastCurveRoadEdge) {
  638. const item = {
  639. handle: HistoryEvents.AddCurveRoadEdge,
  640. curveRoadEdge: historyUtil.getDataForCurveRoadEdge(curveRoadEdge),
  641. };
  642. this.currentData.curveRoadEdges.push(item);
  643. } else {
  644. if (
  645. !historyUtil.isDifferentForCurveRoadEdges(
  646. curveRoadEdge,
  647. lastCurveRoadEdge
  648. )
  649. ) {
  650. delete this.lastData.curveRoadEdges[key];
  651. continue;
  652. } else {
  653. const item = {
  654. handle: HistoryEvents.ModifyCurveRoadEdge,
  655. preCurveRoadEdge:
  656. historyUtil.getDataForCurveRoadEdge(lastCurveRoadEdge),
  657. curCurveRoadEdge:
  658. historyUtil.getDataForCurveRoadEdge(curveRoadEdge),
  659. };
  660. this.currentData.curveRoadEdges.push(item);
  661. }
  662. }
  663. delete this.lastData.curveRoadEdges[key];
  664. }
  665. for (const key in this.lastData.curveRoadEdges) {
  666. const item = {
  667. handle: HistoryEvents.DeleteCurveRoadEdge,
  668. curveRoadEdge: historyUtil.getDataForCurveRoadEdge(
  669. this.lastData.curveRoadEdges[key]
  670. ),
  671. };
  672. this.currentData.curveRoadEdges.push(item);
  673. }
  674. }
  675. compareCrossPoints() {
  676. this.currentData.crossPoints = [];
  677. const crossPoints = dataService.getCrossPoints();
  678. for (const key in crossPoints) {
  679. const crossPoint = crossPoints[key];
  680. const lastCrossPoint = this.lastData.crossPoints[key];
  681. // 不存在意味着增加
  682. if (!lastCrossPoint) {
  683. const item = {
  684. handle: HistoryEvents.AddCrossPoint,
  685. crossPoint: historyUtil.getDataForCrossPoint(crossPoint),
  686. };
  687. this.currentData.crossPoints.push(item);
  688. } else {
  689. if (
  690. !historyUtil.isDifferentForCrossPoints(crossPoint, lastCrossPoint)
  691. ) {
  692. delete this.lastData.crossPoints[key];
  693. continue;
  694. } else {
  695. const item = {
  696. handle: HistoryEvents.ModifyCrossPoint,
  697. preCrossPoint: historyUtil.getDataForCrossPoint(lastCrossPoint),
  698. curCrossPoint: historyUtil.getDataForCrossPoint(crossPoint),
  699. };
  700. this.currentData.crossPoints.push(item);
  701. }
  702. }
  703. delete this.lastData.crossPoints[key];
  704. }
  705. for (const key in this.lastData.crossPoints) {
  706. const item = {
  707. handle: HistoryEvents.DeleteCrossPoint,
  708. crossPoint: historyUtil.getDataForCrossPoint(
  709. this.lastData.crossPoints[key]
  710. ),
  711. };
  712. this.currentData.crossPoints.push(item);
  713. }
  714. }
  715. compareSettings() {
  716. const lastSettings = this.lastData.settings;
  717. this.currentData.settings = null;
  718. if (historyUtil.isDifferentForSettings(Settings, lastSettings)) {
  719. const item = {
  720. handle: HistoryEvents.ModifySettings,
  721. preSettings: historyUtil.getDataForSettings(lastSettings),
  722. curSettings: historyUtil.getDataForSettings(Settings),
  723. };
  724. this.currentData.settings = item;
  725. }
  726. }
  727. }
  728. const change = new Change();
  729. export { change };