DMXImport.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. include("scripts/EAction.js");
  2. include("scripts/simple.js");
  3. include("./FileCTR.js");
  4. include("./FileDMX.js");
  5. include("./FileZDM.js");
  6. function DMXImport() {
  7. }
  8. DMXImport.includeBasePath = includeBasePath;
  9. DMXImport.prototype.interface = function(fileName){
  10. this.fileName = fileName.substring(0,fileName.lastIndexOf("."))+".DMX";;
  11. try {
  12. var ok = this.applyPainting(this.fileName);
  13. } catch (error) {
  14. EAction.handleUserMessage("load file error: " + error.message.toString());
  15. EAction.handleUserMessage("load file error: " + error.stack.toString());
  16. }
  17. }
  18. DMXImport.prototype.applyPainting = function (file) {
  19. // qsTr("地面线文件") + " (*.dmx);"
  20. var fileDMX = new FileDMX();
  21. var tmp = fileDMX.readTxt(file);
  22. if(false == tmp) return;
  23. var dmxData = fileDMX.getArrayData();
  24. // qsTr("纵断面文件") + " (*.zdm);"
  25. var exZDMImport = new FileZDM(this.guiAction);
  26. tmp = exZDMImport.readTxt(file.replace(/.dmx$/i, ".ZDM"));
  27. if(false == tmp) return;
  28. var zdmData = exZDMImport.getZDMArray();
  29. // qsTr("桥梁 隧道") + " (*.ctr);"
  30. var fileCTR = new FileCTR();
  31. tmp = fileCTR.readTxt(file.replace(/.dmx$/i, ".CTR"));
  32. if(false == tmp) return;
  33. fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
  34. fileCTR.applyTunnel(zdmData,new RColor(255, 255, 0));
  35. // 添加图层
  36. var newdate = new Date();
  37. newdate.getTime();
  38. addLayerToView(newdate.getTime().toString(), "white", "CONTINUOUS", RLineweight.Weight025, 0);
  39. setCurrentLayer(newdate.getTime().toString());
  40. // 以下开始绘画表格数据
  41. var extreme_dmx = this.getExtremePosition(dmxData);
  42. addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, new RColor(255, 255, 0));
  43. addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, new RColor(255, 255, 0));
  44. // 设计高程
  45. var startPoint = extreme_dmx[2];
  46. var endPoint = extreme_dmx[3];
  47. var boxPointArray = this.applyDrawBox(startPoint, endPoint, -200, -160, "", new RColor(255, 255, 0));
  48. startPoint = boxPointArray[0];
  49. endPoint = boxPointArray[1];
  50. // 设计高程
  51. this.applyHeightMileage(dmxData,startPoint,50);
  52. var boxPointArray = this.applyDrawBox(startPoint, endPoint, -200, -160, "SJGC (m)", new RColor(255, 255, 0));
  53. // 地面高程
  54. startPoint = boxPointArray[0];
  55. endPoint = boxPointArray[1];
  56. this.applyHeightMileage(zdmData,startPoint,50);
  57. var boxPointArray = this.applyDrawBox(startPoint, endPoint, -200, -160, "DMGC (m)", new RColor(255, 255, 0));
  58. // 百里桩号
  59. startPoint = boxPointArray[0];
  60. endPoint = boxPointArray[1];
  61. this.applyMileage(zdmData,startPoint);
  62. this.applyDrawBox(startPoint, endPoint, -200, -160, "LCZH", new RColor(255, 255, 0));
  63. };
  64. DMXImport.prototype.applyHeightMileage = function(arrayData,startPoint,space){
  65. space = space ? space : 50;
  66. var spaceDistance = 0;
  67. for (var i = 0; i < arrayData.length; i++) {
  68. if (i != 0) {
  69. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  70. }
  71. if (i != 0 && spaceDistance < space) {
  72. // 不足最小间距
  73. continue;
  74. }
  75. spaceDistance = 0;
  76. var text = (round((arrayData[i][1]) * 100) / 100).toString();
  77. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 80], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  78. }
  79. }
  80. DMXImport.prototype.applyMileage = function(arrayData,startPoint){
  81. spaceDistance = 0;
  82. var bailiDistance = 0;
  83. var tenBailiDistance = 0;
  84. for (var i = 0; i < arrayData.length; i++) {
  85. if (i != 0) {
  86. spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  87. bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  88. tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  89. }
  90. if (i == 0 || spaceDistance >= 50) {
  91. // 必须满足最小间距
  92. spaceDistance = 0;
  93. var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
  94. addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 80], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  95. }
  96. if (i == 0) {
  97. var x = arrayData[i][0];
  98. addSimpleTextToView("K" + arrayData[i][0].toString(), [x, startPoint[1] - 130], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  99. addPolylinetoView([[x, startPoint[1] - 160],[x, startPoint[1] - 150]],false,false,0,new RColor(255, 255, 0));
  100. } else if (tenBailiDistance > 1000) {
  101. // 千里标 K
  102. tenBailiDistance = tenBailiDistance % 1000;
  103. bailiDistance = bailiDistance % 100;
  104. var x = Math.floor(arrayData[i][0] / 1000) * 1000;
  105. addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - 130], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  106. addPolylinetoView([[x, startPoint[1] - 160],[x, startPoint[1] - 150]],false,false,0,new RColor(255, 255, 0));
  107. } else if (bailiDistance > 100) {
  108. // 百里标
  109. bailiDistance = bailiDistance % 100;
  110. var x = Math.floor(arrayData[i][0] / 100) * 100;
  111. addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - 130], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  112. addPolylinetoView([[x, startPoint[1] - 160],[x, startPoint[1] - 150]],false,false,0,new RColor(255, 255, 0));
  113. }
  114. }
  115. }
  116. DMXImport.prototype.getExtremePosition = function (array) {
  117. var len = array.length;
  118. if (len == 0) {
  119. EAction.handleUserMessage("extreme data is empty...");
  120. return [
  121. [0, 0],
  122. [0, 0],
  123. [0, 0],
  124. [0, 0],
  125. ];
  126. }
  127. var y_min = array[0][1];
  128. var y_max = array[0][1];
  129. for (var i = 0; i < len; i++) {
  130. y_min = Math.min(array[i][1], y_min);
  131. y_max = Math.max(array[i][1], y_max);
  132. }
  133. var padding = 20;
  134. return [
  135. // 左上
  136. [array[0][0] - padding, y_max + padding],
  137. // 右上
  138. [array[len - 1][0] + padding, y_max + padding],
  139. // 左下
  140. [array[0][0] - padding, y_min - padding],
  141. // 右下
  142. [array[len - 1][0] + padding, y_min - padding],
  143. ];
  144. };
  145. DMXImport.prototype.applyDrawBox = function (startPoint, endPoint, text_width, text_height, text, lineColor) {
  146. // addPolylinetoView([[startPoint[0] + text_width, startPoint[1]], endPoint], false, false, 0, lineColor);
  147. // addPolylinetoView([[startPoint[0] + text_width, startPoint[1] + text_height],[endPoint[0], endPoint[1] + text_height],],false,false,0,lineColor );
  148. // addPolylinetoView([[startPoint[0] + text_width, startPoint[1]],[startPoint[0] + text_width, startPoint[1] + text_height],],false,false,0,lineColor);
  149. // addPolylinetoView([[startPoint[0], startPoint[1]],[startPoint[0], startPoint[1] + text_height],],false,false,0,lineColor);
  150. // addPolylinetoView([[endPoint[0], endPoint[1]],[endPoint[0], endPoint[1] + text_height],],false,false,0,lineColor);
  151. addSimpleTextToView(text, [startPoint[0] + (text_width * 2) / 3, startPoint[1] + (text_height * 1) / 2], 15, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  152. return [
  153. [startPoint[0], startPoint[1] + text_height],
  154. [endPoint[0], endPoint[1] + text_height],
  155. ];
  156. };