using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Reflection;
|
using System.Windows.Media;
|
|
namespace Bro.Common.Helper
|
{
|
public static class EnumHelper
|
{
|
/// <summary>
|
/// 根据枚举的代码名称获取枚举列表信息
|
/// </summary>
|
/// <param name="enumName"></param>
|
/// <returns></returns>
|
public static List<dynamic> GetEnumListByName(string enumName, string assemblyName = "Common.Helper.EnumHelper+")
|
{
|
List<dynamic> list = new List<dynamic>();
|
|
string fullName = assemblyName + enumName;
|
|
Type t = typeof(EnumHelper).Assembly.GetType(fullName);
|
|
t.GetEnumNames().ToList().ForEach(e =>
|
{
|
int value = Convert.ToInt32(Enum.Parse(t, e));
|
string desc = ((Enum)Enum.Parse(t, e)).GetEnumDescription();
|
var item = new { Value = value, Desc = desc, Code = e };
|
list.Add(item);
|
});
|
|
return list;
|
}
|
|
public static List<dynamic> GetEnumListByType(Type enumType)
|
{
|
List<dynamic> list = new List<dynamic>();
|
|
enumType.GetEnumNames().ToList().ForEach(e =>
|
{
|
int value = Convert.ToInt32(Enum.Parse(enumType, e));
|
string desc = ((Enum)Enum.Parse(enumType, e)).GetEnumDescription();
|
var item = new { Value = value, Desc = desc, Code = e };
|
list.Add(item);
|
});
|
|
return list;
|
}
|
|
/// <summary>
|
/// 获取具体某一枚举的中文描述
|
/// </summary>
|
/// <param name="enumObj"></param>
|
/// <returns></returns>
|
public static string GetEnumDescription(this Enum enumObj)
|
{
|
Type t = enumObj.GetType();
|
FieldInfo f = t.GetField(enumObj.ToString());
|
|
DescriptionAttribute attr = f.GetCustomAttribute<DescriptionAttribute>();
|
if (attr != null)
|
{
|
return attr.Description;
|
}
|
else
|
{
|
return enumObj.ToString();
|
}
|
}
|
|
public static System.Windows.Media.Color GetEnumSelectedMediaColor(this Enum enumObj)
|
{
|
Type t = enumObj.GetType();
|
FieldInfo f = t.GetField(enumObj.ToString());
|
|
ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
if (attr != null)
|
{
|
var prop = typeof(Colors).GetProperties().FirstOrDefault(p => p.Name == attr.SelectedColor);
|
if (prop != null)
|
{
|
return (System.Windows.Media.Color)prop.GetValue(null);
|
}
|
}
|
return Colors.Transparent;
|
}
|
|
public static System.Drawing.Color GetEnumSelectedColor(this Enum enumObj)
|
{
|
Type t = enumObj.GetType();
|
FieldInfo f = t.GetField(enumObj.ToString());
|
|
ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
if (attr != null)
|
{
|
return System.Drawing.Color.FromName(attr.SelectedColor);
|
}
|
else
|
{
|
return System.Drawing.Color.Transparent;
|
}
|
}
|
|
public static System.Drawing.Color GetEnumSelectedFontColor(this Enum enumObj)
|
{
|
Type t = enumObj.GetType();
|
FieldInfo f = t.GetField(enumObj.ToString());
|
|
var attr = f.GetCustomAttribute<FontColorSelectAttribute>();
|
if (attr != null)
|
{
|
return System.Drawing.Color.FromName(attr.SelectedColor);
|
}
|
else
|
{
|
return System.Drawing.Color.Transparent;
|
}
|
}
|
|
public static string GetEnumSelectedColorString(this Enum enumObj)
|
{
|
Type t = enumObj.GetType();
|
FieldInfo f = t.GetField(enumObj.ToString());
|
|
ColorSelectAttribute attr = f.GetCustomAttribute<ColorSelectAttribute>();
|
if (attr != null)
|
{
|
return attr.SelectedColor;
|
}
|
else
|
{
|
return "Transparent";
|
}
|
}
|
|
|
/// <summary>
|
/// 当枚举牵涉到状态变换,检查现状态是否满足待转换的状态的前置状态要求
|
/// </summary>
|
/// <param name="stateToBe"></param>
|
/// <param name="currentState"></param>
|
/// <returns></returns>
|
public static bool CheckPreStateValid(this Enum stateToBe, int currentState)
|
{
|
Type t = stateToBe.GetType();
|
FieldInfo f = t.GetField(stateToBe.ToString());
|
|
PreStateAttribute attr = f.GetCustomAttribute<PreStateAttribute>();
|
if (attr == null)
|
{
|
return true;
|
}
|
else
|
{
|
return attr.CheckPreStateValid(currentState);
|
}
|
}
|
|
/// <summary>
|
/// 设备状态定义
|
/// 未初始化和异常状态无前置状态要求
|
/// 初始化操作前置状态必须是未初始化、关闭状态和异常状态
|
/// 打开前置必须是初始化和暂停
|
/// 关闭前置必须是打开和暂停和异常
|
/// 暂停前置必须是打开
|
/// </summary>
|
public enum DeviceState
|
{
|
TBD = -1,
|
|
[ColorSelect("Gray")]
|
[FontColorSelect("Black")]
|
[Description("未初始化")]
|
DSUninit = 1,
|
|
[ColorSelect("Gold")]
|
[FontColorSelect("White")]
|
[PreState(1 + 2 + 4 + 8 + 32)]
|
[Description("已初始化")]
|
DSInit = 2,
|
|
[ColorSelect("Lime")]
|
[FontColorSelect("Black")]
|
[PreState(2 + 4 + 16)]
|
[Description("已打开")]
|
DSOpen = 4,
|
|
[ColorSelect("Gray")]
|
[FontColorSelect("White")]
|
[PreState(1 + 4 + 8 + 16 + 32)]
|
[Description("已关闭")]
|
DSClose = 8,
|
|
[ColorSelect("Gold")]
|
[FontColorSelect("White")]
|
[PreState(4 + 16)]
|
[Description("已暂停")]
|
DSPause = 16,
|
|
[ColorSelect("Red")]
|
[FontColorSelect("White")]
|
[Description("异常状态")]
|
DSExcept = 32
|
}
|
|
/// <summary>
|
/// 工序状态
|
/// </summary>
|
public enum RunState
|
{
|
[Description("空闲")]
|
Idle = 1,
|
[Description("运行中")]
|
Running = 2,
|
[Description("停止")]
|
Stop = 3,
|
[Description("宕机")]
|
Down = 99,
|
}
|
|
[Flags]
|
public enum DeviceAttributeType
|
{
|
[Description("设备驱动")]
|
Device = 1,
|
|
[Description("初始配置")]
|
InitialConfig = 2,
|
[Description("操作配置")]
|
OperationConfig = 4,
|
[Description("设备配置")]
|
DeviceConfig = 8,
|
[Description("输入配置")]
|
InputConfig = 16,
|
|
[Description("初始配置控件")]
|
InitialConfigCtrl = 32,
|
[Description("操作配置控件")]
|
OperationConfigCtrl = 64,
|
[Description("设备配置控件")]
|
DeviceConfigCtrl = 128,
|
[Description("输入配置控件")]
|
InputConfigCtrl = 256,
|
|
[Description("运行控件")]
|
RunCtrl = 512,
|
|
[Description("操作配置面板")]
|
OperationConfigPanel = 1024,
|
}
|
|
public enum EnableState
|
{
|
[Description("启用")]
|
Enabled = 0,
|
[Description("禁用")]
|
Disabled = 1,
|
}
|
|
public enum EnableStateFilter
|
{
|
[Description("全部")]
|
All = -1,
|
[Description("启用")]
|
Enabled = 0,
|
[Description("禁用")]
|
Disabled = 1,
|
}
|
|
public enum OutputResult
|
{
|
[Description("OK")]
|
OK = 1,
|
[Description("NG")]
|
NG = 2,
|
}
|
|
/// <summary>
|
/// PLC项目的值的类型
|
/// </summary>
|
public enum PLCItemType
|
{
|
[Description("布尔类型")]
|
Bool = 0,
|
[Description("整型")]
|
Integer = 1,
|
[Description("字符串型")]
|
String = 2,
|
}
|
|
/// <summary>
|
/// 对PLC项目的操作类型
|
/// </summary>
|
public enum PLCOpType
|
{
|
[Description("读取")]
|
Read = 1,
|
[Description("写入")]
|
Write = 2,
|
[Description("监控")]
|
Monitor = 4,
|
|
/// <summary>
|
/// 报警监控 1+8
|
/// </summary>
|
[Description("报警监控")]
|
WarningMonitor = 9,
|
|
/// <summary>
|
/// CT监控 1+16
|
/// </summary>
|
[Description("CT监控")]
|
CTMonitor = 17,
|
}
|
|
/// <summary>
|
/// 相机运行模式
|
/// </summary>
|
public enum CameraOpMode
|
{
|
[Description("单次拍照")]
|
SingleSnapShot = 1,
|
[Description("连续模式")]
|
ContinuousMode = 2,
|
}
|
|
/// <summary>
|
/// 日志类型
|
/// </summary>
|
public enum LogType
|
{
|
[Description("警告信息")]
|
Exception_Warning = 1,
|
[Description("错误信息")]
|
Exception_Error = 2,
|
[Description("致命信息")]
|
Exception_Fatal = 3,
|
|
[Description("设备信息")]
|
Info_Device = 11,
|
[Description("工序信息")]
|
Info_Process = 12,
|
[Description("操作信息")]
|
Info_Operation = 13,
|
|
[Description("用户操作信息")]
|
User_Operation = 21,
|
|
[Description("测量结果")]
|
MeasureResult = 31,
|
}
|
|
//public enum CameraDriverType
|
//{
|
// Halcon,
|
// //HalconPlugIn,
|
// Hik,
|
//}
|
|
//public enum ImageType
|
//{
|
// Bmp,
|
// Png,
|
// Jpeg,
|
//}
|
|
public enum PLCReplyValue
|
{
|
OK = 1,
|
NG = -1,
|
IGNORE = -999,
|
}
|
|
public enum PriorityDirection
|
{
|
X,
|
Y,
|
}
|
|
public enum ElementState
|
{
|
New = 1,
|
MouseHover = 2,
|
MouseInSide = 3,
|
Selected = 4,
|
Moving = 5,
|
Editing = 6,
|
|
Normal = 11,
|
|
Measuring = 21,
|
MeasureDoneOK = 22,
|
MeasureDoneNG = 23,
|
}
|
|
public enum MouseState
|
{
|
Normal = 1,
|
HoverElement = 2,
|
InSideElement = 3,
|
|
StretchingLeft = 11,
|
StretchingRight = 12,
|
StretchingUp = 13,
|
StretchingDown = 14,
|
MoveElement = 15,
|
|
New = 21,
|
Editing = 22,
|
SelectedElement = 23,
|
|
MovingAll = 31,
|
|
SelectionZone = 41,
|
SelectionZoneDoing = 42,
|
}
|
|
public enum RunMode
|
{
|
[Description("设置模式")]
|
SetMode = 0,
|
[Description("运行模式")]
|
RunMode = 1,
|
}
|
|
public enum MoveType
|
{
|
[Description("绝对运动")]
|
AbsoluteMove = 1,
|
[Description("机器人坐标系相对运动")]
|
RobotRelativeMove = 2,
|
[Description("相对某个基准点位的相对运动")]
|
BasedPointRelativeMove = 3,
|
[Description("回原点")]
|
Origin = 4,
|
[Description("左侧姿势")]
|
LeftPose = 6,
|
[Description("右侧姿势")]
|
RightPose = 5,
|
[Description("前侧姿势")]
|
FrontPose = 7,
|
[Description("相机坐标系相对运动")]
|
CameraRelativeMove = 12,
|
}
|
}
|
}
|