include("scripts/EAction.js"); include("scripts/simple.js"); function FileZDM() { this.newEntityData = new Array(); this.newFZEntityData = new Array(); this.newJPointData = new Array(); this.csvCoor = new Array(); this.allR = new Array(); // this.setUiOptions("ExZDMImport.ui"); this.ratio = 10.0; } FileZDM.prototype.getZDMArray = function (file) { return this.newEntityData; } FileZDM.prototype.applyOperation = function (preview) { // 添加图层 var newdate = new Date(); newdate.getTime(); addLayerToView(newdate.getTime().toString(), "white", "CONTINUOUS", RLineweight.Weight025, 0); setCurrentLayer(newdate.getTime().toString()); 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:10 // addLineToView([this.newEntityData[0][0]-100, this.newEntityData[0][1]],[this.newEntityData[0][0]-20, this.newEntityData[0][1]],0); // addLineToView([this.newEntityData[0][0]-100, this.newEntityData[0][1]],[this.newEntityData[0][0]-100, this.newEntityData[0][1]+15],0); // addLineToView([this.newEntityData[0][0]-20, this.newEntityData[0][1]],[this.newEntityData[0][0]-20, this.newEntityData[0][1]+15],0); // addSimpleTextToView(("ratio 1:10"),[this.newEntityData[0][0]-80, this.newEntityData[0][1]+10], // 7,0,"Standard",RS.VAlignTop,RS.HAlignLeft,false,false,0); //绘制坡道及竖曲线,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("save csv file start!"); // var fname = this.fileName.substring(0,this.fileName.lastIndexOf("."))+".csv"; var fname = RSettings.getStringValue("OpenProject/Current", RSettings.getDocumentsLocation()) + "/K_E_R.csv"; var file = new QFile(fname); if (file.exists()) { //如果文件存在执行的操作,此处为空,因为文件不可能存在 } file.open(makeQIODeviceOpenMode(QIODevice.WriteOnly, QIODevice.Text)); var out = new QTextStream(file); //写表头 out.writeString("K,H,R\n"); //写数据 for (i = 0; i < this.csvCoor.length; i++) { out.writeString(this.csvCoor[i][0] + "," + this.csvCoor[i][1] + "," + this.csvCoor[i][2] + "\n"); } out.flush(); //写完数据需要关闭文件 file.close(); EAction.handleUserMessage("save csv file success!"); var di = getAssignDocumentInterface(0); if (!isNull(di)) { // di.regenerateScenes(); di.autoZoom(); } return true; }; FileZDM.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 false; } //每次都去文件中的一行,然后输出读取到的字符串 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; 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); } } } // this.applyOperation(); reader.close(); return true; };