DrawZdmAll.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. include("scripts/Common/DrawingUtils.js");
  2. include("scripts/Common/FileCTRCSV.js");
  3. include("scripts/Common/FileDMX.js");
  4. include("scripts/Common/FileZDM.js");
  5. // 纵断面,地面线CTR
  6. // 有纵断面,画竖曲线半径和坡度
  7. // 有地面线才画设计高程,地面高程,里程桩号
  8. // 有CTR,才画桥梁,隧道
  9. function DrawZdmAll(ratio) {
  10. // 比例尺
  11. this.ratio = ratio || 10.0;
  12. this.frameColor = new RColor(255, 255, 0);
  13. }
  14. DrawZdmAll.prototype.applyPainting = function (layer, dmxFile, zdmFile, ctrFile, isCertCsv) {
  15. // 图层
  16. var layername = layer || getLayername("ZDM", zdmFile);
  17. addLayerToView(layername, "white", "CONTINUOUS", RLineweight.Weight025, 0);
  18. setCurrentLayer(layername);
  19. // 如果存在同名的DXF就直接在家DXF,解决ZDM加载慢的问题
  20. var dxfFile = zdmFile.replace(/.\w+$/i, ".dxf");
  21. var qFile = new QFile(dxfFile);
  22. if (qFile.exists()) {
  23. // 绘画到ZDM
  24. var di = getAssignDocumentInterface(0);
  25. var importFile = di.importFile(dxfFile, "", false);
  26. di.regenerateScenes();
  27. di.autoZoom();
  28. if (importFile !== RDocumentInterface.IoErrorNoError) {
  29. EAction.handleUserWarning(qsTr("Error while importing file %1").arg(dxfFile));
  30. }
  31. return true;
  32. }
  33. // qsTr("地面线文件") + " (*.dmx);"
  34. var fileDMX = new FileDMX(dmxFile, this.ratio);
  35. fileDMX.applyOperation();
  36. var dmxData = fileDMX.getArrayData();
  37. // qsTr("纵断面文件") + " (*.zdm);"
  38. var drawZdm = new FileZDM(zdmFile, this.ratio);
  39. // 线绘图在生成CSV文件
  40. drawZdm.applyOperation();
  41. if (isCertCsv) {
  42. drawZdm.saveCsvFile();
  43. }
  44. var zdmData = drawZdm.getZDMArray();
  45. // qsTr("桥梁 隧道") + " (*.ctr);"
  46. var fileCTR = new FileCTRCSV(ctrFile, this.ratio);
  47. fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
  48. fileCTR.applyTunnel(zdmData, new RColor(0, 128, 0));
  49. // 以下开始绘画表格数据
  50. var extreme_dmx = this.getExtremePosition(zdmData.length > 0 ? zdmData : dmxData);
  51. addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, this.frameColor);
  52. addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, this.frameColor);
  53. var startPoint = extreme_dmx[2];
  54. var endPoint = extreme_dmx[3];
  55. var text_width = 260;
  56. addPolylinetoView([[startPoint[0] - text_width, startPoint[1]], endPoint], false, false, 0, this.frameColor);
  57. var array = new Array();
  58. array.push({ name: "R", "space": 100, text: "竖曲线半径 (m)" });
  59. array.push({ name: "SJGC", "space": 100, text: "设计高程 (m)" });
  60. array.push({ name: "DMGC", "space": 100, text: "地面高程 (m)" });
  61. array.push({ name: "PDPC", "space": 100, text: "坡度 (%) 坡长 (m)" });
  62. array.push({ name: "BLZH", "space": 100, text: "百里桩号 (km)" });
  63. for (var i = 0; i < array.length; i++) {
  64. var item = array[i];
  65. var space = (item.space || 100);
  66. var text = (item.text || "").toString();
  67. addPolylinetoView([[startPoint[0] - text_width, startPoint[1] - space * (i + 1)], [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, this.frameColor);
  68. addSimpleTextToView(text, [startPoint[0] - text_width + 50, startPoint[1] - space * (i + 1) + 50], 15, 0, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  69. switch (item.name) {
  70. case "R":
  71. drawZdm.applyRadius([startPoint[0], startPoint[1] - space * i], space);
  72. break;
  73. case "SJGC":
  74. this.applyHeightMileage(dmxData, [startPoint[0], startPoint[1] - space * i], space);
  75. break;
  76. case "DMGC":
  77. this.applyHeightMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  78. break;
  79. case "PDPC":
  80. drawZdm.applySlope([startPoint[0], startPoint[1] - space * i], space);
  81. break;
  82. case "BLZH":
  83. this.applyMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  84. break;
  85. }
  86. if (i == array.length - 1) {
  87. addPolylinetoView([startPoint, [startPoint[0], startPoint[1] - space * (i + 1)]], false, false, 0, this.frameColor);
  88. addPolylinetoView([endPoint, [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, this.frameColor);
  89. }
  90. }
  91. // 居中显示
  92. var di = getAssignDocumentInterface(0);
  93. if (!isNull(di)) {
  94. di.autoZoom();
  95. }
  96. return true;
  97. }
  98. DrawZdmAll.prototype.applyHeightMileage = function (arrayData, startPoint, spacetext) {
  99. var space = 50;
  100. var spaceDistance = 0;
  101. for (var i = 0; i < arrayData.length; i++) {
  102. if (i != 0) {
  103. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  104. }
  105. if (i != 0 && spaceDistance < space) {
  106. // 不足最小间距
  107. continue;
  108. }
  109. spaceDistance = 0;
  110. var text = (round((arrayData[i][1]) * 100) / 100).toString();
  111. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - spacetext + 30], 15, 90, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  112. }
  113. }
  114. DrawZdmAll.prototype.applyMileage = function (arrayData, startPoint, space) {
  115. // 记录里程
  116. var mileage = 0.0;
  117. // 最小间距
  118. var space_min = 30;
  119. var y = startPoint[1] - space;
  120. for (var i = 0; i < arrayData.length; i++) {
  121. var x = arrayData[i][0];
  122. var mileage_current = x;
  123. if (i == 0) {
  124. // 显示起始桩号
  125. addSimpleTextToView(formatStake(mileage_current), [x, y + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  126. addPolylinetoView([[x, y], [x, y + 5]], false, false, 0, new RColor(255, 255, 0));
  127. mileage = mileage_current;
  128. continue;
  129. }
  130. if (mileage_current - mileage > space_min) {
  131. // 绘画高程文本
  132. addSimpleTextToView((round((mileage_current % 1000) * 1000) / 1000).toString(), [x, y + (space * 1 / 3) - 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  133. }
  134. mileage = mileage_current;
  135. }
  136. // 绘制标准的百里标、千里表
  137. var start = arrayData[0][0];
  138. var end = arrayData[arrayData.length - 1][0];
  139. // 下一个百里标的位置
  140. var currentMiles = Math.ceil(start / 100) * 100;
  141. // 循环打印百里和千里位置
  142. while (currentMiles <= end) {
  143. if (currentMiles % 1000 === 0) {
  144. addSimpleTextToView("K" + Math.floor(currentMiles / 1000).toString(), [currentMiles, y + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  145. addPolylinetoView([[currentMiles, y], [currentMiles, y + 5]], false, false, 0, new RColor(255, 255, 0));
  146. } else if (currentMiles % 100 === 0) {
  147. var text = currentMiles - (Math.floor(currentMiles / 1000) * 1000);
  148. addSimpleTextToView(Math.floor(text / 100).toString(), [currentMiles, y + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  149. addPolylinetoView([[currentMiles, y], [currentMiles, y + 5]], false, false, 0, new RColor(255, 255, 0));
  150. }
  151. currentMiles += 100;
  152. }
  153. }
  154. DrawZdmAll.prototype.applyMileage_1010 = function (arrayData, startPoint, space) {
  155. var spaceDistance = 0;
  156. var bailiDistance = 0;
  157. var tenBailiDistance = 0;
  158. for (var i = 0; i < arrayData.length; i++) {
  159. if (i != 0) {
  160. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  161. bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  162. tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  163. }
  164. if (i == 0 || spaceDistance >= 50) {
  165. // 绘制桩号 必须满足最小间距
  166. spaceDistance = 0;
  167. var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
  168. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 50], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  169. }
  170. if (i == 0) {
  171. var x = arrayData[i][0];
  172. addSimpleTextToView("K" + (Math.floor(arrayData[i][0] / 1000) * 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  173. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  174. } else if (tenBailiDistance > 1000) {
  175. // 千里标 K
  176. tenBailiDistance = tenBailiDistance % 1000;
  177. bailiDistance = bailiDistance % 100;
  178. var x = Math.floor(arrayData[i][0] / 1000) * 1000;
  179. addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  180. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space - 5]], false, false, 0, new RColor(255, 255, 0));
  181. } else if (bailiDistance > 100) {
  182. // 百里标
  183. bailiDistance = bailiDistance % 100;
  184. var x = Math.floor(arrayData[i][0] / 100) * 100;
  185. addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  186. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  187. }
  188. }
  189. }
  190. DrawZdmAll.prototype.getExtremePosition = function (array) {
  191. var len = array.length;
  192. if (len == 0) {
  193. EAction.handleUserMessage("extreme data is empty...");
  194. return [[0, 0], [0, 0], [0, 0], [0, 0]];
  195. }
  196. var y_min = array[0][1];
  197. var y_max = array[0][1];
  198. for (var i = 0; i < len; i++) {
  199. y_min = Math.min(array[i][1], y_min);
  200. y_max = Math.max(array[i][1], y_max);
  201. }
  202. var padding = 0;
  203. var verPadding = 40
  204. return [
  205. // 左上
  206. [array[0][0] - padding, y_max + verPadding],
  207. // 右上
  208. [array[len - 1][0] + padding, y_max + verPadding],
  209. // 左下
  210. [array[0][0] - padding, y_min - verPadding],
  211. // 右下
  212. [array[len - 1][0] + padding, y_min - verPadding],
  213. ];
  214. };