geboshi_V1/LeatherProject/LeatherApp/Config.cs

344 lines
15 KiB
C#
Raw Normal View History

2024-03-07 14:03:22 +08:00
using LeatherApp.Utils;
using Newtonsoft.Json.Linq;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace LeatherApp
{
public class Config
{
public static string appBasePath;
public static Models.User loginUser;
//对应文件DefectItemList.json
public static JArray defectItemList;
//
public static JArray colorNameList;//, materialNameList;
2024-08-05 09:39:58 +08:00
//
public static JArray materialNameList;//, materialNameList;
2024-03-07 14:03:22 +08:00
//CMDProcess目录下的命令JSON文件
public static Dictionary<CMDName, JObject> CMDProcess;
//剩余N米提示(M)
2024-08-09 10:34:23 +08:00
public static int residueWarnningLen = 20;
2024-03-07 14:03:22 +08:00
//瑕疵暂停跳过几张图
public static int defectPauseSkipPhotoCount=5;
//DB
//有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
//如果用到bulkCopy需要加 AllowLoadLocalInfile=true
//public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
public static string DBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
public static string ErpDBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
public static string ErpSql = "select top 1 a,b,c from tableA where code=@code order by id desc";
//LOG
public static string LogPath;
//DEV
public static bool StopCodeScanner = false;
public static bool StopIO = false;
public static bool StopPLC=true;
public static bool StopLight = true;
public static string PlcIPAdrees;
public static short PlcRackN=0, PlcSolt=1;
public static string Carmer1ConfigFilePath,Carmer2ConfigFilePath;
public static string IOCard_DeviceNum = "PCI-1730,BID#0";
public static bool ScannerReversalX = false;
public static bool ScannerReversalY = false;
public static string Light_PortName;//COM端口号
public static LightDevNameEnum Light_Name = LightDevNameEnum.;
public static CamerDevNameEnum Camer_Name = CamerDevNameEnum.;
//LIB
public static string model_path = "";//./models/best_0805_bs8.onnx
//public static string labels_path = "./models/hexin.names";
public static int cm2px_x = 1;
public static int cm2px_y = 1;
//边缘孔洞宽(门幅计算包含,识别库去除)
public static int MarginHoleWidth = 120, MiddleSuperposition;
public static int expand_pixel=50;
public static string ImagePath;
public static bool IsSaveAllImage, IsSaveDefectSourceImage, IsSaveDefectCutImage;
2024-08-05 09:39:58 +08:00
//材质Material 1
public static string[] SuedeList1 = new string[0];
//材质Material 2
public static string[] SuedeList2 = new string[0];
//材质Material 3
public static string[] SuedeList3 = new string[0];
//材质Material 4
public static string[] SuedeList4 = new string[0];
//材质Material 5
public static string[] SuedeList5 = new string[0];
//材质Material 6
public static string[] SuedeList6 = new string[0];
//忽略的等级判断项目
public static string[] SkipLabelGrade = new string[0];
2024-03-07 14:03:22 +08:00
2024-04-02 15:57:40 +08:00
//云端
public static string cloud_ip, cloud_username, cloud_password, CloudThisName;
public static int cloud_port, cloud_open;
2024-10-18 08:22:25 +08:00
//传统算法
public static bool OpenHalconDefect;
public static string HalconParamPath;
2024-04-02 15:57:40 +08:00
public static void LoadCloudConfig()
{
if (string.IsNullOrWhiteSpace(appBasePath))
appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
IniFile ini = new IniFile(appBasePath + "\\CloudConfig.ini");
cloud_ip = ini.ReadString("Cloud", "cloud_ip", "");
cloud_port = ini.ReadInt("Cloud", "cloud_port", 0);
cloud_open = ini.ReadInt("Cloud", "cloud_open", 0);
cloud_username = ini.ReadString("Cloud", "cloud_username", "");
cloud_password = ini.ReadString("Cloud", "cloud_password", "");
CloudThisName = ini.ReadString("Cloud", "CloudThisName", "");
}
2024-03-07 14:03:22 +08:00
public static void LoadAllConfig()
{
if (string.IsNullOrWhiteSpace(appBasePath))
appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LoadDefectItemList();
LoadColorNameList();
2024-08-05 09:39:58 +08:00
LoadMaterialNameList();
2024-03-07 14:03:22 +08:00
//----
string lsCmdPath = appBasePath + "\\CMDProcess\\";
if (!Directory.Exists(lsCmdPath))
Directory.CreateDirectory(lsCmdPath);
string fileName;
CMDProcess = new Dictionary<CMDName, JObject>();
foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
{
//string name = Enum.GetName(typeof(CMDName), item);//获取名称
fileName = lsCmdPath + item + ".json";
if (File.Exists(fileName))
CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
//else
// CMDProcess.Add((CMDName)item, null);
}
// ----
IniFile ini = new IniFile(appBasePath + "\\SysConfig.ini");
//[DB]
DBConStr = ini.ReadString("DB", "DBConStr", "");
//[Erp]
ErpDBConStr = ini.ReadString("ErpDB", "ErpDBConStr", "");
ErpSql = ini.ReadString("ErpDB", "ErpSql", "");
//[LOG]
LogPath = ini.ReadString("LOG", "LogPath", "");
//[CONTROL]
defectPauseSkipPhotoCount = ini.ReadInt("CONTROL", "DefectPauseSkipPhotoCount", 0);
//[DEV]
StopCodeScanner = ini.ReadBool("DEV", "StopCodeScanner", false);
StopIO = ini.ReadBool("DEV", "StopIO", false);
StopPLC = ini.ReadBool("DEV", "StopPLC", false);
PlcIPAdrees = ini.ReadString("DEV", "PlcIPAdrees", "");
PlcRackN = ini.ReadShort("DEV", "PlcRackN", PlcRackN);
PlcSolt = ini.ReadShort("DEV", "PlcSolt", PlcSolt);
StopLight = ini.ReadBool("DEV", "StopLight", false);
Carmer1ConfigFilePath = ini.ReadString("DEV", "Carmer1ConfigFilePath", "");
Carmer2ConfigFilePath = ini.ReadString("DEV", "Carmer2ConfigFilePath", "");
IOCard_DeviceNum = ini.ReadString("DEV", "IOCard_DeviceNum", "");
Light_Name = (LightDevNameEnum)ini.ReadInt("DEV", "Light_Name");
Light_PortName = ini.ReadString("DEV", "Light_PortName", "");
Camer_Name = (CamerDevNameEnum)ini.ReadInt("DEV", "Camer_Name");
ScannerReversalX = ini.ReadBool("DEV", "ScannerReversalX", false);
ScannerReversalY = ini.ReadBool("DEV", "ScannerReversalY", false);
//[LIB]
model_path = ini.ReadString("LIB", "model_path", "");
//labels_path = ini.ReadString("LIB", "labels_path", "");
cm2px_x = ini.ReadInt("LIB", "cm2px_x", 1);
cm2px_y = ini.ReadInt("LIB", "cm2px_y", 1);
MarginHoleWidth = ini.ReadInt("LIB", "MarginHoleWidth", 0);
MiddleSuperposition = ini.ReadInt("LIB", "MiddleSuperposition", 0);
expand_pixel=ini.ReadInt("LIB", "expand_pixel", 50);
ImagePath = ini.ReadString("LIB", "ImagePath", "");
IsSaveAllImage = ini.ReadBool("LIB", "IsSaveAllImage", false);
IsSaveDefectSourceImage = ini.ReadBool("LIB", "IsSaveDefectSourceImage", false);
IsSaveDefectCutImage = ini.ReadBool("LIB", "IsSaveDefectCutImage", false);
//
string lsTmp = ini.ReadString("Material", "SuedeList", "").Trim();
2024-08-05 09:39:58 +08:00
if (!string.IsNullOrWhiteSpace(lsTmp))
SuedeList1 = lsTmp.Split(new char[] { ',', ';' });
else
SuedeList1 = new string[1] { "" };
lsTmp = ini.ReadString("Material", "SuedeList2", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
SuedeList2 = lsTmp.Split(new char[] { ',', ';' });
else
SuedeList2 = new string[1] { "" };
lsTmp = ini.ReadString("Material", "SuedeList3", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
SuedeList3 = lsTmp.Split(new char[] { ',', ';' });
else
SuedeList3 = new string[1] { "" };
lsTmp = ini.ReadString("Material", "SuedeList4", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
SuedeList4 = lsTmp.Split(new char[] { ',', ';' });
else
SuedeList4 = new string[1] { "" };
lsTmp = ini.ReadString("Material", "SuedeList5", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
SuedeList5 = lsTmp.Split(new char[] { ',', ';' });
else
SuedeList5 = new string[1] { "" };
lsTmp = ini.ReadString("Material", "SuedeList6", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
SuedeList6 = lsTmp.Split(new char[] { ',', ';' });
else
SuedeList6 = new string[1] { "" };
lsTmp = ini.ReadString("SkipLabelGrade", "LabelGradeList", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
SkipLabelGrade = lsTmp.Split(new char[] { ',', ';' });
else
SkipLabelGrade = new string[1] { "" };
2024-10-18 08:22:25 +08:00
//传统参数
OpenHalconDefect = ini.ReadBool("Halcon", "OpenHalconDefect");
lsTmp = ini.ReadString("Halcon", "HalconParamPath", "").Trim();
if (!string.IsNullOrWhiteSpace(lsTmp))
HalconParamPath = lsTmp;
else
HalconParamPath = appBasePath;
2024-03-07 14:03:22 +08:00
}
#region defectItemList <=> DefectItemList.json
public static void LoadDefectItemList()
{
if (string.IsNullOrWhiteSpace(appBasePath))
appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string configPath = appBasePath + "\\DefectItemList.json";
string lsTmp = File.ReadAllText(configPath);
defectItemList = JArray.Parse(lsTmp);
}
public static void SaveDefectItemList(JArray newValue)
{
if (string.IsNullOrWhiteSpace(appBasePath))
appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string configPath = appBasePath + "\\DefectItemList.json";
File.WriteAllText(configPath, newValue.ToString());
}
public static JObject getDefectItem(string code)
{
2024-08-05 09:39:58 +08:00
try
{
var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
if (item == null)
return null;
return (JObject)item;
}
catch { return null; }
2024-03-07 14:03:22 +08:00
}
public static JObject getDefectItem(int id)
{
2024-08-05 09:39:58 +08:00
try
{
2024-10-18 08:22:25 +08:00
if (id == -99)
{
JObject obj = new JObject();
obj.Add("id", 0);
obj.Add("code", "ng");
obj.Add("name", "NG");
obj.Add("color", "Red");
return obj;
}
2024-08-05 09:39:58 +08:00
var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
2024-10-18 08:22:25 +08:00
if (item == null)
return null;
return (JObject)item;
2024-08-05 09:39:58 +08:00
}
catch { return null; }
2024-03-07 14:03:22 +08:00
}
public static string getDefectCode(int id)
{
2024-08-05 09:39:58 +08:00
try
{
var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
if (item == null)
return "";
return ((JObject)item).Value<string>("code");
}
catch { return ""; }
2024-03-07 14:03:22 +08:00
}
public static string getDefectName(string code)
{
2024-08-05 09:39:58 +08:00
try {
var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
if (item == null)
return "";
return ((JObject)item).Value<string>("name");
}
catch { return ""; }
}
public static string getDefectCode(string name)
{
try {
var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("name") == name);
if (item == null)
return "";
return ((JObject)item).Value<string>("code");
}
catch { return ""; }
2024-03-07 14:03:22 +08:00
}
#endregion
#region colorNameList <=> ColorNameList.json
public static void LoadColorNameList()
{
if (string.IsNullOrWhiteSpace(appBasePath))
appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string configPath = appBasePath + "\\ColorNameList.json";
string lsTmp = File.ReadAllText(configPath);
colorNameList = JArray.Parse(lsTmp);
}
public static JObject getColorItem(int code)
{
var item = Config.colorNameList.FirstOrDefault(m => m.Value<int>("code") == code);
if (item == null)
return null;
return (JObject)item;
}
2024-08-05 09:39:58 +08:00
public static void LoadMaterialNameList()
{
if (string.IsNullOrWhiteSpace(appBasePath))
appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string configPath = appBasePath + "\\MaterialName.json";
string lsTmp = File.ReadAllText(configPath);
materialNameList = JArray.Parse(lsTmp);
}
2024-03-07 14:03:22 +08:00
//public static JObject getMaterialItem(string code)
//{
// var item = Config.materialNameList.FirstOrDefault(m => m.Value<string>("code") == code);
// if (item == null)
// return null;
// return (JObject)item;
//}
#endregion
}
}