=head
 NAME: 
 DESCRIPTION: Copy Step
 PARAMETER:
	[
		{
			name : 'org_step',
			title : '原始step',
			type : 'LineEdit',
			property : {tool_tip : '过滤Step名称'},
		},
		{
			name : 'step',
			title : '目标step',
			type : 'LineEdit',
			property : {tool_tip : '料号后缀'},
		},
		{
			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 2021-01-12 Super Zhang
	    1.新版本
 HELP:
	<html><body bgcolor="#DDECFE">
		<font size="3" color="#003DB2"><p>功能简介</p></font>
		  <p> Copy Step </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';
use File::Copy;
use JSON;
use_module('TL_GenMath');
my $json = new JSON;

my ($Job,$Step)=($JOB,undef);
$PAR->{save_job} = 'No' unless $PAR->{save_job};
unless($PAR->{org_step} or $PAR->{step}){
	$GUI->msgbox(-icon=>'error',-text=>"请先设置脚本参数！");
	return 'Cancel';
}

$Job = lc($Job);

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("正在复制Step...",0,position=>'n');
    $GEN->openJob(job=>$Job) unless ($GEN->isJobOpen(job=>$Job));
	$GEN->openStep(job=>$Job,name=>$PAR->{org_step});
	

	my $exitString = `openwindow=>no<>layerindex=>1,2,3,4<>layerCount=>4`;










	
	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();
	}
    ###output and return status, if genesis error, it will output genesis error command
	unless ($GEN->{STATUS}){
		return 'done';
	}
	else{
		$GUI->msgbox(-icon=>'error',-text=>join("\n",@{$GEN->{STATUS}}));
		return 'Error';
	}
}

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







__END__