HistoryUtil.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { mathUtil } from "../Util/MathUtil";
  2. import { dataService } from "../Service/DataService";
  3. import { textService } from "../Service/TextService";
  4. export default class HistoryUtil {
  5. constructor() {}
  6. isDifferentForRoads(road1, road2) {
  7. if (road1.startId == road2.startId && road1.endId == road2.endId) {
  8. return false;
  9. } else {
  10. return true;
  11. }
  12. }
  13. isDifferentForPoints(point1, point2) {
  14. if (
  15. point1.x == point2.x &&
  16. point1.y == point2.y &&
  17. JSON.stringify(point1.parent) == JSON.stringify(point2.parent)
  18. ) {
  19. return false;
  20. } else {
  21. return true;
  22. }
  23. }
  24. isDifferentForLines(line1, line2) {
  25. if (
  26. line1.startId == line2.startId &&
  27. line1.endId == line2.endId &&
  28. line1.category == line2.category
  29. ) {
  30. return false;
  31. } else {
  32. return true;
  33. }
  34. }
  35. isDifferentForCircles(circle1, circle2) {
  36. if (
  37. mathUtil.equalPoint(circle1.center, circle2.center) &&
  38. circle1.radius == circle2.radius
  39. ) {
  40. return false;
  41. } else {
  42. return true;
  43. }
  44. }
  45. isDifferentForTexts(text1, text2) {
  46. if (
  47. mathUtil.equalPoint(text1.center, text2.center) &&
  48. text1.des == text2.des
  49. ) {
  50. return false;
  51. } else {
  52. return true;
  53. }
  54. }
  55. // // road2赋值给road1
  56. // assignRoadFromRoad(road1, road2) {
  57. // const roadInfo = {};
  58. // roadInfo.vectorId = road1.vectorId;
  59. // roadInfo.start = road2.startId;
  60. // roadInfo.end = road2.endId;
  61. // this.setRoadInfo(roadInfo);
  62. // }
  63. assignPointFromPoint(point1, point2) {
  64. const pointInfo = {};
  65. pointInfo.vectorId = point1.vectorId;
  66. pointInfo.position = { x: point2.x, y: point2.y };
  67. pointInfo.parent = JSON.parse(JSON.stringify(point2.parent));
  68. this.setPointInfo(pointInfo);
  69. }
  70. assignLineFromLine(line1, line2) {
  71. const lineInfo = {};
  72. lineInfo.vectorId = line1.vectorId;
  73. lineInfo.start = line2.startId;
  74. lineInfo.end = line2.endId;
  75. lineInfo.category = line2.category;
  76. this.setLineInfo(lineInfo);
  77. }
  78. assignCircleFromCircle(circle1, circle2) {
  79. const circleInfo = {};
  80. circleInfo.vectorId = circle1.vectorId;
  81. circleInfo.center = circle2.center;
  82. circleInfo.radius = circle2.radius;
  83. this.setCircleInfo(circleInfo);
  84. }
  85. assignTextFromText(text1, text2) {
  86. const textInfo = {};
  87. textInfo.vectorId = text1.vectorId;
  88. textInfo.des = text2.des;
  89. textInfo.center = JSON.parse(JSON.stringify(text2.center));
  90. textInfo.points2d = JSON.parse(JSON.stringify(text2.points));
  91. textInfo.adding = false;
  92. this.setTextInfo(textInfo);
  93. }
  94. getDataForPoint(point) {
  95. const data = {};
  96. data.id = point.vectorId;
  97. mathUtil.clonePoint(data, point);
  98. data.parent = JSON.parse(JSON.stringify(point.parent));
  99. data.type = point.geoType;
  100. return data;
  101. }
  102. getDataForLine(line) {
  103. const data = {};
  104. data.id = line.vectorId;
  105. data.start = line.startId;
  106. data.end = line.endId;
  107. data.type = line.geoType;
  108. return data;
  109. }
  110. getDataForCircle(circle) {
  111. const data = {};
  112. data.id = circle.vectorId;
  113. data.center = {};
  114. mathUtil.clonePoint(data.center, circle.center);
  115. data.radius = circle.radius;
  116. data.type = circle.geoType;
  117. return data;
  118. }
  119. getDataForText(text) {
  120. const data = {};
  121. data.id = text.vectorId;
  122. data.type = text.geoType;
  123. data.center = {};
  124. mathUtil.clonePoint(data.center, text.center);
  125. data.points = [].concat(text.points2d);
  126. data.des = text.des;
  127. return data;
  128. }
  129. // setRoadInfo(roadInfo) {
  130. // let road = dataService.getRoad(roadInfo.vectorId);
  131. // road.start = roadInfo.start;
  132. // road.end = roadInfo.end;
  133. // return road;
  134. // }
  135. setPointInfo(pointInfo) {
  136. let point = dataService.getPoint(pointInfo.vectorId);
  137. mathUtil.clonePoint(point, pointInfo.position);
  138. point.parent = JSON.parse(JSON.stringify(pointInfo.parent));
  139. return point;
  140. }
  141. setLineInfo(lineInfo) {
  142. let line = dataService.getLine(lineInfo.vectorId);
  143. line.startId = lineInfo.start;
  144. line.endId = lineInfo.end;
  145. line.category = lineInfo.category;
  146. return line;
  147. }
  148. setCircleInfo(circleInfo) {
  149. let circle = dataService.getCircle(circleInfo.vectorId);
  150. circle.center = circleInfo.center;
  151. circle.radius = circleInfo.radius;
  152. return circle;
  153. }
  154. setTextInfo(textInfo) {
  155. let text = dataService.getText(textInfo.vectorId);
  156. text.vectorId = textInfo.vectorId;
  157. text.center = JSON.parse(JSON.stringify(textInfo.center));
  158. text.points2d = JSON.parse(JSON.stringify(textInfo.points2d));
  159. text.des = textInfo.des;
  160. text.adding = textInfo.adding;
  161. }
  162. }
  163. const historyUtil = new HistoryUtil();
  164. export { historyUtil };