| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- /**
- * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
- *
- * This file is part of the QCAD project.
- *
- * QCAD is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * QCAD is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with QCAD.
- */
- include("scripts/EAction.js");
- include("scripts/simple.js");
- include("../DMXImport/DMXImport.js")
- function ZDM() {
- this.newEntityData = new Array();
- this.newFZEntityData = new Array();
- this.newJPointData = new Array();
- this.csvCoor = new Array();
- this.allR = new Array();
- this.ratio = 10.0;
- }
- ZDM.includeBasePath = includeBasePath;
- ZDM.prototype.interface = function(fileName){
- this.fileName = fileName.substring(0,fileName.lastIndexOf("."))+".csv";
- var ok = this.convert(this.fileName);
- this.cvFile = this.fileName.substring(0,this.fileName.lastIndexOf("."))+"_op.zdm";
- var ok = this.readTxt(this.cvFile);
- if(ok){
- var tmp = RSettings.getStringValue("OpenDisplayFile/ZDMFile", "");
- RSettings.setValue("OpenDisplayFile/ZDMFile", tmp + "," + this.cvFile);
- var dmx = new DMXImport();
- dmx.interface(fileName);
- }
-
- }
- ZDM.prototype.convert = function (fileName) {
- var process = new QProcess;
- // 后台运行
- // process.start(ZDM.includeBasePath + "/railway_vertical_sw_V1-background.exe -f " + fileName + " -e " + ZDM.includeBasePath);
-
- // 阻塞运行
- EAction.handleUserMessage(ZDM.includeBasePath + "/railway_vertical_sw_V1.exe -f " + fileName + " -e " + ZDM.includeBasePath);
- process.setProgram(ZDM.includeBasePath + "/railway_vertical_sw_V1.exe");
- var args = [];
- var input1 = " -f ";
- args.push(input1);
- var input2 = fileName;
- args.push(input2);
- var input3 = " -e ";
- args.push(input3);
- var input4 = ZDM.includeBasePath;
- args.push(input4);
- process.setArguments(args);
- process.start();
- process.waitForStarted(); //等待程序启动
- process.waitForFinished(-1);//等待程序关闭
- return true;
- };
- ZDM.prototype.applyOperation = function (preview) {
- // 添加图层
- addLayerToView(this.cvFile, "white", "CONTINUOUS", RLineweight.Weight025,0);
- setCurrentLayer(this.cvFile);
- 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("."))+"_op.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;
- };
- ZDM.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;
- };
|