ATS_AIM_input_data.js 4.13 KB
Newer Older
Scott Sun's avatar
s  
Scott Sun committed
1 2 3 4 5 6
/*
NAME: 
DESCRIPTION: ;
PARAMETER:
    [
		{
Scott Sun's avatar
s  
Scott Sun committed
7 8 9 10 11 12 13 14 15 16 17
            name : 'auto_save',
			title : '自动保存',
            type : 'RadioBox',
            property : {
				item_list:[
					{name:'yes',text:'YES'},
					{name:'no',text:'NO'},
				],
				tool_tip:'是否自动保存料号开关'
			}
        }
Scott Sun's avatar
s  
Scott Sun committed
18 19 20
	]
	
 VERSION_HISTORY:
Scott Sun's avatar
s  
Scott Sun committed
21
	V1.00 2020-06-10 Scott Sun
Scott Sun's avatar
s  
Scott Sun committed
22 23 24 25 26
	    1.新版本
		
 HELP:
 	<html><body bgcolor="#DDECFE">
		<font size="3" color="#003DB2"><p>功能简介</p></font>
Scott Sun's avatar
s  
Scott Sun committed
27
		<p> 立碑效应 </p>
Scott Sun's avatar
s  
Scott Sun committed
28 29
		<br>
		<font size="3" color="#003DB2"><p>参数配置</p></font>
Scott Sun's avatar
s  
Scott Sun committed
30
		<p> 配置 </p>
Scott Sun's avatar
s  
Scott Sun committed
31 32 33 34 35 36 37 38
		<br>
		<font size="3" color="#003DB2"><p>注意事项</p></font>
		<p> 无 </p>
		<br>
	</body></html>	
*/
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
Scott Sun's avatar
s  
Scott Sun committed
39 40
console.log("==============================>li bei xiao yin start");

Scott Sun's avatar
Scott Sun committed
41 42 43
// 引入模块 包
var $ = require('topcam.scriptfunc').argv();
var fs = require('fs');
Scott Sun's avatar
s  
Scott Sun committed
44
var genmath = require('topcam.genmath')
Scott Sun's avatar
Scott Sun committed
45
var _ = require('lodash');
Scott Sun's avatar
s  
Scott Sun committed
46 47 48
var mode = $.ikm ? "topcam" : "aimdfm";
var IKM = $.ikm;
if (IKM==undefined ) { IKM = require('topcam.ikm6')($) }
Scott Sun's avatar
Scott Sun committed
49
var GEN = $.gen;
Scott Sun's avatar
s  
Scott Sun committed
50 51 52 53 54 55 56 57 58 59
var GUI = $.gui || {};
var Job = $.job || $.job_name;
Job = Job.toLowerCase()
var job = Job
var JobId = $.job_id;
var db = $.db || {}
var PAR = {}
if ($.par) {
	PAR = $.par
} else if ($.hasOwnProperty('script_parameter')){
Scott Sun's avatar
s  
Scott Sun committed
60 61
	PAR = JSON.parse($.script_parameter);
}
Scott Sun's avatar
s  
Scott Sun committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75
var par = PAR;
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 }
		});
Scott Sun's avatar
Scott Sun committed
76
	}
Scott Sun's avatar
s  
Scott Sun committed
77 78 79 80 81
}
var Status = 'ok';
var resultData = [];
var debug = true;
var Step = par.step_fliter
Scott Sun's avatar
Scott Sun committed
82

Scott Sun's avatar
s  
Scott Sun committed
83 84 85
var default_par = {  // par默认参数?
	auto_save: "no"
}
Scott Sun's avatar
s  
Scott Sun committed
86

Scott Sun's avatar
s  
Scott Sun committed
87 88 89 90 91
for(var key in default_par){  // 设置默认属性
    if (!par.hasOwnProperty(key) || par[key] == ""){
        par[key] = default_par[key]
    }
}
Scott Sun's avatar
s  
Scott Sun committed
92

Scott Sun's avatar
s  
Scott Sun committed
93
try {
Scott Sun's avatar
s  
Scott Sun committed
94

Scott Sun's avatar
s  
Scott Sun committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	var layer = "000"
	var step = "cad"
	var layer = "000"
	// GEN.workLayer({name:layer,display_number:2,clear_before:'yes'})
	// var feautres = GEN.getFeatures({job:job,step:step,layer:layer,units:"mm"})
	var data = {"type":"arc","xs":"-5.1252","ys":"7.685785","xe":"-6.5392","ye":"7.1001","xc":"-5.1250975","yc":"5.685835","symbol":"r25.4","polarity":"positive","direction":"ccw","attributes":[]}
	// -5.1252 7.685785 -6.5392 7.1001 -5.1250975 5.685835
	IKM.msg(genmath.arcLength(data))
	// // 根据feautres 算出周长
	// var milling = Object.keys(feautres).reduce(function(a,b){
	// 	var value = feautres[b]
	// 	if (value.type=="line"){
	// 		length = Math.sqrt((value.xe-value.xs)*(value.xe-value.xs) + (value.ye-value.ys)*(value.ye-value.ys))
	// 		a += length
	// 	} else if (value.type=="arc") {
	// 		a += arcLength(Number(value.xs),Number(value.ys),Number(value.xe),Number(value.ye),Number(value.xc),Number(value.yc))
	// 	}
	// 	return a 
	// }, 0)
	// IKM.msg(milling)
Scott Sun's avatar
s  
Scott Sun committed
115

Scott Sun's avatar
s  
Scott Sun committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
	if (mode === "aimdfm") {
		$.QDfm.updateRow({
			table: "pdm_aimdfm_task",
			data: {
				progress: 33.33
			},
			where: { id: $.task_id }
		});
		if (GEN.hasError()) {
			Status = 'error';
			resultData.push({ type: "error", title: "GEN错误!", detail: [{ desc: _.join(GEN.STATUS, "\n") }] });
			return {
				status: Status,
				result_data: resultData
			};
		} else {
			resultData.push({ type: "info", title: "操作完成, 请注意检查!" });
			return {
				status: Status,
				result_data: resultData
			};
		}
	}else {
		return "Done"
Scott Sun's avatar
s  
Scott Sun committed
140
	}
Scott Sun's avatar
s  
Scott Sun committed
141 142
} catch (e) {
	IKM.msg(e)
Scott Sun's avatar
s  
Scott Sun committed
143
	Status = 'error';
Scott Sun's avatar
s  
Scott Sun committed
144 145
	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
146
}
Scott Sun's avatar
s  
Scott Sun committed
147

Scott Sun's avatar
s  
Scott Sun committed
148 149 150 151 152 153
function arcLength(x1,y1,x2,y2,x3,y3){
	var cos0 =  +((x3-x1)*(x2-x3) + (y3-y1)*(y2-y3)) / Math.pow((Math.pow(x2-x3,2) + Math.pow(y2-y3,2)),0.5) * Math.pow((Math.pow(x3-x1,2) + Math.pow(y3-y1,2)),0.5)
	var tmp = Math.acos(cos0)
	var sin0 = Math.sin(tmp)
	var length = +Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2)) / sin0 * tmp
	return length
Scott Sun's avatar
Scott Sun committed
154
}