creat_cover.pl 9.94 KB
Newer Older
Scott Sun's avatar
s  
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 51 52 53 54 55 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 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 249 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
=head
 NAME: 
 DESCRIPTION: 
 PARAMETER:
	[
		{
			name : 'step_filter',
			title : '工作step',
			type : 'LineEdit',
			property : {tool_tip : '过滤Step名称'},
		},
		{
			name : 'units',
			title : '单位',
			type : 'RadioBox',
			property : {
				size_policy:'Expanding,Fixed',
				item_list:[
					{name:'inch',text:'INCH'},
					{name:'mm',text:'MM'},
				],
				tool_tip:'工作单位,未设定,默认为INCH'
			},
			pack : {row:1,column:1},
		},
		{
			name : 'cover_layer_suffix',
			title : '文字套层后缀',
			type : 'LineEdit',
			property : {tool_tip : ''},
		},
		{
			name : 'ss_to_sm',
			title : '文字距离阻焊',
			type : 'LineEdit',
			property : {tool_tip : ''},
		},
		{
			name : 'ss_to_smd',
			title : '文字距离SMD',
			type : 'LineEdit',
			property : {tool_tip : ''},
		},
		{
			name : 'ss_to_bga',
			title : '文字距离bga',
			type : 'LineEdit',
			property : {tool_tip : ''},
		},
		{
			name : 'select_lyr',
			title : '选择层别',
			type : 'RadioBox',
			property : {
				size_policy:'Expanding,Fixed',
				item_list:[
					{name:'yes',text:'Yes'},
					{name:'no',text:'No'},
				],
				tool_tip:'未设定,默认为Yes'
			},
			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},
		}
	]
 VERSION_HISTORY:
	V1.00 2019-05-24 Shyer
		1.新需求
	
 HELP:
  <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>
		<p> </p>
		
		<br>
  </body></html>
=cut

use strict;
#my ($JOB,$GEN,$GUI,$DB,$JOB_ID,$PAR,$APP,$MW);
use utf8;
use Encode;
use Data::Dump 'dump';
my $Return = 'done';
my ($Job,$Step) = ($JOB,undef);
$PAR->{units} = 'inch' unless $PAR->{units};
$PAR->{del_backup} = 'no' unless $PAR->{del_backup};
$PAR->{save_job} = 'no' unless $PAR->{save_job};
$PAR->{select_lyr} = 'yes'  unless($PAR->{select_lyr});
$PAR->{cover_layer_suffix} = '_cover_tl+'  unless($PAR->{cover_layer_suffix});
unless($PAR->{outline_size}){
    $PAR->{outline_size}  =  $PAR->{units} eq 'inch' ? 16 : 200;
}
my $outline = 'gko';
my %matrix;

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} 在Genesis中不存在, 请检查!");
        return 'Error';
    }
	
	##
	update_loading("正在打开料号${Job} ,请稍候..",0,position=>'n');
	$GEN->openJob(job=>$Job) unless ($GEN->isJobOpen(job=>$Job));
	
	##
	update_loading("过滤工作step...",0,position=>'n');
	my $ans_step = get_work_step();
	return 'Cancel' if $ans_step eq 'Cancel';
	
	##
	update_loading("过滤层别...",0,position=>'n');
	my @work_layers = get_work_layer();
	return 'Cancel' if $work_layers[0] eq 'Cancel';
    
    my %info = $GUI->show_form(
		-title => '请手动匹配以下信息',
		-showcheck => 1,-gen=>$GEN,
		-defaultsize=>[500,250],
		-items=>[
			{
				name => 'ss_to_sm',
				label => '文字距离阻焊(单边)',
				type => 'number',
				value=>$PAR->{ss_to_sm},
                units=>$PAR->{units} eq 'inch' ? 'mil' : 'um',
			},
			{
				name => 'ss_to_smd',
				label => '文字距离SMD(单边)',
				type => 'number',
				value=>$PAR->{ss_to_smd},
                units=>$PAR->{units} eq 'inch' ? 'mil' : 'um',
			},
			{
				name => 'ss_to_bga',
				label => '文字距离BGA(单边)',
				type => 'number',
				value=>$PAR->{ss_to_bga},
                units=>$PAR->{units} eq 'inch' ? 'mil' : 'um',
			},
		]
	);
	return 'Cancel' unless %info;
	#
	###
	update_loading("打开${Step} ,请稍候..",0,position=>'n');
	$GEN->openStep(job=>$Job,name=>$Step);
	$GEN->clearLayers();
	$GEN->affectedLayer( mode=>'all',affected=>'no' );
	$GEN->units( type=>$PAR->{units} );
	$GEN->zoomHome();
	update_loading("正在制作文字套层 ,请稍候..",0,position=>'n');
    foreach my $layer (@work_layers) {
        my $cover_lyr = $layer.$PAR->{cover_layer_suffix} ;
        my ($sm,$outer) ;
        if ($matrix{$layer}{side} eq 'top') {
            $sm = 'gts';
            $outer = 'gtl';
            $GEN->createLayer(job=>$Job,layer=>$cover_lyr,context=>'board',type=>'document',before=>$layer,delete_exists=>'yes');
        }else{
            $sm = 'gbs';
            $outer = 'gbl';
            $GEN->createLayer(job=>$Job,layer=>$cover_lyr,context=>'board',type=>'document',after=>$layer,delete_exists=>'yes');
        }
        if ( $GEN->isLayerExists(job=>$Job,layer=>$sm) ) {
            $GEN->affectedLayer(affected=>'yes',layer=>[$sm],clear_before=>'yes');
            $GEN->selectByFilter(
                       polarity=>'positive',
                       profile=>'all',
            );
            $GEN->selCopyOther(dest=>'layer_name',target_layer=>$cover_lyr,invert=>'no',size=>2*$info{ss_to_sm});
        }
        if ( $GEN->isLayerExists(job=>$Job,layer=>$outer) ) {
            $GEN->affectedLayer(affected=>'yes',layer=>[$outer],clear_before=>'yes');
            $GEN->selectByFilter(
                       attribute=>['.smd'],
                       profile=>'all',
            );
            if ( $GEN->getSelectCount() > 0 ){
                $GEN->selCopyOther(dest=>'layer_name',target_layer=>$cover_lyr,invert=>'no',size=>2*$info{ss_to_smd});
            }
            $GEN->selectByFilter(
                       attribute=>['.bga'],
                       profile=>'all',
            );
            if ( $GEN->getSelectCount() > 0 ){
                $GEN->selCopyOther(dest=>'layer_name',target_layer=>$cover_lyr,invert=>'no',size=>2*$info{ss_to_bga});
            }
        }
        if ( $GEN->isLayerExists(job=>$Job,layer=>$outline) ) {
            my $outline_tmp = $outline.'_tmp_tl';
            $GEN->copyLayer(source_job=>$Job,
                            source_step=>$Step,
                            source_layer=>$outline,
                            dest_layer=>$outline_tmp,
                            mode=>'replace', #append/replace
                            invert=>'no') ;#|'yes'
            
            $GEN->affectedLayer(affected=>'yes',layer=>[$outline_tmp],clear_before=>'yes');
            $GEN->selectByFilter(
                        feat_types=>'line\;arc',
                        polarity=>'positive',
                        profile=>'all',
            );
            $GEN->selChangeSym(symbol=>'r'.$PAR->{outline_size})  if ( $GEN->getSelectCount() > 0 );
            $GEN->copyLayer(source_job=>$Job,
                            source_step=>$Step,
                            source_layer=>$outline_tmp,
                            dest_layer=>$cover_lyr,
                            mode=>'append', #append/replace
                            invert=>'no') ;#|'yes'      
            $GEN->deleteLayer(job=>$Job,layer=>[$outline_tmp],step=>$Step);
        }
    }
	
	$GEN->clearLayers();
	$GEN->affectedLayer( mode=>'all',affected=>'no' );
	update_loading("程序运行完成,请检查运行结果..",0,position=>'n');
	sleep(2);
	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 = encode("utf8",shift);
	$GUI->msgbox(-icon=>'error',-text=>$error);
	return 'Error';
}
finally{
	
};

######################################################################################
sub get_work_step {
    my @steps =  $GEN->getStepList(job=>$Job);
	if ( @steps == 0 ) {
		$GUI->msgbox(-icon=>'error',-text=>'在料号中没有Step存在,你将退出!');
		return 'Cancel';
	}
	elsif (@steps != 0){
		my @tmp_steps = grep(/$PAR->{step_filter}/,@steps);
		if ( @tmp_steps == 0 ) {
		   $GUI->msgbox(-icon=>'warning',-text=>'根据脚本参数过滤出来的step不存在,请检查资料或者脚本参数配置!');
		   return 'Cancel';
		}
		elsif (@tmp_steps == 1) {
			$Step = $tmp_steps[0];
		}
        else {
            $Step = $GUI->select_step(-title=>'请选择工作 Step',
                                      -steplist=>[@tmp_steps],
									  -default=>[$tmp_steps[0]],
									  -gen=>$GEN,
                                      -selectmode=>'single');
            return 'Cancel' unless ($Step);            
        }
	}
	return undef;
}

sub isChecklistExist{
    my %par = @_ ;
    my @chklists = $GEN->getChecklist(job=>$par{job},step=>$par{step});
    if(grep /^$par{checkklist}$/,@chklists){
        return 1;
    }
    else{
        return 0;
    }
}
sub get_work_layer{
	my @work_layers;
	# 获取工作层
	%matrix = $GEN->getMatrix(job=>$Job,type=>'hash');
	foreach my $layer (sort {$matrix{$a}{row} <=> $matrix{$b}{row}}  keys %matrix) {
		if(defined($matrix{$layer}{context}) and $matrix{$layer}{context} eq 'board' ){
			if(defined($matrix{$layer}{tl_type}) and $matrix{$layer}{tl_type} eq 'silk_screen' ){
				push @work_layers,$layer;
			}
		}
	}
	
	#
	my %tmp_matrix;
	foreach my $layer (@work_layers) {
		$tmp_matrix{$layer} = $matrix{$layer};
	}	
	##
	
	if (@work_layers > 1 and $PAR->{select_lyr} eq 'yes') {
		@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;
}


__END__