DrawZdmAll.js 10 KB

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