-
Notifications
You must be signed in to change notification settings - Fork 1
/
getset_masteritems_meas.js
127 lines (113 loc) · 4.2 KB
/
getset_masteritems_meas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Converts master item measures
const enigma = require('enigma.js');
const WebSocket = require('ws');
const schema = require('enigma.js/schemas/3.2.json');
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs');
const gh = require('./getset_helper_functions');
if ( argv.hasOwnProperty("h") || !argv.hasOwnProperty("m") || !argv.hasOwnProperty("a")) {
console.log('\nUsage: node getset_masteritems_meas.js -m=read/write/undo -a appname');
console.log('Usage: node -h => this message.\n');
process.exit(1);
}
// Global variables for the app handle and the updates to be made
let app_glob;
let numberOfMasterMeas = 0;
let appname = argv.a; // 'LabelExtract_small.qvf'
var mode = argv.m; // read write undo
let id_counter = 100000;
var logger = fs.createWriteStream(appname.replace(".qvf","") + '_ms_meas.csv', { flags: 'w' });
function writeLine(string) {
if (gh.isString(string) && string.length > 0 ) {
logger.write(string + '\n');
}
};
// First, count objects to modify
const count_session2 = enigma.create({schema,url: 'ws://localhost:9076/app/engineData',createSocket: url => new WebSocket(url)});
count_session2.open()
.then(global => global.openDoc(appname))
.then(app => {
return app.createSessionObject({
qMeasureListDef: { qType: 'measure', qData: { id: "/qInfo/qId" } },
qInfo: { qType: 'MeasureList'}
});
})
.then(list => list.getLayout())
.then(masterlayout => {
numberOfMasterMeas = masterlayout.qMeasureList.qItems.length;
count_session2.close()
.then(() => {
console.log('Master meas: ' + numberOfMasterMeas);
})
});
// Master measures
const session2 = enigma.create({schema,url: 'ws://localhost:9076/app/engineData',createSocket: url => new WebSocket(url)});
session2.open()
.then(global => global.openDoc(appname))
.then(app => {
app_glob = app;
return app.createSessionObject({
qMeasureListDef: { qType: 'measure', qData: { id: "/qInfo/qId" } },
qInfo: { qType: 'MeasureList'}
});
})
.then(list => list.getLayout())
.then(masterlayout => {
masterlayout.qMeasureList.qItems.map(function(meas) {
app_glob.getMeasure(meas.qInfo.qId)
.then(obj => {
return Promise.all([obj.getProperties(),obj])
})
.then(([visprop,obj]) => {
// Master measure label
// New key, expr in string
if( (!(visprop.qMeasure.hasOwnProperty("qLabelExpression")) || visprop.qMeasure.qLabelExpression == "" ) &&
visprop.qMetaDef.title != "" ) {
writeLine(visprop.qMetaDef.title);
if ( mode == 'write' ) {
visprop.qMeasure.qLabelExpression = gh.toTransString(visprop.qMetaDef.title);
}
} else {
if ( mode == 'undo' && gh.isTransString(visprop.qMeasure.qLabelExpression) ) {
visprop.qMetaDef.title = gh.revertString(visprop.qMeasure.qLabelExpression);
delete visprop.qMeasure.qLabelExpression;
}
}
// Master measure description
// New key, expr struct
if( (!(visprop.qMeasure.hasOwnProperty("descriptionExpression")) || visprop.qMeasure.descriptionExpression == "") &&
visprop.qMetaDef.description != "" ) {
writeLine(visprop.qMetaDef.description);
if ( mode == 'write' ) {
visprop.qMeasure.descriptionExpression = gh.strToExpr(visprop.qMetaDef.description);
}
} else {
if ( mode == 'undo' && visprop.qMeasure.hasOwnProperty("descriptionExpression") &&
gh.isTransString(visprop.qMeasure.descriptionExpression.qStringExpression.qExpr) ) {
visprop.qMetaDef.description = gh.revertString(visprop.qMeasure.descriptionExpression.qStringExpression.qExpr);
delete visprop.qMeasure.descriptionExpression;
}
}
obj.setProperties(visprop)
.then(() => {
numberOfMasterMeas = numberOfMasterMeas - 1;
if ( numberOfMasterMeas == 0 ) {
if ( mode == "read" ) {
session2.close()
.then(() => {
logger.end();
console.log('Session closed');
});
} else {
app_glob.doSave()
.then(() => session2.close())
.then(() => {
logger.end();
console.log('App saved, session closed');
})
}
}
})
})
})
});