通用工业视觉软件设计之几何工具插件模块-点线距离-后端实现
一 构造器
public ModuleFrm ( )
{
InitializeComponent ( ) ;
this. MaxHeight = SystemParameters. MaximizedPrimaryScreenHeight - 16 ;
this. MaxWidth = SystemParameters. MaximizedPrimaryScreenWidth;
this. DataContext = this;
this. Loaded + = ModuleFrm_Loaded;
}
二 加载函数
private void ModuleFrm_Loaded ( object sender, RoutedEventArgs e)
{
try
{
frm_ModuleObj = ( ModuleObj) m_ModuleObjBase;
Title. HeadName = frm_ModuleObj. ModuleParam. ModuleName;
CurrentModelID = frm_ModuleObj. ModuleParam. ModuleName;
if ( ! frm_ModuleObj. blnNewModule)
{
theFirsttime ( ) ;
}
else
{
theSecondTime ( ) ;
}
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
System. Windows. Forms. MessageBox. Show ( ex. ToString ( ) ) ;
}
}
private ModuleObj frm_ModuleObj;
三 链接图像变量
private void Gen_ImgPath_EValueAlarm ( object sender, RoutedEventArgs e)
{
ModuleDataVar. DataVar data = ( ModuleDataVar. DataVar) e. OriginalSource;
if ( data. m_DataValue != null && data. m_DataType == ModuleDataVar. DataVarType. DataType. Image)
{
try
{
if ( data. m_DataValue is List< HImageExt> )
{
frm_ModuleObj. m_Image = ( ( List< HImageExt> ) ( data) . m_DataValue) [ 0 ] ;
frm_ModuleObj. Link_Image_Data = data;
DispHwImg. UpdateWindow ( frm_ModuleObj, this. Main_HalconView) ;
}
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
}
}
}
public DataVar Link_Image_Data;
四 链接点X
private void Gen_Point1_x ( object sender, RoutedEventArgs e)
{
ModuleDataVar. DataVar data = ( ModuleDataVar. DataVar) e. OriginalSource;
if ( data. m_DataValue != null && data. m_DataType == ModuleDataVar. DataVarType. DataType. Double)
{
try
{
frm_ModuleObj. Link_Pont1_x_Data = data;
frm_ModuleObj. Pont1_x_Data = ( double) frm_ModuleObj. Link_Pont1_x_Data. m_DataValue;
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
}
}
}
public DataVar Link_Pont1_x_Data;
[ NonSerialized]
public double Pont1_x_Data = 0 ;
五 链接点Y
private void Gen_Point1_y ( object sender, RoutedEventArgs e)
{
ModuleDataVar. DataVar data = ( ModuleDataVar. DataVar) e. OriginalSource;
if ( data. m_DataValue != null && data. m_DataType == ModuleDataVar. DataVarType. DataType. Double)
{
try
{
frm_ModuleObj. Link_Pont1_y_Data = data;
frm_ModuleObj. Pont1_y_Data = ( double) frm_ModuleObj. Link_Pont1_y_Data. m_DataValue;
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
}
}
}
public DataVar Link_Pont1_y_Data;
[ NonSerialized]
public double Pont1_y_Data = 0 ;
六 直线X
private void Gen_LinePoint_x ( object sender, RoutedEventArgs e)
{
ModuleDataVar. DataVar data = ( ModuleDataVar. DataVar) e. OriginalSource;
if ( data. m_DataValue != null && data. m_DataType == ModuleDataVar. DataVarType. DataType. Double)
{
try
{
frm_ModuleObj. Link_LinePont_x_Data = data;
frm_ModuleObj. LinePont_x_Data = ( double) frm_ModuleObj. Link_LinePont_x_Data. m_DataValue;
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
}
}
}
public DataVar Link_LinePont_x_Data;
[ NonSerialized]
public double LinePont_x_Data = 0 ;
七 直线Y
private void Gen_LinePoint_y ( object sender, RoutedEventArgs e)
{
ModuleDataVar. DataVar data = ( ModuleDataVar. DataVar) e. OriginalSource;
if ( data. m_DataValue != null && data. m_DataType == ModuleDataVar. DataVarType. DataType. Double)
{
try
{
frm_ModuleObj. Link_LinePont_y_Data = data;
frm_ModuleObj. LinePont_y_Data = ( double) frm_ModuleObj. Link_LinePont_y_Data. m_DataValue;
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
}
}
}
public DataVar Link_LinePont_y_Data;
[ NonSerialized]
public double LinePont_y_Data = 0 ;
八 直线角度
private void Gen_Line1_phi ( object sender, RoutedEventArgs e)
{
ModuleDataVar. DataVar data = ( ModuleDataVar. DataVar) e. OriginalSource;
if ( data. m_DataValue != null && data. m_DataType == ModuleDataVar. DataVarType. DataType. Double)
{
try
{
frm_ModuleObj. Link_m_LinePhi_Data = data;
frm_ModuleObj. LinePhi_Data = ( double) frm_ModuleObj. Link_m_LinePhi_Data. m_DataValue;
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
}
}
}
public DataVar Link_m_LinePhi_Data;
[ NonSerialized]
public double LinePhi_Data = 0 ;
九 是否转换
private void CheckBox_Click ( object sender, RoutedEventArgs e)
{
CheckBox chk = ( CheckBox) sender;
if ( chk. IsChecked == true )
{
frm_ModuleObj. ConverValue = true ;
}
else
{
frm_ModuleObj. ConverValue = false ;
}
}
public bool ConverValue = false ;
十 保护操作
public override bool ProtectModuel ( )
{
if ( frm_ModuleObj. Link_Image_Data. m_DataValue == null )
{
System. Windows. Forms. MessageBox. Show ( "图像未设置!" ) ;
return false ;
}
if ( ! ( frm_ModuleObj. Link_Image_Data. m_DataValue is List< HImageExt> ) )
{
System. Windows. Forms. MessageBox. Show ( "图像类型错误!" ) ;
return false ;
}
frm_ModuleObj. m_CurentImgName = CurrentImage;
if ( Point1_x. Length == 0 )
{
System. Windows. Forms. MessageBox. Show ( "点1.x链接未选择!" ) ;
return false ;
}
if ( Point1_y. Length == 0 )
{
System. Windows. Forms. MessageBox. Show ( "点1.y链接未选择!" ) ;
return false ;
}
if ( LinePoint_x. Length == 0 )
{
System. Windows. Forms. MessageBox. Show ( "输入直线中心点1.X未设置!" ) ;
return false ;
}
if ( LinePoint_y. Length == 0 )
{
System. Windows. Forms. MessageBox. Show ( "输入直线中心点1.Y未设置!" ) ;
return false ;
}
if ( LinePhi. Length == 0 )
{
System. Windows. Forms. MessageBox. Show ( "输入直线角度未设置" ) ;
return false ;
}
frm_ModuleObj. m_Point1_x = Point1_x;
frm_ModuleObj. m_Point1_y = Point1_y;
frm_ModuleObj. m_LinePoint_x = LinePoint_x;
frm_ModuleObj. m_LinePoint_y = LinePoint_y;
frm_ModuleObj. m_LinePhi = LinePhi;
return true ;
}
public string m_CurentImgName = string. Empty;
public string m_Point1_x = string. Empty;
public string m_Point1_y = string. Empty;
public string m_LinePoint_x = string. Empty;
public string m_LinePoint_y = string. Empty;
public string m_LinePhi = string. Empty;
#region 输入点1. x
public string Point1_x
{
get { return ( string) this. GetValue ( Point1_xProperty) ; }
set { this. SetValue ( Point1_xProperty, value) ; }
}
public static readonly DependencyProperty Point1_xProperty =
DependencyProperty. Register ( "Point1_x" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
#endregion
#region 输入点1. y
public string Point1_y
{
get { return ( string) this. GetValue ( Point1_yProperty) ; }
set { this. SetValue ( Point1_yProperty, value) ; }
}
public static readonly DependencyProperty Point1_yProperty =
DependencyProperty. Register ( "Point1_y" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
#endregion
#region 输入直线. x
public string LinePoint_x
{
get { return ( string) this. GetValue ( LinePoint_xProperty) ; }
set { this. SetValue ( LinePoint_xProperty, value) ; }
}
public static readonly DependencyProperty LinePoint_xProperty =
DependencyProperty. Register ( "LinePoint_x" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
#region 输入直线. y
public string LinePoint_y
{
get { return ( string) this. GetValue ( LinePoint_yProperty) ; }
set { this. SetValue ( LinePoint_yProperty, value) ; }
}
public static readonly DependencyProperty LinePoint_yProperty =
DependencyProperty. Register ( "LinePoint_y" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
#endregion
#region 直线角度
public string LinePhi
{
get { return ( string) this. GetValue ( LinePhiProperty) ; }
set { this. SetValue ( LinePhiProperty, value) ; }
}
public static readonly DependencyProperty LinePhiProperty =
DependencyProperty. Register ( "LinePhi" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
#endregion
十一 执行
public override void ExModule ( )
{
try
{
if ( ProtectModuel ( ) )
{
int proIndex = SysProcessSln. g_ProjectList. FindIndex ( c = > c. ProjectInfo. m_ProjectID == frm_ModuleObj. ModuleParam. ProjectID) ;
if ( proIndex > - 1 )
{
SysProcessSln. g_ProjectList[ proIndex] . m_Var_List. RemoveAll ( c = > c. m_DataTip. Contains ( frm_ModuleObj. ModuleParam. ModuleName) ) ;
}
frm_ModuleObj. ExeModule ( ) ;
if ( frm_ModuleObj. ConverValue)
{
Dp_Y = frm_ModuleObj. Droopfoot_dis_y. ToString ( "0.000" ) ;
Dp_X = frm_ModuleObj. Droopfoot_dis_x. ToString ( "0.000" ) ;
Dp_Rstult = frm_ModuleObj. Droopfoot_dis. ToString ( "0.000" ) ;
}
else
{
Dp_Y = frm_ModuleObj. Droopfoot_dis_y_w. ToString ( "0.000" ) ;
Dp_X = frm_ModuleObj. Droopfoot_dis_x_w. ToString ( "0.000" ) ;
Dp_Rstult = frm_ModuleObj. Droopfoot_dis. ToString ( "0.000" ) ;
}
if ( Dp_X != null )
{
Main_HalconView. HobjectToHimage ( frm_ModuleObj. m_Image) ;
hxld_Point1. GenCrossContourXld ( frm_ModuleObj. Pont1_ImageY_Data, frm_ModuleObj. Pont1_ImageX_Data, 100 , new HTuple ( 45 ) . TupleRad ( ) ) ;
Main_HalconView. DispObj ( hxld_Point1, "blue" ) ;
hxld_Point2. GenCrossContourXld ( frm_ModuleObj. LinePont_y_Data, frm_ModuleObj. LinePont_x_Data, 100 , new HTuple ( 45 ) . TupleRad ( ) ) ;
Main_HalconView. DispObj ( hxld_Point2, "green" ) ;
Main_HalconView. DispObj ( frm_ModuleObj. Line. genXLD ( ) , "yellow" ) ;
hxld_Dp. GenCrossContourXld ( frm_ModuleObj. Droopfoot_dis_y, frm_ModuleObj. Droopfoot_dis_x, 100 , new HTuple ( 45 ) . TupleRad ( ) ) ;
Main_HalconView. DispObj ( hxld_Dp, "red" ) ;
}
}
}
catch ( Exception ex)
{
System. Windows. Forms. MessageBox. Show ( ex. ToString ( ) ) ;
Log. Error ( ex. ToString ( ) ) ;
}
}
#region 结果显示
public string Dp_X
{
get { return ( string) this. GetValue ( Dp_XProperty) ; }
set { this. SetValue ( Dp_XProperty, value) ; }
}
public static readonly DependencyProperty Dp_XProperty =
DependencyProperty. Register ( "Dp_X" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
public string Dp_Y
{
get { return ( string) this. GetValue ( Dp_YProperty) ; }
set { this. SetValue ( Dp_YProperty, value) ; }
}
public static readonly DependencyProperty Dp_YProperty =
DependencyProperty. Register ( "Dp_Y" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
public string Dp_Rstult
{
get { return ( string) this. GetValue ( Dp_RstultProperty) ; }
set { this. SetValue ( Dp_RstultProperty, value) ; }
}
public static readonly DependencyProperty Dp_RstultProperty =
DependencyProperty. Register ( "Dp_Rstult" , typeof ( string) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( string) ) ) ;
#endregion
[ NonSerialized]
public double Droopfoot_dis_x;
[ NonSerialized]
public double Droopfoot_dis_y;
[ NonSerialized]
public double Droopfoot_dis;
[ NonSerialized]
public double Droopfoot_dis_x_w;
[ NonSerialized]
public double Droopfoot_dis_y_w;
[ NonSerialized]
public double Droopfoot_dis_w;
[ NonSerialized]
public double Pont1_ImageX_Data = 0 ;
[ NonSerialized]
public double Pont1_ImageY_Data = 0 ;
[ NonSerialized]
public Line_INFO Line = new Line_INFO ( ) ;
private HXLDCont hxld_Point1 = new HXLDCont ( ) ;
private HXLDCont hxld_Point2 = new HXLDCont ( ) ;
private HXLDCont hxld_Dp = new HXLDCont ( ) ;
十二 后端执行
public override void ExeModule ( bool blnByHand = false )
{
base. ExeModule ( blnByHand) ;
sw = new System. Diagnostics. Stopwatch ( ) ;
sw. Start ( ) ;
try
{
Droopfoot_dis_x = 0.0 ;
Droopfoot_dis_y = 0.0 ;
Droopfoot_dis = 0.0 ;
Droopfoot_dis_x_w = 0.0 ;
Droopfoot_dis_y_w = 0.0 ;
Droopfoot_dis_w = 0.0 ;
int proIndex = SysProcessSln. g_ProjectList. FindIndex ( c = > c. ProjectInfo. m_ProjectID == ModuleParam. ProjectID) ;
if ( proIndex > - 1 )
{
DataVar data = ModuleProject. GetLocalVarValue ( Link_Image_Data) ;
if ( data. m_DataValue != null && data. m_DataValue is List< HImageExt> )
{
m_Image = ( ( List< HImageExt> ) ( data) . m_DataValue) [ 0 ] ;
if ( m_Image != null || m_Image. IsInitialized ( ) )
{
{
if ( m_Point1_x != null )
{
int Info1 = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List. FindIndex ( c = > c. m_DataName == Link_Pont1_x_Data. m_DataName &&
c. m_DataModuleID == Link_Pont1_x_Data. m_DataModuleID) ;
if ( Info1 > - 1 )
{
Link_Pont1_x_Data = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List[ Info1] ;
Pont1_ImageX_Data = Pont1_x_Data = ( double) Link_Pont1_x_Data. m_DataValue;
}
}
if ( m_Point1_y != null )
{
int Info2 = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List. FindIndex ( c = > c. m_DataName == Link_Pont1_y_Data. m_DataName &&
c. m_DataModuleID == Link_Pont1_y_Data. m_DataModuleID) ;
if ( Info2 > - 1 )
{
Link_Pont1_y_Data = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List[ Info2] ;
Pont1_ImageY_Data = Pont1_y_Data = ( double) Link_Pont1_y_Data. m_DataValue;
}
}
}
{
if ( m_Point1_x != null )
{
int Info1 = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List. FindIndex ( c = > c. m_DataName == Link_LinePont_x_Data. m_DataName &&
c. m_DataModuleID == Link_LinePont_x_Data. m_DataModuleID) ;
if ( Info1 > - 1 )
{
Link_LinePont_x_Data = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List[ Info1] ;
LinePont_x_Data = ( double) Link_LinePont_x_Data. m_DataValue;
}
}
if ( m_Point1_y != null )
{
int Info2 = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List. FindIndex ( c = > c. m_DataName == Link_LinePont_y_Data. m_DataName &&
c. m_DataModuleID == Link_LinePont_y_Data. m_DataModuleID) ;
if ( Info2 > - 1 )
{
Link_LinePont_y_Data = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List[ Info2] ;
LinePont_y_Data = ( double) Link_LinePont_y_Data. m_DataValue;
}
}
if ( m_LinePhi != null )
{
int Info3 = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List. FindIndex ( c = > c. m_DataName == Link_m_LinePhi_Data. m_DataName &&
c. m_DataModuleID == Link_m_LinePhi_Data. m_DataModuleID) ;
if ( Info3 > - 1 )
{
Link_m_LinePhi_Data = SysProcessSln. g_ProjectList[ proIndex] . m_Var_List[ Info3] ;
LinePhi_Data = ( double) Link_m_LinePhi_Data. m_DataValue;
}
}
}
{
Algo_Function. CreateLine ( LinePont_y_Data, LinePont_x_Data, LinePhi_Data, out Line) ;
Algo_Function. DroopFootLine ( Pont1_y_Data, Pont1_x_Data, Line, out Droopfoot_dis_y, out Droopfoot_dis_x) ;
Droopfoot_dis = Algo_Function. DistancePP ( Pont1_y_Data, Pont1_x_Data, Droopfoot_dis_y, Droopfoot_dis_x) ;
DataVar dp_x = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标X图像. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_x) ;
ModuleProject. UpdateLocalVarValue ( dp_x) ;
DataVar dp_y = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标Y图像. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_y) ;
ModuleProject. UpdateLocalVarValue ( dp_y) ;
DataVar dis = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 距离图像. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis) ;
ModuleProject. UpdateLocalVarValue ( dis) ;
}
{
Line_INFO line1 = new Line_INFO ( ) ;
Algo_Function. CreateLine ( LinePont_y_Data, LinePont_x_Data, LinePhi_Data, out line1) ;
Algo_Function. DroopFootLine ( Pont1_y_Data, Pont1_x_Data, line1, out Droopfoot_dis_y_w, out Droopfoot_dis_x_w) ;
if ( ! ConverValue)
{
}
Droopfoot_dis_w = Algo_Function. DistancePP ( Pont1_y_Data, Pont1_x_Data, Droopfoot_dis_y_w, Droopfoot_dis_x_w) ;
DataVar dp_x = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标X世界. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_x_w) ;
ModuleProject. UpdateLocalVarValue ( dp_x) ;
DataVar dp_y = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标Y世界. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_y_w) ;
ModuleProject. UpdateLocalVarValue ( dp_y) ;
DataVar dis = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 距离世界. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_w) ;
ModuleProject. UpdateLocalVarValue ( dis) ;
}
double Middis = 0 ;
if ( ! ConverValue)
{
Middis = Droopfoot_dis_w;
}
else
{
Middis = Droopfoot_dis;
}
ModuleParam. BlnSuccessed = true ;
}
else
{
ModuleParam. BlnSuccessed = false ;
}
}
else
{
ModuleParam. BlnSuccessed = false ;
}
}
else
{
ModuleParam. BlnSuccessed = false ;
}
}
catch ( Exception ex)
{
DataVar dp_x = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标X图像. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_x) ;
ModuleProject. UpdateLocalVarValue ( dp_x) ;
DataVar dp_y = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标Y图像. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_y) ;
ModuleProject. UpdateLocalVarValue ( dp_y) ;
DataVar dis = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 距离图像. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis) ;
ModuleProject. UpdateLocalVarValue ( dis) ;
DataVar dp_w_x = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标X世界. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_x_w) ;
ModuleProject. UpdateLocalVarValue ( dp_w_x) ;
DataVar dp_w_y = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 坐标Y世界. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_y_w) ;
ModuleProject. UpdateLocalVarValue ( dp_w_y) ;
DataVar dis_w = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 距离世界. ToString ( ) ,
DataVarType. DataType. Double, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, Droopfoot_dis_w) ;
ModuleProject. UpdateLocalVarValue ( dis_w) ;
ModuleParam. BlnSuccessed = false ;
Log. Error ( string. Format ( $"{ModuleProject.ProjectInfo.m_ProjectName}{" , "}{ModuleParam.ModuleName}{" , 执行失败, "}{ex.ToString()}" ) ) ;
}
finally
{
sw. Stop ( ) ;
ModuleParam. ModuleCostTime = Convert. ToInt32 ( sw. ElapsedMilliseconds) ;
{
DataVar objStatus = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 状态. ToString ( ) ,
DataVarType. DataType. Bool, DataVarType. DataGroup. 单量, 1 , "false" , ModuleParam. ModuleName, ModuleParam. BlnSuccessed) ;
ModuleProject. UpdateLocalVarValue ( objStatus) ;
}
{
DataVar objTime = new DataVar ( DataVarType. DataAtrribution. 局部变量, ModuleParam. ModuleID, ConstantVar. 时间. ToString ( ) ,
DataVarType. DataType. Int, DataVarType. DataGroup. 单量, 1 , "0" , ModuleParam. ModuleName, ModuleParam. ModuleCostTime) ;
ModuleProject. UpdateLocalVarValue ( objTime) ;
}
sw. Reset ( ) ;
}
}
十四 保存参数
public override void SaveModuleParam ( )
{
try
{
if ( ProtectModuel ( ) )
{
( ( ModuleObj) m_ModuleObjBase) . blnNewModule = true ;
}
else
{
return ;
}
this. Close ( ) ;
}
catch ( Exception ex)
{
Log. Error ( ex. ToString ( ) ) ;
System. Windows. Forms. MessageBox. Show ( ex. ToString ( ) ) ;
}
}
十五 关闭窗口
private void Title_CloseWindow ( object sender, RoutedEventArgs e)
{
CancelModuleParam ( ) ;
}
十六 首次打开和二次打开
public override void theFirsttime ( )
{
base. theFirsttime ( ) ;
#region 查询该流程中为图像的模块.
if ( frm_ModuleObj. GenModuleIndex ( out string str, out frm_ModuleObj. m_Image, out frm_ModuleObj. Link_Image_Data) )
{
CurrentImage = str;
DispHwImg. UpdateWindow ( frm_ModuleObj, this. Main_HalconView) ;
}
#endregion
}
public override void theSecondTime ( )
{
base. theSecondTime ( ) ;
#region 读取链接图像并显示
CurrentImage = frm_ModuleObj. m_CurentImgName;
if ( CurrentImage != null && CurrentImage. Length > 0 )
{
DataVar var = frm_ModuleObj. m_ModuleProject. GetCurLocalVarValue ( frm_ModuleObj. Link_Image_Data) ;
if ( var. m_DataValue is List< HImageExt> )
{
frm_ModuleObj. m_Image = ( ( List< HImageExt> ) var. m_DataValue) [ 0 ] ;
DispHwImg. UpdateWindow ( frm_ModuleObj, this. Main_HalconView) ;
}
}
#endregion
#region 输入点1. x
Point1_x = frm_ModuleObj. m_Point1_x;
if ( frm_ModuleObj. m_Point1_x != null )
{
if ( frm_ModuleObj. m_Point1_x. Length > 0 )
{
frm_ModuleObj. Link_Pont1_x_Data = SysProcessSln. Cur_Project. m_Var_List. Find ( c = > c. m_DataName == frm_ModuleObj. Link_Pont1_x_Data. m_DataName &&
c. m_DataModuleID == frm_ModuleObj. Link_Pont1_x_Data. m_DataModuleID) ;
frm_ModuleObj. Pont1_x_Data = ( double) frm_ModuleObj. Link_Pont1_x_Data. m_DataValue;
}
}
#endregion
#region 输入点1. y
Point1_y = frm_ModuleObj. m_Point1_y;
if ( frm_ModuleObj. m_Point1_y != null )
{
if ( frm_ModuleObj. m_Point1_y. Length > 0 )
{
frm_ModuleObj. Link_Pont1_y_Data = SysProcessSln. Cur_Project. m_Var_List. Find ( c = > c. m_DataName == frm_ModuleObj. Link_Pont1_y_Data. m_DataName &&
c. m_DataModuleID == frm_ModuleObj. Link_Pont1_y_Data. m_DataModuleID) ;
frm_ModuleObj. Pont1_y_Data = ( double) frm_ModuleObj. Link_Pont1_y_Data. m_DataValue;
}
}
#endregion
#region 输入直线中心. x
LinePoint_x = frm_ModuleObj. m_LinePoint_x;
if ( frm_ModuleObj. m_LinePoint_x != null )
{
if ( frm_ModuleObj. m_LinePoint_x. Length > 0 )
{
frm_ModuleObj. Link_LinePont_x_Data = SysProcessSln. Cur_Project. m_Var_List. Find ( c = > c. m_DataName == frm_ModuleObj. Link_LinePont_x_Data. m_DataName &&
c. m_DataModuleID == frm_ModuleObj. Link_LinePont_x_Data. m_DataModuleID) ;
frm_ModuleObj. LinePont_x_Data = ( double) frm_ModuleObj. Link_LinePont_x_Data. m_DataValue;
}
}
#endregion
#region 输入直线中心. y
LinePoint_y = frm_ModuleObj. m_LinePoint_y;
if ( frm_ModuleObj. m_LinePoint_y != null )
{
if ( frm_ModuleObj. m_LinePoint_y. Length > 0 )
{
frm_ModuleObj. Link_LinePont_y_Data = SysProcessSln. Cur_Project. m_Var_List. Find ( c = > c. m_DataName == frm_ModuleObj. Link_LinePont_y_Data. m_DataName &&
c. m_DataModuleID == frm_ModuleObj. Link_LinePont_y_Data. m_DataModuleID) ;
frm_ModuleObj. LinePont_y_Data = ( double) frm_ModuleObj. Link_LinePont_y_Data. m_DataValue;
}
}
#endregion
#region 输入直线角度
LinePhi = frm_ModuleObj. m_LinePhi;
if ( frm_ModuleObj. m_LinePhi != null )
{
if ( frm_ModuleObj. m_LinePhi. Length > 0 )
{
frm_ModuleObj. Link_m_LinePhi_Data = SysProcessSln. Cur_Project. m_Var_List. Find ( c = > c. m_DataName == frm_ModuleObj. Link_m_LinePhi_Data. m_DataName &&
c. m_DataModuleID == frm_ModuleObj. Link_m_LinePhi_Data. m_DataModuleID) ;
frm_ModuleObj. LinePhi_Data = ( double) frm_ModuleObj. Link_m_LinePhi_Data. m_DataValue;
}
}
#endregion
#region 是否转换
converValue = frm_ModuleObj. ConverValue;
#endregion
}
public bool converValue
{
get { return ( bool) this. GetValue ( converValueProperty) ; }
set { this. SetValue ( converValueProperty, value) ; }
}
public static readonly DependencyProperty converValueProperty =
DependencyProperty. Register ( "converValue" , typeof ( bool) , typeof ( ModuleFrm) , new PropertyMetadata ( default ( bool) ) ) ;