DrawZdmAll.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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": 60, 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": 120, 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. var spaceDistance = 0;
  102. var bailiDistance = 0;
  103. var tenBailiDistance = 0;
  104. for (var i = 0; i < arrayData.length; i++) {
  105. if (i != 0) {
  106. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  107. bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  108. tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  109. }
  110. if (i == 0 || spaceDistance >= 50) {
  111. // 绘制桩号 必须满足最小间距
  112. spaceDistance = 0;
  113. var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
  114. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 50], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  115. }
  116. if (i == 0) {
  117. var x = arrayData[i][0];
  118. 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);
  119. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  120. } else if (tenBailiDistance > 1000) {
  121. // 千里标 K
  122. tenBailiDistance = tenBailiDistance % 1000;
  123. bailiDistance = bailiDistance % 100;
  124. var x = Math.floor(arrayData[i][0] / 1000) * 1000;
  125. addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  126. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space - 5]], false, false, 0, new RColor(255, 255, 0));
  127. } else if (bailiDistance > 100) {
  128. // 百里标
  129. bailiDistance = bailiDistance % 100;
  130. var x = Math.floor(arrayData[i][0] / 100) * 100;
  131. addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  132. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  133. }
  134. }
  135. }
  136. DrawZdmAll.prototype.getExtremePosition = function (array) {
  137. var len = array.length;
  138. if (len == 0) {
  139. EAction.handleUserMessage("extreme data is empty...");
  140. return [[0, 0], [0, 0], [0, 0], [0, 0]];
  141. }
  142. var y_min = array[0][1];
  143. var y_max = array[0][1];
  144. for (var i = 0; i < len; i++) {
  145. y_min = Math.min(array[i][1], y_min);
  146. y_max = Math.max(array[i][1], y_max);
  147. }
  148. var padding = 0;
  149. var verPadding = 40
  150. return [
  151. // 左上
  152. [array[0][0] - padding, y_max + verPadding],
  153. // 右上
  154. [array[len - 1][0] + padding, y_max + verPadding],
  155. // 左下
  156. [array[0][0] - padding, y_min - verPadding],
  157. // 右下
  158. [array[len - 1][0] + padding, y_min - verPadding],
  159. ];
  160. };