FileZDM.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. include("scripts/EAction.js");
  2. include("scripts/simple.js");
  3. include("scripts/Common/DrawingUtils.js");
  4. function FileZDM(file, ratio) {
  5. this.newEntityData = new Array();
  6. this.newFZEntityData = new Array();
  7. this.newJPointData = new Array();
  8. this.csvCoor = new Array();
  9. this.allR = new Array();
  10. // 比例尺
  11. this.ratio = ratio || 1.0;
  12. this.readTxt(file);
  13. }
  14. FileZDM.prototype.getZDMArray = function () {
  15. return this.newEntityData;
  16. }
  17. FileZDM.prototype.applyOperation = function () {
  18. var colorReady = new Array(
  19. [new RColor(255, 0, 0), new RColor(160, 32, 240), new RColor(0, 255, 0)],
  20. [new RColor(128, 0, 128), new RColor(200, 96, 255), new RColor(160, 32, 240)],
  21. [new RColor(255, 153, 77), new RColor(128, 255, 255), new RColor(0, 255, 255)],
  22. [new RColor(77, 255, 255), new RColor(255, 255, 128), new RColor(255, 255, 0)],
  23. [new RColor(148, 121, 253), new RColor(255, 192, 128), new RColor(255, 165, 0)]
  24. );
  25. var colorIndex = Math.floor(Math.random() * colorReady.length);
  26. var selectedArray = colorReady[colorIndex];
  27. var PDColor = selectedArray[0];
  28. var SQXColor = selectedArray[1];
  29. var FZXColor = selectedArray[2];
  30. // // 添加纵横比1:10
  31. // addLineToView([this.newEntityData[0][0]-100, this.newEntityData[0][1]],[this.newEntityData[0][0]-20, this.newEntityData[0][1]],0);
  32. // addLineToView([this.newEntityData[0][0]-100, this.newEntityData[0][1]],[this.newEntityData[0][0]-100, this.newEntityData[0][1]+15],0);
  33. // addLineToView([this.newEntityData[0][0]-20, this.newEntityData[0][1]],[this.newEntityData[0][0]-20, this.newEntityData[0][1]+15],0);
  34. // addSimpleTextToView(("ratio 1:10"),[this.newEntityData[0][0]-80, this.newEntityData[0][1]+10],
  35. // 7,0,"Standard",RS.VAlignTop,RS.HAlignLeft,false,false,0);
  36. EAction.handleUserMessage("ZDM-40: " + formatDateTime());
  37. //绘制坡道及竖曲线,1为坡道,2为竖曲线
  38. var c = 0;
  39. for (var i = 0; i < this.newEntityData.length - 1; i++) {
  40. var TempLineData = new Array();
  41. TempLineData.push([this.newEntityData[i][0], this.newEntityData[i][1]]);
  42. TempLineData.push([this.newEntityData[i + 1][0], this.newEntityData[i + 1][1]]);
  43. if (this.newEntityData[i][2] == 1) {
  44. addPolylinetoView(TempLineData, false, false, 0, PDColor);
  45. // 计算斜率
  46. var pdAngle = (this.newEntityData[i + 1][1] - this.newEntityData[i][1]) / (this.newEntityData[i + 1][0] - this.newEntityData[i][0]);
  47. // 计算长度
  48. var pdLen = sqrt((this.newEntityData[i + 1][1] - this.newEntityData[i][1]) * (this.newEntityData[i + 1][1] - this.newEntityData[i][1]) + (this.newEntityData[i + 1][0] - this.newEntityData[i][0]) * (this.newEntityData[i + 1][0] - this.newEntityData[i][0]));
  49. addSimpleTextToView((round(pdAngle * 100 * 1000) / 1000).toString(), [(this.newEntityData[i + 1][0] + this.newEntityData[i][0]) / 2 - 2, (this.newEntityData[i + 1][1] + this.newEntityData[i][1]) / 2 + 9], 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  50. addSimpleTextToView((round(this.csvCoor[c+1][0]-this.csvCoor[c][0])).toString(), [(this.newEntityData[i + 1][0] + this.newEntityData[i][0]) / 2 - 2, (this.newEntityData[i + 1][1] + this.newEntityData[i][1]) / 2 - 2], 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  51. c++;
  52. // addSimpleTextToView((round(pdLen * 1000) / 1000).toString(), [(this.newEntityData[i + 1][0] + this.newEntityData[i][0]) / 2 - 2, (this.newEntityData[i + 1][1] + this.newEntityData[i][1]) / 2 - 2], 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  53. } else if (this.newEntityData[i][2] == 2) {
  54. addPolylinetoView(TempLineData, false, false, 0, SQXColor);
  55. }
  56. }
  57. EAction.handleUserMessage("ZDM-58: " + formatDateTime());
  58. // var min_y = this.newEntityData[0][1];
  59. // 绘制竖曲线
  60. // if (this.newEntityData.length > 0) {
  61. // for (var i = 0; i < this.newEntityData.length; i++) {
  62. // if (min_y > this.newEntityData[i][1]) {
  63. // min_y = this.newEntityData[i][1];
  64. // }
  65. // }
  66. // var firstItem = this.newEntityData[0];
  67. // var lastItem = this.newEntityData[this.newEntityData.length - 1];
  68. // addLineToView([firstItem[0] - 100, min_y - 50], [lastItem[0], min_y - 50], 0); //横坐标
  69. // addLineToView([firstItem[0], min_y - 110], [firstItem[0], min_y + 150], 0); //纵坐标
  70. // addLineToView([firstItem[0] - 100, min_y - 110], [lastItem[0], min_y - 110], 0); //格线
  71. // addSimpleTextToView(qsTr("R"), [firstItem[0] - 80, min_y - 70], 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0);
  72. // }
  73. //绘制辅助线,1为竖曲线切线起点,2为变坡点,3为竖曲线切线终点
  74. for (var i = 0; i < this.newFZEntityData.length;) {
  75. var TempLineData = new Array();
  76. if (i < this.newFZEntityData.length && this.newFZEntityData[i][2] == 1) {
  77. TempLineData.push([this.newFZEntityData[i][0], this.newFZEntityData[i][1]]);
  78. addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] - 1.5], [this.newFZEntityData[i][0], this.newFZEntityData[i][1] + 1.5], 0);
  79. addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] - 1.5], [this.newFZEntityData[i][0] + 0.5, this.newFZEntityData[i][1] - 1.5], 0);
  80. addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] + 1.5], [this.newFZEntityData[i][0] + 0.5, this.newFZEntityData[i][1] + 1.5], 0);
  81. }
  82. if (i + 1 < this.newFZEntityData.length && this.newFZEntityData[i + 1][2] == 2) {
  83. TempLineData.push([this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1]]);
  84. addCircleToView(this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1], 0.5, 0, FZXColor);
  85. addLineToView([this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1] + 1.5], [this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1] + 50], 0);
  86. addSimpleTextToView("K" + (round(this.newFZEntityData[i + 1][0] * 1000 * this.ratio) / 1000).toString(), [this.newFZEntityData[i + 1][0] - 9, this.newFZEntityData[i + 1][1] + 2.5], 7, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  87. addSimpleTextToView(this.newFZEntityData[i + 1][1].toString(), [this.newFZEntityData[i + 1][0] + 2, this.newFZEntityData[i + 1][1] + 3], 7, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  88. // EAction.handleUserMessage("start point end point:" + this.newFZEntityData[i + 1][0] + "," + (this.newFZEntityData[i + 1][1]+1)+";"+this.newFZEntityData[i + 1][0]+","+ (this.newFZEntityData[i + 1][1]+10));
  89. }
  90. if (i + 2 < this.newFZEntityData.length && this.newFZEntityData[i + 2][2] == 3) {
  91. TempLineData.push([this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1]]);
  92. addLineToView([this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] - 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] + 1.5], 0);
  93. addLineToView([this.newFZEntityData[i + 2][0] - 0.5, this.newFZEntityData[i + 2][1] - 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] - 1.5], 0);
  94. addLineToView([this.newFZEntityData[i + 2][0] - 0.5, this.newFZEntityData[i + 2][1] + 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] + 1.5], 0);
  95. }
  96. addPolylinetoView(TempLineData, false, false, 0, FZXColor);
  97. i = i + 3;
  98. }
  99. EAction.handleUserMessage("ZDM-100: " + formatDateTime());
  100. var di = getAssignDocumentInterface(0);
  101. if (!isNull(di)) {
  102. // di.regenerateScenes();
  103. di.autoZoom();
  104. }
  105. return true;
  106. };
  107. FileZDM.prototype.saveCsvFile = function () {
  108. EAction.handleUserMessage("save csv file start!");
  109. // var fname = this.fileName.substring(0,this.fileName.lastIndexOf("."))+".csv";
  110. var fname = RSettings.getStringValue("OpenProject/Current", RSettings.getDocumentsLocation()) + "/K_E_R.csv";
  111. var file = new QFile(fname);
  112. if (file.exists()) {
  113. //如果文件存在执行的操作,此处为空,因为文件不可能存在
  114. }
  115. file.open(makeQIODeviceOpenMode(QIODevice.WriteOnly, QIODevice.Text));
  116. var out = new QTextStream(file);
  117. //写表头
  118. out.writeString("K,H,R\n");
  119. //写数据
  120. for (i = 0; i < this.csvCoor.length; i++) {
  121. out.writeString(this.csvCoor[i][0] + "," + this.csvCoor[i][1] + "," + this.csvCoor[i][2] + "\n");
  122. }
  123. out.flush();
  124. //写完数据需要关闭文件
  125. file.close();
  126. EAction.handleUserMessage("save csv file success!");
  127. }
  128. FileZDM.prototype.readTxt = function (file) {
  129. var reader = new QFile(file);
  130. var flags = makeQIODeviceOpenMode(QIODevice.ReadOnly, QIODevice.Text);
  131. if (!reader.open(flags)) {
  132. EAction.handleUserWarning("cannot open file: " + file);
  133. return false;
  134. }
  135. EAction.handleUserMessage("Starting to load ZDM file: " + file);
  136. //每次都去文件中的一行,然后输出读取到的字符串
  137. var ts = new QTextStream(reader);
  138. setUtf8Codec(ts);
  139. var TempEntityData = new Array();
  140. //当读取出现错误(返回 -1)或者读取到的字符数为 0 时,结束读取
  141. do {
  142. var textLine = ts.readLine().trim();
  143. // EAction.handleUserWarning(textLine);
  144. textLine = textLine.replace(/[\t]+/g, " ").replace(/[\s]+/g, " ");
  145. textLine = textLine.replace(/[ABC]/g, "").replace(/\r\n/g, "");
  146. // EAction.handleUserMessage(textLine2);
  147. var fields = textLine.split(" "); // Reserved: ',&[' & ';&['
  148. if (fields.length !== 5) {
  149. // With two extra fields >
  150. continue;
  151. } // End with two extra
  152. qDebug(parseFloat(fields[0]));
  153. qDebug(parseFloat(fields[1]));
  154. qDebug(parseFloat(fields[2]));
  155. qDebug(parseFloat(this.ratio));
  156. TempEntityData.push([parseFloat(fields[0]), parseFloat(fields[1]), parseFloat(fields[2])]);
  157. this.csvCoor.push([parseFloat(fields[0]), parseFloat(fields[1]), parseFloat(fields[2])]);
  158. } while (!ts.atEnd());
  159. var CurRampZH = 0.0;
  160. var CurRampBG = 0.0;
  161. var CurRampR = 0.0;
  162. var PreRampZH = 0.0;
  163. var PreRampBG = 0.0;
  164. var PreRampR = 0.0;
  165. var NextRampZH = 0.0;
  166. var NextRampBG = 0.0;
  167. var NextRampR = 0.0;
  168. var CurLineType = 1;
  169. var DeltaS = 10.0; //竖曲线取样点间隔
  170. for (var i = 0; i < TempEntityData.length; i++) {
  171. CurRampZH = TempEntityData[i][0];
  172. CurRampBG = TempEntityData[i][1];
  173. CurRampR = TempEntityData[i][2];
  174. if (CurRampR < 1.0 || i == TempEntityData.length - 1 || i == 0) {
  175. CurLineType = 1;
  176. this.newEntityData.push([CurRampZH / parseFloat(this.ratio), CurRampBG, CurLineType]);
  177. } else {
  178. var i_1 = 0.0; //前坡坡度 lyz
  179. var i_2 = 0.0; //后坡坡度 lyz
  180. var CurL = 0.0; //竖曲线长 lyz
  181. var CurT = 0.0; //竖曲线切线长 lyz
  182. var CurE = 0.0; //竖曲线外距 lyz
  183. var CurQD = 0.0; //竖曲线起点桩号 lyz
  184. var CurZD = 0.0; //竖曲线终点桩号 lyz
  185. PreRampZH = TempEntityData[i - 1][0];
  186. PreRampBG = TempEntityData[i - 1][1];
  187. PreRampR = TempEntityData[i - 1][2];
  188. NextRampZH = TempEntityData[i + 1][0];
  189. NextRampBG = TempEntityData[i + 1][1];
  190. NextRampR = TempEntityData[i + 1][2];
  191. i_1 = (CurRampBG - PreRampBG) / (CurRampZH - PreRampZH);
  192. i_2 = (NextRampBG - CurRampBG) / (NextRampZH - CurRampZH);
  193. CurL = CurRampR * Math.abs(i_2 - i_1);
  194. CurT = CurL / 2;
  195. CurE = (CurT * CurT) / (2 * CurRampR);
  196. CurQD = CurRampZH - CurT;
  197. CurZD = CurRampZH + CurT;
  198. for (var j = CurQD; j < CurZD; j = j + DeltaS) {
  199. var jQBG = 0.0; //j点切线标高 lyz
  200. var jE = 0.0; //j点外距 lyz
  201. var jBG = 0.0; //j点标高 lyz
  202. if (j <= CurRampZH) {
  203. jQBG = CurRampBG - (CurRampZH - j) * i_1;
  204. jE = ((j - CurQD) * (j - CurQD)) / (2 * CurRampR);
  205. if (i_1 - i_2 >= 0) {
  206. //确定是凸曲线还是凹曲线 lyz
  207. jBG = jQBG - jE;
  208. } else {
  209. jBG = jQBG + jE;
  210. }
  211. } else {
  212. jQBG = CurRampBG - (CurRampZH - j) * i_2;
  213. jE = ((CurZD - j) * (CurZD - j)) / (2 * CurRampR);
  214. if (i_1 - i_2 >= 0) {
  215. //确定是凸曲线还是凹曲线 lyz
  216. jBG = jQBG - jE;
  217. } else {
  218. jBG = jQBG + jE;
  219. }
  220. }
  221. if (j + DeltaS >= CurZD) {
  222. CurLineType = 1;
  223. } else CurLineType = 2;
  224. this.newEntityData.push([j / parseFloat(this.ratio), jBG, CurLineType]);
  225. //插入辅助线数据
  226. if (j == CurQD) {
  227. this.newFZEntityData.push([j / parseFloat(this.ratio), jBG, 1]);
  228. this.newFZEntityData.push([CurRampZH / parseFloat(this.ratio), CurRampBG, 2]);
  229. }
  230. if (j + DeltaS >= CurZD) {
  231. this.newFZEntityData.push([j / parseFloat(this.ratio), jBG, 3]);
  232. }
  233. this.allR.push(CurRampR);
  234. }
  235. }
  236. }
  237. reader.close();
  238. return true;
  239. };
  240. FileZDM.prototype.applyRadius = function (startPoint, space) {
  241. for (var i = 0; i < this.newFZEntityData.length; i += 3) {
  242. if (i + 2 < this.newFZEntityData.length && this.newFZEntityData[i + 2][2] == 3) {
  243. // addLineToView([this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] - 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] + 1.5], 0);
  244. // addLineToView([this.newFZEntityData[i + 2][0] - 0.5, this.newFZEntityData[i + 2][1] - 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] - 1.5], 0);
  245. // addLineToView([this.newFZEntityData[i + 2][0] - 0.5, this.newFZEntityData[i + 2][1] + 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] + 1.5], 0);
  246. addSimpleTextToView("R-" + this.allR[i % 3].toString(), [this.newFZEntityData[i][0], startPoint[1] - 20], 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0);
  247. addLineToView([this.newFZEntityData[i][0], startPoint[1] - 40], [this.newFZEntityData[i + 2][0], startPoint[1] - 40], 0);
  248. }
  249. }
  250. }
  251. FileZDM.prototype.applySlope = function (startPoint, space) {
  252. var lastPoint = undefined;
  253. for (var i = 0; i < this.newFZEntityData.length; i += 3) {
  254. if (i + 1 < this.newFZEntityData.length && this.newFZEntityData[i + 1][2] == 2) {
  255. addLineToView([lastPoint[0], lastPoint[1]], [startPoint[0], startPoint[1]], 0);
  256. if (lastPoint && this.newFZEntityData[i + 1][1] > lastPoint[1]) {
  257. addLineToView([lastPoint[0], startPoint[1] - space], [this.newFZEntityData[i + 1][0], startPoint[1]], 0);
  258. } else if (lastPoint) {
  259. addLineToView([lastPoint[0], startPoint[1]], [this.newFZEntityData[i + 1][0], startPoint[1] - space], 0);
  260. }
  261. lastPoint = this.newFZEntityData[i + 1];
  262. }
  263. }
  264. }