| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- /**
- * 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("scripts/Misc/MiscIO/MiscIO.js");
- //include("scripts/File/File.js");
- /**
- * SAX style XML handler.
- */
- /**
- * \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 ZDMDialogInput(guiAction) {
- EAction.call(this, guiAction);
- this.row = 0;
- this.newEntityData = new Array();
- this.newFZEntityData = new Array();
- this.newJPointData = new Array();
- this.csvCoor = new Array();
- this.allR = new Array();
- this.ratio = 10.0;
- // this.setUiOptions("ZDMDialogInput.ui");
- }
- ZDMDialogInput.prototype = new EAction();
- ZDMDialogInput.includeBasePath = includeBasePath;
- ZDMDialogInput.prototype.beginEvent = function() {
- EAction.prototype.beginEvent.call(this);
- var appWin = EAction.getMainWindow();
- this.dialog = this.createWidget(ZDMDialogInput.includeBasePath + "/ZDMDialogInput.ui", appWin);
- var tableWidget = this.dialog.findChild("tableWidget");
- tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch);//布局
- tableWidget.setHorizontalHeaderLabels(["K", "H", "R"]);
- tableWidget.cellPressed.connect(this, this.selectRow);
- // 添加一行
- var addBtn = this.dialog.findChild("addBtn");
- addBtn.clicked.connect(this, this.addClicked);
- // 删除一行
- var delBtn = this.dialog.findChild("delBtn");
- delBtn.clicked.connect(this, this.delClicked);
- // 计算绘图
- var calBtn = this.dialog.findChild("calBtn");
- calBtn.clicked.connect(this, this.calClicked);
- if (!this.dialog.exec()) {
- EAction.handleUserMessage("clicked~");
- destr(this.dialog);
- EAction.activateMainWindow();
- return undefined;
- }
- };
- // 添加行
- ZDMDialogInput.prototype.addClicked = function(){
- var tableWidget = this.dialog.findChild("tableWidget");
- tableWidget.insertRow(tableWidget.rowCount);
- };
- // 删除行
- ZDMDialogInput.prototype.delClicked = function(){
- var tableWidget = this.dialog.findChild("tableWidget");
- if (this.curRow == -1) {
- // EAction.handleUserMessage("111~");
- return;
- }else{
- tableWidget.model().removeRow(this.curRow);
- }
- };
- // 选择行
- ZDMDialogInput.prototype.selectRow = function(currentRow, curCol){
- this.curRow = currentRow;
- }
- // 计算绘图
- ZDMDialogInput.prototype.calClicked = function(){
- //首先获取表格内容,先试着保存到csv
- var tmpStr = RSettings.getStringValue("OpenProject/Current", RSettings.getDocumentsLocation()) + "/k_E_R_input.csv";
- var fileName = tmpStr;
- var file = new QFile(fileName);
- file.open(makeQIODeviceOpenMode(QIODevice.ReadWrite, QIODevice.Text));
- var stream = new QTextStream(file);
- var conTents="";
- // 写入头
- var tableWidget = this.dialog.findChild("tableWidget");
- var header = tableWidget.horizontalHeader();
- if (null != header)
- {
- for (var i = 0; i < header.count(); i++)
- {
- var item = tableWidget.horizontalHeaderItem(i);
- conTents += item.text();
- if(i < header.count() - 1){
- conTents += ",";
- }
- }
- conTents += "\n";
- }
- // 写内容
- for (var row = 0; row < tableWidget.rowCount; row++)
- {
- for (var column = 0; column < tableWidget.columnCount; column++)
- {
- var item = tableWidget.item(row, column);
- var str = item.text();
- conTents += str;
- if(column < tableWidget.columnCount - 1){
- conTents += ",";
- }
- }
- conTents += "\n";
- }
- stream.writeString(conTents);
- file.close();
- //调用
- var ok = this.convert(fileName);
- }
- ZDMDialogInput.prototype.convert = function(filename) {
- var process = new QProcess;
- EAction.handleUserMessage(ZDMDialogInput.includeBasePath + "/csv2zdm.exe");
- process.setProgram(ZDMDialogInput.includeBasePath + "/csv2zdm.exe");
- var args = [];
- args.push(filename);
- process.setArguments(args);
- process.start();
- process.waitForStarted(); //等待程序启动
- process.waitForFinished(-1);//等待程序关闭
- this.sFile = filename.substring(0, filename.lastIndexOf(".")) + ".zdm";
- var ok = this.readTxt(filename.substring(0, filename.lastIndexOf(".")) + ".zdm");
- if(ok){
- var tmp = RSettings.getStringValue("OpenDisplayFile/ZDMFile", "");
- RSettings.setValue("OpenDisplayFile/ZDMFile", tmp + "," + this.sFile);
- }
-
- return true;
- };
- ZDMDialogInput.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;
- };
- ZDMDialogInput.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);
- }
- }
- }
- this.applyOperation();
- reader.close();
- return true;
- };
|