| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- include("scripts/EAction.js");
- include("scripts/simple.js");
- include("./FileCTR.js");
- include("./FileDMX.js");
- include("./FileZDM.js");
- function DMXImport() {
- }
- DMXImport.includeBasePath = includeBasePath;
- DMXImport.prototype.interface = function(fileName){
- this.fileName = fileName.substring(0,fileName.lastIndexOf("."))+".DMX";;
- try {
- var ok = this.applyPainting(this.fileName);
- } catch (error) {
- EAction.handleUserMessage("load file error: " + error.message.toString());
- EAction.handleUserMessage("load file error: " + error.stack.toString());
- }
- }
- DMXImport.prototype.applyPainting = function (file) {
- // qsTr("地面线文件") + " (*.dmx);"
- var fileDMX = new FileDMX();
- var tmp = fileDMX.readTxt(file);
- if(false == tmp) return;
- var dmxData = fileDMX.getArrayData();
- // qsTr("纵断面文件") + " (*.zdm);"
- var exZDMImport = new FileZDM(this.guiAction);
- tmp = exZDMImport.readTxt(file.replace(/.dmx$/i, ".ZDM"));
- if(false == tmp) return;
- var zdmData = exZDMImport.getZDMArray();
- // qsTr("桥梁 隧道") + " (*.ctr);"
- var fileCTR = new FileCTR();
- tmp = fileCTR.readTxt(file.replace(/.dmx$/i, ".CTR"));
- if(false == tmp) return;
- fileCTR.applyBridge(zdmData, dmxData, new RColor(31, 57, 197));
- fileCTR.applyTunnel(zdmData,new RColor(255, 255, 0));
- // 添加图层
- var newdate = new Date();
- newdate.getTime();
- addLayerToView(newdate.getTime().toString(), "white", "CONTINUOUS", RLineweight.Weight025, 0);
- setCurrentLayer(newdate.getTime().toString());
- // 以下开始绘画表格数据
- var extreme_dmx = this.getExtremePosition(dmxData);
- addPolylinetoView([extreme_dmx[0], extreme_dmx[2]], false, false, 0, new RColor(255, 255, 0));
- addPolylinetoView([extreme_dmx[1], extreme_dmx[3]], false, false, 0, new RColor(255, 255, 0));
- // 设计高程
- var startPoint = extreme_dmx[2];
- var endPoint = extreme_dmx[3];
- var boxPointArray = this.applyDrawBox(startPoint, endPoint, -200, -160, "", new RColor(255, 255, 0));
- startPoint = boxPointArray[0];
- endPoint = boxPointArray[1];
- // 设计高程
- this.applyHeightMileage(dmxData,startPoint,50);
- var boxPointArray = this.applyDrawBox(startPoint, endPoint, -200, -160, "SJGC (m)", new RColor(255, 255, 0));
- // 地面高程
- startPoint = boxPointArray[0];
- endPoint = boxPointArray[1];
- this.applyHeightMileage(zdmData,startPoint,50);
- var boxPointArray = this.applyDrawBox(startPoint, endPoint, -200, -160, "DMGC (m)", new RColor(255, 255, 0));
- // 百里桩号
- startPoint = boxPointArray[0];
- endPoint = boxPointArray[1];
- this.applyMileage(zdmData,startPoint);
- this.applyDrawBox(startPoint, endPoint, -200, -160, "LCZH", new RColor(255, 255, 0));
- };
- DMXImport.prototype.applyHeightMileage = function(arrayData,startPoint,space){
- space = space ? 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] - 80], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- }
- }
- DMXImport.prototype.applyMileage = function(arrayData,startPoint){
- 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] - 80], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- }
- if (i == 0) {
- var x = arrayData[i][0];
- addSimpleTextToView("K" + arrayData[i][0].toString(), [x, startPoint[1] - 130], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, startPoint[1] - 160],[x, startPoint[1] - 150]],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] - 130], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, startPoint[1] - 160],[x, startPoint[1] - 150]],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] - 130], 15, 90, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- addPolylinetoView([[x, startPoint[1] - 160],[x, startPoint[1] - 150]],false,false,0,new RColor(255, 255, 0));
- }
- }
- }
- DMXImport.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 = 20;
- return [
- // 左上
- [array[0][0] - padding, y_max + padding],
- // 右上
- [array[len - 1][0] + padding, y_max + padding],
- // 左下
- [array[0][0] - padding, y_min - padding],
- // 右下
- [array[len - 1][0] + padding, y_min - padding],
- ];
- };
- DMXImport.prototype.applyDrawBox = function (startPoint, endPoint, text_width, text_height, text, lineColor) {
- // addPolylinetoView([[startPoint[0] + text_width, startPoint[1]], endPoint], false, false, 0, lineColor);
- // addPolylinetoView([[startPoint[0] + text_width, startPoint[1] + text_height],[endPoint[0], endPoint[1] + text_height],],false,false,0,lineColor );
- // addPolylinetoView([[startPoint[0] + text_width, startPoint[1]],[startPoint[0] + text_width, startPoint[1] + text_height],],false,false,0,lineColor);
- // addPolylinetoView([[startPoint[0], startPoint[1]],[startPoint[0], startPoint[1] + text_height],],false,false,0,lineColor);
- // addPolylinetoView([[endPoint[0], endPoint[1]],[endPoint[0], endPoint[1] + text_height],],false,false,0,lineColor);
- addSimpleTextToView(text, [startPoint[0] + (text_width * 2) / 3, startPoint[1] + (text_height * 1) / 2], 15, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false, 0);
- return [
- [startPoint[0], startPoint[1] + text_height],
- [endPoint[0], endPoint[1] + text_height],
- ];
- };
|