ZDMCsvImport copy.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. include("scripts/EAction.js");
  2. include("scripts/simple.js");
  3. include("scripts/Common/DrawingUtils.js");
  4. include("scripts/Common/CsvToZdmConvert.js")
  5. include("scripts/Common/DrawZdmAll.js");
  6. /**
  7. * \ingroup ecma_misc_examples_ioexamples
  8. * \class ExTxtImport
  9. * This action reads an XML file and outputs information to stderr.
  10. * This can be used as starting point for XML importers.
  11. */
  12. function ZDMCsvImport(guiAction) {
  13. EAction.call(this, guiAction);
  14. // 绘图比例
  15. this.ratio = 10.0;
  16. this.newEntityData = new Array();
  17. this.newFZEntityData = new Array();
  18. this.newJPointData = new Array();
  19. this.csvCoor = new Array();
  20. this.allR = new Array();
  21. // this.setUiOptions("ZDMCsvImport.ui");
  22. }
  23. ZDMCsvImport.prototype = new EAction();
  24. ZDMCsvImport.includeBasePath = includeBasePath;
  25. ZDMCsvImport.prototype.beginEvent = function () {
  26. EAction.handleUserMessage("current project:");
  27. EAction.prototype.beginEvent.call(this);
  28. try {
  29. var appWin = EAction.getMainWindow();
  30. if (RSettings.getStringValue("OpenProject/Current", "") == "") {
  31. QMessageBox.critical(appWin, qsTr("提示"), qsTr("请先选择工程路径"));
  32. return;
  33. }
  34. var lastOpenFileDir = RSettings.getStringValue("OpenProject/Current", RSettings.getDocumentsLocation());
  35. EAction.handleUserMessage("current project:" + lastOpenFileDir);
  36. var filterAll = qsTr("csv文件") + " (*.csv);";//+ qsTr("All Files") + " (*)";
  37. var fileDialog = new QFileDialog(appWin, qsTr("请选择纵断面表格文件"), lastOpenFileDir, "");
  38. fileDialog.setNameFilters([filterAll]);
  39. fileDialog.selectNameFilter(filterAll);
  40. fileDialog.setOption(QFileDialog.DontUseNativeDialog, getDontUseNativeDialog());
  41. fileDialog.fileMode = QFileDialog.ExistingFiles;
  42. if (!fileDialog.exec()) {
  43. destr(fileDialog);
  44. EAction.activateMainWindow();
  45. this.terminate();
  46. return;
  47. }
  48. var files = fileDialog.selectedFiles();
  49. if (files.length === 0) {
  50. destr(fileDialog);
  51. EAction.activateMainWindow();
  52. this.terminate();
  53. return;
  54. }
  55. destr(fileDialog);
  56. EAction.activateMainWindow();
  57. var fileName = files[0];
  58. EAction.handleUserMessage("Starting to load file: " + fileName);
  59. this.convert(fileName);
  60. } catch (error) {
  61. EAction.handleUserMessage("ZDMCsvImport.js, ERROR: " + error.toString());
  62. }
  63. };
  64. ZDMCsvImport.prototype.convert = function (csvFile) {
  65. try {
  66. // CSV => ZDM
  67. var convert = new CsvToZdmConvert(csvFile);
  68. convert.convert();
  69. var filename = convert.getZdmFileName();
  70. // 图层
  71. var layername = getLayername("ZDM-CSV", csvFile);
  72. // 绘制ZDM
  73. var drawZdmAll = new DrawZdmAll(this.ratio, false);
  74. var dmxFile = filename.replace(/.\w+$/i, ".DMX");
  75. var zdmFile = filename.replace(/.\w+$/i, ".ZDM");
  76. var ctrFile = filename.replace(/.\w+$/i, ".CTR");
  77. drawZdmAll.applyPainting(layername, dmxFile, zdmFile, ctrFile, true);
  78. if (true) {
  79. var tmp = RSettings.getStringValue("OpenDisplayFile/ZDMFile", "");
  80. RSettings.setValue("OpenDisplayFile/ZDMFile", tmp + "," + zdmFile);
  81. }
  82. } catch (error) {
  83. EAction.handleUserMessage("ZDMCsvImport.js, ERROR: " + error.toString());
  84. }
  85. return true;
  86. };
  87. // ZDMCsvImport.prototype.applyOperation = function (preview) {
  88. // // 添加图层
  89. // addLayerToView(this.sFile, "white", "CONTINUOUS", RLineweight.Weight025, 0);
  90. // setCurrentLayer(this.sFile);
  91. // var colorReady = new Array(
  92. // [
  93. // new RColor(255, 0, 0),
  94. // new RColor(160, 32, 240),
  95. // new RColor(0, 255, 0),
  96. // ]
  97. // // ,
  98. // // [
  99. // // new RColor(128, 0, 128),
  100. // // new RColor(200, 96, 255),
  101. // // new RColor(160, 32, 240),
  102. // // ],
  103. // // [
  104. // // new RColor(255, 153, 77),
  105. // // new RColor(128, 255, 255),
  106. // // new RColor(0, 255, 255),
  107. // // ],
  108. // // [
  109. // // new RColor(77, 255, 255),
  110. // // new RColor(255, 255, 128),
  111. // // new RColor(255, 255, 0),
  112. // // ],
  113. // // [
  114. // // new RColor(148, 121, 253),
  115. // // new RColor(255, 192, 128),
  116. // // new RColor(255, 165, 0),
  117. // // ]
  118. // );
  119. // var colorIndex = Math.floor(Math.random() * colorReady.length);
  120. // var selectedArray = colorReady[colorIndex];
  121. // var PDColor = selectedArray[0];
  122. // var SQXColor = selectedArray[1];
  123. // var FZXColor = selectedArray[2];
  124. // //绘制坡道及竖曲线,1为坡道,2为竖曲线
  125. // for (var i = 0; i < this.newEntityData.length - 1; i++) {
  126. // var TempLineData = new Array();
  127. // TempLineData.push([this.newEntityData[i][0], this.newEntityData[i][1]]);
  128. // TempLineData.push([this.newEntityData[i + 1][0], this.newEntityData[i + 1][1]]);
  129. // if (this.newEntityData[i][2] == 1) {
  130. // addPolylinetoView(TempLineData, false, false, 0, PDColor);
  131. // // 计算斜率
  132. // var pdAngle = (this.newEntityData[i + 1][1] - this.newEntityData[i][1]) / (this.newEntityData[i + 1][0] - this.newEntityData[i][0]);
  133. // // 计算长度
  134. // var pdLen = sqrt((this.newEntityData[i + 1][1] - this.newEntityData[i][1]) * (this.newEntityData[i + 1][1] - this.newEntityData[i][1]) + (this.newEntityData[i + 1][0] - this.newEntityData[i][0]) * (this.newEntityData[i + 1][0] - this.newEntityData[i][0]));
  135. // addSimpleTextToView((round(pdAngle * 1000) / 1000).toString(), [(this.newEntityData[i + 1][0] + this.newEntityData[i][0]) / 2 - 2, (this.newEntityData[i + 1][1] + this.newEntityData[i][1]) / 2 + 9],
  136. // 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  137. // addSimpleTextToView((round(pdLen * 1000) / 1000).toString(), [(this.newEntityData[i + 1][0] + this.newEntityData[i][0]) / 2 - 2, (this.newEntityData[i + 1][1] + this.newEntityData[i][1]) / 2 - 2],
  138. // 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  139. // }
  140. // else if (this.newEntityData[i][2] == 2) {
  141. // addPolylinetoView(TempLineData, false, false, 0, SQXColor);
  142. // }
  143. // }
  144. // var min_y = this.newEntityData[0][1];
  145. // // 绘制竖曲线
  146. // if (this.newEntityData.length > 0) {
  147. // for (var i = 0; i < this.newEntityData.length; i++) {
  148. // if (min_y > this.newEntityData[i][1]) {
  149. // min_y = this.newEntityData[i][1];
  150. // }
  151. // }
  152. // var firstItem = this.newEntityData[0];
  153. // var lastItem = this.newEntityData[this.newEntityData.length - 1];
  154. // addLineToView([firstItem[0] - 100, min_y - 50], [lastItem[0], min_y - 50], 0);//横坐标
  155. // addLineToView([firstItem[0], min_y - 110], [firstItem[0], min_y + 150], 0); //纵坐标
  156. // addLineToView([firstItem[0] - 100, min_y - 110], [lastItem[0], min_y - 110], 0); //格线
  157. // addSimpleTextToView(qsTr("R"), [firstItem[0] - 80, min_y - 70],
  158. // 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0);
  159. // }
  160. // //绘制辅助线,1为竖曲线切线起点,2为变坡点,3为竖曲线切线终点
  161. // for (var i = 0; i < this.newFZEntityData.length;) {
  162. // var TempLineData = new Array();
  163. // if (i < this.newFZEntityData.length && this.newFZEntityData[i][2] == 1) {
  164. // TempLineData.push([this.newFZEntityData[i][0], this.newFZEntityData[i][1]]);
  165. // addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] - 1.5], [this.newFZEntityData[i][0], this.newFZEntityData[i][1] + 1.5], 0);
  166. // addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] - 1.5], [this.newFZEntityData[i][0] + 0.5, this.newFZEntityData[i][1] - 1.5], 0);
  167. // addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] + 1.5], [this.newFZEntityData[i][0] + 0.5, this.newFZEntityData[i][1] + 1.5], 0);
  168. // }
  169. // if (i + 1 < this.newFZEntityData.length && this.newFZEntityData[i + 1][2] == 2) {
  170. // TempLineData.push([this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1]]);
  171. // addCircleToView(this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1], 0.5, 0, FZXColor);
  172. // addLineToView([this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1] + 1.5], [this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1] + 50], 0);
  173. // addSimpleTextToView("K" + (round(this.newFZEntityData[i + 1][0] * 1000 * this.ratio) / 1000).toString(), [this.newFZEntityData[i + 1][0] - 9, this.newFZEntityData[i + 1][1] + 2.5], 7, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  174. // addSimpleTextToView(this.newFZEntityData[i + 1][1].toString(), [this.newFZEntityData[i + 1][0] + 2, this.newFZEntityData[i + 1][1] + 3], 7, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
  175. // // EAction.handleUserMessage("start point end point:" + this.newFZEntityData[i + 1][0] + "," + (this.newFZEntityData[i + 1][1]+1)+";"+this.newFZEntityData[i + 1][0]+","+ (this.newFZEntityData[i + 1][1]+10));
  176. // }
  177. // if (i + 2 < this.newFZEntityData.length && this.newFZEntityData[i + 2][2] == 3) {
  178. // TempLineData.push([this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1]]);
  179. // addLineToView([this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] - 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] + 1.5], 0);
  180. // addLineToView([this.newFZEntityData[i + 2][0] - 0.5, this.newFZEntityData[i + 2][1] - 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] - 1.5], 0);
  181. // addLineToView([this.newFZEntityData[i + 2][0] - 0.5, this.newFZEntityData[i + 2][1] + 1.5], [this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1] + 1.5], 0);
  182. // addSimpleTextToView("R-" + this.allR[i % 3].toString(), [this.newFZEntityData[i][0], min_y - 70], 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0);
  183. // addLineToView([this.newFZEntityData[i][0], min_y - 90], [this.newFZEntityData[i + 2][0], min_y - 90], 0);
  184. // }
  185. // addPolylinetoView(TempLineData, false, false, 0, FZXColor);
  186. // i = i + 3;
  187. // }
  188. // EAction.handleUserMessage("load success!");
  189. // var di = getAssignDocumentInterface(0);
  190. // if (!isNull(di)) {
  191. // // di.regenerateScenes();
  192. // di.autoZoom();
  193. // }
  194. // return true;
  195. // };
  196. // ZDMCsvImport.prototype.readTxt = function (file) {
  197. // var reader = new QFile(file);
  198. // var flags = makeQIODeviceOpenMode(QIODevice.ReadOnly, QIODevice.Text);
  199. // if (!reader.open(flags)) {
  200. // EAction.handleUserWarning("cannot open file: " + file);
  201. // return;
  202. // }
  203. // //每次都去文件中的一行,然后输出读取到的字符串
  204. // var ts = new QTextStream(reader);
  205. // setUtf8Codec(ts);
  206. // var TempEntityData = new Array();
  207. // //当读取出现错误(返回 -1)或者读取到的字符数为 0 时,结束读取
  208. // do {
  209. // var textLine = ts.readLine().trim();
  210. // // EAction.handleUserWarning(textLine);
  211. // textLine = textLine.replace(/[\t]+/g, " ").replace(/[\s]+/g, " ");
  212. // textLine = textLine.replace(/[ABC]/g, "").replace(/\r\n/g, "");
  213. // // EAction.handleUserMessage(textLine2);
  214. // var fields = textLine.split(" "); // Reserved: ',&[' & ';&['
  215. // if (fields.length !== 5) { // With two extra fields >
  216. // continue;
  217. // } // End with two extra
  218. // qDebug(parseFloat(fields[0]));
  219. // qDebug(parseFloat(fields[1]));
  220. // qDebug(parseFloat(fields[2]));
  221. // qDebug(parseFloat(this.ratio));
  222. // TempEntityData.push([parseFloat(fields[0]), parseFloat(fields[1]), parseFloat(fields[2])]);
  223. // this.csvCoor.push([parseFloat(fields[0]), parseFloat(fields[1]), parseFloat(fields[2])]);
  224. // }
  225. // while (!ts.atEnd());
  226. // var CurRampZH = 0.0;
  227. // var CurRampBG = 0.0;
  228. // var CurRampR = 0.0;
  229. // var PreRampZH = 0.0;
  230. // var PreRampBG = 0.0;
  231. // var PreRampR = 0.0;
  232. // var NextRampZH = 0.0;
  233. // var NextRampBG = 0.0;
  234. // var NextRampR = 0.0;
  235. // var CurLineType = 1;
  236. // var DeltaS = 10.0;//竖曲线取样点间隔
  237. // for (var i = 0; i < TempEntityData.length; i++) {
  238. // CurRampZH = TempEntityData[i][0];
  239. // CurRampBG = TempEntityData[i][1];
  240. // CurRampR = TempEntityData[i][2];
  241. // if (CurRampR < 1.0 || i == (TempEntityData.length - 1) || i == 0) {
  242. // CurLineType = 1;
  243. // this.newEntityData.push([CurRampZH / parseFloat(this.ratio), CurRampBG, CurLineType]);
  244. // }
  245. // else {
  246. // var i_1 = 0.0;//前坡坡度 lyz
  247. // var i_2 = 0.0;//后坡坡度 lyz
  248. // var CurL = 0.0;//竖曲线长 lyz
  249. // var CurT = 0.0;//竖曲线切线长 lyz
  250. // var CurE = 0.0;//竖曲线外距 lyz
  251. // var CurQD = 0.0;//竖曲线起点桩号 lyz
  252. // var CurZD = 0.0;//竖曲线终点桩号 lyz
  253. // PreRampZH = TempEntityData[i - 1][0];
  254. // PreRampBG = TempEntityData[i - 1][1];
  255. // PreRampR = TempEntityData[i - 1][2];
  256. // NextRampZH = TempEntityData[i + 1][0];
  257. // NextRampBG = TempEntityData[i + 1][1];
  258. // NextRampR = TempEntityData[i + 1][2];
  259. // i_1 = (CurRampBG - PreRampBG) / (CurRampZH - PreRampZH);
  260. // i_2 = (NextRampBG - CurRampBG) / (NextRampZH - CurRampZH);
  261. // CurL = CurRampR * Math.abs(i_2 - i_1);
  262. // CurT = CurL / 2;
  263. // CurE = (CurT * CurT) / (2 * CurRampR);
  264. // CurQD = CurRampZH - CurT;
  265. // CurZD = CurRampZH + CurT;
  266. // // EAction.handleUserMessage("CurL: " + CurL.toString());
  267. // for (var j = CurQD; j < CurZD; j = j + DeltaS) {
  268. // var jQBG = 0.0; //j点切线标高 lyz
  269. // var jE = 0.0; //j点外距 lyz
  270. // var jBG = 0.0; //j点标高 lyz
  271. // if (j <= CurRampZH) {
  272. // jQBG = CurRampBG - (CurRampZH - j) * i_1;
  273. // jE = (j - CurQD) * (j - CurQD) / (2 * CurRampR);
  274. // if ((i_1 - i_2) >= 0) {//确定是凸曲线还是凹曲线 lyz
  275. // jBG = jQBG - jE;
  276. // }
  277. // else {
  278. // jBG = jQBG + jE;
  279. // }
  280. // }
  281. // else {
  282. // jQBG = CurRampBG - (CurRampZH - j) * i_2;
  283. // jE = (CurZD - j) * (CurZD - j) / (2 * CurRampR);
  284. // if ((i_1 - i_2) >= 0) {//确定是凸曲线还是凹曲线 lyz
  285. // jBG = jQBG - jE;
  286. // }
  287. // else {
  288. // jBG = jQBG + jE;
  289. // }
  290. // }
  291. // if (j + DeltaS >= CurZD) {
  292. // CurLineType = 1;
  293. // }
  294. // else CurLineType = 2;
  295. // this.newEntityData.push([j / parseFloat(this.ratio), jBG, CurLineType]);
  296. // //插入辅助线数据
  297. // if (j == CurQD) {
  298. // this.newFZEntityData.push([j / parseFloat(this.ratio), jBG, 1]);
  299. // this.newFZEntityData.push([CurRampZH / parseFloat(this.ratio), CurRampBG, 2]);
  300. // }
  301. // if (j + DeltaS >= CurZD) {
  302. // this.newFZEntityData.push([j / parseFloat(this.ratio), jBG, 3]);
  303. // }
  304. // this.allR.push(CurRampR);
  305. // }
  306. // }
  307. // }
  308. // // EAction.handleUserMessage(this.newEntityData.toString());
  309. // // EAction.handleUserMessage(this.newFZEntityData.toString());
  310. // this.applyOperation();
  311. // reader.close();
  312. // return true;
  313. // };