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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
saveMeans({job:job,step:pcs_step,chklist:oChecklistName})
function mkPath(path, list) {
if (list.length) {
var newPath = path + '/' + list.shift()
if (!fs.dirExists(newPath)) {fs.mkdir(newPath)}
return mkPath(newPath, list)
} else {
return path
}
}
function saveMeans(props){
var job = props.job
var custstep = props.step
var chklist = props.chklist
var nact = props.nact
var jobpath = GEN.getJobPath({job: job})
var filter = props.filter
var afterPath = mkPath(jobpath, ["user", "opencam", "steps"])
var steps;
if (custstep) {
steps = [custstep]
} else {
steps = GEN.getStepList({job: job})
}
if(!steps || steps.length==0){
return
}
steps.forEach(function (step) {
var chkPath = mkPath(afterPath, [step, "chk"])
var chks
if (chklist) {chks = [chklist]}else {
chks = GEN.getChecklist({job: job,step: step})
}
if(chks && chks.length){
chks.forEach(function (item, i) {
var afterChkPath = mkPath(chkPath, [item])
var hdr = "{\n\
\"title\": \"" + item + "\",\n\
\"sequence\": " + (i + 1) + "\n\
}"
fs.writeFile(afterChkPath + "/hdr", _.toString(hdr))
var nacts = []
if (nact) {
nacts = [nact]
} else {
var nactCount = GEN.getChklistActCount({job:job,step:step,chklist:item})
for (var i = 0; i < nactCount; i++) {
nacts.push(i+1)
}
}
if(nacts.length > 0){
var actionPath = mkPath(afterChkPath, ["actions"])
nacts.forEach(function(index){
var titleFile = GEN.INFO({
entity_type: "check",
entity_path: job + "/" + step + "/" + item,
data_type: "TITLE",
options: "action=" + index,
parse:'no'
})
var title = fs.readFile(titleFile)
title = title.split("=")[1].trim()
title = title.substring(1, title.length-1)
var nackPath = mkPath(actionPath, [index+"-"+title])
fs.writeFile(nackPath + "/hdr", "{\n\
\"title\": \"" + (index + "-" + title) + "\",\n\
\"sequence\": " + index + ",\n\
\"dfm_name\": \"" + title + "\"\n\
}")
var displayFile = GEN.INFO({
entity_type: 'check',
entity_path: job + "/" + step + "/" + item,
data_type: 'MEAS_DISP_ID',
options: "action=" + index,
parse:'no'
});
fs.writeFile(nackPath + "/disp", fs.readFile(displayFile))
var measFile = GEN.INFO({entity_type:'check', entity_path:job+'/'+step+'/'+item, data_type:'MEAS', options:"index+action="+index, parse:'no'});
var means
if(filter){ // 处理过滤
var fileArray = []
var file = fs.openFile(measFile,'r');
while(!file.atEnd()) {
fileArray.push(file.readLine())
}
if(Array.isArray(filter)){
var nowFilter = filter.filter(function(item2){
for (var key in item2) {
var value = item2[key]
if (!Array.isArray(value)){
item2[key] = [value]
}
}
return item2.step.indexOf(step)>=0 && item2.chk.indexOf(item)>=0 && item2.nact.indexOf(index)>=0
})
if (nowFilter.length > 0){
var nowfilter = nowFilter.map(function(v){return v.filter}).reduce(function(a,b){
b.forEach(function(v2){
if (a.indexOf(v2)<0){
a.push(v2)
}
})
return a
},[])
fileArray = fileArray.filter(function(line){
var flag = false
nowfilter.forEach(function(f){
var reg = new RegExp(f, "ig")
if (reg.test(line)){
flag = true
}
})
return flag
})
}
} else if (typeof filter == "object") {
if (filter[step] && filter[step][item] && filter[step][item][String(index)]) {
var nowFilter = filter[step][item][String(index)]
if (!Array.isArray(nowFilter)){nowFilter = [nowFilter]}
fileArray = fileArray.filter(function(line){
var flag = false
nowFilter.forEach(function(f){
var reg = new RegExp(f, "ig")
if (reg.test(line)){
flag = true
}
})
return flag
})
}
}
means = fileArray.join("\n")
} else {
means = fs.readFile(measFile)
}
fs.writeFile(nackPath + "/meas", means)
})
}
})
}
})
}
// 自定义信息
saveCustChk({job:job,custChk:custChk})
function saveCustChk(props){
var job = props.job
var chkinfo = props.custChk
var path = mkPath(GEN.getJobPath({job: job}), ["user", "opencam", "steps"])
chkinfo.forEach(function(chk){
var ckpath = mkPath(path, [chk.step, "chk","custom_chk"])
// 写入action hdr
fs.writeFile(ckpath+"/hdr", "{\n\
\"title\": \"cust_chk\",\n\
\"sequence\": 0\n\
}")
var actionPath = mkPath(ckpath, ["actions"])
chk.action.forEach(function(action, i){
var nact = i + 1
var nactPath = mkPath(actionPath, [nact+"-"+action.name])
// nactPath 写入 meas hdr display
fs.writeFile(nactPath + "/hdr", "{\n\
\"title\": \"" + (nact + "-" + action.name) + "\",\n\
\"sequence\": " + nact + ",\n\
\"dfm_name\": \"" + action.name + "\"\n\
}")
if (Array.isArray(action.meas)){
action.meas = action.meas.map(function(mea, i){
return mea + " " + nact + " R " + String(i + 1)
})
action.meas = action.meas.join("\n")
} else {
action.meas = action.meas + " " + nact + " G " + 1
}
if (!/string/ig.test(typeof action.disp) ) {
action.disp = action.disp.workLayer + " "+ nact+" "+action.disp.showLayers.join(" ")
}
fs.writeFile(nactPath + "/disp", action.disp)
fs.writeFile(nactPath + "/meas", action.meas)
})
})
}