| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- include("scripts/EAction.js");
- include("scripts/simple.js");
- include("scripts/Common/DrawingUtils.js");
- include("scripts/Common/CsvToZdmConvert.js")
- include("scripts/Common/DrawZdmAll.js");
- /**
- * \ingroup ecma_misc_examples_ioexamples
- * \class ExTxtImport
- * This action reads an XML file and outputs information to stderr.
- * This can be used as starting point for XML importers.
- */
- function ZDMCsvImport(guiAction) {
- EAction.call(this, guiAction);
- // 绘图比例
- this.ratio = 10.0;
- this.newEntityData = new Array();
- this.newFZEntityData = new Array();
- this.newJPointData = new Array();
- this.csvCoor = new Array();
- this.allR = new Array();
- // this.setUiOptions("ZDMCsvImport.ui");
- }
- ZDMCsvImport.prototype = new EAction();
- ZDMCsvImport.includeBasePath = includeBasePath;
- ZDMCsvImport.prototype.beginEvent = function () {
- EAction.handleUserMessage("current project:");
- EAction.prototype.beginEvent.call(this);
- try {
- var appWin = EAction.getMainWindow();
- if (RSettings.getStringValue("OpenProject/Current", "") == "") {
- QMessageBox.critical(appWin, qsTr("提示"), qsTr("请先选择工程路径"));
- return;
- }
- var lastOpenFileDir = RSettings.getStringValue("OpenProject/Current", RSettings.getDocumentsLocation());
- EAction.handleUserMessage("current project:" + lastOpenFileDir);
- var filterAll = qsTr("csv文件") + " (*.csv);";//+ qsTr("All Files") + " (*)";
- var fileDialog = new QFileDialog(appWin, qsTr("请选择纵断面表格文件"), lastOpenFileDir, "");
- fileDialog.setNameFilters([filterAll]);
- fileDialog.selectNameFilter(filterAll);
- fileDialog.setOption(QFileDialog.DontUseNativeDialog, getDontUseNativeDialog());
- fileDialog.fileMode = QFileDialog.ExistingFiles;
- if (!fileDialog.exec()) {
- destr(fileDialog);
- EAction.activateMainWindow();
- this.terminate();
- return;
- }
- var files = fileDialog.selectedFiles();
- if (files.length === 0) {
- destr(fileDialog);
- EAction.activateMainWindow();
- this.terminate();
- return;
- }
- destr(fileDialog);
- EAction.activateMainWindow();
- var fileName = files[0];
- EAction.handleUserMessage("Starting to load file: " + fileName);
- this.convert(fileName);
- } catch (error) {
- EAction.handleUserMessage("ZDMCsvImport.js, ERROR: " + error.toString());
- }
- };
- ZDMCsvImport.prototype.convert = function (csvFile) {
- try {
- // CSV => ZDM
- var convert = new CsvToZdmConvert(csvFile);
- convert.convert();
- var filename = convert.getZdmFileName();
- // 图层
- var layername = getLayername("ZDM-CSV", csvFile);
- // 绘制ZDM
- var drawZdmAll = new DrawZdmAll(this.ratio, false);
- var dmxFile = filename.replace(/.\w+$/i, ".DMX");
- var zdmFile = filename.replace(/.\w+$/i, ".ZDM");
- var ctrFile = filename.replace(/.\w+$/i, ".CTR");
- drawZdmAll.applyPainting(layername, dmxFile, zdmFile, ctrFile, true);
- if (true) {
- var tmp = RSettings.getStringValue("OpenDisplayFile/ZDMFile", "");
- RSettings.setValue("OpenDisplayFile/ZDMFile", tmp + "," + zdmFile);
- }
- } catch (error) {
- EAction.handleUserMessage("ZDMCsvImport.js, ERROR: " + error.toString());
- }
- return true;
- };
- // ZDMCsvImport.prototype.applyOperation = function (preview) {
- // // 添加图层
- // addLayerToView(this.sFile, "white", "CONTINUOUS", RLineweight.Weight025, 0);
- // setCurrentLayer(this.sFile);
- // var colorReady = new Array(
- // [
- // new RColor(255, 0, 0),
- // new RColor(160, 32, 240),
- // new RColor(0, 255, 0),
- // ]
- // // ,
- // // [
- // // new RColor(128, 0, 128),
- // // new RColor(200, 96, 255),
- // // new RColor(160, 32, 240),
- // // ],
- // // [
- // // new RColor(255, 153, 77),
- // // new RColor(128, 255, 255),
- // // new RColor(0, 255, 255),
- // // ],
- // // [
- // // new RColor(77, 255, 255),
- // // new RColor(255, 255, 128),
- // // new RColor(255, 255, 0),
- // // ],
- // // [
- // // new RColor(148, 121, 253),
- // // new RColor(255, 192, 128),
- // // new RColor(255, 165, 0),
- // // ]
- // );
- // var colorIndex = Math.floor(Math.random() * colorReady.length);
- // var selectedArray = colorReady[colorIndex];
- // var PDColor = selectedArray[0];
- // var SQXColor = selectedArray[1];
- // var FZXColor = selectedArray[2];
- // //绘制坡道及竖曲线,1为坡道,2为竖曲线
- // for (var i = 0; i < this.newEntityData.length - 1; i++) {
- // var TempLineData = new Array();
- // TempLineData.push([this.newEntityData[i][0], this.newEntityData[i][1]]);
- // TempLineData.push([this.newEntityData[i + 1][0], this.newEntityData[i + 1][1]]);
- // if (this.newEntityData[i][2] == 1) {
- // addPolylinetoView(TempLineData, false, false, 0, PDColor);
- // // 计算斜率
- // var pdAngle = (this.newEntityData[i + 1][1] - this.newEntityData[i][1]) / (this.newEntityData[i + 1][0] - this.newEntityData[i][0]);
- // // 计算长度
- // 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]));
- // 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],
- // 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- // 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],
- // 7, rad2deg(pdAngle), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- // }
- // else if (this.newEntityData[i][2] == 2) {
- // addPolylinetoView(TempLineData, false, false, 0, SQXColor);
- // }
- // }
- // var min_y = this.newEntityData[0][1];
- // // 绘制竖曲线
- // if (this.newEntityData.length > 0) {
- // for (var i = 0; i < this.newEntityData.length; i++) {
- // if (min_y > this.newEntityData[i][1]) {
- // min_y = this.newEntityData[i][1];
- // }
- // }
- // var firstItem = this.newEntityData[0];
- // var lastItem = this.newEntityData[this.newEntityData.length - 1];
- // addLineToView([firstItem[0] - 100, min_y - 50], [lastItem[0], min_y - 50], 0);//横坐标
- // addLineToView([firstItem[0], min_y - 110], [firstItem[0], min_y + 150], 0); //纵坐标
- // addLineToView([firstItem[0] - 100, min_y - 110], [lastItem[0], min_y - 110], 0); //格线
- // addSimpleTextToView(qsTr("R"), [firstItem[0] - 80, min_y - 70],
- // 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0);
- // }
- // //绘制辅助线,1为竖曲线切线起点,2为变坡点,3为竖曲线切线终点
- // for (var i = 0; i < this.newFZEntityData.length;) {
- // var TempLineData = new Array();
- // if (i < this.newFZEntityData.length && this.newFZEntityData[i][2] == 1) {
- // TempLineData.push([this.newFZEntityData[i][0], this.newFZEntityData[i][1]]);
- // addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] - 1.5], [this.newFZEntityData[i][0], this.newFZEntityData[i][1] + 1.5], 0);
- // addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] - 1.5], [this.newFZEntityData[i][0] + 0.5, this.newFZEntityData[i][1] - 1.5], 0);
- // addLineToView([this.newFZEntityData[i][0], this.newFZEntityData[i][1] + 1.5], [this.newFZEntityData[i][0] + 0.5, this.newFZEntityData[i][1] + 1.5], 0);
- // }
- // if (i + 1 < this.newFZEntityData.length && this.newFZEntityData[i + 1][2] == 2) {
- // TempLineData.push([this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1]]);
- // addCircleToView(this.newFZEntityData[i + 1][0], this.newFZEntityData[i + 1][1], 0.5, 0, FZXColor);
- // 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);
- // 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);
- // 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);
- // // 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));
- // }
- // if (i + 2 < this.newFZEntityData.length && this.newFZEntityData[i + 2][2] == 3) {
- // TempLineData.push([this.newFZEntityData[i + 2][0], this.newFZEntityData[i + 2][1]]);
- // 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);
- // 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);
- // 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);
- // addSimpleTextToView("R-" + this.allR[i % 3].toString(), [this.newFZEntityData[i][0], min_y - 70], 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0);
- // addLineToView([this.newFZEntityData[i][0], min_y - 90], [this.newFZEntityData[i + 2][0], min_y - 90], 0);
- // }
- // addPolylinetoView(TempLineData, false, false, 0, FZXColor);
- // i = i + 3;
- // }
- // EAction.handleUserMessage("load success!");
- // var di = getAssignDocumentInterface(0);
- // if (!isNull(di)) {
- // // di.regenerateScenes();
- // di.autoZoom();
- // }
- // return true;
- // };
- // ZDMCsvImport.prototype.readTxt = function (file) {
- // var reader = new QFile(file);
- // var flags = makeQIODeviceOpenMode(QIODevice.ReadOnly, QIODevice.Text);
- // if (!reader.open(flags)) {
- // EAction.handleUserWarning("cannot open file: " + file);
- // return;
- // }
- // //每次都去文件中的一行,然后输出读取到的字符串
- // var ts = new QTextStream(reader);
- // setUtf8Codec(ts);
- // var TempEntityData = new Array();
- // //当读取出现错误(返回 -1)或者读取到的字符数为 0 时,结束读取
- // do {
- // var textLine = ts.readLine().trim();
- // // EAction.handleUserWarning(textLine);
- // textLine = textLine.replace(/[\t]+/g, " ").replace(/[\s]+/g, " ");
- // textLine = textLine.replace(/[ABC]/g, "").replace(/\r\n/g, "");
- // // EAction.handleUserMessage(textLine2);
- // var fields = textLine.split(" "); // Reserved: ',&[' & ';&['
- // if (fields.length !== 5) { // With two extra fields >
- // continue;
- // } // End with two extra
- // qDebug(parseFloat(fields[0]));
- // qDebug(parseFloat(fields[1]));
- // qDebug(parseFloat(fields[2]));
- // qDebug(parseFloat(this.ratio));
- // TempEntityData.push([parseFloat(fields[0]), parseFloat(fields[1]), parseFloat(fields[2])]);
- // this.csvCoor.push([parseFloat(fields[0]), parseFloat(fields[1]), parseFloat(fields[2])]);
- // }
- // while (!ts.atEnd());
- // var CurRampZH = 0.0;
- // var CurRampBG = 0.0;
- // var CurRampR = 0.0;
- // var PreRampZH = 0.0;
- // var PreRampBG = 0.0;
- // var PreRampR = 0.0;
- // var NextRampZH = 0.0;
- // var NextRampBG = 0.0;
- // var NextRampR = 0.0;
- // var CurLineType = 1;
- // var DeltaS = 10.0;//竖曲线取样点间隔
- // for (var i = 0; i < TempEntityData.length; i++) {
- // CurRampZH = TempEntityData[i][0];
- // CurRampBG = TempEntityData[i][1];
- // CurRampR = TempEntityData[i][2];
- // if (CurRampR < 1.0 || i == (TempEntityData.length - 1) || i == 0) {
- // CurLineType = 1;
- // this.newEntityData.push([CurRampZH / parseFloat(this.ratio), CurRampBG, CurLineType]);
- // }
- // else {
- // var i_1 = 0.0;//前坡坡度 lyz
- // var i_2 = 0.0;//后坡坡度 lyz
- // var CurL = 0.0;//竖曲线长 lyz
- // var CurT = 0.0;//竖曲线切线长 lyz
- // var CurE = 0.0;//竖曲线外距 lyz
- // var CurQD = 0.0;//竖曲线起点桩号 lyz
- // var CurZD = 0.0;//竖曲线终点桩号 lyz
- // PreRampZH = TempEntityData[i - 1][0];
- // PreRampBG = TempEntityData[i - 1][1];
- // PreRampR = TempEntityData[i - 1][2];
- // NextRampZH = TempEntityData[i + 1][0];
- // NextRampBG = TempEntityData[i + 1][1];
- // NextRampR = TempEntityData[i + 1][2];
- // i_1 = (CurRampBG - PreRampBG) / (CurRampZH - PreRampZH);
- // i_2 = (NextRampBG - CurRampBG) / (NextRampZH - CurRampZH);
- // CurL = CurRampR * Math.abs(i_2 - i_1);
- // CurT = CurL / 2;
- // CurE = (CurT * CurT) / (2 * CurRampR);
- // CurQD = CurRampZH - CurT;
- // CurZD = CurRampZH + CurT;
- // // EAction.handleUserMessage("CurL: " + CurL.toString());
- // for (var j = CurQD; j < CurZD; j = j + DeltaS) {
- // var jQBG = 0.0; //j点切线标高 lyz
- // var jE = 0.0; //j点外距 lyz
- // var jBG = 0.0; //j点标高 lyz
- // if (j <= CurRampZH) {
- // jQBG = CurRampBG - (CurRampZH - j) * i_1;
- // jE = (j - CurQD) * (j - CurQD) / (2 * CurRampR);
- // if ((i_1 - i_2) >= 0) {//确定是凸曲线还是凹曲线 lyz
- // jBG = jQBG - jE;
- // }
- // else {
- // jBG = jQBG + jE;
- // }
- // }
- // else {
- // jQBG = CurRampBG - (CurRampZH - j) * i_2;
- // jE = (CurZD - j) * (CurZD - j) / (2 * CurRampR);
- // if ((i_1 - i_2) >= 0) {//确定是凸曲线还是凹曲线 lyz
- // jBG = jQBG - jE;
- // }
- // else {
- // jBG = jQBG + jE;
- // }
- // }
- // if (j + DeltaS >= CurZD) {
- // CurLineType = 1;
- // }
- // else CurLineType = 2;
- // this.newEntityData.push([j / parseFloat(this.ratio), jBG, CurLineType]);
- // //插入辅助线数据
- // if (j == CurQD) {
- // this.newFZEntityData.push([j / parseFloat(this.ratio), jBG, 1]);
- // this.newFZEntityData.push([CurRampZH / parseFloat(this.ratio), CurRampBG, 2]);
- // }
- // if (j + DeltaS >= CurZD) {
- // this.newFZEntityData.push([j / parseFloat(this.ratio), jBG, 3]);
- // }
- // this.allR.push(CurRampR);
- // }
- // }
- // }
- // // EAction.handleUserMessage(this.newEntityData.toString());
- // // EAction.handleUserMessage(this.newFZEntityData.toString());
- // this.applyOperation();
- // reader.close();
- // return true;
- // };
|