版本初始化,建立主窗体页面

This commit is contained in:
liu.wenjie
2019-07-13 19:28:22 +08:00
committed by liu.wenjie
commit 32b9b5ed0b
270 changed files with 360846 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,73 @@
namespace HalconWindowTest.HalconWindow
{
partial class HWindow_Final
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.m_CtrlHStatusLabelCtrl = new System.Windows.Forms.Label();
this.mCtrl_HWindow = new HalconDotNet.HWindowControl();
this.SuspendLayout();
//
// m_CtrlHStatusLabelCtrl
//
this.m_CtrlHStatusLabelCtrl.AutoSize = true;
this.m_CtrlHStatusLabelCtrl.Location = new System.Drawing.Point(14, 533);
this.m_CtrlHStatusLabelCtrl.Name = "m_CtrlHStatusLabelCtrl";
this.m_CtrlHStatusLabelCtrl.Size = new System.Drawing.Size(41, 12);
this.m_CtrlHStatusLabelCtrl.TabIndex = 1;
this.m_CtrlHStatusLabelCtrl.Text = "label1";
//
// mCtrl_HWindow
//
this.mCtrl_HWindow.BackColor = System.Drawing.Color.Black;
this.mCtrl_HWindow.BorderColor = System.Drawing.Color.Black;
this.mCtrl_HWindow.Dock = System.Windows.Forms.DockStyle.Fill;
this.mCtrl_HWindow.ImagePart = new System.Drawing.Rectangle(0, 0, 640, 480);
this.mCtrl_HWindow.Location = new System.Drawing.Point(0, 0);
this.mCtrl_HWindow.Name = "mCtrl_HWindow";
this.mCtrl_HWindow.Size = new System.Drawing.Size(629, 558);
this.mCtrl_HWindow.TabIndex = 2;
this.mCtrl_HWindow.WindowSize = new System.Drawing.Size(629, 558);
//
// HWindow_Final
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.m_CtrlHStatusLabelCtrl);
this.Controls.Add(this.mCtrl_HWindow);
this.Name = "HWindow_Final";
this.Size = new System.Drawing.Size(629, 558);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label m_CtrlHStatusLabelCtrl;
private HalconDotNet.HWindowControl mCtrl_HWindow;
}
}

View File

@@ -0,0 +1,433 @@
using System;
using System.Windows.Forms;
using HalconDotNet;
namespace HalconWindowTest.HalconWindow
{
public partial class HWindow_Final : UserControl
{
#region .
private HWindow /**/ hv_window; //halcon窗体控件的句柄 this.mCtrl_HWindow.HalconWindow;
private ContextMenuStrip /**/ hv_MenuStrip; //右键菜单控件
// 窗体控件右键菜单内容
ToolStripMenuItem fit_strip;
ToolStripMenuItem saveImg_strip;
ToolStripMenuItem saveWindow_strip;
ToolStripMenuItem barVisible_strip;
ToolStripMenuItem histogram_strip;
private HImage /**/ hv_image; //缩放时操作的图片 此处千万不要使用hv_image = new HImage(),不然在生成控件dll的时候,会导致无法序列化,去你妈隔壁,还好老子有版本控制,不然都找不到这种恶心问题
private int /**/ hv_imageWidth, hv_imageHeight; //图片宽,高
private string /**/ str_imgSize; //图片尺寸大小 5120X3840
private HTuple str_channel; //通道数
private bool /**/ drawModel = false; //绘制模式下,不允许缩放和鼠标右键菜单
public ViewWindow.ViewWindow viewWindow; /**/ //ViewWindow
public HWindowControl hWindowControl; /**/ // 当前halcon窗口
#endregion
/// <summary>
/// 初始化控件
/// </summary>
public HWindow_Final()
{
InitializeComponent();
//
viewWindow = new ViewWindow.ViewWindow(mCtrl_HWindow);
hWindowControl = this.mCtrl_HWindow;
hv_window = this.mCtrl_HWindow.HalconWindow;
// 设定鼠标按下时图标的形状
// 'arrow' 'default' 'crosshair' 'text I-beam' 'Slashed circle' 'Size All'
// 'Size NESW' 'Size S' 'Size NWSE' 'Size WE' 'Vertical Arrow' 'Hourglass'
//
// hv_window.SetMshape("Hourglass");
fit_strip = new ToolStripMenuItem("适应窗口");
fit_strip.Click += new EventHandler((s, e) => DispImageFit(mCtrl_HWindow));
barVisible_strip = new ToolStripMenuItem("显示StatusBar");
barVisible_strip.CheckOnClick = true;
barVisible_strip.CheckedChanged += new EventHandler(barVisible_strip_CheckedChanged);
m_CtrlHStatusLabelCtrl.Visible = false;
mCtrl_HWindow.Height = this.Height;
saveImg_strip = new ToolStripMenuItem("保存原始图像");
saveImg_strip.Click += new EventHandler((s, e) => SaveImage());
saveWindow_strip = new ToolStripMenuItem("保存窗口缩略图");
saveWindow_strip.Click += new EventHandler((s, e) => SaveWindowDump());
histogram_strip = new ToolStripMenuItem("显示直方图(H)");
histogram_strip.CheckOnClick = true;
histogram_strip.Checked = false;
hv_MenuStrip = new ContextMenuStrip();
hv_MenuStrip.Items.Add(fit_strip);
hv_MenuStrip.Items.Add(barVisible_strip);
hv_MenuStrip.Items.Add(new ToolStripSeparator());
hv_MenuStrip.Items.Add(saveImg_strip);
hv_MenuStrip.Items.Add(saveWindow_strip);
barVisible_strip.Enabled = true;
fit_strip.Enabled = false;
histogram_strip.Enabled = false;
saveImg_strip.Enabled = false;
saveWindow_strip.Enabled = false;
mCtrl_HWindow.ContextMenuStrip = hv_MenuStrip;
mCtrl_HWindow.SizeChanged += new EventHandler((s, e) => DispImageFit(mCtrl_HWindow));
}
/// <summary>
/// 绘制模式下,不允许缩放和鼠标右键菜单
/// </summary>
public bool DrawModel
{
get { return drawModel; }
set
{
//缩放控制
viewWindow.setDrawModel(value);
//绘制模式 不现实右键
if (value == true)
{
mCtrl_HWindow.ContextMenuStrip = null;
}
else
{
//恢复
mCtrl_HWindow.ContextMenuStrip = hv_MenuStrip;
}
drawModel = value;
}
}
private bool _EditModel = true;//绘制的图形是否可以编辑
public bool EditModel
{
get
{
return _EditModel;
}
set
{
viewWindow.setEditModel(value);
_EditModel = value;
}
}
/// <summary>
/// 设置image,初始化控件参数
/// </summary>
public HImage Image
{
get
{
return this.hv_image;
}
set
{
if (value != null)
{
if (this.hv_image != null)
{
this.hv_image.Dispose();
}
this.hv_image = value;
hv_image.GetImageSize(out hv_imageWidth, out hv_imageHeight);
HOperatorSet.CountChannels(hv_image, out str_channel);
str_imgSize = String.Format("{0}X{1}", hv_imageWidth, hv_imageHeight);
// str_channel = string.Format("C{0}", str_channel);
//DispImageFit(mCtrl_HWindow);
try
{
barVisible_strip.Enabled = true;
fit_strip.Enabled = true;
histogram_strip.Enabled = true;
saveImg_strip.Enabled = true;
saveWindow_strip.Enabled = true;
}
catch (Exception)
{
}
viewWindow.displayImage(hv_image);
}
}
}
/// <summary>
/// 获得halcon窗体控件的句柄
/// </summary>
public IntPtr HWindowHalconID
{
get { return this.mCtrl_HWindow.HalconID; }
}
public HWindowControl getHWindowControl()
{
return this.mCtrl_HWindow;
}
/// <summary>
/// 状态条 显示/隐藏 CheckedChanged事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void barVisible_strip_CheckedChanged(object sender, EventArgs e)
{
ToolStripMenuItem strip = sender as ToolStripMenuItem;
this.SuspendLayout();
if (strip.Checked)
{
m_CtrlHStatusLabelCtrl.Visible = true;
//mCtrl_HWindow.Height = this.Height - m_CtrlHStatusLabelCtrl.Height - m_CtrlHStatusLabelCtrl.Margin.Top - m_CtrlHStatusLabelCtrl.Margin.Bottom;
mCtrl_HWindow.HMouseMove += HWindowControl_HMouseMove;
}
else
{
m_CtrlHStatusLabelCtrl.Visible = false;
//mCtrl_HWindow.Height = this.Height;
mCtrl_HWindow.HMouseMove -= HWindowControl_HMouseMove;
}
//DispImageFit(mCtrl_HWindow);
this.ResumeLayout(false);
this.PerformLayout();
}
public void showStatusBar()
{
barVisible_strip.Checked = true;
}
/// <summary>
/// 保存窗体截图到本地
/// </summary>
private void SaveWindowDump()
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "PNG图像|*.png|所有文件|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
if (String.IsNullOrEmpty(sfd.FileName))
return;
//截取窗口图
HOperatorSet.DumpWindow(HWindowHalconID, "png best", sfd.FileName);
}
}
/// <summary>
/// 保存原始图片到本地
/// </summary>
private void SaveImage()
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "BMP图像|*.bmp|所有文件|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
if (String.IsNullOrEmpty(sfd.FileName))
{
return;
}
HOperatorSet.WriteImage(hv_image, "bmp", 0, sfd.FileName);
}
}
/// <summary>
/// 图片适应大小显示在窗体
/// </summary>
/// <param name="hw_Ctrl">halcon窗体控件</param>
private void DispImageFit(HWindowControl hw_Ctrl)
{
try
{
this.viewWindow.resetWindowImage();
}
catch (Exception)
{
}
}
/// <summary>
/// 鼠标在空间窗体里滑动,显示鼠标所在位置的灰度值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void HWindowControl_HMouseMove(object sender, HMouseEventArgs e)
{
if (hv_image != null)
{
try
{
int button_state;
double positionX, positionY;
string str_value;
string str_position;
bool _isXOut = true, _isYOut = true;
HTuple channel_count;
HOperatorSet.CountChannels(hv_image, out channel_count);
hv_window.GetMpositionSubPix(out positionY, out positionX, out button_state);
str_position = String.Format("R: {0:0000.0}, C: {1:0000.0}", positionY, positionX);
_isXOut = (positionX < 0 || positionX >= hv_imageWidth);
_isYOut = (positionY < 0 || positionY >= hv_imageHeight);
if (!_isXOut && !_isYOut)
{
if ((int)channel_count == 1)
{
int grayVal;
grayVal = hv_image.GetGrayval((int)positionY, (int)positionX);
str_value = String.Format("V: {0:000}", grayVal);
}
else if ((int)channel_count == 3)
{
double grayValRed, grayValGreen, grayValBlue;
HImage _RedChannel, _GreenChannel, _BlueChannel;
_RedChannel = hv_image.AccessChannel(1);
_GreenChannel = hv_image.AccessChannel(2);
_BlueChannel = hv_image.AccessChannel(3);
grayValRed = _RedChannel.GetGrayval((int)positionY, (int)positionX);
grayValGreen = _GreenChannel.GetGrayval((int)positionY, (int)positionX);
grayValBlue = _BlueChannel.GetGrayval((int)positionY, (int)positionX);
_RedChannel.Dispose();
_GreenChannel.Dispose();
_BlueChannel.Dispose();
str_value = String.Format("V: ({0:000.0}, {1:000.0}, {2:000.0})", grayValRed, grayValGreen, grayValBlue);
}
else
{
str_value = "";
}
m_CtrlHStatusLabelCtrl.Text = str_channel + " " + str_imgSize + " " + str_position + " " + str_value;
}
}
catch (Exception ex)
{
//不处理
}
}
}
public void ClearWindow()
{
try
{
this.Invoke(new Action(
() =>
{
//this.hv_image = null;
m_CtrlHStatusLabelCtrl.Visible = false;
barVisible_strip.Enabled = false;
fit_strip.Enabled = false;
histogram_strip.Enabled = false;
saveImg_strip.Enabled = false;
saveWindow_strip.Enabled = false;
mCtrl_HWindow.HalconWindow.ClearWindow();
viewWindow.ClearWindow();
}
));
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
/// <summary>
/// Hobject转换为的临时Himage,显示背景图
/// </summary>
/// <param name="hobject">传递Hobject,必须为图像</param>
public void HobjectToHimage(HObject hobject)
{
if (hobject == null || !hobject.IsInitialized())
{
ClearWindow();
return;
}
this.Image = new HImage(hobject);
}
#region ,HObject
/// <summary>
/// 默认红颜色显示
/// </summary>
/// <param name="hObj">传入的region.xld,image</param>
public void DispObj(HObject hObj)
{
lock (this)
{
viewWindow.displayHobject(hObj, null);
}
}
/// <summary>
/// 重新开辟内存保存 防止被传入的HObject在其他地方dispose后,不能重现
/// </summary>
/// <param name="hObj">传入的region.xld,image</param>
/// <param name="color">颜色</param>
public void DispObj(HObject hObj, string color)
{
lock (this)
{
viewWindow.displayHobject(hObj, color);
}
}
#endregion
/// <summary>
/// 鼠标离开事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void mCtrl_HWindow_MouseLeave(object sender, EventArgs e)
{
//避免鼠标离开窗口,再返回的时候,图表随着鼠标移动
viewWindow.mouseleave();
}
}
}

View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="mCtrl_HWindow.LayoutBitmap" type="System.Resources.ResXNullRef, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value />
</metadata>
</root>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,310 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HalconDotNet;
namespace ViewWindow
{
public class ViewWindow : Model.IViewWindow
{
public Model.HWndCtrl _hWndControl;
private Model.ROIController _roiController;
public ViewWindow(HWindowControl window)
{
this._hWndControl = new Model.HWndCtrl(window);
this._roiController = new Model.ROIController();
this._hWndControl.setROIController(this._roiController);
this._hWndControl.setViewState(Model.HWndCtrl.MODE_VIEW_NONE);
}
//清空所有显示内容
public void ClearWindow()
{
//清空显示image
_hWndControl.clearList();
//清空hobjectList
_hWndControl.clearHObjectList();
}
public void displayImage(HObject img)
{
//添加背景图片
this._hWndControl.addImageShow(img);
//清空roi容器,不让roi显示
this._roiController.reset();
//显示图片
this._roiController.resetWindowImage();
//this._hWndControl.resetWindow();
// this._hWndControl.resetAll();
//this._hWndControl.repaint();
}
public void notDisplayRoi()
{
this._roiController.reset();
//显示图片
this._roiController.resetWindowImage();
}
//获取当前窗口显示的roi数量
public int getRoiCount()
{
return _roiController.ROIList.Count;
}
//是否开启缩放事件
public void setDrawModel(bool flag)
{
_hWndControl.drawModel = flag;
}
//是否开启编辑事件
public void setEditModel(bool flag)
{
_roiController.EditModel = flag;
// _hWndControl.drawModel = flag;
}
public void resetWindowImage()
{
this._hWndControl.resetWindow();
this._roiController.resetWindowImage();
}
public void mouseleave()
{
_hWndControl.raiseMouseup();
}
public void zoomWindowImage()
{
this._roiController.zoomWindowImage();
}
public void moveWindowImage()
{
this._roiController.moveWindowImage();
}
public void noneWindowImage()
{
this._roiController.noneWindowImage();
}
public void genRect1(double row1, double col1, double row2, double col2, ref List<Model.ROI> rois)
{
this._roiController.genRect1(row1, col1, row2, col2, ref rois);
}
public void genRect2(double row, double col, double phi, double length1, double length2, ref List<Model.ROI> rois)
{
this._roiController.genRect2(row, col, phi, length1, length2, ref rois);
}
public void genCircle(double row, double col, double radius, ref List<Model.ROI> rois)
{
this._roiController.genCircle(row, col, radius, ref rois);
}
public void genCircularArc(double row, double col, double radius, double startPhi, double extentPhi, string direct,ref List<Model.ROI> rois)
{
this._roiController.genCircularArc(row, col, radius, startPhi, extentPhi,direct,ref rois);
}
public void genLine(double beginRow, double beginCol, double endRow, double endCol, ref List<Model.ROI> rois)
{
this._roiController.genLine(beginRow, beginCol, endRow, endCol, ref rois);
}
public List<double> smallestActiveROI(out string name, out int index)
{
List<double> resual = this._roiController.smallestActiveROI(out name,out index);
return resual;
}
public Model.ROI smallestActiveROI(out List<double> data, out int index)
{
Model.ROI roi = this._roiController.smallestActiveROI(out data, out index);
return roi;
}
public void selectROI(int index)
{
this._roiController.selectROI(index);
}
public void selectROI( List<Model.ROI> rois, int index)
{
//this._roiController.selectROI(index);
if ((rois.Count > index)&&(index>=0))
{
this._hWndControl.resetAll();
this._hWndControl.repaint();
HTuple m_roiData = null;
m_roiData = rois[index].getModelData();
switch (rois[index].Type)
{
case "ROIRectangle1":
if (m_roiData != null)
{
this._roiController.displayRect1(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
}
break;
case "ROIRectangle2":
if (m_roiData != null)
{
this._roiController.displayRect2(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
}
break;
case "ROICircle":
if (m_roiData != null)
{
this._roiController.displayCircle(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D);
}
break;
case "ROICircularArc":
if (m_roiData != null)
{
this._roiController.displayCircularArc(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
}
break;
case "ROILine":
if (m_roiData != null)
{
this._roiController.displayLine(rois[index].Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
}
break;
default:
break;
}
}
}
public void displayROI(List<Model.ROI> rois)
{
if (rois == null)
{
return;
}
//this._hWndControl.resetAll();
//this._hWndControl.repaint();
foreach (var roi in rois)
{
HTuple m_roiData = null;
m_roiData = roi.getModelData();
switch (roi.Type)
{
case "ROIRectangle1":
if (m_roiData != null)
{
this._roiController.displayRect1(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
}
break;
case "ROIRectangle2":
if (m_roiData != null)
{
this._roiController.displayRect2(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D, m_roiData[4].D);
}
break;
case "ROICircle":
if (m_roiData != null)
{
this._roiController.displayCircle(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D);
}
break;
case "ROILine":
if (m_roiData != null)
{
this._roiController.displayLine(roi.Color, m_roiData[0].D, m_roiData[1].D, m_roiData[2].D, m_roiData[3].D);
}
break;
default:
break;
}
}
}
public void removeActiveROI(ref List<Model.ROI> rois)
{
this._roiController.removeActiveROI(ref rois);
}
public void setActiveRoi(int index)
{
this._roiController.activeROIidx = index;
}
public void saveROI(List<Model.ROI> rois, string fileNmae)
{
List<Model.RoiData> m_RoiData = new List<Model.RoiData>();
for (int i = 0; i < rois.Count; i++)
{
m_RoiData.Add(new Model.RoiData(i, rois[i]));
}
Config.SerializeHelper.Save(m_RoiData, fileNmae);
}
public void loadROI(string fileName, out List<Model.ROI> rois)
{
rois = new List<Model.ROI>();
List<Model.RoiData> m_RoiData = new List<Model.RoiData>();
m_RoiData = (List<Model.RoiData>)Config.SerializeHelper.Load(m_RoiData.GetType(), fileName);
for (int i = 0; i < m_RoiData.Count; i++)
{
switch (m_RoiData[i].Name)
{
case "Rectangle1":
this._roiController.genRect1(m_RoiData[i].Rectangle1.Row1, m_RoiData[i].Rectangle1.Column1,
m_RoiData[i].Rectangle1.Row2, m_RoiData[i].Rectangle1.Column2, ref rois);
rois.Last().Color = m_RoiData[i].Rectangle1.Color;
break;
case "Rectangle2":
this._roiController.genRect2(m_RoiData[i].Rectangle2.Row, m_RoiData[i].Rectangle2.Column,
m_RoiData[i].Rectangle2.Phi, m_RoiData[i].Rectangle2.Lenth1, m_RoiData[i].Rectangle2.Lenth2, ref rois);
rois.Last().Color = m_RoiData[i].Rectangle2.Color;
break;
case "Circle":
this._roiController.genCircle(m_RoiData[i].Circle.Row, m_RoiData[i].Circle.Column, m_RoiData[i].Circle.Radius, ref rois);
rois.Last().Color = m_RoiData[i].Circle.Color;
break;
case "Line":
this._roiController.genLine(m_RoiData[i].Line.RowBegin, m_RoiData[i].Line.ColumnBegin,
m_RoiData[i].Line.RowEnd, m_RoiData[i].Line.ColumnEnd, ref rois);
rois.Last().Color = m_RoiData[i].Line.Color;
break;
default:
break;
}
}
this._hWndControl.resetAll();
this._hWndControl.repaint();
}
#region region xld的方法
public void displayHobject(HObject obj,string color)
{
_hWndControl.DispObj(obj, color);
}
public void displayHobject(HObject obj)
{
_hWndControl.DispObj(obj, null);
}
#endregion
}
}