Commit fcb3acbc authored by Scott Sun's avatar Scott Sun

s

parent de2bd998
/*
NAME:
DESCRIPTION: 圆弧调整;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayers',
title : 'workLayers',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> 圆弧调整 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "cad",
auto_save: "No",
workLayers:"out",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
var workLayers = par.workLayers.split(";")
workLayers = workLayers.filter(function(l){return GEN.isLayerExists({job:job, layer:l})})
if(workLayers.length == 0) {
throw "没有找到工作层"
}
stepList.forEach(function (step) {
GEN.openStep({ job: job, name: step });
GEN.clearLayers(); //清除层显示
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.COM("sel_options, =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();
GEN.affectedLayer({affected:"yes", layer:workLayers});
// 现有做法:使用InCAM Pro 中的Simplify Lines/Arcs功能将连续的线段转化为弧或线
// 通过公差调整,但不能完全去除线段或圆弧(只是线段减少)
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
/*
NAME:
DESCRIPTION: chain;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayer',
title : '工作层',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> chain </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "array",
workLayer: "rou",
auto_save: "No",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
// {
// name : 'pth_compensation',
// title : 'PTH补偿',
// type : 'ComboBox',
// property : {
// item_list:[
// 'less_75um',
// '75_and_100um',
// '100_and_150um',
// '150_and_200um',
// ],
// tool_tip : 'PTH补偿'
// },
// },
var func = "function (props) {\
return GUI.showForm({\
title: 'Create array routing chain',\
size: '400x360',\
use_core_engine: true,\
include_hidden_items: true,\
items: {\
type: 'ScrollArea',\
property: {\
widget_resizable: true,\
frame_shape: 'NoFrame'\
},\
child: [{\
type: 'FormGridLayout',\
child: [{\
name: 'size',\
title: 'size(mm)',\
type: 'LineEdit'\
}, {\
name: 'comp',\
title: 'comp',\
type: 'ComboBox',\
property : {\
item_list:[\
'none',\
'right',\
'left',\
],\
tool_tip : 'comp'\
},\
}, {\
name: 'flag',\
title: 'flag',\
type: 'LineEdit'\
}, {\
name: 'feed',\
title: 'feed',\
type: 'LineEdit'\
}, {\
name: 'speed',\
title: 'speed',\
type: 'LineEdit'\
}]\
}]\
},\
values: {\
size:0.025,\
comp: 'none',\
flag:0,\
feed:0,\
speed:0\
},\
})\
}"
var data = IKM.command(func, {}, 1).data;
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()
if(GEN.isLayerExists({job:job, layer:par.workLayer})) {
GEN.COM("chain_add,layer="+par.workLayer+",chain=1,size="+data.size+",comp="+data.comp+",flag="+data.flag+",feed="+data.feed+",speed="+data.speed)
}
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
/*
NAME:
DESCRIPTION: 打断连接肋;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayers',
title : 'workLayers',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> 线段转弧 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "cad",
auto_save: "No",
workLayers:"out",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
var workLayers = par.workLayers.split(";")
workLayers = workLayers.filter(function(l){return GEN.isLayerExists({job:job, layer:l})})
if(workLayers.length == 0) {
throw "没有找到工作层"
}
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()
workLayers.forEach(function (layer) {
GEN.workLayer({name:layer, clear_before:"yes"})
})
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
/*
NAME:
DESCRIPTION: chain;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayer',
title : '工作层',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> chain </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "array",
workLayer: "rou",
auto_save: "No",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
// {
// name : 'pth_compensation',
// title : 'PTH补偿',
// type : 'ComboBox',
// property : {
// item_list:[
// 'less_75um',
// '75_and_100um',
// '100_and_150um',
// '150_and_200um',
// ],
// tool_tip : 'PTH补偿'
// },
// },
var func = "function (props) {\
return GUI.showForm({\
title: 'Create array routing chain',\
size: '400x360',\
use_core_engine: true,\
include_hidden_items: true,\
items: {\
type: 'ScrollArea',\
property: {\
widget_resizable: true,\
frame_shape: 'NoFrame'\
},\
child: [{\
type: 'FormGridLayout',\
child: [{\
name: 'size',\
title: 'size(mm)',\
type: 'LineEdit'\
}, {\
name: 'comp',\
title: 'comp',\
type: 'ComboBox',\
property : {\
item_list:[\
'none',\
'right',\
'left',\
],\
tool_tip : 'comp'\
},\
}, {\
name: 'flag',\
title: 'flag',\
type: 'LineEdit'\
}, {\
name: 'feed',\
title: 'feed',\
type: 'LineEdit'\
}, {\
name: 'speed',\
title: 'speed',\
type: 'LineEdit'\
}]\
}]\
},\
values: {\
size:0.025,\
comp: 'none',\
flag:0,\
feed:0,\
speed:0\
},\
})\
}"
var data = IKM.command(func, {}, 1).data;
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()
if(GEN.isLayerExists({job:job, layer:par.workLayer})) {
GEN.COM("chain_add,layer="+par.workLayer+",chain=1,size="+data.size+",comp="+data.comp+",flag="+data.flag+",feed="+data.feed+",speed="+data.speed)
}
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
/*
NAME:
DESCRIPTION: 线段转弧;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayers',
title : 'workLayers',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> 线段转弧 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "cad",
auto_save: "No",
workLayers:"out",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
var workLayers = par.workLayers.split(";")
workLayers = workLayers.filter(function(l){return GEN.isLayerExists({job:job, layer:l})})
if(workLayers.length == 0) {
throw "没有找到工作层"
}
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()
GEN.affectedLayer({affected:"yes", layer:workLayers})
// 现有做法:使用InCAM Pro 中的Simplify Lines/Arcs功能将连续的线段转化为弧或线
// 通过公差调整,但不能完全去除线段或圆弧(只是线段减少)
GEN.COM("rv_tab_empty,report=design2rout_rep,is_empty=yes")
GEN.COM("sel_design2rout,det_tol=25.4,con_tol=25.4,rad_tol=2.54")
GEN.COM("rv_tab_view_results_enabled,report=design2rout_rep,is_enabled=yes,serial_num=-1,all_count=-1")
GEN.COM("rv_tab_empty,report=design2rout_rep,is_empty=no")
GEN.COM("editor_results_show,action=design2rout_rep,is_end_results=yes")
GEN.COM("zoom_mode,zoom=zoom,family=general")
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
/*
NAME:
DESCRIPTION: 连接位修复;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayers',
title : 'workLayers',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> 连接位修复 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "cad",
auto_save: "No",
workLayers:"out",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
var workLayers = par.workLayers.split(";")
workLayers = workLayers.filter(function(l){return GEN.isLayerExists({job:job, layer:l})})
if(workLayers.length == 0) {
throw "没有找到工作层"
}
var func = 'function(props){return GUI.showForm({\
title: "连接位公差(um)",\
size: "400x220",\
use_core_engine: true,\
include_hidden_items: true,\
items: {\
type: "ScrollArea",\
property: {\
widget_resizable: true,\
frame_shape: "NoFrame"\
},\
child: [{\
type: "FormGridLayout",\
property: {\
},\
child: [{\
name : "tolerance",\
title: "tolerance",\
type : "LineEdit",\
property : {tool_tip : "tolerance"}\
}]\
}]\
},\
values: { tolerance: 200 },\
}) }';
var data = IKM.command(func, {}, 1).data;
if(data && data.tolerance && /\d/.test(data.tolerance) ){
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()
workLayers.forEach(function(layer){
GEN.workLayer({name:layer, clear_before:"yes"})
var feats = GEN.getFeatures({job:job, step:step, layer:layer, units:"mm", options:"feat_index"})
feats = feats.filter(function (feat) {
return feat.type == "line" || feat.type == "arc"
})
var ret = [];
feats.forEach(function (feat1, i) {
for (var i2 = i+1; i2 < feats.length; i2++) {
var feat2 = feats[i2]
if(feat2) {
var len1 = p2p({x1: feat1.xs, y1:feat1.ys, x2:feat2.xs ,y2:feat2.ys})
var len2 = p2p({x1: feat1.xs, y1:feat1.ys, x2:feat2.xe ,y2:feat2.ye})
var len3 = p2p({x1: feat1.xe, y1:feat1.ye, x2:feat2.xs ,y2:feat2.ys})
var len4 = p2p({x1: feat1.xe, y1:feat1.ye, x2:feat2.xe ,y2:feat2.ye})
if(FlagTolerance(len1) || FlagTolerance(len2) || FlagTolerance(len3) || FlagTolerance(len4)) {
ret.push({
feat1: feat1,
feat2: feat2
})
}
}
}
})
if(ret.length > 0) {
// 1. 判断两个线是否有角度 或者是否有弧
// 选中执行命令
ret.forEach(function (item) {
var feat1 = item.feat1
var feat2 = item.feat2
var flag = false;
if(feat1.type == "arc" || feat2.type == "arc") {
flag = true
} else if (Math.abs((feat1.xe - feat1.xs)/(feat1.ye-feat1.ye) - (feat2.xe - feat2.xs)/(feat2.ye-feat2.ye)) <= 0.001) {
flag = true
}
if(flag) {
GEN.selLayerFeat({layer:layer, index:feat1.index,operation:"select"})
GEN.selLayerFeat({layer:layer, index:feat2.index,operation:"select"})
if(GEN.getSelectCount() == 2) {
GEN.COM("sel_design2rout,det_tol="+data.tolerance+",con_tol="+data.tolerance+",rad_tol=10")
}
GEN.selClearFeature()
}
})
}
})
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
}
function FlagTolerance(len) {
return len >= 0.001 && len <= data.tolerance/1000
}
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
function p2p(props) {
var x1 = props.x1
var y1 = props.y1
var x2 = props.x2
var y2 = props.y2
return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1))
}
\ No newline at end of file
/*
NAME:
DESCRIPTION: rout输出;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'export_path',
title : 'export_path',
type : 'LineEdit',
property : {tool_tip : '输出路径'},
},
{
name : 'nf1',
title : 'nf1',
type : 'LineEdit',
property : {tool_tip : 'nf1'},
},
{
name : 'nf2',
title : 'nf2',
type : 'LineEdit',
property : {tool_tip : 'nf2'},
},
{
name : 'units',
title : '单位',
type : 'RadioBox',
property : {
item_list:[
{name:'mm',text:'mm'},
{name:'inch',text:'inch'},
],
tool_tip:'单位默认是mm'
}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> rout输出 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "array",
workLayer: "rou",
export_path:"E:/1",
auto_save: "No",
nf1:3,nf2:3,
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
if( !fs.dirExists(par.export_path) ){
throw "输出路径错误"
}
//判断当前路径是否存在此料号的文件夹
if( !fs.dirExists(par.export_path + "/" + job) ){
fs.mkdir(par.export_path + "/" + job);
}
var workLayer = par.workLayer;
if(GEN.isLayerExists({job:job, layer: workLayer})) {
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()
GEN.COM("output_layer_reset")
GEN.COM("output_layer_set,layer="+workLayer+",angle=0,mirror=no,x_scale=1,y_scale=1,comp=0,polarity=positive,setupfile=,setupfiletmp=,line_units="+par.units+",gscl_file=,step_scale=no")
GEN.COM("output,job="+job+",step="+step+",format=Excellon2,dir_path="+ (par.export_path + "/" + job) +",prefix=,suffix=,break_sr=yes,break_symbols=yes,break_arc=no,scale_mode=all,surface_mode=fill,min_brush=25.4,units="+par.units+",coordinates=absolute,decimal=no,zeroes=none,nf1="+par.nf1+",nf2="+par.nf2+",modal=yes,tool_units="+par.units+",optimize=no,iterations=5,reduction_percent=1,cool_spread=0,x_anchor=0,y_anchor=0,x_offset=0,y_offset=0,line_units="+par.units+",override_online=yes,canned_text_mode=break")
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
} else {
IKM.msg("没有找到工作层")
}
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
/*
NAME:
DESCRIPTION: 回读;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'suffix',
title : 'suffix',
type : 'LineEdit',
property : {tool_tip : 'suffix'}
},
{
name : 'export_path',
title : 'export_path',
type : 'LineEdit',
property : {tool_tip : '输出路径'},
},
{
name : 'nf1',
title : 'nf1',
type : 'LineEdit',
property : {tool_tip : 'nf1'},
},
{
name : 'nf2',
title : 'nf2',
type : 'LineEdit',
property : {tool_tip : 'nf2'},
},
{
name : 'units',
title : '单位',
type : 'RadioBox',
property : {
item_list:[
{name:'mm',text:'mm'},
{name:'inch',text:'inch'},
],
tool_tip:'单位默认是mm'
}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> 回读 </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "array",
workLayer: "rou",
export_path:"E:/1",
suffix:"_read",
auto_save: "No",
nf1:3,nf2:3,
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
if( !fs.dirExists(par.export_path) ){
throw "路径错误"
}
//判断当前路径是否存在此料号的文件夹
if( !fs.dirExists(par.export_path + "/" + job) ){
fs.mkdir(par.export_path + "/" + job);
}
var workLayer = par.workLayer;
if(fs.exists(par.export_path+"/" + job+"/"+workLayer)) {
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()
var read = workLayer + par.suffix;
if(GEN.isLayerExists({job:job, layer:read})) {
GEN.deleteLayer({job:job, layer:read})
}
GEN.COM( "input_manual_reset");
GEN.COM( "input_manual_set,path="+(par.export_path+"/" + job+"/"+workLayer)+",job="+job+",step="+step
+",format=Excellon2,data_type=ascii,units=mm,coordinates=absolute,"
+"zeroes=none,nf1="+par.nf1+",nf2="+par.nf2+",decimal=no,separator=nl,tool_units=mm,layer="+read
+",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.zoomHome();
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
} else {
IKM.msg("没有找到资料")
}
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
This diff is collapsed.
/*
NAME:
DESCRIPTION: chain;
PARAMETER:
[
{
name : 'step',
title : 'step',
type : 'LineEdit',
property : {tool_tip : '目标step,默认是orig'}
},
{
name : 'workLayer',
title : '工作层',
type : 'LineEdit',
property : {tool_tip : '工作层'}
},
{
name : 'auto_save',
title : '自动保存',
type : 'RadioBox',
property : {
item_list:[
{name:'yes',text:'YES'},
{name:'no',text:'NO'},
],
tool_tip:'是否自动保存料号开关'
}
}
]
VERSION_HISTORY:
V1.00 2021-04-08 template
1.新版本
HELP:
<html><body bgcolor="#DDECFE">
<font size="3" color="#003DB2"><p>功能简介</p></font>
<p> template </ p>
<br>
<font size="3" color="#003DB2"><p>参数配置</p></font>
<p> chain </p>
<br>
<font size="3" color="#003DB2"><p>注意事项</p></font>
<p> 无 </p>
<br>
</body></html>
*/
// 引入模块 包 外部参数
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
var _ = require('lodash');
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm ? $.ikm : require('topcam.ikm6')($);
var GEN = $.gen;
var Job = $.job || $.job_name;
var JobId = $.job_id;
var db = $.db || IKM.db;
var plugin = require('topsin.gengui');
var GUI = plugin.newGui(plugin.__dirname);
var PAR = {};
if ($.par) {
PAR = $.par;
} else if ($.hasOwnProperty('script_parameter')) {
PAR = JSON.parse($.script_parameter);
}
if (mode === "aimdfm") {
IKM.crud("updateRow", {
table: "pdm_aimdfm_task",
data: { current_process_title: $.process_title },
where: { id: $.task_id }
});
}
var Status = 'ok';
var resultData = [];
var par = PAR; // 接收参数
var default_par = { // 设置默认参数
step: "array",
workLayer: "rou",
auto_save: "No",
units: "mm"
};
for (var key in default_par) {
if (!par.hasOwnProperty(key) || par[key] == "") {
par[key] = default_par[key];
}
}
// 定义变量
var job = Job.toLowerCase();
require("topsin.genmath");
var genMath = new GenMath();
try {
// 常规验证 准备工作
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 });
stepList = stepList.filter(function (v) {
var tmpreg = new RegExp(par.step, "ig");
return tmpreg.test(v);
});
if (stepList.length == 0) {
throw "未找到" + par.step
}
// {
// name : 'pth_compensation',
// title : 'PTH补偿',
// type : 'ComboBox',
// property : {
// item_list:[
// 'less_75um',
// '75_and_100um',
// '100_and_150um',
// '150_and_200um',
// ],
// tool_tip : 'PTH补偿'
// },
// },
var func = "function (props) {\
return GUI.showForm({\
title: 'Create array routing chain',\
size: '400x360',\
use_core_engine: true,\
include_hidden_items: true,\
items: {\
type: 'ScrollArea',\
property: {\
widget_resizable: true,\
frame_shape: 'NoFrame'\
},\
child: [{\
type: 'FormGridLayout',\
child: [{\
name: 'size',\
title: 'size(mm)',\
type: 'LineEdit'\
}, {\
name: 'comp',\
title: 'comp',\
type: 'ComboBox',\
property : {\
item_list:[\
'none',\
'right',\
'left',\
],\
tool_tip : 'comp'\
},\
}, {\
name: 'flag',\
title: 'flag',\
type: 'LineEdit'\
}, {\
name: 'feed',\
title: 'feed',\
type: 'LineEdit'\
}, {\
name: 'speed',\
title: 'speed',\
type: 'LineEdit'\
}]\
}]\
},\
values: {\
size:0.025,\
comp: 'none',\
flag:0,\
feed:0,\
speed:0\
},\
})\
}"
var data = IKM.command(func, {}, 1).data;
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()
if(GEN.isLayerExists({job:job, layer:par.workLayer})) {
GEN.COM("chain_add,layer="+par.workLayer+",chain=1,size="+data.size+",comp="+data.comp+",flag="+data.flag+",feed="+data.feed+",speed="+data.speed)
}
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
});
// 保存料号
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";
if (mode === "aimdfm") {
IKM.crud("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;
} catch (e) {
var showGUI = true;
if (GEN.STATUS.length > 0) {
if (GEN.STATUS.indexOf("Pause Exit:0") >= 0) {
showGUI = false;
}
e = _.toString(e) + "\n" + GEN.STATUS.join("\n");
}
if (showGUI) {
IKM.msg(e);
}
Status = 'error';
resultData.push({ type: "error", title: "脚本执行出错!", detail: [{ desc: _.toString(e) }] });
return mode === "aimdfm" ? { status: Status, result_data: resultData } : "Error";
}
/**
* 获取层别
* @param {Object} 过滤选项
* @returns {Array}
*/
function getLayer(props) {
if (!props) {
props = {};
}
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 (info[_key]) {
if (/object string|object number/ig.test({}.toString.call(props[_key]))) {
if (props[_key] != info[_key]) {
ret = false;
}
}
if (/object RegExp/ig.test({}.toString.call(props[_key]))) {
if (!props[_key].test(info[_key])) {
ret = false;
}
}
if (/object function/ig.test({}.toString.call(props[_key]))) {
if (!props[_key](info[_key])) {
ret = false;
}
}
}
}
if (ret) {
a.push(props.res == "info" ? info : b);
}
return a;
}, []);
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment