scotttest.js 15.9 KB
Newer Older
Scott Sun's avatar
Scott Sun committed
1 2
/*
NAME: 
Scott Sun's avatar
Scott Sun committed
3
DESCRIPTION: 锣带输出;
Scott Sun's avatar
Scott Sun committed
4
PARAMETER:
Scott Sun's avatar
Scott Sun committed
5
    [
Scott Sun's avatar
Scott Sun committed
6 7 8 9 10 11 12 13 14 15 16 17 18
		{
            name : 'auto_save',
			title : '自动保存',
            type : 'RadioBox',
            property : {
				item_list:[
					{name:'yes',text:'YES'},
					{name:'no',text:'NO'},
				],
				tool_tip:'是否自动保存料号开关'
			}
        }
	]
Scott Sun's avatar
Scott Sun committed
19
	
Scott Sun's avatar
Scott Sun committed
20
 VERSION_HISTORY:
Scott Sun's avatar
Scott Sun committed
21
	V1.00 2020-09-01 Scott Sun
Scott Sun's avatar
Scott Sun committed
22 23 24
	    1.新版本
		
 HELP:
Scott Sun's avatar
Scott Sun committed
25
 	<html><body bgcolor="#DDECFE">
Scott Sun's avatar
Scott Sun committed
26
		<font size="3" color="#003DB2"><p>功能简介</p></font>
Scott Sun's avatar
Scott Sun committed
27
		<p> 锣带输出 </p>
Scott Sun's avatar
Scott Sun committed
28 29
		<br>
		<font size="3" color="#003DB2"><p>参数配置</p></font>
Scott Sun's avatar
Scott Sun committed
30
		<p> step信息 </p>
Scott Sun's avatar
Scott Sun committed
31 32 33 34 35 36
		<br>
		<font size="3" color="#003DB2"><p>注意事项</p></font>
		<p> 无 </p>
		<br>
	</body></html>	
*/
Scott Sun's avatar
Scott Sun committed
37 38
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
Scott Sun's avatar
Scott Sun committed
39
console.log("==============================>template");
Scott Sun's avatar
Scott Sun committed
40 41 42 43 44 45 46 47 48 49 50
// 引入模块 包
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm; 
if (IKM==undefined ) { IKM = require('topcam.ikm6')($) }
var GEN = $.gen;
var GUI = $.gui || {};
var Job = $.job || $.job_name;
var JobId = $.job_id;
Scott Sun's avatar
Scott Sun committed
51
var db = $.db || IKM.db
Scott Sun's avatar
Scott Sun committed
52
var PAR = {}
Scott Sun's avatar
Scott Sun committed
53
if ($.par) { PAR = $.par } else if ($.hasOwnProperty('script_parameter')){ PAR = JSON.parse($.script_parameter); }
Scott Sun's avatar
Scott Sun committed
54 55 56 57 58 59
if (mode === "aimdfm") {
	var database = require("topsin.database");
	database.addConnection($.conf.database_conf, "DFM");
	var QDfm = database.query("DFM");
	$.QDfm = QDfm;
	if ($.conf.product_type == "aimdfm") {
Scott Sun's avatar
Scott Sun committed
60
		QDfm.updateRow({ table: "pdm_aimdfm_task", data: { current_process_title: $.process_title }, where: { id: $.task_id } });
Scott Sun's avatar
Scott Sun committed
61 62
	}
}
Scott Sun's avatar
Scott Sun committed
63 64 65
require("topsin.genmath")
var genMath = new GenMath();
var gui = new NewGUI(GUI);
Scott Sun's avatar
Scott Sun committed
66 67
var Status = 'ok';
var resultData = [];
Scott Sun's avatar
Scott Sun committed
68 69 70
var par = PAR;
var default_par = {
	auto_save: "No",
Scott Sun's avatar
Scott Sun committed
71
	step:"orig",
Scott Sun's avatar
Scott Sun committed
72 73 74 75 76
	units:"mm"
}
for(var key in default_par){ if (!par.hasOwnProperty(key) || par[key] == ""){ par[key] = default_par[key] }}
var job = Job;
var Step;
Scott Sun's avatar
Scott Sun committed
77 78
var rou_layer = [];

Scott Sun's avatar
Scott Sun committed
79
try {
Scott Sun's avatar
Scott Sun committed
80
	if(_.isEmpty(job)){throw "参数job不存在"} else { job = job.toLowerCase() }
Scott Sun's avatar
Scott Sun committed
81
	if(!GEN.isJobExists({job:job})){throw "料号"+job+"不存在"}
Scott Sun's avatar
Scott Sun committed
82
	
Scott Sun's avatar
Scott Sun committed
83 84 85
	// 选择工作step
	var workstep = getWorkStep()
	if(workstep.length == 0){throw "未找到工作step"}
Scott Sun's avatar
Scott Sun committed
86
	
Scott Sun's avatar
Scott Sun committed
87 88 89
	workstep.forEach(function(step){
		Step = step;
		GEN.openStep({job:Job,name:step});
Scott Sun's avatar
Scott Sun committed
90 91 92 93 94
		GEN.clearLayers();
		GEN.affectedLayer( {mode:'all',affected:'no'} );
		GEN.COM( "sel_options,clear_mode=clear_after,display_mode=all_layers,area_inout=inside,area_select=select,select_mode=standard,area_touching_mode=exclude");
		GEN.zoomHome();

Scott Sun's avatar
Scott Sun committed
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
		var layer = "gtl";

		GEN.workLayer({name:layer,display_number:2,clear_before:'yes'})
		var drl_layer = layer + "_drl"
		if(GEN.isLayerExists({job:job, layer:drl_layer})){GEN.deleteLayer({job:job, layer:drl_layer})}
		GEN.createLayer({job:job,layer:drl_layer,type:'drill'})
		GEN.selCopyOther({dest:'layer_name',target_layer:drl_layer,invert:'no',dx:0,dy:0,size:0})


		if(GEN.isChklistExists({job:job,step:step,chklist:'tmp_chk'})){
			GEN.COM("chklist_delete,chklist=tmp_chk")
		}
		GEN.COM("chklist_create,chklist=tmp_chk")
		GEN.COM("chklist_show,chklist=tmp_chk")
		GEN.COM("chklist_single,action=valor_analysis_drill,show=yes")
		GEN.COM("chklist_pclear")
		GEN.COM("chklist_cupd,chklist=valor_analysis_drill,nact=1,params=((pp_drill_layer="+drl_layer+
		")(pp_rout_distance=200)(pp_tests=Hole Separation)(pp_extra_hole_type=Pth\;Via)(pp_use_compensated_rout=Skeleton)),mode=regular")
		GEN.COM("chklist_pcopy,chklist=valor_analysis_drill,nact=1")
		GEN.COM("chklist_ppaste,chklist=tmp_chk,row=0")
		GEN.COM("chklist_run,chklist=tmp_chk,nact=1,area=profile")
		GEN.COM("chklist_close,chklist=valor_analysis_drill,mode=hide")
		GEN.COM("chklist_close,chklist=tmp_chk,mode=hide")
		GEN.deleteLayer({job:job, layer:drl_layer})
		var meas = GEN.getCheckMeas({job:job,step:step,chklist:'tmp_chk',nact:1})
		meas = ["touchh gtl_drl 1.302 mil r5.315 r5.512 SG 2.0707502 6.2600882 2.0695853 6.2595058 1 R",
		 "touchh gtl_drl 3.222 mil r5.315 r5.512 SG 2.0915237 6.2635829 2.0883541 6.2641619 1 R", 
		 "closeh gtl_drl 11.209 mil r5.512 r5.512 SG 2.0849209 6.2506255 2.0876766 6.2614906 1 R",
		 "closeh gtl_drl 11.828 mil r5.315 r5.512 SG 2.0904016 6.2611739 2.085407 6.2504523 1 R", 
		 "closeh gtl_drl 12.656 mil r5.315 r5.512 SG 2.0733393 6.2606873 2.0856692 6.2635406 1 Y", 
		 "closeh gtl_drl 12.733 mil r5.315 r5.512 SG 2.0727262 6.2583112 2.0821941 6.2497969 1 Y", 
		 "closeh gtl_drl 13.151 mil r5.512 r5.512 SG 2.0820787 6.2496599 2.0717499 6.2578 1 Y", 
		 "closeh gtl_drl 13.826 mil r5.512 r5.512 SG 2.0722601 6.2601694 2.0856793 6.2634983 1 Y", 
		 "closeh gtl_drl 15.75 mil r5.315 r5.315 SG 2.0733709 6.260529 2.0889031 6.263142 1 G", 
		 "closeh gtl_drl 16.901 mil r5.315 r5.512 SG 2.088911 6.2630973 2.0722949 6.2600094 1 G", 
		 "overlap_width gtl_drl 2.191 mil r5.315 r5.512 SG 2.0889095 6.2640604 2.0910652 6.2636666 1 R", 
		 "overlap_width gtl_drl 4.111 mil r5.315 r5.512 SG 2.0683732 6.2588998 2.0720503 6.2607382 1 R"
		]
	
		meas = meas.filter(function(v){return /^touch/.test(v)})
		if(meas.length){
			meas.forEach(function(v){
				var tmparr = v.split(" ")
				GEN.COM("sel_net_feat,operation=select,x="+tmparr[7]+",y="+tmparr[8]+",use_ffilter=no")
				if(GEN.getSelectCount() > 0){GEN.selDelete()}
			})
Scott Sun's avatar
Scott Sun committed
141 142
		}
	})
Scott Sun's avatar
Scott Sun committed
143

Scott Sun's avatar
Scott Sun committed
144 145
	// 保存 
	if(/yes/ig.test(par.auto_save)){GEN.checkInout({job:job,mode:"out"}); GEN.saveJob({ job: job });GEN.checkInout({job:job,mode:"in"});GEN.closeJob({job:job});} else {GEN.checkInout({job:job,mode:"in"})}
Scott Sun's avatar
Scott Sun committed
146 147
	if (mode === "aimdfm") {
		$.QDfm.updateRow({table: "pdm_aimdfm_task",data: {progress: 33.33},where: { id: $.task_id }});
Scott Sun's avatar
Scott Sun committed
148
		if (GEN.hasError()) { Status = 'error';resultData.push({ type: "error", title: "GEN错误!", detail: [{ desc: _.join(GEN.STATUS, "\n") }] });
Scott Sun's avatar
Scott Sun committed
149
			return {status: Status,result_data: resultData};
Scott Sun's avatar
Scott Sun committed
150 151
		} else { resultData.push({ type: "info", title: "操作完成, 请注意检查!" }); return {status: Status,result_data: resultData}; }
	}else { return "Done" }
Scott Sun's avatar
Scott Sun committed
152
} catch (e) {
Scott Sun's avatar
Scott Sun committed
153
	IKM.msg(_.join(GEN.STATUS, "\n"));IKM.msg(e);Status = 'error';
Scott Sun's avatar
Scott Sun committed
154 155
    resultData.push({type: "error", title: "脚本执行出错!", detail: [{desc: _.toString(e)}]});
    return (mode === "aimdfm") ? {status: Status, result_data: resultData} : "Error";
Scott Sun's avatar
Scott Sun committed
156
}
Scott Sun's avatar
Scott Sun committed
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

function NewGUI (gui) {
    this.msgBox = function(props){ // title  type  content  button
        props = props || {}
        return gui.msgBox(props.title || "title",props.type || "info",props.content || "content",props.button || ["ok", "cancel"]);
    }
    this.selectFromTreeview = gui.selectFromTreeview
    this.selectFile = function(props){ // "choose something", "*", true, "file", "/home/abby/fast_io"
        props = props || {}
        return gui.selectFile(props.title || "choose something",props.filter || "*",props.multiple || false, "file","");
    }
    this.selectSingle = function(props) {
        props = props || {}
        return gui.selectSingle({
            "title": props.title || "select",
            "list": props.list || [],
            "default": props["default"] || "",
            "columns": props.columns || 2,
            "gen":props.gen || GEN
        });
    }
    this.selectMultiple = function(props) {
        props = props || {}
        return gui.selectMultiple({
            "title": props.title || "select",
            "list": props.list || [],
            "defaultvalue": props["defaultvalue"] || [""],
            "defaultsize": props["defaultsize"] || [200, 100],
            "columns": props.columns || 2,
            "gen":props.gen || GEN
        });
    }
    this.selectFromTable = gui.selectFromTable
    this.snapScreen = gui.snapScreen
    this.imageViewer = gui.imageViewer
    this.inputBox = gui.inputBox
    this.showForm = gui.showForm
    this.lockUnlockLayer = function(props){
        props = props || {}
        var tmp = {}
        if (props.matrix) {
            for (var key in props.matrix) {
                var item = props.matrix[key]
                tmp[key] = {
                    row : item.row,
                    name : item.name
                }
            }
        }
        return gui.lockUnlockLayer({
            title: props.title || "lockUnlockLayer",
            layermatrix:props.layermatrix || tmp 
        })
    } 
    this.passwordBox = function(props){
        props = props || {}
        return gui.passwordBox({title:props.title || "password", password:props.password || "1212"})
    } 
    this.selectJobLayer = function (props) {
        props = props || {}
        return gui.selectJobLayer({
            layertypelist: props.layertypelist || [
                {name: "all", display_name: "all", filter: function(x) { return x }},
                {name: "signal", display_name: "signal", filter: function(x) { return x["layer_type"] === "signal"; }},
                {name: "power_ground", display_name: "power_ground", filter: function(x) { return x["layer_type"] === "power_ground"; }},
                {name: "mixed", display_name: "mixed", filter: function(x) { return x["layer_type"] === "mixed"; }},
                {name: "solder_mask", display_name: "solder_mask", filter: function(x) { return x["layer_type"] === "solder_mask"; }},
                {name: "silk_screen", display_name: "silk_screen", filter: function(x) { return x["layer_type"] === "silk_screen"; }},
                {name: "solder_paste", display_name: "solder_paste", filter: function(x) { return x["layer_type"] === "solder_paste"; }},
                {name: "drill", display_name: "drill", filter: function(x) { return x["layer_type"] === "drill"; }},
                {name: "rout", display_name: "rout", filter: function(x) { return x["layer_type"] === "rout"; }},
                {name: "document", display_name: "document", filter: function(x) { return x["layer_type"] === "document"; }}
            ],
            //defaultlayertype: "ha",
            joblist: props.joblist || [],
            defaultJob: props.defaultJob || [], // select by default
            steplist: props.steplist || [],
            // defaultstep: "step3",
            showstep: props.showstep || true,
            selectmode: props.selectmode || "multiple", // single/multiple
            layermatrix: props.layermatrix || {  },
            defaultlayer: props.defaultlayer || []
        })
    }
}

Scott Sun's avatar
Scott Sun committed
243 244 245 246 247 248
function getWorkStep(props){
	var steplists = GEN.getStepList({job:job});
	if(steplists.length == 0){return "该料号没有step"}
	var steps_tmp = steplists.filter(function(name){
		var reg = new RegExp(par.step, "ig")
		return reg.test(name)
Scott Sun's avatar
Scott Sun committed
249
	})
Scott Sun's avatar
Scott Sun committed
250 251 252 253 254 255 256 257 258
	if(steplists.length == 0){return "根据脚本参数过滤出来的step不存在,请检查资料或者脚本参数配置!"}
	var workstep = gui.selectMultiple({
		title: "请先择工作step",
		size:[200,100],
		defaultsize:[200,100],
		list: steplists.map(function(v){ var tmp = {}; tmp[v] = v ;return tmp}),
		defaultvalue: steps_tmp,
		columns: 1,
		gen: GEN
Scott Sun's avatar
Scott Sun committed
259
	})
Scott Sun's avatar
Scott Sun committed
260 261
	if(workstep.length == 0 ) {return "没有先择step"}
	return workstep
Scott Sun's avatar
Scott Sun committed
262 263
}

Scott Sun's avatar
Scott Sun committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277
// rou输出
function output_rou(par) {
	var info = par.info;
	// var PL = GEN.getProfileLimits({job:Job,step:Step,units:'mm'});
	var nc_set = 'zda';
	var machine = 'sintai_excellon';
	var layers = [];
	for (var key in info.layer_info) {
		layers.push(info.layer_info[key])
	}
	layers.forEach(function(layer){
		if(/^yes$/i.test(layer.output_flag)){
			if(GEN.getNcsetsList({job:Job,step:Step,layer:layer.layer_name}).indexOf(nc_set) >= 0) {
				GEN.COM('ncrset_delete',{name:nc_set});
Scott Sun's avatar
Scott Sun committed
278
			}
Scott Sun's avatar
Scott Sun committed
279 280 281 282 283 284
			GEN.COM('ncrset_cur',{job:Job,step:Step,layer:layer.layer_name,ncset:nc_set});
			GEN.COM('ncr_set_machine',{machine:machine,thickness:0});
			GEN.COM('ncr_register',{angle:0,mirror:layer.is_mirror,xoff:0,yoff:0,version:1,xorigin:0,yorigin:0,xscale:layer.scale_x,yscale:layer.scale_y,xscale_o:0,yscale_o:0});
			GEN.COM('ncr_cre_rout');
			GEN.COM('ncr_ncf_export',{dir:info.output_path,name:layer.layer_name});
			GEN.COM('ncrset_delete',{name:nc_set});
Scott Sun's avatar
Scott Sun committed
285 286
		}
	})
Scott Sun's avatar
Scott Sun committed
287
}
Scott Sun's avatar
Scott Sun committed
288

Scott Sun's avatar
Scott Sun committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
// 用户配置参数
function confirm_gui(par) {
	var rows={},n=0;
	// var cam = IKM.get_jobinfo({jobname:Job,jobid:JobId,jobcategory:'work',jobinfo:'cam_serial_number',withspec:1});
	var folder = 'rou';
	var path = PAR.Outpath+"/"+folder;
	fs.mkdir(path)
	par.layers.forEach(function(layer){
		n++;
		rows[n] = {};
		rows[n].sequence = n;
		rows[n].layer_name = layer;
		rows[n].scale_x = 1;
		rows[n].scale_y = 1;
		rows[n].output_flag = 'Yes';
		rows[n].is_mirror = 'no';
Scott Sun's avatar
Scott Sun committed
305
	})
Scott Sun's avatar
Scott Sun committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
	rows.output_path = path;
	// var v_data = GUI.showForm({
	// 	title:"Rou输出参数确认单",
	// 	defaultsize:[520,500],
	// 	items: [
	// 		{
	// 			type : 'title',
	// 			property:{
	// 				title:'输出料号和名称',
	// 			},	
	// 			n_columns:2,
	// 		},
	// 		{
	// 			type : 'title',
	// 			property:{
	// 				title:'参数确认',
	// 			},	
	// 			n_columns:8,
	// 		},
	// 		{
	// 			name : 'layer_info',
	// 			label :'参数确认',
	// 			label_position : 'no',
	// 			"class" : 'TL::Gtk2::TableFormPanel',
	// 			expand : 1,
	// 			property : {
	// 				tl_columns :[
	// 					{
	// 						column_name:'layer_name',
	// 						label:'层别名称',
	// 						width:100,
	// 						type:'label',
	// 					},
	// 					{
	// 						column_name:'scale_x',
	// 						label:'涨缩值X',
	// 						width:80,
	// 						type:'number',
	// 						must_field:1,
	// 					},
	// 					{
	// 						column_name:'scale_y',
	// 						label:'涨缩值Y',
	// 						width:80,
	// 						type:'number',
	// 						must_field:1,
	// 					},
	// 					{
	// 						column_name:'output_flag',
	// 						label:'是否输出',
	// 						width:80,
	// 						type:'radio',
	// 						property:{
	// 							tl_columns : 2,  
	// 							tl_list : [{'Yes' : '是'}, {'No':'否'}],   
	// 						},
	// 					},
	// 					{
	// 						column_name:'is_mirror',
	// 						label:'是否镜像',
	// 						width:80,
	// 						type:'radio',
	// 						property:{
	// 							tl_columns : 2,  
	// 							tl_list : [{'yes' : '是'}, {'no':'否'}],   
	// 						},
	// 					}
	// 				],
	// 				tl_rows:rows,
	// 			},
	// 			set_value_func : function(par){
	// 				var data = par.value;
	// 				Object.keys(data).forEach(function(row_name){
	// 					Object.keys(data[row_name]).forEach(function(col_name){
	// 						par.widget.set_value(row_name,col_name,data[row_name][col_name]);
	// 					})
	// 				})
	// 			},
	// 			get_value_func : function(par){return par.widget.get_all_value();},
	// 		},
	// 		{
	// 			type : 'title',
	// 			property:{
	// 				title:'输出设置',
	// 			},	
	// 			n_columns:1,
	// 		},
	// 		{
	// 			name : 'username',
	// 			label : '输出者:',
	// 			type : 'string',
	// 			value:GEN.getUserName(),
	// 			width:100,
	// 			must_field:1,
	// 		},
	// 		{
	// 			name : 'output_path',
	// 			label : '输出路径:',
	// 			type : 'string',
	// 			value:path,
	// 			width:100,
	// 			must_field:1,
	// 			property : {
	// 				editable:0,
	// 			},
	// 			buttons : [
	// 				{   
	// 					name:'btn1',label:'选择路径',stock:'gtk-add',
	// 					command:function(par){
	// 						var folder = GUI.select_file({title:'选择路径',type:'select-folder',defaultdir:PAR.Outpath});
	// 						if(!folder){return}
	// 						p.formpanel.set_value('output_path', folder);
	// 					}
	// 				},
	// 			],
	// 		},
	// 	]
	// });
	return rows;
Scott Sun's avatar
Scott Sun committed
425 426
}

Scott Sun's avatar
Scott Sun committed
427 428
// 文件导入设置
function input_layers(par) {
Scott Sun's avatar
Scott Sun committed
429
	var info = par.info;
Scott Sun's avatar
Scott Sun committed
430 431 432 433 434 435 436 437 438 439 440 441 442 443
	var layers = [];
	for (var key in info.layer_info) {
		layers.push(info.layer_info[key])
	}
	layers.forEach(function(lyr){
		if(/yes/i.test(lyr.output_flag)){
			var name = info.output_path+'/'+lyr.layer_name;
			var layer= lyr.layer_name.toLowerCase();
			GEN.COM("input_manual_reset");
			GEN.COM("input_manual_set,path="+name+",job="+par.job+",step="+par.step+
			",format=Excellon2,data_type=ascii,units=mm,coordinates=absolute,zeroes=none,nf1=3,nf2=3,decimal=no,separator=nl,tool_units=mm,layer="+layer
			+",wheel=,wheel_template=,nf_comp=0,multiplier=1,text_line_width=0.0024,signed_coords=no,break_sr=yes,drill_only=no,merge_by_rule=no,threshold=200,resolution=3");
			GEN.COM("input_manual,script_path=");
			GEN.COM("matrix_layer_context,job="+par.job+",matrix=matrix,layer="+layer+",context=misc");
Scott Sun's avatar
Scott Sun committed
444 445 446
		}
	})
}