DrawZdmAll.js 9.0 KB

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