DrawZdmAll.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. }
  13. DrawZdmAll.prototype.applyPainting = function (layer, dmxFile, zdmFile, ctrFile, isCertCsv) {
  14. // 图层
  15. var layername = layer || getLayername("ZDM", zdmFile);
  16. addLayerToView(layername, "white", "CONTINUOUS", RLineweight.Weight025, 0);
  17. setCurrentLayer(layername);
  18. // qsTr("地面线文件") + " (*.dmx);"
  19. var fileDMX = new FileDMX(dmxFile, this.ratio);
  20. fileDMX.applyOperation();
  21. var dmxData = fileDMX.getArrayData();
  22. // qsTr("纵断面文件") + " (*.zdm);"
  23. var drawZdm = new FileZDM(zdmFile, this.ratio);
  24. // 线绘图在生成CSV文件
  25. drawZdm.applyOperation();
  26. if (isCertCsv) {
  27. drawZdm.saveCsvFile();
  28. }
  29. var zdmData = drawZdm.getZDMArray();
  30. // qsTr("桥梁 隧道") + " (*.ctr);"
  31. var fileCTR = new FileCTR(ctrFile, this.ratio);
  32. fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
  33. fileCTR.applyTunnel(zdmData, new RColor(255, 255, 0));
  34. // 以下开始绘画表格数据
  35. var extreme_dmx = this.getExtremePosition(zdmData.length > 0 ? zdmData : dmxData);
  36. addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, new RColor(255, 255, 0));
  37. addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, new RColor(255, 255, 0));
  38. var startPoint = extreme_dmx[2];
  39. var endPoint = extreme_dmx[3];
  40. var text_width = 260;
  41. addPolylinetoView([[startPoint[0] - text_width, startPoint[1]], endPoint], false, false, 0, new RColor(255, 255, 0));
  42. var array = new Array();
  43. array.push({ name: "R", "space": 60, text: "竖曲线半径 (m)" });
  44. array.push({ name: "SJGC", "space": 100, text: "设计高程 (m)" });
  45. array.push({ name: "DMGC", "space": 100, text: "地面高程 (m)" });
  46. array.push({ name: "PDPC", "space": 100, text: "坡度 (%) 坡长 (m)" });
  47. array.push({ name: "BLZH", "space": 120, text: "百里桩号 (m)" });
  48. for (var i = 0; i < array.length; i++) {
  49. var item = array[i];
  50. var space = (item.space || 100);
  51. var text = (item.text || "").toString();
  52. addPolylinetoView([[startPoint[0] - text_width, startPoint[1] - space * (i + 1)], [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  53. addSimpleTextToView(text, [startPoint[0] - text_width + 50, startPoint[1] - space * (i + 1) + 50], 15, 0, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  54. switch (item.name) {
  55. case "R":
  56. drawZdm.applyRadius([startPoint[0], startPoint[1] - space * i], space);
  57. break;
  58. case "SJGC":
  59. this.applyHeightMileage(dmxData, [startPoint[0], startPoint[1] - space * i], space);
  60. break;
  61. case "DMGC":
  62. this.applyHeightMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  63. break;
  64. case "PDPC":
  65. drawZdm.applySlope([startPoint[0], startPoint[1] - space * i], space);
  66. break;
  67. case "BLZH":
  68. this.applyMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  69. break;
  70. }
  71. if (i == array.length - 1) {
  72. addPolylinetoView([startPoint, [startPoint[0], startPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  73. addPolylinetoView([endPoint, [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  74. }
  75. }
  76. // 居中显示
  77. var di = getAssignDocumentInterface(0);
  78. if (!isNull(di)) {
  79. di.autoZoom();
  80. }
  81. return true;
  82. }
  83. DrawZdmAll.prototype.applyHeightMileage = function (arrayData, startPoint, spacetext) {
  84. var space = 50;
  85. var spaceDistance = 0;
  86. for (var i = 0; i < arrayData.length; i++) {
  87. if (i != 0) {
  88. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  89. }
  90. if (i != 0 && spaceDistance < space) {
  91. // 不足最小间距
  92. continue;
  93. }
  94. spaceDistance = 0;
  95. var text = (round((arrayData[i][1]) * 100) / 100).toString();
  96. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - spacetext + 30], 15, 90, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  97. }
  98. }
  99. DrawZdmAll.prototype.applyMileage = function (arrayData, startPoint, space) {
  100. spaceDistance = 0;
  101. var bailiDistance = 0;
  102. var tenBailiDistance = 0;
  103. for (var i = 0; i < arrayData.length; i++) {
  104. if (i != 0) {
  105. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  106. bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  107. tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  108. }
  109. if (i == 0 || spaceDistance >= 50) {
  110. // 绘制桩号 必须满足最小间距
  111. spaceDistance = 0;
  112. var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
  113. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 50], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  114. }
  115. if (i == 0) {
  116. var x = arrayData[i][0];
  117. 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);
  118. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  119. } else if (tenBailiDistance > 1000) {
  120. // 千里标 K
  121. tenBailiDistance = tenBailiDistance % 1000;
  122. bailiDistance = bailiDistance % 100;
  123. var x = Math.floor(arrayData[i][0] / 1000) * 1000;
  124. addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  125. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space - 5]], false, false, 0, new RColor(255, 255, 0));
  126. } else if (bailiDistance > 100) {
  127. // 百里标
  128. bailiDistance = bailiDistance % 100;
  129. var x = Math.floor(arrayData[i][0] / 100) * 100;
  130. addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  131. addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  132. }
  133. }
  134. }
  135. DrawZdmAll.prototype.getExtremePosition = function (array) {
  136. var len = array.length;
  137. if (len == 0) {
  138. EAction.handleUserMessage("extreme data is empty...");
  139. return [[0, 0], [0, 0], [0, 0], [0, 0]];
  140. }
  141. var y_min = array[0][1];
  142. var y_max = array[0][1];
  143. for (var i = 0; i < len; i++) {
  144. y_min = Math.min(array[i][1], y_min);
  145. y_max = Math.max(array[i][1], y_max);
  146. }
  147. var padding = 0;
  148. var verPadding = 40
  149. return [
  150. // 左上
  151. [array[0][0] - padding, y_max + verPadding],
  152. // 右上
  153. [array[len - 1][0] + padding, y_max + verPadding],
  154. // 左下
  155. [array[0][0] - padding, y_min - verPadding],
  156. // 右下
  157. [array[len - 1][0] + padding, y_min - verPadding],
  158. ];
  159. };