include("scripts/EAction.js"); include("scripts/simple.js"); include("scripts/Common/DrawingUtils.js"); function FileZDM(file, ratio) { this.newEntityData = new Array(); this.newFZEntityData = new Array(); this.newJPointData = new Array(); this.csvCoor = new Array(); this.allR = new Array(); // 比例尺 this.ratio = ratio || 1.0; this.readTxt(file); } FileZDM.prototype.getZDMArray = function () { return this.newEntityData; } FileZDM.prototype.applyOperation = function () { 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); EAction.handleUserMessage("ZDM-40: " + formatDateTime()); //绘制坡道及竖曲线,1为坡道,2为竖曲线 var c = 0; 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 pdAngle = (this.csvCoor[c + 1][1] - this.csvCoor[c][1]) / (this.csvCoor[c + 1][0] - this.csvCoor[c][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) / 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(this.csvCoor[c + 1][0] - this.csvCoor[c][0])).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); c++; // 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); } } EAction.handleUserMessage("ZDM-58: " + formatDateTime()); // 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); } addPolylinetoView(TempLineData, false, false, 0, FZXColor); i = i + 3; } EAction.handleUserMessage("ZDM-100: " + formatDateTime()); var di = getAssignDocumentInterface(0); if (!isNull(di)) { // di.regenerateScenes(); di.autoZoom(); } return true; }; FileZDM.prototype.saveCsvFile = function () { 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!"); } 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; } EAction.handleUserMessage("Starting to load ZDM file: " + file); //每次都去文件中的一行,然后输出读取到的字符串 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); } } } reader.close(); return true; }; FileZDM.prototype.applyRadius = function (startPoint, space) { for (var i = 0; i < this.newFZEntityData.length; i += 3) { if (i + 2 < this.newFZEntityData.length && this.newFZEntityData[i + 2][2] == 3) { // 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], startPoint[1] - 20], 12, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, true, false, 0); addLineToView([this.newFZEntityData[i][0], startPoint[1] - 40], [this.newFZEntityData[i + 2][0], startPoint[1] - 40], 0); } } } FileZDM.prototype.applySlope = function (startPoint, space) { // 节点的数组 var array = this.csvCoor; // 上一个节点的坐标 var lastPoint = undefined; var yMax = startPoint[1]; var yMin = startPoint[1] - space; for (var i = 0; i < array.length; i++) { var item = array[i]; if (i == 0) { // 第一次进来 lastPoint = item; continue; } var textAngle = undefined; var revers = 1; if (lastPoint && item[1] > lastPoint[1]) { addLineToView([lastPoint[0] / this.ratio, yMin], [item[0] / this.ratio, yMax], 0); textAngle = Math.atan((yMax - yMin) / ((item[0] - lastPoint[0]) / this.ratio)); revers = 1; } else if (lastPoint && item[1] <= lastPoint[1]) { addLineToView([lastPoint[0] / this.ratio, yMax], [item[0] / this.ratio, yMin], 0); textAngle = Math.atan((yMin - yMax) / ((item[0] - lastPoint[0]) / this.ratio)); revers = -1; } // 计算斜率 var angle = (item[1] - lastPoint[1]) / (item[0] - lastPoint[0]); var x = (lastPoint[0] + (item[0] - lastPoint[0]) * 1 / 2) / this.ratio; var y = yMax - space * 1 / 2; if (revers == 1) { addSimpleTextToView((round(angle * 1000 * 1000) / 1000).toString(), [x - 2, y + 8], 7, rad2deg(textAngle || 0), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0); addSimpleTextToView((round((item[0] - lastPoint[0]) * 1000) / 1000).toString(), [x - 2, y - 4], 7, rad2deg(textAngle || 0), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0); } else { addSimpleTextToView((round(angle * 1000 * 1000) / 1000).toString(), [x + 2, y + 8], 7, rad2deg(textAngle || 0), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0); addSimpleTextToView((round((item[0] - lastPoint[0]) * 1000) / 1000).toString(), [x - 2, y - 4], 7, rad2deg(textAngle || 0), "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0); } // 绘画竖线 addLineToView([item[0] / this.ratio, yMax], [item[0] / this.ratio, yMin], 0); addSimpleTextToView("+" + (round((item[0]) * 1000) / 1000).toString(), [item[0] / this.ratio - 10, y - 25], 7, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0); addSimpleTextToView((round((item[1] - lastPoint[1]) * 1000) / 1000).toString(), [item[0] / this.ratio + 6, y - 25], 7, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0); lastPoint = item; } }