| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- include("scripts/EAction.js");
- include("scripts/simple.js");
- function FileDMX(file, ratio) {
- // 地面线数据
- this.newEntityData = new Array();
- // 比例尺
- this.ratio = ratio || 1.0;
- // 图层名称
- this.layername = "DMX-" + Math.floor(Math.random() * 100);
- this.readTxt(file);
- }
- FileDMX.prototype.getArrayData = function () {
- return this.newEntityData;
- };
- FileDMX.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 DMX file: " + file);
- //每次都去文件中的一行,然后输出读取到的字符串
- var ts = new QTextStream(reader);
- setUtf8Codec(ts);
- //当读取出现错误(返回 -1)或者读取到的字符数为 0 时,结束读取
- do {
- var textLine = ts.readLine().trim();
- textLine = textLine.replace(/[\t]+/g, " ").replace(/[\s]+/g, " ");
- textLine = textLine.replace(/[ABC]/g, "").replace(/\r\n/g, "");
- var fields = textLine.split(" "); // Reserved: ',&[' & ';&['
- if (fields.length == 1) {
- fields = fields[0].split(",");
- }
- if (fields.length !== 2) {
- // With two extra fields >
- continue;
- } // End with two extra
- qDebug(parseFloat(fields[0]));
- qDebug(parseFloat(fields[1]));
- this.newEntityData.push([parseFloat(fields[0]) / this.ratio, parseFloat(fields[1])]);
- } while (!ts.atEnd());
- reader.close();
- return true;
- };
- FileDMX.prototype.applyOperation = function () {
- if (this.newEntityData.length == 0) {
- EAction.handleUserMessage("DMX data is empty...");
- return false;
- }
- EAction.handleUserMessage("DMX-50: " + formatDateTime());
- 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];
- //绘制多线段
- EAction.handleUserMessage("DMX-64: " + formatDateTime());
- 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]]);
- addPolylinetoView(TempLineData, false, false, 0, PDColor);
- }
- EAction.handleUserMessage("DMX-71: " + formatDateTime());
- return true;
- };
|