test.js 11.6 KB
Newer Older
Scott Sun's avatar
Scott Sun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
=head
 NAME: 
 DESCRIPTION: 层别对齐
 PARAMETER:
	[
		{
			name : 'step_filter',
			type : 'LineEdit',
			title : 'step过滤',
			pack : {row:0,column:1},
			property:{tool_tip:'step过滤,未设置则手动选择'},
		},
		{
			name : 'base_layer',
			type : 'LineEdit',
			title : '初始参考层',
			pack : {row:0,column:1},
			property:{tool_tip:'选择参考基准的参考层,未设定则手动选择'},
		},
		{
			name : 'register_layers',
			title : '需对齐的层别',
			type : 'ComboBox',
			property : {
				size_policy:'Expanding,Fixed',
				item_list:[
					{name:'all',text:'所有层'},
					{name:'board',text:'board层'},
					{name:'select',text:'选择层'},
				],
				tool_tip:'如果未设置,默认为选择层'
			},
			pack : {row:1,column:1},
		},
		{
			name : 'save_job',
			title : '保存料号',
			type : 'RadioBox',
			property : {
				size_policy:'Expanding,Fixed',
				item_list:[
					{name:'Yes',text:'Yes'},
					{name:'No',text:'No'},
				],
				tool_tip:'脚本结束后自动保存料号,未设定,默认为No'
			},
			pack : {row:1,column:1},
		}
	]
	
Scott Sun's avatar
Scott Sun committed
51
 VERSION_HISTORY:
Scott Sun's avatar
Scott Sun committed
52 53 54
	V1.00 2018-01-15 Cody Yu
	    1.新版本
		
Scott Sun's avatar
Scott Sun committed
55
 HELP:
Scott Sun's avatar
Scott Sun committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	<html><body bgcolor="#DDECFE">
		<font size="3" color="#003DB2"><p>功能简介</p></font>
		  <p> 层别对齐  </p>
		  <br>
		<font size="3" color="#003DB2"><p>参数配置</p></font>
		<font color="#008000"><p>  </p></font>
		<font size="3" color="#003DB2"><p>注意事项</p></font>
		  <p>   </p>
		  <br>
	</body></html>
  
=cut

use strict;
use Encode;
use utf8;
use Data::Dump 'dump';
my ($Job,$Step)=($JOB,undef);
my $Return = 'done';
$PAR->{step_filter} = '.*' unless $PAR->{step_filter};
$PAR->{units} = 'inch' unless $PAR->{units};
$PAR->{cmp_tol} = 0.003 unless $PAR->{cmp_tol};
$PAR->{register_layers} = 'select' unless $PAR->{register_layers};
$PAR->{save_job} = 'No' unless $PAR->{save_job};

my $Matrix = $GEN->getMatrix(job=>$Job);
my $Replace_symbol = 'moire1x1x1x1x1x1';

# 设定参考层
$PAR->{base_layer} = 'out' unless $PAR->{base_layer};

Scott Sun's avatar
Scott Sun committed
87
try {
Scott Sun's avatar
Scott Sun committed
88 89 90 91 92 93 94 95 96 97 98
	##
	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';
Scott Sun's avatar
Scott Sun committed
99
    }
Scott Sun's avatar
Scott Sun committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	
    update_loading("正在打开料号$Job...",0,position=>'n');
    $GEN->openJob(job=>$Job) unless ($GEN->isJobOpen(job=>$Job));
	
	# 获取工作step
	update_loading("正在过滤工作step ,请稍候..",0,position=>'n');
	my @steps =  $GEN->getStepList(job=>$Job);
	if ( @steps == 0 ) {
		$GUI->msgbox(-icon=>'error',-text=>'在料号中没有Step存在,你将退出!');
		return 0;
	}
	elsif (@steps != 1){
        my @tmp_steps = grep(/$PAR->{step_filter}/,@steps);
		if ( @tmp_steps == 0 ) {
            $GUI->msgbox(-icon=>'warning',-text=>'根据脚本参数过滤出来的step不存在,请检查资料或者脚本参数配置!');
			return 'Cancel';
Scott Sun's avatar
Scott Sun committed
116
        }
Scott Sun's avatar
Scott Sun committed
117 118
        elsif ( @tmp_steps == 1 ) {
            $Step = $tmp_steps[0];
Scott Sun's avatar
Scott Sun committed
119 120
        }
        else {
Scott Sun's avatar
Scott Sun committed
121 122 123 124
            $Step = $GUI->select_step(-title=>'请选择工作Step',
                                      -steplist=>[@tmp_steps],
                                      -selectmode=>'single');
            return 'Cancel' unless ($Step);            
Scott Sun's avatar
Scott Sun committed
125
        }
Scott Sun's avatar
Scott Sun committed
126
	}
Scott Sun's avatar
Scott Sun committed
127
    else {
Scott Sun's avatar
Scott Sun committed
128
        $Step = $steps[0];
Scott Sun's avatar
Scott Sun committed
129
    }
Scott Sun's avatar
Scott Sun committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	
	$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();
	
	# 开始层对齐
	#create tmp layer
	my ($base_lyr) = ('base_lyr_tl');
	$GEN->createLayer(job=>$Job,layer=>$base_lyr,delete_exists=>'yes');
 
	my %step_limits = $GEN->getStepLimits(job=>$Job,step=>$Step,units=>$PAR->{units});
	##select register features and create base layer
	update_loading("选择对齐基准..",0,position=>'n');
	my $ans = select_register_basic(step=>$Step,base_lyr=>$base_lyr,step_limits=>\%step_limits);
	return $ans if($ans eq 'Cancel');
	##
	my %register_info = %{$ans};
	
	update_loading("选择需对齐的层别..",0,position=>'n');
	my $layers = select_work_layer();
	return $layers if $layers eq 'Cancel';
	
	my $report = register_layers(step=>$Step,layers=>$layers,register_info=>\%register_info,step_limits=>\%step_limits,base_lyr=>$base_lyr);
	##储存比对报告
	if( $report ){
		$IKM->update_flow_report(-report=>$report,-job_id=>$ARGS{job_id},-process_id=>$ARGS{process_id});
	}
	else{
		$IKM->update_flow_report(-report=>'',-job_id=>$ARGS{job_id},-process_id=>$ARGS{process_id});
	}
	
	$GEN->deleteLayer(job=>$Job,layer=>['base_lyr_tl']);
	$GEN->affectedLayer(mode=>'all',affected=>'no');
	update_loading("【 层对齐 】完成,..",1,position=>'n');
	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 $Return;
	}
	else{
		$GUI->msgbox(-icon=>'error',-text=>join("\n",@{$GEN->{STATUS}}));
		addFlowNotes(-notes=>"   Genesis Error:\n ".join("\n   ",@{$GEN->{STATUS}}));
		return 'Error';
	}
}

catch Error::Simple with {
	my $error = shift;
	$GUI->msgbox(-icon=>'error',-text=>$error);
	return 'Error';
}
finally{

};


sub select_register_basic{
	my %par = @_;
	my $step = $par{step};
	my $base_lyr = $par{base_lyr};
	my %step_limits = %{$par{step_limits}};
	my %info ;

	update_loading("请选择层别对齐的参照物(一般选择外形或钻孔,最少选择3个)",0,position=>'n');
	while(1){
		$GEN->openStep(job=>$Job,name=>$step);
		#如果存在默认基准层,则打开它;
		if (defined $PAR->{base_layer} and $PAR->{base_layer} !~ /^\s*$/){
			$GEN->workLayer(name=>$PAR->{base_layer},display_number=>2,clear_before=>'yes') if ($GEN->isLayerExists(job=>$Job,layer=>$PAR->{base_layer}));
		}
		my $ok = $GEN->PAUSE('Please Select Register Features');
		return 'Cancel' unless $ok;
		
		$info{sel_count} = $GEN->getSelectCount();
		unless ($info{sel_count}){
			$GUI->msgbox(-icon=>'error',-text=>'请选择参考对象');
		}
		else{
			last;
		}
	}
	#生成基准层
	$GEN->selCopyOther(dest=>'layer_name',target_layer=>$base_lyr,invert=>'no',);
	$GEN->clearLayers();
	$GEN->affectedLayer(mode=>'all',affected=>'no');
	my %layer_limits = $GEN->getLayerLimits(job=>$Job,step=>$step,layer=>$base_lyr,units=>$PAR->{units},);
	$info{shift_x} =  abs($layer_limits{xmax}-$step_limits{xmin}) + 1;
	$GEN->workLayer(name=>$base_lyr,display_number=>1);
	$GEN->selMove(dx=>-$info{shift_x},dy=>0);
	return \%info;
}


sub select_work_layer{
	my @layers;
	#选择层
	if ($PAR->{register_layers} eq 'all'){
		@layers = sort {$Matrix->{$a}{row} <=> $Matrix->{$b}{row}} keys %$Matrix;
	}
	elsif ($PAR->{register_layers} eq 'board'){
		@layers = grep({$Matrix->{$_}{context} eq 'board'}keys %$Matrix);
		@layers = sort {$Matrix->{$a}{row} <=> $Matrix->{$b}{row}} @layers;
	}
	elsif($PAR->{register_layers} eq 'select'){
		@layers = $GUI->select_layer(-title=>'请选择需对齐的层',-layermatrix=>$Matrix,-selectmode=>'multiple');
		return 'Cancel' unless @layers;
	}
	return \@layers;
Scott Sun's avatar
Scott Sun committed
249
}
Scott Sun's avatar
Scott Sun committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377

sub register_layers{
	my %par = @_;
	my $step = $par{step};
	my @layers = @{$par{layers}};
	my %register_info = %{$par{register_info}};
	my %step_limits = %{$par{step_limits}};

	my $base_lyr = $par{base_lyr};
	#my $report;
	my $report = '<html><body bgcolor="#DDECFE"><font size="3" color="#003DB2"><p>层间对齐报告</p></font>';
	$report .= '<font size="3" color="#003DB2">Step:'.$step.'&nbsp;&nbsp;&nbsp;&nbsp;运行时间:'.now().'</font>';
	$report .= '<table border="1"><tr bg_color><th>层别</th><th>是否对位</th><th>是否镜像</th></tr>';
	my $n_progress = 0;
	my $tmp_lyr = 'tmp_lyr_tl';
	foreach my $layer (@layers){
		update_loading("正在对齐${layer}..",(++$n_progress/scalar(@layers)));

		$GEN->clearLayers();
		$GEN->affectedLayer(mode=>'all',affected=>'no');
		$GEN->affectedLayer(affected=>'yes',layer=>[$layer],mode=>'single');
		$GEN->selReverse();
		next if ($register_info{sel_count} >$GEN->getSelectCount());
		my ($moved,$mirror) = ('No','No');
		foreach my $n (0..4){
			$GEN->deleteLayer(layer=>$tmp_lyr) if ($GEN->isLayerExists(job=>$Job,layer=>$tmp_lyr));
			$GEN->clearLayers();
			$GEN->affectedLayer(mode=>'all',affected=>'no');
			if ($n ==1 or $n == 2){
				$GEN->affectedLayer(affected=>'yes',layer=>[$layer],mode=>'single');
				$GEN->selTransform(
					oper=>'mirror',
					x_anchor=>$step_limits{xmin} + $step_limits{xsize}/2,
					y_anchor=>$step_limits{ymin} + $step_limits{ysize}/2,
					mode=>'anchor',
				);
				$GEN->affectedLayer(mode=>'all',affected=>'no');
				$mirror = ($n%2)?'Yes':'No';
			}
			if ($n ==3 or $n == 4){
				$GEN->affectedLayer(affected=>'yes',layer=>[$layer],mode=>'single');
				$GEN->selTransform(
					oper=>'mirror',
					x_anchor=>$step_limits{xmin} + $step_limits{xsize}/2,
					y_anchor=>$step_limits{ymin} + $step_limits{ysize}/2,
					mode=>'anchor',
				);
				$GEN->selTransform(
					oper=>'rotate',
					x_anchor=>$step_limits{xmin} + $step_limits{xsize}/2,
					y_anchor=>$step_limits{ymin} + $step_limits{ysize}/2,
					mode=>'anchor',
					angle=>180,
				);
				$GEN->affectedLayer(mode=>'all',affected=>'no');
				$mirror = ($n%2)?'Yes':'No';
				
			}
			if ($n == 0 or $n == 1 or $n == 3){
				$GEN->affectedLayer(affected=>'yes',layer=>[$base_lyr,$layer],mode=>'single');
				$GEN->selCopyOther(
					dest=>'layer_name',
					target_layer=>$tmp_lyr,
				);
				$GEN->clearLayers();
				$GEN->affectedLayer(mode=>'all',affected=>'no');		
				$GEN->workLayer(name=>$tmp_lyr,display_number=>1);
				$GEN->selectByFilter(feat_types=>'pad\;line\;arc',);
				$GEN->selChangeSym(symbol=>'r1') if ($GEN->getSelectCount());
				
				$GEN->selRefFeat(
					use=>'filter',
					layers=>$base_lyr,
					mode=>'touch',
					f_types=>'line\;pad\;surface\;arc\;text',
					polarity=>'positive\;negative',
					filter=>{
						feat_types=>'pad\;line\;surface\;arc\;text',
						polarity=>'positive\;negative',
					}
				);
				
				$GEN->selSubstitute(
					mode=>'substitute',
					symbol=>$Replace_symbol,
					x_datum=>0,
					y_datum=>0,
					tol=>$PAR->{cmp_tol}*1000,
				);
				$GEN->selectByFilter(
					feat_types=>'pad',
					include_syms=>$Replace_symbol,
					polarity=>'positive\;negative',
				);
				my $count = $GEN->getSelectCount();
				if ($GEN->getSelectCount() > 1.5){
					my @features = $GEN->getFeatures(
						job=>$Job,
						step=>$step,
						layer=>$tmp_lyr,
						options=>'select',
						units=>$PAR->{units},
					);
					
					foreach my $feat (@features){
						if (abs($feat->{x}) > 0.0001 or abs($feat->{y}) > 0.0001){
							$GEN->workLayer(name=>$layer,display_number=>1);
							$GEN->selMove(dx=>$register_info{shift_x}-$feat->{x},dy=>-$feat->{y}) if (abs($register_info{shift_x}-$feat->{x}) > 0.0001);
							$moved = 'Yes';
							last;
						}
					}
					last;
				}
			}
			else{
				$mirror = 'No';
				$moved = 'No';
			}
			
		}
		$report .= '<tr><th>'.$layer.'</th>'.(($moved eq 'Yes')?'<th bgcolor="green">Yes':'<th>No').'</th>'.(($mirror eq 'Yes')?'<th bgcolor="yellow">Yes':'<th>No').'</th></tr>'."\n";
	}
	$GEN->deleteLayer(job=>$Job,layer=>[$tmp_lyr],step=>$step);
	$GEN->affectedLayer(mode=>'all',affected=>'no');
	$GEN->units( type=>$PAR->{units});
	$report .='</table></body></html>';
	return $report;
Scott Sun's avatar
Scott Sun committed
378
}
Scott Sun's avatar
Scott Sun committed
379 380 381 382



__END__