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

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

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace ViewWindow.Config
{
[Serializable]
public class Circle
{
private double _row;
private double _column;
private double _radius;
[XmlElement(ElementName = "Row")]
public double Row
{
get { return this._row; }
set { this._row = value; }
}
[XmlElement(ElementName = "Column")]
public double Column
{
get { return this._column; }
set { this._column = value; }
}
[XmlElement(ElementName = "Radius")]
public double Radius
{
get { return this._radius; }
set { this._radius = value; }
}
private string color = "yellow";
[XmlElement(ElementName = "Color")]
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public Circle()
{
}
public Circle(double row, double column, double radius)
{
this._row = row;
this._column = column;
this._radius = radius;
}
}
}

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace ViewROI.Config
{
[Serializable]
class CircularArc
{
private double _row;
private double _column;
private double _radius;
private double _startPhi;
private double _extentPhi;
[XmlElement(ElementName = "Row")]
public double Row
{
get { return this._row; }
set { this._row = value; }
}
[XmlElement(ElementName = "Column")]
public double Column
{
get { return this._column; }
set { this._column = value; }
}
[XmlElement(ElementName = "Radius")]
public double Radius
{
get { return this._radius; }
set { this._radius = value; }
}
[XmlElement(ElementName = "startPhi")]
public double StartPhi
{
get { return this._startPhi; }
set { this._startPhi = value; }
}
[XmlElement(ElementName = "ExtentPhi")]
public double ExtentPhi
{
get { return this._extentPhi; }
set { this._extentPhi = value; }
}
private string color = "yellow";
[XmlElement(ElementName = "Color")]
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public CircularArc()
{
}
public CircularArc(double row, double column, double radius,double startPhi, double extentPhi)
{
this._row = row;
this._column = column;
this._radius = radius;
this._startPhi = startPhi;
this._extentPhi = extentPhi;
}
}
}

View File

@@ -0,0 +1,36 @@
using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ViewROI.Config
{
/// <summary>
/// 显示xld和region 带有颜色
/// </summary>
class HObjectWithColor
{
private HObject hObject;
private string color;
public HObjectWithColor(HObject _hbj, string _color)
{
hObject = _hbj;
color = _color;
}
public HObject HObject
{
get { return hObject; }
set { hObject = value; }
}
public string Color
{
get { return color; }
set { color = value; }
}
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace ViewWindow.Config
{
[Serializable]
public class Line
{
private double _rowBegin;
private double _columnBegin;
private double _rowEnd;
private double _columnEnd;
[XmlElement(ElementName = "RowBegin")]
public double RowBegin
{
get { return this._rowBegin; }
set { this._rowBegin = value; }
}
[XmlElement(ElementName = "ColumnBegin")]
public double ColumnBegin
{
get { return this._columnBegin; }
set { this._columnBegin = value; }
}
[XmlElement(ElementName = "RowEnd")]
public double RowEnd
{
get { return this._rowEnd; }
set { this._rowEnd = value; }
}
[XmlElement(ElementName = "ColumnEnd")]
public double ColumnEnd
{
get { return this._columnEnd; }
set { this._columnEnd = value; }
}
private string color = "yellow";
[XmlElement(ElementName = "Color")]
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public Line()
{
}
public Line(double rowBegin, double columnBegin, double rowEnd, double columnEnd)
{
this._rowBegin = rowBegin;
this._columnBegin = columnBegin;
this._rowEnd = rowEnd;
this._columnEnd = columnEnd;
}
}
}

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace ViewWindow.Config
{
[Serializable]
public class Rectangle1
{
private double _row1;
private double _column1;
private double _row2;
private double _column2;
[XmlElement(ElementName = "Row1")]
public double Row1
{
get { return this._row1; }
set { this._row1 = value; }
}
[XmlElement(ElementName = "Column1")]
public double Column1
{
get { return this._column1; }
set { this._column1 = value; }
}
[XmlElement(ElementName = "Row2")]
public double Row2
{
get { return this._row2; }
set { this._row2 = value; }
}
[XmlElement(ElementName = "Column2")]
public double Column2
{
get { return this._column2; }
set { this._column2 = value; }
}
private string color = "yellow";
[XmlElement(ElementName = "Color")]
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public Rectangle1()
{
}
public Rectangle1(double row1, double column1, double row2, double column2)
{
this._row1 = row1;
this._column1 = column1;
this._row2 = row2;
this._column2 = column2;
}
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace ViewWindow.Config
{
[Serializable]
public class Rectangle2
{
private double _row;
private double _column;
private double _phi;
private double _lenth1;
private double _lenth2;
[XmlElement(ElementName = "Row")]
public double Row
{
get { return this._row; }
set { this._row = value; }
}
[XmlElement(ElementName = "Column")]
public double Column
{
get { return this._column; }
set { this._column = value; }
}
[XmlElement(ElementName = "Phi")]
public double Phi
{
get { return this._phi; }
set { this._phi = value; }
}
[XmlElement(ElementName = "Lenth1")]
public double Lenth1
{
get { return this._lenth1; }
set { this._lenth1 = value; }
}
[XmlElement(ElementName = "Lenth2")]
public double Lenth2
{
get { return this._lenth2; }
set { this._lenth2 = value; }
}
private string color = "yellow";
[XmlElement(ElementName = "Color")]
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public Rectangle2()
{
}
public Rectangle2(double row, double column, double phi, double lenth1, double lenth2)
{
this._row = row;
this._column = column;
this._phi = phi;
this._lenth1 = lenth1;
this._lenth2 = lenth2;
}
}
}

View File

@@ -0,0 +1,266 @@
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
//using System.Runtime.Serialization.Json;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.Serialization.Formatters.Binary;
namespace ViewWindow.Config
{
public class SerializeHelper
{
public SerializeHelper()
{ }
#region XML序列化
/// <summary>
/// 文件化XML序列化
/// </summary>
/// <param name="obj">对象</param>
/// <param name="filename">文件路径</param>
public static void Save(object obj, string filename)
{
FileStream fs = null;
try
{
fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
XmlSerializer serializer = new XmlSerializer(obj.GetType());
serializer.Serialize(fs, obj);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (fs != null) fs.Close();
}
}
/// <summary>
/// 文件化XML反序列化
/// </summary>
/// <param name="type">对象类型</param>
/// <param name="filename">文件路径</param>
public static object Load(Type type, string filename)
{
FileStream fs = null;
try
{
fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlSerializer serializer = new XmlSerializer(type);
return serializer.Deserialize(fs);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (fs != null) fs.Close();
}
}
/// <summary>
/// 文本化XML序列化
/// </summary>
/// <param name="item">对象</param>
public string ToXml<T>(T item)
{
XmlSerializer serializer = new XmlSerializer(item.GetType());
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb))
{
serializer.Serialize(writer, item);
return sb.ToString();
}
}
/// <summary>
/// 文本化XML反序列化
/// </summary>
/// <param name="str">字符串序列</param>
public T FromXml<T>(string str)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (XmlReader reader = new XmlTextReader(new StringReader(str)))
{
return (T)serializer.Deserialize(reader);
}
}
#endregion
#region Json序列化
/// <summary>
/// JsonSerializer序列化
/// </summary>
/// <param name="item">对象</param>
//public string ToJson<T>(T item)
//{
// DataContractJsonSerializer serializer = new DataContractJsonSerializer(item.GetType());
// using (MemoryStream ms = new MemoryStream())
// {
// serializer.WriteObject(ms, item);
// return Encoding.UTF8.GetString(ms.ToArray());
// }
//}
///// <summary>
///// JsonSerializer反序列化
///// </summary>
///// <param name="str">字符串序列</param>
//public T FromJson<T>(string str) where T : class
//{
// DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
// using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
// {
// return serializer.ReadObject(ms) as T;
// }
//}
#endregion
#region SoapFormatter序列化
/// <summary>
/// SoapFormatter序列化
/// </summary>
/// <param name="item">对象</param>
public string ToSoap<T>(T item)
{
SoapFormatter formatter = new SoapFormatter();
using (MemoryStream ms = new MemoryStream())
{
formatter.Serialize(ms, item);
ms.Position = 0;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(ms);
return xmlDoc.InnerXml;
}
}
/// <summary>
/// SoapFormatter反序列化
/// </summary>
/// <param name="str">字符串序列</param>
public T FromSoap<T>(string str)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(str);
SoapFormatter formatter = new SoapFormatter();
using (MemoryStream ms = new MemoryStream())
{
xmlDoc.Save(ms);
ms.Position = 0;
return (T)formatter.Deserialize(ms);
}
}
#endregion
#region BinaryFormatter序列化
/// <summary>
/// BinaryFormatter序列化
/// </summary>
/// <param name="item">对象</param>
public string ToBinary<T>(T item)
{
BinaryFormatter formatter = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
formatter.Serialize(ms, item);
ms.Position = 0;
byte[] bytes = ms.ToArray();
StringBuilder sb = new StringBuilder();
foreach (byte bt in bytes)
{
sb.Append(string.Format("{0:X2}", bt));
}
return sb.ToString();
}
}
/// <summary>
/// BinaryFormatter反序列化
/// </summary>
/// <param name="str">字符串序列</param>
public T FromBinary<T>(string str)
{
int intLen = str.Length / 2;
byte[] bytes = new byte[intLen];
for (int i = 0; i < intLen; i++)
{
int ibyte = Convert.ToInt32(str.Substring(i * 2, 2), 16);
bytes[i] = (byte)ibyte;
}
BinaryFormatter formatter = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream(bytes))
{
return (T)formatter.Deserialize(ms);
}
}
#endregion
/// <summary>
/// 获取对象序列化的二进制版本
/// </summary>
/// <param name="pObj">对象实体</param>
/// <returns>如果对象实体为Null则返回结果为Null。</returns>
public static byte[] GetBytes(object pObj)
{
if (pObj == null) { return null; }
MemoryStream serializationStream = new MemoryStream();
new BinaryFormatter().Serialize(serializationStream, pObj);
serializationStream.Position = 0L;
byte[] buffer = new byte[serializationStream.Length];
serializationStream.Read(buffer, 0, buffer.Length);
serializationStream.Close();
return buffer;
}
/// <summary>
/// 获取对象序列化的XmlDocument版本
/// </summary>
/// <param name="pObj">对象实体</param>
/// <returns>如果对象实体为Null则返回结果为Null。</returns>
public static XmlDocument GetXmlDoc(object pObj)
{
if (pObj == null) { return null; }
XmlSerializer serializer = new XmlSerializer(pObj.GetType());
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
serializer.Serialize((TextWriter)writer, pObj);
XmlDocument document = new XmlDocument();
document.LoadXml(sb.ToString());
writer.Close();
return document;
}
/// <summary>
/// 从已序列化数据中(byte[])获取对象实体
/// </summary>
/// <typeparam name="T">要返回的数据类型</typeparam>
/// <param name="binData">二进制数据</param>
/// <returns>对象实体</returns>
public static T GetObject<T>(byte[] binData)
{
if (binData == null) { return default(T); }
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream serializationStream = new MemoryStream(binData);
return (T)formatter.Deserialize(serializationStream);
}
/// <summary>
/// 从已序列化数据(XmlDocument)中获取对象实体
/// </summary>
/// <typeparam name="T">要返回的数据类型</typeparam>
/// <param name="xmlDoc">已序列化的文档对象</param>
/// <returns>对象实体</returns>
public static T GetObject<T>(XmlDocument xmlDoc)
{
if (xmlDoc == null) { return default(T); }
XmlNodeReader xmlReader = new XmlNodeReader(xmlDoc.DocumentElement);
XmlSerializer serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(xmlReader);
}
}
}