Commit 59dac80a authored by Scott Sun's avatar Scott Sun

Merge branch 'develop' of http://gitlab.topibd.net/super.zhang/cam_t into develop

parents 33dc87f8 11ca6bff
# CAM_T
这个一个CAM新人测试脚本仓库a
\ No newline at end of file
这个一个CAM新人测试脚本仓库lll
\ No newline at end of file
=head
NAME: UNF_Creat_Model
_map
DESCRIPTION: 製作模具防壓點區域
PARAMETER:{}
VERSION_HISTORY:
V1.00 2021-03-25 Jessica_Wang
1.New version
HELP:
=cut
use warnings;
use strict;
use utf8;
use Encode;
use Data::Dump qw/dump/;
#use_module('TL_GenMath');
use JSON;
my ($Job,$Step)= ($JOB,undef);
my @work_layers;
###############################################################################
try{
show_loading("判断是否选择料号..",0,position=>'n');
unless( $Job){
$GUI->msgbox(-icon=>'error',-text=>"请先选择料号后再执行脚本!");
return 'Cancel';
}
##
update_loading("检查${Job}是否存在..",0,position=>'n');
unless ( $GEN->isJobExists(job=>$Job) ){
$GUI->msgbox(-icon=>'error',-text=>"料号${Job}不存在,请确认。");
return 'Cancel';
}
##
update_loading("正在打开料号 ${Job} ...",0,position=>'n');
$GEN->openJob(job=>$Job);
#判断pcs wpnl step是否存在
my $stepname1="pcs";
my $stepname2="wpnl";
my $s1 = $GEN->isStepExists(job=>$Job,step=>$stepname1);
my $s2 = $GEN->isStepExists(job=>$Job,step=>$stepname2);
if($s1==0 or $s2==0){
$GUI->msgbox(-icon=>'error',-text=>"Step不存在,请确认。");
return 'Cancel';
}
#打开Step
open_step($stepname1);
# 以pcs外型外擴1.5mm 创建临时层tmp_profile
update_loading("1. pcs step暫存層作tmp_profile ...",0,position=>'n');
$GEN->createLayer(job=>$Job,layer=>'tmp_profile',conext=>'misc',type=>'signal',delete_exists => 'yes');
$GEN->workLayer(name=>'tmp_profile',display_number=>1,clear_before=>'yes');
$GEN->COM("fill_params,type=solid,origin_type=datum,solid_type=surface,std_type=line,min_brush=25.4,use_arcs=yes,symbol=,dx=2.54,dy=2.54,x_off=0,y_off=0,std_angle=45,std_line_width=254,std_step_dist=1270,std_indent=odd,break_partial=yes,cut_prims=no,outline_draw=no,outline_width=0,outline_invert=no");
$GEN->COM("sr_fill,polarity=positive,step_margin_x=-1.5,step_margin_y=-1.5,step_max_dist_x=2540,step_max_dist_y=2540,sr_margin_x=0,sr_margin_y=0,sr_max_dist_x=0,sr_max_dist_y=0,nest_sr=yes,stop_at_steps=,consider_feat=no,consider_drill=no,consider_rout=no,dest=affected_layers,attributes=no,use_profile=use_profile");
#关闭当前pcs step 打开wpnl Step\
$GEN->closeStep();
open_step($stepname2);
#开始选择需要制作的层
update_loading("过滤层别...",0,position=>'n');
my @work_layers = get_work_layer();
return 'Cancel' if grep /^Cancel$/,@work_layers;
#对用户选择的层进行制作
foreach my $worklayer(@work_layers){
my $tmplayer="tmp_$worklayer";
$GEN->flattenLayer(job=>$Job,step=>$stepname2,source_layer=>'tmp_profile',target_layer=>$tmplayer);
#請手動添加模具範圍surface
add_surface($tmplayer);
#依選擇的模具層所對應的圖框範圍及角度作clip area
#第一步 找到圆框所在的层
my $p1="p";
my $tmplayer1="$worklayer$p1";
find_clip_layer($tmplayer1);
#第二步 clip area
get_clip_area($stepname2,$tmplayer1,$tmplayer);
#$GUI->debug(-text=>dump('okk'));
# 如層別中有punch_beac-mid,需先將這個給break再cutting data
my $p2="cutting";
my $cuttinglayer="$worklayer$p2";
chk_break($cuttinglayer,$stepname2,$worklayer);
# 將選擇的模具層(如p5a)複製到其他暫存層,作cutting data
# resize3000,複製負片到模具-wp暫存層(例:tmp-p5a-wp)
#複製後將模具-wp暫存層(例:tmp-p5a-wp)contourize
$GEN->COM("sel_cut_data,det_tol=25.4,con_tol=25.4,rad_tol=2.54,filter_overlaps=no,delete_doubles=no,use_order=yes,ignore_width=yes,ignore_holes=none,start_positive=yes,polarity_of_touching=same");
$GEN->COM("sel_resize,size=3000,corner_ctl=no");
$GEN->COM("sel_copy_other,dest=layer_name,target_layer=$tmplayer,invert=yes,dx=0,dy=0,size=0,x_anchor=0,y_anchor=0,rotation=0,mirror=none");
$GEN->workLayer(name=>$tmplayer,display_number=>2,clear_before=>'yes');
$GEN->selContourize();
#執行fill
$GEN->COM("fill_params,type=standard,origin_type=datum,solid_type=surface,std_type=line,min_brush=25.4,use_arcs=yes,symbol=,dx=2.54,dy=2.54,x_off=0,y_off=0,std_angle=45,std_line_width=49,std_step_dist=3000,std_indent=odd,break_partial=yes,cut_prims=no,outline_draw=yes,outline_width=50,outline_invert=no");
$GEN->COM("sel_fill");
$GEN->COM("sel_copy_other,dest=layer_name,target_layer=$worklayer,invert=no,dx=0,dy=0,size=0,x_anchor=0,y_anchor=0,rotation=0,mirror=none");
#删除临时层
del_tmplayer($tmplayer,$stepname2,$cuttinglayer);
}
$GEN->deleteLayer(job=>$Job,layer=>'tmp_profile',step=>$stepname2);
update_loading("程式运行结束...",0,position=>'n');
$GEN->clearLayers();
$GEN->affectedLayer( mode=>'all',affected=>'no' );
hide_loading();
#保存料号
if( $PAR->{save_job} =~ /yes/i ){
show_loading("$Job 正在保存料号,请稍候...",0,position=>'n');
$GEN->checkInout(job=>$Job,mode=>'out');
$GEN->saveJob(job=>$Job);
hide_loading();
}
unless ($GEN->{STATUS}){
return 'done';
}
else{
$GUI->msgbox(-icon=>'error',-text=>join("\n",@{$GEN->{STATUS}}));
return 'Error';
}
}
catch Error::Simple with {
my $error = encode("utf8",shift);
$GUI->msgbox(-icon=>'error',-text=>$error);
$GEN->COM("disp_on");
return 'Error';
}
finally{
};
=head
获取工作层
#1:需過濾層名為p或abp為首(如附件p5a、p6a、abp1a)\
#2:用户选择需要操作的层 需可多選,但以選擇層各別製作
=cut
sub get_work_layer{
# 获取工作层
my %matrix = $GEN->getMatrix(job=>$Job,type=>'hash');
update_loading("请选择工作层别....",0,position=>'n');
foreach my $layer (sort {$matrix{$a}{row} <=> $matrix{$b}{row}} keys %matrix) {
if(($layer =~ /^p/) or ($layer =~ /^abp/)){
push @work_layers,$layer;
}
}
##
my %tmp_matrix;
foreach my $layer (@work_layers) {
$tmp_matrix{$layer} = $matrix{$layer};
}
if (@work_layers > 1) {
@work_layers = $GUI->select_layer(
-title=>'请选择工作层别',
-layermatrix=>\%tmp_matrix,
-selectmode => 'multiple');#single
return 'Cancel' unless(@work_layers);
}
else {
@work_layers = @work_layers;
}
return @work_layers;
}
=head
設定暫停,彈出提示“請手動添加模具範圍surface
=cut
sub add_surface{
#$GUI->debug(-text=>dump('okkkk'));
my ($tmplayer) = @_;
update_loading("请手动在$tmplayer 层添加模具范围surface ...",0,position=>'n');
$GEN->workLayer(name=>$tmplayer,display_number=>2,clear_before=>'yes');
$GEN->zoomHome();
$GEN->COM("fill_params,type=solid,origin_type=datum,solid_type=surface,std_type=line,min_brush=25.4,use_arcs=yes,symbol=,dx=2.54,dy=2.54,x_off=0,y_off=0,std_angle=45,std_line_width=49,std_step_dist=3000,std_indent=odd,break_partial=yes,cut_prims=no,outline_draw=yes,outline_width=50,outline_invert=no");
$GEN->PAUSE("Please manually add surface For $tmplayer");
$GEN->clearLayers();
$GEN->affectedLayer( mode=>'all',affected=>'no' );
$GEN->zoomHome();
}
=head
依選擇的模具層所對應的圖框範圍及角度作clip area
第一步找到圖框範圍对应的层
=cut
sub find_clip_layer{
my ($tmplayer) = @_;
#判断该层是否存在
update_loading("正在选择圖框....",0,position=>'n');
if (! $GEN->isLayerExists(job=>$Job,layer=>$tmplayer) ) {
$GUI->msgbox(-type=>'error',-text=>"$tmplayer 不存在, 请检查!");
return 'Error';
}
$GEN->workLayer(name=>$tmplayer,display_number=>2,clear_before=>'yes');
$GEN->COM("filter_reset,filter_name=popup");
$GEN->selectByFilter(
feat_types=>'pad',
polarity=>'positive',
profile=>'all',
include_syms=>'punch_*_tl',
);
if(!$GEN->getSelectCount()==1){
$GUI->msgbox(-icon=>'error',-text=>"圖框範圍不存在,请确认。");
return 'Cancel';
}
}
=head
获取圆框的角度,中心坐标,尺寸,计算出clip area时两个点的坐标x1 y1 /x2 y2
=cut
sub get_clip_area{
my ($stepname2,$tmplayer1,$tmplayer) = @_;
update_loading("正在进行clip area....",0,position=>'n');
my @feat = $GEN->getFeatures(job=>$Job,step=>$stepname2,layer=>$tmplayer1,options=>select,units=>'mm');
my $feat= $feat[0];
my $angle=$feat->{angle};
my $x_loc=$feat->{x};
my $y_loc=$feat->{y};
my $symbolsize=$feat->{symbol};
# 圖框symbol為punch_qaa_180x300_tl,clip範圍為250x130mm
# punch_qd_250x300_tl,clip範圍為250x200mm
# punch_beac_130x130_tl,clip範圍為130x130mm
my $x1;
my $y1;
my $x2;
my $y2;
if($angle%180==0){
if($symbolsize eq "punch_qaa_180x300_tl"){
$x1=$x_loc-125;
$x2=$x_loc+125;
$y1=$y_loc-65;
$y2=$y_loc+65;
}
if($symbolsize eq "punch_qd_250x300_tl"){
$x1=$x_loc-125;
$x2=$x_loc+125;
$y1=$y_loc-100;
$y2=$y_loc+100;
}
if($symbolsize eq "punch_beac_130x130_tl"){
$x1=$x_loc-65;
$x2=$x_loc+65;
$y1=$y_loc-65;
$y2=$y_loc+65;
}
}else{
if($symbolsize eq "punch_qaa_180x300_tl"){
$x1=$x_loc-65;
$x2=$x_loc+65;
$y1=$y_loc-125;
$y2=$y_loc+125;
}
if($symbolsize eq "punch_qd_250x300_tl"){
$x1=$x_loc-100;
$x2=$x_loc+100;
$y1=$y_loc-125;
$y2=$y_loc+125;
}
if($symbolsize eq "punch_beac_130x130_tl"){
$x1=$x_loc-65;
$x2=$x_loc+65;
$y1=$y_loc-65;
$y2=$y_loc+65;
}
}
$GEN->clearLayers();
$GEN->affectedLayer( mode=>'all',affected=>'no' );
$GEN->zoomHome();
$GEN->workLayer(name=>$tmplayer,display_number=>1,clear_before=>'yes');
$GEN->clipArea(layers_mode =>'affected_layers',area=>'manual',area_type=>'rectangle',area_rect=>{x1=>$x1,y1=>$y1,x2=>$x2,y2=>$y2},inout=>'outside',contour_cut=>'no');
$GEN->COM("sel_resize,size=50,corner_ctl=no");
}
=head
检查是否存在punch_beac-mid 有则进行break
=cut
sub chk_break{
my ($cuttinglayer,$stepname2,$worklayer) = @_;
update_loading("检查是否存在punch_beac-mid 有则进行break...",0,position=>'n');
$GEN->deleteLayer(job=>$Job,layer=>$cuttinglayer,step=>$stepname2);
$GEN->copyLayer(source_job=>$Job,source_step=>$stepname2,source_layer=>$worklayer,dest_layer=>$cuttinglayer);
$GEN->workLayer(name=>$cuttinglayer,display_number=>1,clear_before=>'yes');
my %symsHist = $GEN->getLayerSymsHist(job=>$Job,step=>$stepname2,layer=>$cuttinglayer,options=>'break_sr',units=>'mm');
my @keysymsHist=keys %symsHist;
my @msg = grep(/punch_beac-mid/,@keysymsHist);
if(@msg>0){
$GEN->selBreak();
}
}
=head
删除临时层
=cut
sub del_tmplayer{
my ($tmplayer,$stepname2,$cuttinglayer) = @_;
update_loading("删除临时层...",0,position=>'n');
$GEN->deleteLayer(job=>$Job,layer=>$tmplayer,step=>$stepname2);
$GEN->deleteLayer(job=>$Job,layer=>$cuttinglayer."+++",step=>$stepname2);
$GEN->deleteLayer(job=>$Job,layer=>$cuttinglayer,step=>$stepname2);
}
=head
打开step
清除之前选中的层
=cut
sub open_step{
my ($stepname) = @_;
update_loading("正在打开Step $stepname ...",0,position=>'n');
$GEN->openStep(job=>$Job,name=>$stepname);
$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=>'mm' );
$GEN->zoomHome();
}
__END__
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