ExZDMImport.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. include("scripts/EAction.js");
  2. include("scripts/simple.js");
  3. include("scripts/Common/DrawingUtils.js");
  4. include("scripts/Common/DrawZdmAll.js");
  5. function ExZDMImport(guiAction) {
  6. EAction.call(this, guiAction);
  7. this.ratio = 10.0;
  8. }
  9. ExZDMImport.prototype = new EAction();
  10. ExZDMImport.includeBasePath = includeBasePath;
  11. ExZDMImport.prototype.beginEvent = function () {
  12. EAction.prototype.beginEvent.call(this);
  13. var appWin = EAction.getMainWindow();
  14. if (RSettings.getStringValue("OpenProject/Current", "") == "") {
  15. QMessageBox.critical(appWin, qsTr("提示"), qsTr("请先选择工程路径"));
  16. return;
  17. }
  18. var lastOpenFileDir = RSettings.getStringValue("OpenProject/Current", RSettings.getDocumentsLocation());
  19. var filterAll = qsTr("纵断面文件") + " (*.zdm);";
  20. var fileDialog = new QFileDialog(appWin, qsTr("请选择纵断面文件"), lastOpenFileDir, "");
  21. fileDialog.setNameFilters([filterAll]);
  22. fileDialog.selectNameFilter(filterAll);
  23. fileDialog.setOption(QFileDialog.DontUseNativeDialog, getDontUseNativeDialog());
  24. fileDialog.fileMode = QFileDialog.ExistingFiles;
  25. if (!fileDialog.exec()) {
  26. destr(fileDialog);
  27. EAction.activateMainWindow();
  28. this.terminate();
  29. return;
  30. }
  31. var files = fileDialog.selectedFiles();
  32. if (files.length === 0) {
  33. destr(fileDialog);
  34. EAction.activateMainWindow();
  35. this.terminate();
  36. return;
  37. }
  38. destr(fileDialog);
  39. EAction.activateMainWindow();
  40. try {
  41. this.fileName = files[0];
  42. var ok = this.applyPainting(this.fileName);
  43. if (ok) {
  44. var tmp = RSettings.getStringValue("OpenDisplayFile/ZDMFile", "");
  45. RSettings.setValue("OpenDisplayFile/ZDMFile", tmp + "," + this.fileName);
  46. // EAction.handleUserMessage("sucessful load!");
  47. }
  48. // RSettings.setValue("ImportZdmFile/Path", this.fileName);
  49. } catch (error) {
  50. EAction.handleUserMessage("fail load, error: " + error.toString());
  51. }
  52. };
  53. ExZDMImport.prototype.slotRatioButtonclicked = function (v) {
  54. qDebug(v);
  55. this.ratio = v;
  56. this.applyOperation();
  57. };
  58. ExZDMImport.prototype.applyPainting = function (file) {
  59. var drawZdmAll = new DrawZdmAll(this.ratio);
  60. var layername = getLayername("ZDM", file);
  61. var dmxFile = file.replace(/.\w+$/i, ".DMX");
  62. var zdmFile = file.replace(/.\w+$/i, ".ZDM");
  63. var ctrFile = file.replace(/.\w+$/i, ".CTR");
  64. drawZdmAll.applyPainting(layername, dmxFile, zdmFile, ctrFile, true);
  65. }
  66. // ExZDMImport.prototype.applyPainting = function (file) {
  67. // // 图层
  68. // var layername = getLayername("ZDM", file);
  69. // addLayerToView(layername, "white", "CONTINUOUS", RLineweight.Weight025, 0);
  70. // setCurrentLayer(layername);
  71. // // qsTr("地面线文件") + " (*.dmx);"
  72. // var fileDMX = new FileDMX(file.replace(/.\w+$/i, ".DMX"), this.ratio);
  73. // fileDMX.applyOperation();
  74. // var dmxData = fileDMX.getArrayData();
  75. // // qsTr("纵断面文件") + " (*.zdm);"
  76. // var exZDMImport = new FileZDM(file.replace(/.\w+$/i, ".ZDM"), this.ratio);
  77. // // 线绘图在生成CSV文件
  78. // exZDMImport.applyOperation();
  79. // exZDMImport.saveCsvFile();
  80. // var zdmData = exZDMImport.getZDMArray();
  81. // // qsTr("桥梁 隧道") + " (*.ctr);"
  82. // var fileCTR = new FileCTR(file.replace(/.\w+$/i, ".CTR"), this.ratio);
  83. // fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
  84. // fileCTR.applyTunnel(zdmData, new RColor(255, 255, 0));
  85. // // 以下开始绘画表格数据
  86. // var extreme_dmx = this.getExtremePosition(dmxData);
  87. // addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, new RColor(255, 255, 0));
  88. // addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, new RColor(255, 255, 0));
  89. // var startPoint = extreme_dmx[2];
  90. // var endPoint = extreme_dmx[3];
  91. // var text_width = 260;
  92. // addPolylinetoView([[startPoint[0] - text_width, startPoint[1]], endPoint], false, false, 0, new RColor(255, 255, 0));
  93. // var array = new Array();
  94. // array.push({ name: "R", "space": 60, text: "竖曲线半径 (m)" });
  95. // array.push({ name: "SJGC", "space": 100, text: "设计高程 (m)" });
  96. // array.push({ name: "DMGC", "space": 100, text: "地面高程 (m)" });
  97. // // array.push({ name: "PDPC", "space": 100, text: "坡度 (%) 坡长 (m)" });
  98. // array.push({ name: "BLZH", "space": 120, text: "百里桩号 (m)" });
  99. // for (var i = 0; i < array.length; i++) {
  100. // var item = array[i];
  101. // var space = (item.space || 100);
  102. // var text = (item.text || "").toString();
  103. // 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));
  104. // addSimpleTextToView(text, [startPoint[0] - text_width + 50, startPoint[1] - space * (i + 1) + 50], 15, 0, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  105. // switch (item.name) {
  106. // case "R":
  107. // exZDMImport.applyRadius([startPoint[0], startPoint[1] - space * i], space);
  108. // break;
  109. // case "SJGC":
  110. // this.applyHeightMileage(dmxData, [startPoint[0], startPoint[1] - space * i], space);
  111. // break;
  112. // case "DMGC":
  113. // this.applyHeightMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  114. // break;
  115. // case "PDPC":
  116. // exZDMImport.applySlope([startPoint[0], startPoint[1] - space * i], space);
  117. // break;
  118. // case "BLZH":
  119. // this.applyMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  120. // break;
  121. // }
  122. // if (i == array.length - 1) {
  123. // addPolylinetoView([startPoint, [startPoint[0], startPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  124. // addPolylinetoView([endPoint, [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  125. // }
  126. // }
  127. // // 居中显示
  128. // var di = getAssignDocumentInterface(0);
  129. // if (!isNull(di)) {
  130. // di.autoZoom();
  131. // }
  132. // return true;
  133. // };
  134. // ExZDMImport.prototype.applyHeightMileage = function (arrayData, startPoint, spacetext) {
  135. // var space = 50;
  136. // var spaceDistance = 0;
  137. // for (var i = 0; i < arrayData.length; i++) {
  138. // if (i != 0) {
  139. // spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  140. // }
  141. // if (i != 0 && spaceDistance < space) {
  142. // // 不足最小间距
  143. // continue;
  144. // }
  145. // spaceDistance = 0;
  146. // var text = (round((arrayData[i][1]) * 100) / 100).toString();
  147. // addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - spacetext + 30], 15, 90, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  148. // }
  149. // }
  150. // ExZDMImport.prototype.applyMileage = function (arrayData, startPoint, space) {
  151. // spaceDistance = 0;
  152. // var bailiDistance = 0;
  153. // var tenBailiDistance = 0;
  154. // for (var i = 0; i < arrayData.length; i++) {
  155. // if (i != 0) {
  156. // spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  157. // bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  158. // tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  159. // }
  160. // if (i == 0 || spaceDistance >= 50) {
  161. // // 绘制桩号 必须满足最小间距
  162. // spaceDistance = 0;
  163. // var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
  164. // addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 50], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  165. // }
  166. // if (i == 0) {
  167. // var x = arrayData[i][0];
  168. // 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);
  169. // addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  170. // } else if (tenBailiDistance > 1000) {
  171. // // 千里标 K
  172. // tenBailiDistance = tenBailiDistance % 1000;
  173. // bailiDistance = bailiDistance % 100;
  174. // var x = Math.floor(arrayData[i][0] / 1000) * 1000;
  175. // addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  176. // addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space - 5]], false, false, 0, new RColor(255, 255, 0));
  177. // } else if (bailiDistance > 100) {
  178. // // 百里标
  179. // bailiDistance = bailiDistance % 100;
  180. // var x = Math.floor(arrayData[i][0] / 100) * 100;
  181. // addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  182. // addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  183. // }
  184. // }
  185. // }
  186. // ExZDMImport.prototype.getExtremePosition = function (array) {
  187. // var len = array.length;
  188. // if (len == 0) {
  189. // EAction.handleUserMessage("extreme data is empty...");
  190. // return [[0, 0], [0, 0], [0, 0], [0, 0]];
  191. // }
  192. // var y_min = array[0][1];
  193. // var y_max = array[0][1];
  194. // for (var i = 0; i < len; i++) {
  195. // y_min = Math.min(array[i][1], y_min);
  196. // y_max = Math.max(array[i][1], y_max);
  197. // }
  198. // var padding = 0;
  199. // var verPadding = 20
  200. // return [
  201. // // 左上
  202. // [array[0][0] - padding, y_max + verPadding],
  203. // // 右上
  204. // [array[len - 1][0] + padding, y_max + verPadding],
  205. // // 左下
  206. // [array[0][0] - padding, y_min - verPadding],
  207. // // 右下
  208. // [array[len - 1][0] + padding, y_min - verPadding],
  209. // ];
  210. // };