Commit 9e0658fe authored by Scott Sun's avatar Scott Sun

s

parent d9a6c1ce
......@@ -117,26 +117,101 @@ try {
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.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"})
// todo GEN.workLayer({name:layer, clear_before:"yes"})
// 前处理 将特殊钻孔和层的线弧拷贝到辅助层
// 1. 找特殊钻孔 计算特殊钻孔间距 小于xxx的为一组
layer = GEN.getWorkLayer()
GEN.selectByFilter({feat_types:"pad", attribute:".smd"})
if(GEN.getSelectCount() > 0) {
var feats = GEN.getFeatures({job:job, step:step, layer:layer, units:"mm", options:"select+feat_index"})
GEN.selClearFeature();
feats.forEach(function (feat) {
feats.forEach(function (feat2) {
if(feat.index != feat2.index) {
var p2p = Math.sqrt((feat2.x - feat.x)*(feat2.x - feat.x) + (feat2.y - feat.y)*(feat2.y - feat.y))
if(p2p > 2 && p2p < 5) {
GEN.workLayer({name:layer, clear_before:"yes"})
GEN.selLayerFeat({layer:layer, index:feat.index,operation:"select"})
GEN.selLayerFeat({layer:layer, index:feat2.index,operation:"select"})
delLayer(["tmp"])
GEN.selCopyOther({dest:"layer_name", target_layer:"tmp", size: 2000})
GEN.workLayer({name:"tmp", clear_before:"yes"})
GEN.PAUSE(0)
GEN.selRefFeat({layers: layer, use:"filter", mode:"touch"})
if(GEN.getSelectCount() > 0) {
var line = {xs:feat.x, ys:feat.y, xe:feat2.x, ye: feat2.y, symbol:"r10" }
var lineLen = p2p
var k = (line.xe-line.xs)/(line.ye-line.ys)
var q = (line.ye-line.ys)/(line.xe-line.xs)
var lineCenter = {
x: (line.xe-line.xs)/2 + line.xs,
y: (line.ye-line.ys)/2 + line.ys
}
GEN.addLine(line);
GEN.selectByFilter({feat_types:"line"})
GEN.COM("sel_transform,mode=anchor,oper=rotate,duplicate=no,x_anchor="+lineCenter.x+",y_anchor="+lineCenter.y
+",angle=90,x_scale=1,y_scale=1,x_offset=0,y_offset=0")
GEN.workLayer({name:layer, clear_before:"yes"})
GEN.selRefFeat({layers:"tmp", use:"filter", mode:"touch"})
GEN.selectByFilter({feat_types:"pad\;text\;arc\;surface", operation:"unselect"})
if(GEN.getSelectCount() > 0) {
var lines=GEN.getFeatures({job:job, step:step, layer:layer, units:"mm", options:"select+feat_index"})
// 获取ines里面最大的symbol
var ls = [];
lines.forEach(function (l) {
var l_k = (l.xe-l.xs)/(l.ye-l.ys)
if(Math.abs(l_k-k) < 0.001) {
var p2l = p2line(lineCenter.x, lineCenter.y, l.xs,l.ys,l.xe,l.ye)
if (p2l > 0.001) {
ls.push({
p2l:p2l, l:l
})
}
}
})
if(ls && ls.length) {
var length = ls[0].p2l
var line = {xs:feat.x, ys:feat.y, xe:feat2.x, ye: feat2.y, symbol:"r420" }
var xChange = (line.xe-line.xs)*(length/p2p)
var yChange = (line.ye-line.ys)*(length/p2p)
GEN.addLine({xs:feat.x+xChange, ys:feat.y+yChange, xe:feat2.x+xChange, ye: feat2.y+yChange, symbol:"r420" , attributes:".imp_line"});
GEN.addLine({xs:feat.x-xChange, ys:feat.y-yChange, xe:feat2.x-xChange, ye: feat2.y-yChange, symbol:"r420" , attributes:".imp_line"});
}
}
GEN.PAUSE(0)
}
}
}
})
})
}
// 2. 遍历特殊钻孔组 放大xxtouch线弧 钻孔相连 画2平行辅助线
// 3. 辅助线完全覆盖的线 且斜率差不多的 删除
// 4. incam特殊用法点击辅助线中点
})
GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
GEN.clearLayers(); //清除层显示
// GEN.affectedLayer({ mode: 'all', affected: 'no' }); //设置影响层全部不影响
// GEN.clearLayers(); //清除层显示
});
// 保存料号
......@@ -217,3 +292,28 @@ function getLayer(props) {
return a;
}, []);
}
/**
*
* @param {*} layer
*/
function delLayer(layer){
if(!Array.isArray(layer)){
layer = [layer]
}
layer = layer.filter(function(v){return GEN.isLayerExists({job:job, layer:v})})
if(layer.length > 0){
GEN.deleteLayer({job:job, layer:layer})
}
}
function p2line(x, y, x1, y1, x2, y2) {
var A = Math.abs(Math.sqrt(Math.pow((x - x1), 2) + Math.pow((y - y1), 2)));
var B = Math.abs(Math.sqrt(Math.pow((x - x2), 2) + Math.pow((y - y2), 2)));
var C = Math.abs(Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2))); //利用海伦公式计算三角形面积 //周长的一半
var P = (A + B + C) / 2;
var allArea = Math.abs(Math.sqrt(P * (P - A) * (P - B) * (P - C))); //普通公式计算三角形面积反推点到线的垂直距离
var dis = (2 * allArea) / C;
return dis;
}
\ No newline at end of file
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