| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- include("scripts/Common/DrawingUtils.js");
- include("scripts/Common/FileCTRCSV.js");
- include("scripts/Common/FileDMX.js");
- include("scripts/Common/FileZDM.js");
- // 纵断面,地面线CTR
- // 有纵断面,画竖曲线半径和坡度
- // 有地面线才画设计高程,地面高程,里程桩号
- // 有CTR,才画桥梁,隧道
- function DrawZdmAll(ratio) {
- // 比例尺
- this.ratio = ratio || 10.0;
- this.frameColor = new RColor(255, 255, 0);
- }
- DrawZdmAll.prototype.applyPainting = function (layer, dmxFile, zdmFile, ctrFile, isCertCsv) {
- // 图层
- var layername = layer || getLayername("ZDM", zdmFile);
- addLayerToView(layername, "white", "CONTINUOUS", RLineweight.Weight025, 0);
- setCurrentLayer(layername);
- // 如果存在同名的DXF就直接在家DXF,解决ZDM加载慢的问题
- var dxfFile = zdmFile.replace(/.\w+$/i, ".dxf");
- var qFile = new QFile(dxfFile);
- if (qFile.exists()) {
- // 绘画到ZDM
- var di = getAssignDocumentInterface(0);
- var importFile = di.importFile(dxfFile, "", false);
- di.regenerateScenes();
- di.autoZoom();
- if (importFile !== RDocumentInterface.IoErrorNoError) {
- EAction.handleUserWarning(qsTr("Error while importing file %1").arg(dxfFile));
- }
- return true;
- }
- // qsTr("地面线文件") + " (*.dmx);"
- var fileDMX = new FileDMX(dmxFile, this.ratio);
- fileDMX.applyOperation();
- var dmxData = fileDMX.getArrayData();
- // qsTr("纵断面文件") + " (*.zdm);"
- var drawZdm = new FileZDM(zdmFile, this.ratio);
- // 线绘图在生成CSV文件
- drawZdm.applyOperation();
- if (isCertCsv) {
- drawZdm.saveCsvFile();
- }
- var zdmData = drawZdm.getZDMArray();
- // qsTr("桥梁 隧道") + " (*.ctr);"
- var fileCTR = new FileCTRCSV(ctrFile, this.ratio);
- fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
- fileCTR.applyTunnel(zdmData, new RColor(0, 128, 0));
- // 以下开始绘画表格数据
- var extreme_dmx = this.getExtremePosition(zdmData.length > 0 ? zdmData : dmxData);
- addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, this.frameColor);
- addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, this.frameColor);
- var startPoint = extreme_dmx[2];
- var endPoint = extreme_dmx[3];
- var text_width = 260;
- addPolylinetoView([[startPoint[0] - text_width, startPoint[1]], endPoint], false, false, 0, this.frameColor);
- var array = new Array();
- array.push({ name: "R", "space": 100, text: "竖曲线半径 (m)" });
- array.push({ name: "SJGC", "space": 100, text: "设计高程 (m)" });
- array.push({ name: "DMGC", "space": 100, text: "地面高程 (m)" });
- array.push({ name: "PDPC", "space": 100, text: "坡度 (%) 坡长 (m)" });
- array.push({ name: "BLZH", "space": 100, text: "百里桩号 (km)" });
- for (var i = 0; i < array.length; i++) {
- var item = array[i];
- var space = (item.space || 100);
- var text = (item.text || "").toString();
- addPolylinetoView([[startPoint[0] - text_width, startPoint[1] - space * (i + 1)], [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, this.frameColor);
- addSimpleTextToView(text, [startPoint[0] - text_width + 50, startPoint[1] - space * (i + 1) + 50], 15, 0, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- switch (item.name) {
- case "R":
- drawZdm.applyRadius([startPoint[0], startPoint[1] - space * i], space);
- break;
- case "SJGC":
- this.applyHeightMileage(dmxData, [startPoint[0], startPoint[1] - space * i], space);
- break;
- case "DMGC":
- this.applyHeightMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
- break;
- case "PDPC":
- drawZdm.applySlope([startPoint[0], startPoint[1] - space * i], space);
- break;
- case "BLZH":
- this.applyMileage(zdmData, [startPoint[0], startPoint[1] - space * i], space);
- break;
- }
- if (i == array.length - 1) {
- addPolylinetoView([startPoint, [startPoint[0], startPoint[1] - space * (i + 1)]], false, false, 0, this.frameColor);
- addPolylinetoView([endPoint, [endPoint[0], endPoint[1] - space * (i + 1)]], false, false, 0, this.frameColor);
- }
- }
- // 居中显示
- var di = getAssignDocumentInterface(0);
- if (!isNull(di)) {
- di.autoZoom();
- }
- return true;
- }
- DrawZdmAll.prototype.applyHeightMileage = function (arrayData, startPoint, spacetext) {
- var space = 50;
- var spaceDistance = 0;
- for (var i = 0; i < arrayData.length; i++) {
- if (i != 0) {
- spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
- }
- if (i != 0 && spaceDistance < space) {
- // 不足最小间距
- continue;
- }
- spaceDistance = 0;
- var text = (round((arrayData[i][1]) * 100) / 100).toString();
- addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - spacetext + 30], 15, 90, "宋体", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- }
- }
- DrawZdmAll.prototype.applyMileage = function (arrayData, startPoint, space) {
- // 记录里程
- var mileage = 0.0;
- // 最小间距
- var space_min = 30;
- var y = startPoint[1] - space;
- for (var i = 0; i < arrayData.length; i++) {
- var x = arrayData[i][0];
- var mileage_current = x;
- if (i == 0) {
- // 显示起始桩号
- addSimpleTextToView(formatStake(mileage_current), [x, y + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, y], [x, y + 5]], false, false, 0, new RColor(255, 255, 0));
- mileage = mileage_current;
- continue;
- }
- if (mileage_current - mileage > space_min) {
- // 绘画高程文本
- addSimpleTextToView((round((mileage_current % 1000) * 1000) / 1000).toString(), [x, y + (space * 1 / 3) - 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- }
- mileage = mileage_current;
- }
- // 绘制标准的百里标、千里表
- var start = arrayData[0][0];
- var end = arrayData[arrayData.length - 1][0];
- // 下一个百里标的位置
- var currentMiles = Math.ceil(start / 100) * 100;
- // 循环打印百里和千里位置
- while (currentMiles <= end) {
- if (currentMiles % 1000 === 0) {
- addSimpleTextToView("K" + Math.floor(currentMiles / 1000).toString(), [currentMiles, y + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[currentMiles, y], [currentMiles, y + 5]], false, false, 0, new RColor(255, 255, 0));
- } else if (currentMiles % 100 === 0) {
- var text = currentMiles - (Math.floor(currentMiles / 1000) * 1000);
- addSimpleTextToView(Math.floor(text / 100).toString(), [currentMiles, y + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[currentMiles, y], [currentMiles, y + 5]], false, false, 0, new RColor(255, 255, 0));
- }
- currentMiles += 100;
- }
- }
- DrawZdmAll.prototype.applyMileage_1010 = function (arrayData, startPoint, space) {
- var spaceDistance = 0;
- var bailiDistance = 0;
- var tenBailiDistance = 0;
- for (var i = 0; i < arrayData.length; i++) {
- if (i != 0) {
- spaceDistance = spaceDistance + (arrayData[i][0] - arrayData[i - 1][0]);
- bailiDistance = bailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
- tenBailiDistance = tenBailiDistance + (arrayData[i][0] - arrayData[i - 1][0]);
- }
- if (i == 0 || spaceDistance >= 50) {
- // 绘制桩号 必须满足最小间距
- spaceDistance = 0;
- var text = (round((arrayData[i][0] % 1000) * 1000) / 1000).toString();
- addSimpleTextToView(text, [arrayData[i][0], startPoint[1] - 50], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- }
- if (i == 0) {
- var x = arrayData[i][0];
- addSimpleTextToView("K" + (Math.floor(arrayData[i][0] / 1000) * 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
- } else if (tenBailiDistance > 1000) {
- // 千里标 K
- tenBailiDistance = tenBailiDistance % 1000;
- bailiDistance = bailiDistance % 100;
- var x = Math.floor(arrayData[i][0] / 1000) * 1000;
- addSimpleTextToView("K" + Math.floor(arrayData[i][0] / 1000).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space - 5]], false, false, 0, new RColor(255, 255, 0));
- } else if (bailiDistance > 100) {
- // 百里标
- bailiDistance = bailiDistance % 100;
- var x = Math.floor(arrayData[i][0] / 100) * 100;
- addSimpleTextToView(Math.floor(arrayData[i][0] / 100).toString(), [x, startPoint[1] - space + 10], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, startPoint[1] - space], [x, startPoint[1] - space + 5]], false, false, 0, new RColor(255, 255, 0));
- }
- }
- }
- DrawZdmAll.prototype.getExtremePosition = function (array) {
- var len = array.length;
- if (len == 0) {
- EAction.handleUserMessage("extreme data is empty...");
- return [[0, 0], [0, 0], [0, 0], [0, 0]];
- }
- var y_min = array[0][1];
- var y_max = array[0][1];
- for (var i = 0; i < len; i++) {
- y_min = Math.min(array[i][1], y_min);
- y_max = Math.max(array[i][1], y_max);
- }
- var padding = 0;
- var verPadding = 40
- return [
- // 左上
- [array[0][0] - padding, y_max + verPadding],
- // 右上
- [array[len - 1][0] + padding, y_max + verPadding],
- // 左下
- [array[0][0] - padding, y_min - verPadding],
- // 右下
- [array[len - 1][0] + padding, y_min - verPadding],
- ];
- };
|