Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
A
ats_cam_script
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Scott Sun
ats_cam_script
Commits
f9173440
Commit
f9173440
authored
Oct 17, 2022
by
Scott Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
s
parent
9e0658fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
383 additions
and
96 deletions
+383
-96
ATS_rout_break_connect.js
rout/ATS_rout_break_connect.js
+75
-38
ATS_rout_optimize_connect.js
rout/ATS_rout_optimize_connect.js
+308
-58
No files found.
rout/ATS_rout_break_connect.js
View file @
f9173440
...
...
@@ -117,39 +117,48 @@ try {
throw
"没有找到工作层"
}
var
drls
=
getLayer
({
layer_type
:
"drill"
,
context
:
"board"
})
var
specialAttr
=
".drill_noopt"
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
)
{
// todo GEN.workLayer({name:layer, clear_before:"yes"})
// 前处理 将特殊钻孔和层的线弧拷贝到辅助层
drls
.
forEach
(
function
(
drl
)
{
GEN
.
workLayer
({
name
:
drl
,
clear_before
:
"yes"
})
GEN
.
selectByFilter
({
feat_types
:
"pad"
,
attribute
:
specialAttr
})
if
(
GEN
.
getSelectCount
()
>
0
)
{
GEN
.
selCopyOther
({
dest
:
"layer_name"
,
target_layer
:
layer
})
}
})
GEN
.
workLayer
({
name
:
layer
,
clear_before
:
"yes"
})
delLayer
([
"tmp"
,
layer
+
"_tmp"
])
// 1. 找特殊钻孔 计算特殊钻孔间距 小于xxx的为一组
layer
=
GEN
.
getWorkLayer
()
GEN
.
selectByFilter
({
feat_types
:
"pad"
,
attribute
:
".smd"
})
GEN
.
selectByFilter
({
feat_types
:
"pad"
,
attribute
:
specialAttr
})
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
)
{
GEN
.
selClearFeature
()
feats
.
forEach
(
function
(
feat
,
i1
)
{
feats
.
forEach
(
function
(
feat2
,
i2
)
{
if
(
feat
.
index
!=
feat2
.
index
&&
i2
>
i1
)
{
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
line
=
{
xs
:
feat
.
x
-
0
,
ys
:
feat
.
y
-
0
,
xe
:
feat2
.
x
-
0
,
ye
:
feat2
.
y
-
0
,
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
)
...
...
@@ -161,7 +170,16 @@ try {
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
.
selectByFilter
({
feat_types
:
"line"
})
GEN
.
selReverse
()
if
(
GEN
.
getSelectCount
()
>
0
)
{
GEN
.
selDelete
()
}
GEN
.
workLayer
({
name
:
layer
,
clear_before
:
"yes"
})
GEN
.
selectByFilter
({
attribute
:
".imp_line"
})
if
(
GEN
.
getSelectCount
()
>
0
)
{
GEN
.
selDelete
()
}
GEN
.
selRefFeat
({
layers
:
"tmp"
,
use
:
"filter"
,
mode
:
"touch"
})
GEN
.
selectByFilter
({
feat_types
:
"pad
\
;text
\
;arc
\
;surface"
,
operation
:
"unselect"
})
if
(
GEN
.
getSelectCount
()
>
0
)
{
...
...
@@ -169,38 +187,57 @@ try {
// 获取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
)
{
var
xmid
=
l
.
xs
+
(
l
.
xe
-
l
.
xs
)
/
2
var
ymid
=
l
.
ys
+
(
l
.
ye
-
l
.
ys
)
/
2
ls
.
push
({
p2l
:
p2l
,
l
:
l
p2l
:
p2l
,
l
:
l
,
symbol
:
l
.
symbol
,
xmid
:
xmid
,
ymid
:
ymid
})
}
}
})
GEN
.
selClearFeature
()
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"
});
ls
.
forEach
(
function
(
lsv
)
{
var
length
=
lsv
.
p2l
var
line
=
{
xs
:
feat
.
x
-
0
,
ys
:
feat
.
y
-
0
,
xe
:
feat2
.
x
-
0
,
ye
:
feat2
.
y
-
0
,
symbol
:
lsv
.
symbol
}
var
yChange
=
(
line
.
xe
-
line
.
xs
)
*
(
length
/
p2p
)
var
xChange
=
(
line
.
ye
-
line
.
ys
)
*
(
length
/
p2p
)
GEN
.
addLine
({
xs
:
feat
.
x
-
0
+
xChange
,
ys
:
feat
.
y
-
0
+
yChange
,
xe
:
feat2
.
x
-
0
+
xChange
,
ye
:
feat2
.
y
-
0
+
yChange
,
symbol
:
"r420"
,
attributes
:
".imp_line"
});
GEN
.
addLine
({
xs
:
feat
.
x
-
0
-
xChange
,
ys
:
feat
.
y
-
0
-
yChange
,
xe
:
feat2
.
x
-
0
-
xChange
,
ye
:
feat2
.
y
-
yChange
,
symbol
:
"r420"
,
attributes
:
".imp_line"
});
})
GEN
.
selectByFilter
({
attribute
:
".imp_line"
})
GEN
.
selRefFeat
({
layers
:
layer
,
use
:
"select"
,
mode
:
"cover"
})
GEN
.
selectByFilter
({
feat_types
:
"pad
\
;text
\
;arc
\
;surface"
,
operation
:
"unselect"
})
if
(
GEN
.
getSelectCount
()
>
0
)
{
GEN
.
selMoveOther
({
target_layer
:
layer
+
"_tmp"
})
}
GEN
.
selectByFilter
({
attribute
:
".imp_line"
})
if
(
GEN
.
getSelectCount
()
>
0
)
{
GEN
.
selDelete
()
}
// todo ls 循环 incam特殊命令点选
ls
.
forEach
(
function
(
lsv
)
{
var
xmid
=
lsv
.
xmid
var
ymid
=
lsv
.
ymid
GEN
.
COM
(
"sel_single_feat,operation=select,x="
+
xmid
+
",y="
+
ymid
+
",cyclic=yes"
)
})
}
GEN
.
PAUSE
(
0
)
}
}
}
}
})
})
GEN
.
workLayer
({
name
:
layer
,
clear_before
:
"yes"
})
GEN
.
selectByFilter
({
feat_types
:
"pad"
,
attribute
:
specialAttr
})
if
(
GEN
.
getSelectCount
()
>
0
)
{
GEN
.
selDelete
()
}
}
...
...
rout/ATS_rout_optimize_connect.js
View file @
f9173440
...
...
@@ -152,53 +152,49 @@ try {
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.zoomHome(); //窗口显示回到原始位置
GEN
.
selClearFeature
()
workLayers
.
forEach
(
function
(
layer
){
GEN
.
workLayer
({
name
:
layer
,
clear_before
:
"yes"
})
var
retCount
;
var
indexObj
=
{}
var
oldIndex
=
{}
for
(
var
index
=
0
;
index
<
5
;
index
++
)
{
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"
});
if
(
index
==
0
)
{
feats
.
forEach
(
function
(
params
)
{
oldIndex
[
params
.
index
]
=
true
})
}
var
ret
=
[];
var
indexObj
=
{}
var
keys
=
{}
feats
.
forEach
(
function
(
feat
)
{
var
x
=
feat
.
xs
+
(
feat
.
xe
-
feat
.
xs
)
/
2
var
y
=
feat
.
ys
+
(
feat
.
ye
-
feat
.
ys
)
/
2
keys
[
x
+
"_"
+
y
]
=
true
})
feats
.
forEach
(
function
(
feat1
,
i
)
{
// feat1 不要是迭代后的新index
if
(
oldIndex
[
feat1
.
index
])
{
for
(
var
i2
=
i
+
1
;
i2
<
feats
.
length
;
i2
++
)
{
var
feat2
=
feats
[
i2
]
if
(
feat2
&&
lineLength
(
feat1
)
>
0.2
&&
lineLength
(
feat2
)
>
0.2
)
{
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
))
{
var
flag
=
true
var
midx
;
var
midy
;
if
(
FlagTolerance
(
len1
))
{
midx
=
feat1
.
xs
+
(
feat2
.
xs
-
feat1
.
xs
)
/
2
midy
=
feat1
.
ys
+
(
feat2
.
ys
-
feat1
.
ys
)
/
2
}
else
if
(
FlagTolerance
(
len2
))
{
midx
=
feat1
.
xs
+
(
feat2
.
xe
-
feat1
.
xs
)
/
2
midy
=
feat1
.
ys
+
(
feat2
.
ye
-
feat1
.
ys
)
/
2
}
else
if
(
FlagTolerance
(
len3
))
{
midx
=
feat1
.
xe
+
(
feat2
.
xs
-
feat1
.
xe
)
/
2
midy
=
feat1
.
ye
+
(
feat2
.
ys
-
feat1
.
ye
)
/
2
}
else
if
(
FlagTolerance
(
len4
))
{
midx
=
feat1
.
xe
+
(
feat2
.
xe
-
feat1
.
xe
)
/
2
midy
=
feat1
.
ye
+
(
feat2
.
ye
-
feat1
.
ye
)
/
2
}
var
key
=
midx
+
"_"
+
midy
var
len1
=
PointToLineDistance
(
feat1
.
xs
,
feat1
.
ys
,
feat2
.
xs
,
feat2
.
ys
,
feat2
.
xe
,
feat2
.
ye
)
var
len2
=
PointToLineDistance
(
feat1
.
xe
,
feat1
.
ye
,
feat2
.
xs
,
feat2
.
ys
,
feat2
.
xe
,
feat2
.
ye
)
var
len3
=
PointToLineDistance
(
feat2
.
xs
,
feat2
.
ys
,
feat1
.
xs
,
feat1
.
ys
,
feat1
.
xe
,
feat1
.
ye
)
var
len4
=
PointToLineDistance
(
feat2
.
xe
,
feat2
.
ye
,
feat1
.
xs
,
feat1
.
ys
,
feat1
.
xe
,
feat1
.
ye
)
if
((
FlagTolerance
(
len1
[
0
])
&&!
pinLine
({
x
:
feat1
.
xs
,
y
:
feat1
.
ys
},
feats
,
[
feat1
.
index
,
feat2
.
index
]))
||
(
FlagTolerance
(
len2
[
0
])
&&!
pinLine
({
x
:
feat1
.
xe
,
y
:
feat1
.
ye
},
feats
,
[
feat1
.
index
,
feat2
.
index
]))
||
(
FlagTolerance
(
len3
[
0
])
&&!
pinLine
({
x
:
feat2
.
xs
,
y
:
feat2
.
ys
},
feats
,
[
feat1
.
index
,
feat2
.
index
]))
||
(
FlagTolerance
(
len4
[
0
])
&&!
pinLine
({
x
:
feat2
.
xe
,
y
:
feat2
.
ye
},
feats
,
[
feat1
.
index
,
feat2
.
index
])))
{
var
key
;
if
((
feat1
.
index
-
0
)
>
(
feat2
.
index
-
0
))
{
key
=
feat1
.
index
+
"_"
+
feat2
.
index
}
else
{
key
=
feat2
.
index
+
"_"
+
feat1
.
index
}
if
(
!
keys
[
key
])
{
if
(
!
indexObj
[
feat1
.
index
]
&&
!
indexObj
[
feat2
.
index
]
&&
flag
&&
!
keys
[
key
])
{
indexObj
[
feat1
.
index
]
=
true
indexObj
[
feat2
.
index
]
=
true
keys
[
key
]
=
true
ret
.
push
({
feat1
:
feat1
,
feat2
:
feat2
,
...
...
@@ -207,8 +203,8 @@ try {
}
}
}
})
}
});
if
(
ret
.
length
>
0
)
{
// 1. 判断两个线是否有角度 或者是否有弧
// 选中执行命令
...
...
@@ -216,27 +212,72 @@ try {
var
feat1
=
item
.
feat1
var
feat2
=
item
.
feat2
var
flag
=
true
;
// 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
)
{
if
(
flag
&&
!
indexObj
[
feat1
.
index
]
&&
!
indexObj
[
feat2
.
index
])
{
GEN
.
selLayerFeat
({
layer
:
layer
,
index
:
feat1
.
index
,
operation
:
"select"
})
GEN
.
selLayerFeat
({
layer
:
layer
,
index
:
feat2
.
index
,
operation
:
"select"
})
if
(
GEN
.
getSelectCount
()
==
2
)
{
// GEN.PAUSE(0)
// GEN.COM("sel_design2rout,det_tol="+data.tolerance+",con_tol="+data.tolerance+",rad_tol=10")
// GEN.PAUSE(1)
if
(
GEN
.
getSelectCount
()
==
2
)
{
GEN
.
COM
(
"sel_design2rout,det_tol="
+
data
.
tolerance
+
",con_tol="
+
data
.
tolerance
+
",rad_tol=10"
)
indexObj
[
feat1
.
index
]
=
true
indexObj
[
feat2
.
index
]
=
true
}
GEN
.
selClearFeature
()
}
})
}
else
{
break
}
// GEN.selClearFeature()
}
{
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
=
[];
var
keys
=
{}
feats
.
forEach
(
function
(
feat1
,
i
)
{
for
(
var
i2
=
i
+
1
;
i2
<
feats
.
length
;
i2
++
)
{
var
feat2
=
feats
[
i2
]
if
(
feat2
&&
lineLength
(
feat1
)
>
0.2
&&
lineLength
(
feat2
)
>
0.2
)
{
var
len1
=
PointToLineDistance
(
feat1
.
xs
,
feat1
.
ys
,
feat2
.
xs
,
feat2
.
ys
,
feat2
.
xe
,
feat2
.
ye
)
var
len2
=
PointToLineDistance
(
feat1
.
xe
,
feat1
.
ye
,
feat2
.
xs
,
feat2
.
ys
,
feat2
.
xe
,
feat2
.
ye
)
var
len3
=
PointToLineDistance
(
feat2
.
xs
,
feat2
.
ys
,
feat1
.
xs
,
feat1
.
ys
,
feat1
.
xe
,
feat1
.
ye
)
var
len4
=
PointToLineDistance
(
feat2
.
xe
,
feat2
.
ye
,
feat1
.
xs
,
feat1
.
ys
,
feat1
.
xe
,
feat1
.
ye
)
if
((
FlagTolerance
(
len1
[
0
])
&&!
pinLine
({
x
:
feat1
.
xs
,
y
:
feat1
.
ys
},
feats
,
[
feat1
.
index
,
feat2
.
index
],
true
))
||
(
FlagTolerance
(
len2
[
0
])
&&!
pinLine
({
x
:
feat1
.
xe
,
y
:
feat1
.
ye
},
feats
,
[
feat1
.
index
,
feat2
.
index
],
true
))
||
(
FlagTolerance
(
len3
[
0
])
&&!
pinLine
({
x
:
feat2
.
xs
,
y
:
feat2
.
ys
},
feats
,
[
feat1
.
index
,
feat2
.
index
],
true
))
||
(
FlagTolerance
(
len4
[
0
])
&&!
pinLine
({
x
:
feat2
.
xe
,
y
:
feat2
.
ye
},
feats
,
[
feat1
.
index
,
feat2
.
index
],
true
)))
{
var
key
;
if
((
feat1
.
index
-
0
)
>
(
feat2
.
index
-
0
))
{
key
=
feat1
.
index
+
"_"
+
feat2
.
index
}
else
{
key
=
feat2
.
index
+
"_"
+
feat1
.
index
}
if
(
!
keys
[
key
])
{
keys
[
key
]
=
true
ret
.
push
({
feat1
:
feat1
,
feat2
:
feat2
,
})
GEN
.
PAUSE
(
0
)
}
}
}
}
})
GEN
.
selClearFeature
()
if
(
ret
.
length
>
0
)
{
ret
.
forEach
(
function
(
item
)
{
var
feat1
=
item
.
feat1
var
feat2
=
item
.
feat2
GEN
.
selLayerFeat
({
layer
:
layer
,
index
:
feat1
.
index
,
operation
:
"select"
})
GEN
.
selLayerFeat
({
layer
:
layer
,
index
:
feat2
.
index
,
operation
:
"select"
})
})
GEN
.
PAUSE
(
"check not optimize lines"
)
}
}
})
GEN
.
affectedLayer
({
mode
:
'all'
,
affected
:
'no'
});
//设置影响层全部不影响
GEN
.
clearLayers
();
//清除层显示
...
...
@@ -245,7 +286,7 @@ try {
function
FlagTolerance
(
len
)
{
return
len
>
0
&&
len
<=
data
.
tolerance
/
1000
return
len
>
0
.001
&&
len
<=
data
.
tolerance
/
1000
}
// 保存料号
...
...
@@ -338,3 +379,212 @@ function p2p(props) {
var
y2
=
props
.
y2
return
Math
.
sqrt
((
x2
-
x1
)
*
(
x2
-
x1
)
+
(
y2
-
y1
)
*
(
y2
-
y1
))
}
function
pinLine
(
p
,
lines
,
is
,
flag
)
{
// 点在线上
var
line
;
var
len
=
lines
.
length
;
// if(flag && is[0] == "462" && is[1] == "470") {
// IKM.msg(is)
// fs.writeFile("D:/vsCodeWork/test/tmp1.js", _.toString({
// p:p, lines:lines, is:is
// }))
// }
for
(
var
index
=
0
;
index
<
len
;
index
++
)
{
if
(
lines
[
index
].
index
!=
is
[
0
]
&&
lines
[
index
].
index
!=
is
[
1
])
{
var
xs
=
lines
[
index
].
xs
var
ys
=
lines
[
index
].
ys
var
xe
=
lines
[
index
].
xe
var
ye
=
lines
[
index
].
ye
if
((
p
.
x
==
xs
&&
p
.
y
==
ys
)
||
(
p
.
x
==
xe
&&
p
.
y
==
ye
)){
line
=
lines
[
index
]
break
}
else
if
(
Math
.
abs
(
ye
-
ys
)
<=
0.001
&&
Math
.
abs
(
ye
-
p
.
y
)
<=
0.001
)
{
line
=
lines
[
index
]
break
}
else
if
(
Math
.
abs
(
xe
-
xs
)
<=
0.001
&&
Math
.
abs
(
xe
-
p
.
x
)
<=
0.001
)
{
line
=
lines
[
index
]
break
}
else
if
(
Math
.
abs
((
xs
-
xe
)
/
(
ys
-
ye
)
-
(
p
.
x
-
xe
)
/
(
p
.
y
-
ye
))
<=
0.0001
)
{
line
=
lines
[
index
]
break
}
}
}
// if(!line) {
// GEN.selLayerFeat({layer:GEN.getWorkLayer(), index:is[0],operation:"select"})
// GEN.selLayerFeat({layer:GEN.getWorkLayer(), index:is[1],operation:"select"})
// fs.writeFile("D:/vsCodeWork/test/tmp1.js", _.toString({
// p:p, lines:lines, is:is
// }))
// GEN.PAUSE(0)
// GEN.selClearFeature()
// }
return
line
}
function
PointToLineDistance
(
xx
,
yy
,
x1
,
y1
,
x2
,
y2
)
{
var
ang1
,
ang2
,
ang
,
m
;
var
result
=
0
;
// 分别计算三条边的长度
var
a
=
Math
.
sqrt
((
x1
-
xx
)
*
(
x1
-
xx
)
+
(
y1
-
yy
)
*
(
y1
-
yy
));
if
(
a
===
0
)
{
return
[
0
,
{
x
:
x1
,
y
:
y1
}];
}
var
b
=
Math
.
sqrt
((
x2
-
xx
)
*
(
x2
-
xx
)
+
(
y2
-
yy
)
*
(
y2
-
yy
));
if
(
b
===
0
)
{
return
[
0
,
{
x
:
x2
,
y
:
y2
}];
}
var
c
=
Math
.
sqrt
((
x1
-
x2
)
*
(
x1
-
x2
)
+
(
y1
-
y2
)
*
(
y1
-
y2
));
// 如果线段是一个点则退出函数并返回距离
if
(
c
===
0
)
{
result
=
a
;
return
[
result
,
{
x
:
x1
,
y
:
y1
}];
}
// 如果点(xx,yy到点x1,y1)这条边短
if
(
a
<
b
)
{
// 如果直线段AB是水平线。得到直线段AB的弧度
if
(
y1
===
y2
)
{
if
(
x1
<
x2
)
{
ang1
=
0
;
}
else
{
ang1
=
Math
.
PI
;
}
}
else
{
m
=
(
x2
-
x1
)
/
c
;
if
(
m
-
1
>
0.00001
)
{
m
=
1
;
}
ang1
=
Math
.
acos
(
m
);
if
(
y1
>
y2
)
{
ang1
=
Math
.
PI
*
2
-
ang1
;
}
// 直线(x1,y1)-(x2,y2)与折X轴正向夹角的弧度
}
m
=
(
xx
-
x1
)
/
a
;
if
(
m
-
1
>
0.00001
)
{
m
=
1
;
}
ang2
=
Math
.
acos
(
m
);
if
(
y1
>
yy
)
{
ang2
=
Math
.
PI
*
2
-
ang2
;
}
// 直线(x1,y1)-(xx,yy)与折X轴正向夹角的弧度
ang
=
ang2
-
ang1
;
if
(
ang
<
0
)
{
ang
=
-
ang
;
}
if
(
ang
>
Math
.
PI
)
{
ang
=
Math
.
PI
*
2
-
ang
;
}
// 如果是钝角则直接返回距离
if
(
ang
>
Math
.
PI
/
2
)
{
return
[
a
,
{
x
:
x1
,
y
:
y1
}];
}
// 返回距离并且求得当前距离所在线段的坐标
if
(
x1
===
x2
)
{
return
[
b
*
Math
.
sin
(
ang
),
{
x
:
x1
,
y
:
yy
}];
}
else
if
(
y1
===
y2
)
{
return
[
b
*
Math
.
sin
(
ang
),
{
x
:
xx
,
y
:
y1
}];
}
// 直线的斜率存在且不为0的情况下
var
x
=
0
,
y
=
0
;
var
k1
=
((
y2
-
y1
)
/
x2
-
x1
);
var
kk
=
-
1
/
k1
;
var
bb
=
yy
-
xx
*
kk
;
var
b1
=
y2
-
x2
*
k1
;
x
=
(
b1
-
bb
)
/
(
kk
-
k1
);
y
=
kk
*
x
+
bb
;
return
[
a
*
Math
.
sin
(
ang
),
{
x
:
x
,
y
:
y
}];
}
// 如果两个点的纵坐标相同,则直接得到直线斜率的弧度
if
(
y1
===
y2
)
{
if
(
x1
<
x2
)
{
ang1
=
Math
.
PI
;
}
else
{
ang1
=
0
;
}
}
else
{
m
=
(
x1
-
x2
)
/
c
;
if
(
m
-
1
>
0.00001
)
{
m
=
1
;
}
ang1
=
Math
.
acos
(
m
);
if
(
y2
>
y1
)
{
ang1
=
Math
.
PI
*
2
-
ang1
;
}
}
m
=
(
xx
-
x2
)
/
b
;
if
(
m
-
1
>
0.00001
)
{
m
=
1
;
}
ang2
=
Math
.
acos
(
m
);
// 直线(x2-x1)-(xx,yy)斜率的弧度
if
(
y2
>
yy
)
{
ang2
=
Math
.
PI
*
2
-
ang2
;
}
ang
=
ang2
-
ang1
;
if
(
ang
<
0
)
{
ang
=
-
ang
;
}
if
(
ang
>
Math
.
PI
)
{
ang
=
Math
.
PI
*
2
-
ang
;
}
// 交角的大小
// 如果是对角则直接返回距离
if
(
ang
>
Math
.
PI
/
2
)
{
return
[
b
,
{
x
:
x2
,
y
:
y2
}];
}
// 如果是锐角,返回计算得到的距离,并计算出相应的坐标
if
(
x1
===
x2
)
{
return
[
b
*
Math
.
sin
(
ang
),
{
x
:
x1
,
y
:
yy
}];
}
else
if
(
y1
===
y2
)
{
return
[
b
*
Math
.
sin
(
ang
),
{
x
:
xx
,
y
:
y1
}];
}
// 直线的斜率存在且不为0的情况下
var
x
=
0
,
y
=
0
;
var
k1
=
((
y2
-
y1
)
/
x2
-
x1
);
var
kk
=
-
1
/
k1
;
var
bb
=
yy
-
xx
*
kk
;
var
b1
=
y2
-
x2
*
k1
;
x
=
(
b1
-
bb
)
/
(
kk
-
k1
);
y
=
kk
*
x
+
bb
;
return
[
b
*
Math
.
sin
(
ang
),
{
x
:
x
,
y
:
y
}];
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment