template.js 5.8 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
		{
			name : 'step',
			title : 'step',
			type : 'LineEdit',
Scott Sun's avatar
Scott Sun committed
10
			property : {tool_tip : '目标step,默认是orig'}
Scott Sun's avatar
Scott Sun committed
11 12
		},
		{
Scott Sun's avatar
Scott Sun committed
13
			name : 'auto_save',
Scott Sun's avatar
Scott Sun committed
14
			title : '自动保存',
Scott Sun's avatar
Scott Sun committed
15 16
			type : 'RadioBox',
			property : {
Scott Sun's avatar
Scott Sun committed
17 18 19 20 21 22
				item_list:[
					{name:'yes',text:'YES'},
					{name:'no',text:'NO'},
				],
				tool_tip:'是否自动保存料号开关'
			}
Scott Sun's avatar
Scott Sun committed
23
		}
Scott Sun's avatar
Scott Sun committed
24 25 26
	]
	
 VERSION_HISTORY:
Scott Sun's avatar
Scott Sun committed
27 28
	V1.00 2021-03-08 Scott Sun
		1.新版本
Scott Sun's avatar
Scott Sun committed
29 30
		
 HELP:
Scott Sun's avatar
Scott Sun committed
31
	  <html><body bgcolor="#DDECFE">
Scott Sun's avatar
Scott Sun committed
32
		<font size="3" color="#003DB2"><p>功能简介</p></font>
Scott Sun's avatar
s  
Scott Sun committed
33
		<p> 标题 </ p>
Scott Sun's avatar
Scott Sun committed
34 35 36 37 38 39 40 41 42
		<br>
		<font size="3" color="#003DB2"><p>参数配置</p></font>
		<p> step信息 </p>
		<br>
		<font size="3" color="#003DB2"><p>注意事项</p></font>
		<p> 无 </p>
		<br>
	</body></html>	
*/
Scott Sun's avatar
Scott Sun committed
43 44

// 引入模块 包 外部参数
Scott Sun's avatar
Scott Sun committed
45 46 47 48
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
Scott Sun's avatar
Scott Sun committed
49
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
Scott Sun's avatar
Scott Sun committed
50 51 52
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
Scott Sun's avatar
Scott Sun committed
53 54 55 56 57
var db = $.db || IKM.db;
var gui_piug = require('topsin.gengui');
var GUI = gui_piug.newGui(gui_piug.__dirname);
var PAR = {};
if ($.par) { PAR = $.par } else if ($.hasOwnProperty('script_parameter')) { PAR = JSON.parse($.script_parameter); }
Scott Sun's avatar
Scott Sun committed
58 59 60 61 62 63 64 65 66 67 68
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") {
		QDfm.updateRow({ table: "pdm_aimdfm_task", data: { current_process_title: $.process_title }, where: { id: $.task_id } });
	}
}
var Status = 'ok';
var resultData = [];
Scott Sun's avatar
Scott Sun committed
69 70 71
var par = PAR;  // 接收参数
var default_par = { // 设置默认参数
	step: "orig",
Scott Sun's avatar
Scott Sun committed
72
	auto_save: "No",
Scott Sun's avatar
Scott Sun committed
73 74 75 76 77 78
	units: "mm"
}
for (var key in default_par) {
	if (!par.hasOwnProperty(key) || par[key] == "") {
		par[key] = default_par[key]
	}
Scott Sun's avatar
Scott Sun committed
79
}
Scott Sun's avatar
Scott Sun committed
80 81

// 定义变量
Scott Sun's avatar
Scott Sun committed
82
var job = Job;
Scott Sun's avatar
Scott Sun committed
83

Scott Sun's avatar
Scott Sun committed
84
try {
Scott Sun's avatar
Scott Sun committed
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
	// 常规验证 准备工作

	if (!GEN.isJobExists({ job: job })) { throw "料号" + job + "不存在" }
	if (!GEN.isJobOpen({ job: job })) { GEN.openJob({ job: job }) }
	if (mode == "aimdfm") {
		if (GEN.checkInout({job: job,mode: "test"}) != 0) {
			throw "the job check"
		}
		GEN.checkInout({job: job,mode: "out"});
	}

	// 主体

	var stepList = GEN.getStepList({job:job})     // 工作step列表
	stepList = stepList.filter(function(step){
		var reg = new RegExp(par.step,"ig");
		return reg.test(step);
	})

    var verification = function(size) {
        return size <= 500
    }

    var drills = getLayer({layer_type:"drill",name:"drl"})

	stepList.forEach(function(step) {
        GEN.openStep({ job: job, name: step });
        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.units({ type: par.units }); //单位初始化
        GEN.zoomHome(); //窗口显示回到原始位置
		GEN.selClearFeature()
		drills.forEach(function(drl) {
            GEN.workLayer({name:drl,display_number:2,clear_before:'yes'})
            var sys = GEN.getLayerSymsHist({job:Job,step:'net',layer:drl,units:'mm'})
            var includesys = [];
            // r700":{"symbol":"r700","line":"0","pad":"400","arc":"0","size":"700"},
            Object.keys(sys).forEach(function(key){
                var symbolinfo = sys[key];
                if(!symbolinfo.size && symbolinfo.width){
                    symbolinfo.size = symbolinfo.width > symbolinfo.height ? symbolinfo.width : symbolinfo.height;
                }
                if(symbolinfo.size){
                    symbolinfo.size = symbolinfo.size - 0;
                    if(verification(symbolinfo.size)){
                        includesys.push(symbolinfo.symbol)
                    }
                }
            })
            if(includesys.length){
                GEN.selectByFilter({include_syms:includesys.join(";")})
                if(GEN.getSelectCount()>0){
                    GEN.COM("cur_atr_set,attribute=.drill,option=via")
                    GEN.COM("sel_change_atr,mode=add")
                }
            }
		})
	})
Scott Sun's avatar
s  
Scott Sun committed
144 145


Scott Sun's avatar
Scott Sun committed
146 147 148 149 150 151 152 153 154 155 156 157 158



	
	// 保存料号
	if (/yes/ig.test(par.auto_save)) { 
		GEN.checkInout({ job: job, mode: "out" }); 
		GEN.saveJob({ job: job }); 
	} 
	GEN.checkInout({ job: job, mode: "in" });
	
	// 结尾返回 固定写法
	var Return = "Done"
Scott Sun's avatar
Scott Sun committed
159
	if (mode === "aimdfm") {
Scott Sun's avatar
Scott Sun committed
160 161 162 163 164 165 166 167 168 169
		$.QDfm.updateRow({ table: "pdm_aimdfm_task", data: { progress: 100 }, where: { id: $.task_id } });
		var tmperr = { type: "info", title: "操作完成, 请注意检查!" }
		if (GEN.hasError()) {
			Status = 'error'; 
			tmperr = { type: "error", title: "GEN错误!", detail: [{ desc: GEN.STATUS.join("\n") }] }
		}
		resultData.push(tmperr);
		Return = { status: Status, result_data: resultData };
	}
	return Return
Scott Sun's avatar
Scott Sun committed
170
} catch (e) {
Scott Sun's avatar
Scott Sun committed
171 172 173 174 175 176 177 178
	if(GEN.STATUS.length > 0) {
		IKM.msg(GEN.STATUS.join("\n")); 
	}
	IKM.msg(e); 
	Status = 'error';
	resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
	return (mode === "aimdfm") ? { status: Status, result_data: resultData } : "Error";
}
Scott Sun's avatar
s  
Scott Sun committed
179 180


Scott Sun's avatar
Scott Sun committed
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

function getLayer(props){ // 获取层
    if (!props) {
    	return
    }
    if (!props.context) {
    	props.context = "board"
    }
    var matrix = GEN.getMatrix({job:job})
    return Object.keys(matrix).reduce(function(a,b){
        var info = matrix[b];
        var ret = true;
        for (var key in props) {
        	if (!Array.isArray(props[key])) {
        		props[key] = [props[key]]
        	}
        	if (info[key] && props[key].indexOf(info[key]) < 0) {
        		ret = false
        	}
        }
        if (ret) {
        	a.push(props.res == "info" ? info : b)
        }
        return a
    },[])
}