ExZDMImport.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. if (true) {
  66. var tmp = RSettings.getStringValue("OpenDisplayFile/ZDMFile", "");
  67. RSettings.setValue("OpenDisplayFile/ZDMFile", tmp + "," + zdmFile);
  68. }
  69. }
  70. // ExZDMImport.prototype.applyPainting = function (file) {
  71. // // 图层
  72. // var layername = getLayername("ZDM", file);
  73. // addLayerToView(layername, "white", "CONTINUOUS", RLineweight.Weight025, 0);
  74. // setCurrentLayer(layername);
  75. // // qsTr("地面线文件") + " (*.dmx);"
  76. // var fileDMX = new FileDMX(file.replace(/.\w+$/i, ".DMX"), this.ratio);
  77. // fileDMX.applyOperation();
  78. // var dmxData = fileDMX.getArrayData();
  79. // // qsTr("纵断面文件") + " (*.zdm);"
  80. // var exZDMImport = new FileZDM(file.replace(/.\w+$/i, ".ZDM"), this.ratio);
  81. // // 线绘图在生成CSV文件
  82. // exZDMImport.applyOperation();
  83. // exZDMImport.saveCsvFile();
  84. // var zdmData = exZDMImport.getZDMArray();
  85. // // qsTr("桥梁 隧道") + " (*.ctr);"
  86. // var fileCTR = new FileCTR(file.replace(/.\w+$/i, ".CTR"), this.ratio);
  87. // fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
  88. // fileCTR.applyTunnel(zdmData, new RColor(255, 255, 0));
  89. // // 以下开始绘画表格数据
  90. // var extreme_dmx = this.getExtremePosition(dmxData);
  91. // addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, new RColor(255, 255, 0));
  92. // addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, new RColor(255, 255, 0));
  93. // var startPoint = extreme_dmx[2];
  94. // var endPoint = extreme_dmx[3];
  95. // var text_width = 260;
  96. // addPolylinetoView([[startPoint[0] - text_width, startPoint[1]], endPoint], false, false, 0, new RColor(255, 255, 0));
  97. // var array = new Array();
  98. // array.push({ name: "R", "space": 60, text: "竖曲线半径 (m)" });
  99. // array.push({ name: "SJGC", "space": 100, text: "设计高程 (m)" });
  100. // array.push({ name: "DMGC", "space": 100, text: "地面高程 (m)" });
  101. // // array.push({ name: "PDPC", "space": 100, text: "坡度 (%) 坡长 (m)" });
  102. // array.push({ name: "BLZH", "space": 120, text: "百里桩号 (m)" });
  103. // for (var i = 0; i < array.length; i++) {
  104. // var item = array[i];
  105. // var space = (item.space || 100);
  106. // var text = (item.text || "").toString();
  107. // 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));
  108. // addSimpleTextToView(text, [startPoint[0] - text_width + 50, startPoint[1] - space * (i + 1) + 50], 15, 0, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  109. // switch (item.name) {
  110. // case "R":
  111. // exZDMImport.applyRadius([startPoint[0], startPoint[1] - space * i], space);
  112. // break;
  113. // case "SJGC":
  114. // this.applyHeightMileage(dmxData, [startPoint[0], startPoint[1] - space * i], space);
  115. // break;
  116. // case "DMGC":
  117. // this.applyHeightMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  118. // break;
  119. // case "PDPC":
  120. // exZDMImport.applySlope([startPoint[0], startPoint[1] - space * i], space);
  121. // break;
  122. // case "BLZH":
  123. // this.applyMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
  124. // break;
  125. // }
  126. // if (i == array.length - 1) {
  127. // addPolylinetoView([startPoint, [startPoint[0], startPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  128. // addPolylinetoView([endPoint, [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, new RColor(255, 255, 0));
  129. // }
  130. // }
  131. // // 居中显示
  132. // var di = getAssignDocumentInterface(0);
  133. // if (!isNull(di)) {
  134. // di.autoZoom();
  135. // }
  136. // return true;
  137. // };
  138. // ExZDMImport.prototype.applyHeightMileage = function (arrayData, startPoint, spacetext) {
  139. // var space = 50;
  140. // var spaceDistance = 0;
  141. // for (var i = 0; i < arrayData.length; i++) {
  142. // if (i != 0) {
  143. // spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  144. // }
  145. // if (i != 0 && spaceDistance < space) {
  146. // // 不足最小间距
  147. // continue;
  148. // }
  149. // spaceDistance = 0;
  150. // var text = (round((arrayData[i][1]) * 100) / 100).toString();
  151. // addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - spacetext + 30], 15, 90, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  152. // }
  153. // }
  154. // ExZDMImport.prototype.applyMileage = function (arrayData, startPoint, space) {
  155. // spaceDistance = 0;
  156. // var bailiDistance = 0;
  157. // var tenBailiDistance = 0;
  158. // for (var i = 0; i < arrayData.length; i++) {
  159. // if (i != 0) {
  160. // spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  161. // bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  162. // tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
  163. // }
  164. // if (i == 0 || spaceDistance >= 50) {
  165. // // 绘制桩号 必须满足最小间距
  166. // spaceDistance = 0;
  167. // var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
  168. // addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 50], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  169. // }
  170. // if (i == 0) {
  171. // var x = arrayData[i][0];
  172. // 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);
  173. // addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  174. // } else if (tenBailiDistance > 1000) {
  175. // // 千里标 K
  176. // tenBailiDistance = tenBailiDistance % 1000;
  177. // bailiDistance = bailiDistance % 100;
  178. // var x = Math.floor(arrayData[i][0] / 1000) * 1000;
  179. // addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  180. // addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space - 5]], false, false, 0, new RColor(255, 255, 0));
  181. // } else if (bailiDistance > 100) {
  182. // // 百里标
  183. // bailiDistance = bailiDistance % 100;
  184. // var x = Math.floor(arrayData[i][0] / 100) * 100;
  185. // addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  186. // addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
  187. // }
  188. // }
  189. // }
  190. // ExZDMImport.prototype.getExtremePosition = function (array) {
  191. // var len = array.length;
  192. // if (len == 0) {
  193. // EAction.handleUserMessage("extreme data is empty...");
  194. // return [[0, 0], [0, 0], [0, 0], [0, 0]];
  195. // }
  196. // var y_min = array[0][1];
  197. // var y_max = array[0][1];
  198. // for (var i = 0; i < len; i++) {
  199. // y_min = Math.min(array[i][1], y_min);
  200. // y_max = Math.max(array[i][1], y_max);
  201. // }
  202. // var padding = 0;
  203. // var verPadding = 20
  204. // return [
  205. // // 左上
  206. // [array[0][0] - padding, y_max + verPadding],
  207. // // 右上
  208. // [array[len - 1][0] + padding, y_max + verPadding],
  209. // // 左下
  210. // [array[0][0] - padding, y_min - verPadding],
  211. // // 右下
  212. // [array[len - 1][0] + padding, y_min - verPadding],
  213. // ];
  214. // };