FileZDM.js 12 KB

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