#!/usr/bin/perl use strict; use lib qq{$ENV{GENESIS_DIR}/e$ENV{GENESIS_VER}/all/perl}; use Data::Dumper; use Genesis; use POSIX qw(strftime); sub getJobPath{ my $job_name = shift @_; my $job_path = `$ENV{GENESIS_DIR}/e$ENV{GENESIS_VER}/misc/dbutil path jobs $job_name`; chomp $job_path; return $job_path; } #读取Csh文件 sub cshInfo{ my $source_script = shift @_; my %csh; my $csh_file; open (CSH_FILE, "$source_script") or warn "Cannot open info file - $csh_file: $! 1314 $source_script\n"; while () { chomp; next if /^\s*$/; my($var,$value) = /set\s+(\S+)\s*=\s*(.*)\s*/; $value =~ s/^\s*|\s*$//g; $value =~ s/\cM/<^M>/g; my @value = shellwords($_); if ($value =~ /^\(/ ) { $value =~ s/^\(|\)$//g; my @words = shellwords($value); grep {s/\Q<^M>/\cM/g} @words; $csh{$var} = [@words]; } else { $value =~ s/\Q<^M>/\cM/g; $value =~ s/^'|'$//g; $csh{$var} = $value; } #print "$_\n"; } close (CSH_FILE); return %csh; } sub shellwords { #no warnings 'uninitialized'; # we will be testing undef strings local *_ = \join('', @_) if @_; my (@words, $snippet); s/\A\s+//; while ($_ ne '') { my $field = substr($_, 0, 0); # leave results tainted for (;;) { if (s/\A"(([^"\\]|\\.)*)"//s) { ($snippet = $1) =~ s#\\(.)#$1#sg; } elsif (/\A"/) { require Carp; Carp::carp("Unmatched double quote: $_"); return(); } elsif (s/\A'(([^'\\]|\\.)*)'//s) { ($snippet = $1) =~ s#\\(.)#$1#sg; } elsif (/\A'/) { require Carp; Carp::carp("Unmatched single quote: $_"); return(); } elsif (s/\A\\(.?)//s) { $snippet = $1; } elsif (s/\A([^\s\\'"]+)//) { $snippet = $1; } else { s/\A\s+//; last; } $field .= $snippet; } push(@words, $field); } return @words; } sub AddTool{ my $self = shift @_; my $hole = shift @_; my $order = $self->{ORDER}; my $temp_tool_num = $self->{TOOL_NUM}; for(my $i = 0,my $n = 1;$i<=$#$hole;$i++,$n++){ #添加刀序 push @{$hole->[$i]},$order; push @{$hole->[$i]},$temp_tool_num; push @{$self->{OUT_FILE}},$hole->[$i]; if($n <= $#$hole){ #如果大小相同,则同一顺序 unless($hole->[$i]->[0] == $hole->[$n]->[0]){ $order++; $temp_tool_num = $order; } } else{ $order++; $temp_tool_num = $order; } } $self->{ORDER} = $order; $self->{TOOL_NUM} = $temp_tool_num; return $self; } sub SortTool{ my $self = shift @_; my $OutputFile; my $order = 1; my $temp_tool_num = $order; $self->{ORDER} = 1; $self->{TOOL_NUM} = $self->{ORDER}; ####正常圆孔 if(exists $self->{NORMAL}){ if(exists $self->{NORMAL}->{hole1}){ my @normal_hole = @{$self->{NORMAL}->{hole1}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole2}){ my @normal_hole = @{$self->{NORMAL}->{hole2}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole3}){ my @normal_hole = @{$self->{NORMAL}->{hole3}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole4}){ my @normal_hole = @{$self->{NORMAL}->{hole4}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole5}){ my @normal_hole = @{$self->{NORMAL}->{hole5}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole6}){ my @normal_hole = @{$self->{NORMAL}->{hole6}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole7}){ my @normal_hole = @{$self->{NORMAL}->{hole7}}; AddTool($self,\@normal_hole); } if(exists $self->{NORMAL}->{hole}){ my @normal_hole = @{$self->{NORMAL}->{hole}}; AddTool($self,\@normal_hole); } } ####正常扩孔 if(exists $self->{NIBBLE}){ if(exists $self->{NIBBLE}->{hole}){ my @nibble_hole = @{$self->{NIBBLE}->{hole}}; AddTool($self,\@nibble_hole); } } ####正常槽孔 if(exists $self->{NORMAL}){ if(exists $self->{NORMAL}->{slot}){ my @normal_slot = @{$self->{NORMAL}->{slot}}; AddTool($self,\@normal_slot); } } if(exists $self->{END_DRL1}){ my @nibble_hole = @{$self->{END_DRL1}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL2}){ my @nibble_hole = @{$self->{END_DRL2}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL3}){ my @nibble_hole = @{$self->{END_DRL3}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL4}){ my @nibble_hole = @{$self->{END_DRL4}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL5}){ my @nibble_hole = @{$self->{END_DRL5}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL6}){ my @nibble_hole = @{$self->{END_DRL6}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL7}){ my @nibble_hole = @{$self->{END_DRL7}}; AddTool($self,\@nibble_hole); } if(exists $self->{END_DRL}){ my @nibble_hole = @{$self->{END_DRL}}; AddTool($self,\@nibble_hole); } } sub ToolCategorization{ my $self = shift @_; my $ncLAYER = $self->{csh_file}->{ncLAYER}->[0]; my $ncSET = $self->{csh_file}->{ncSET}->[0]; my $ncMACHINE = $self->{csh_file}->{ncMACHINE}->[0]; my $ncTHICKNESS = $self->{csh_file}->{ncTHICKNESS}->[0]; my @ncSHAPE = @{$self->{csh_file}->{ncSHAPE}}; my @ncTYPE = @{$self->{csh_file}->{ncTYPE}}; my @ncSIZE = @{$self->{csh_file}->{ncSIZE}}; my @ncTOUCH_COPPER = @{$self->{csh_file}->{ncTOUCH_COPPER}}; my @ncFLAG = @{$self->{csh_file}->{ncFLAG}}; my @ncCOUNT = @{$self->{csh_file}->{ncCOUNT}}; my @ncPLUS_TOL = @{$self->{csh_file}->{ncPLUS_TOL}}; my @ncMINUS_TOL = @{$self->{csh_file}->{ncMINUS_TOL}}; my @ncFINISH_SIZE = @{$self->{csh_file}->{ncFINISH_SIZE}}; my @ncDESIGNATOR = @{$self->{csh_file}->{ncDESIGNATOR}}; $self->{LAYER_NAME} = $ncLAYER; my $pid = (split(/\./,$ARGV[0]))[1]; $self->{HEADER_PATH} = $ENV{GENESIS_TMP} . '/'. $ENV{JOB} . '_'. $ncSET . '_' . $ncLAYER .'_header_path' . '.' .$pid; $self->{NCEOF_PATH} = $ENV{GENESIS_TMP} . '/'. $ENV{JOB} . '_'. $ncSET . '_' . $ncLAYER .'_nceof_path' . '.' .$pid; my $PILOT = 'n'; my $MODE = "regular"; my $TYPE = "machine"; my $SPIN = '0'; my $FEED = '0'; my $STAGE = '1'; my $HITS = '500'; my $NIBB_DRL = $self->{NIBB_SIZE}; my $FIRST_DRL = $self->{FIRST_SIZE}; my $END_DRL = $self->{END_SIZE}; my $PTH_NIBB = $self->{PTH_NIBB}; for(my $i=0,my $COUNT=1;$i<=$#ncSIZE;$i++,$COUNT++){ my $TOOL_SIZE=sprintf('%.3f',$ncSIZE[$i]); #扩钻 if($TOOL_SIZE > $PTH_NIBB){ $MODE = "nibble"; $TYPE = "machine"; my @line = ($ncSIZE[$i],$COUNT,$NIBB_DRL,$PILOT,$MODE,$SPIN,$FEED,$TYPE,$STAGE,'sep',$HITS,$COUNT,$TOOL_SIZE); push @{$self->{NIBBLE}->{hole}},\@line; } #非扩钻 else{ $MODE = "regular"; $TYPE = $ncSHAPE[$i] eq 'text' ? "machine" : "machine"; #slot槽 if($ncSHAPE[$i] eq 'slot'){ my @line = ($ncSIZE[$i],$COUNT,$TOOL_SIZE,$PILOT,$MODE,$SPIN,$FEED,$TYPE,$STAGE,'sep',$HITS,$COUNT,0); push @{$self->{NORMAL}->{slot}},\@line; } #非slot槽 (正常圆孔) else { my @line = ($ncSIZE[$i],$COUNT,$TOOL_SIZE,$PILOT,$MODE,$SPIN,$FEED,$TYPE,$STAGE,'sep',$HITS,$COUNT,0); #最后一把刀,机台号 if($ncSHAPE[$i] eq 'text1'){ push @{$self->{END_DRL}},\@line; } elsif($ncSIZE[$i] == 20){ push @{$self->{END_DRL1}},\@line; } elsif($ncSIZE[$i] == 1){ push @{$self->{END_DRL}},\@line; } #第一把刀,调位孔孔1.001 elsif($ncSIZE[$i] == 39.409){ unshift @{$self->{NORMAL}->{hole1}}, \@line; } elsif($ncSIZE[$i] == 80.748){ unshift @{$self->{NORMAL}->{hole2}}, \@line; } elsif($ncSIZE[$i] == 125){ unshift @{$self->{NORMAL}->{hole3}}, \@line; } #私印孔3.201 elsif($ncSIZE[$i] == 126.024 || $ncSIZE[$i] == 124.055){ unshift @{$self->{NORMAL}->{hole4}}, \@line; } elsif($ncSIZE[$i] == 15.866){ unshift @{$self->{NORMAL}->{hole5}}, \@line; } # elsif($ncSIZE[$i] == 19.803){ unshift @{$self->{NORMAL}->{hole6}}, \@line; } #普通刀 else{ push @{$self->{NORMAL}->{hole}},\@line; } } } } return $self; } sub OutputFile{ my $self = shift @_; my $out_file = shift @_; my @tool_num; my $tmp = 0; #钻孔大小,类型文件 open (OUTPUT, "> $out_file") or warn "Cannot open info file -$! \n"; for(@{$self->{OUT_FILE}}){ my @row = @$_; my $tool_size = shift @row; print OUTPUT "@row\n"; } close OUTPUT; } sub main{ print "start hooks time:".strftime("%Y-%m-%d %H:%M:%S\n", localtime(time))."\n"; if(scalar @ARGV < 2) { print "-1\n"; exit; } my $source_script = $ARGV[0]; my $out_file = $ARGV[1]; my $self = undef; #扩孔 $self->{PTH_NIBB} = 255.906; #扩孔大小 $self->{NIBB_SIZE} = 126.063; #第一把刀 $self->{FIRST_SIZE} = 106.456; #最后一把刀 $self->{END_SIZE} = 404; $self->{JOB_PATH} = getJobPath($ENV{JOB}); %{$self->{csh_file}} = cshInfo($source_script); #刀分类 $self = ToolCategorization($self); #刀排序 SortTool($self); #输出 OutputFile($self, $out_file); print "end hooks time:".strftime("%Y-%m-%d %H:%M:%S\n", localtime(time))."\n"; } main(); __END__