革博士程序V1仓库
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

344 řádky
15 KiB

  1. using LeatherApp.Utils;
  2. using Newtonsoft.Json.Linq;
  3. using Sunny.UI;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace LeatherApp
  12. {
  13. public class Config
  14. {
  15. public static string appBasePath;
  16. public static Models.User loginUser;
  17. //对应文件:DefectItemList.json
  18. public static JArray defectItemList;
  19. //
  20. public static JArray colorNameList;//, materialNameList;
  21. //
  22. public static JArray materialNameList;//, materialNameList;
  23. //CMDProcess目录下的命令JSON文件
  24. public static Dictionary<CMDName, JObject> CMDProcess;
  25. //剩余N米提示(M)
  26. public static int residueWarnningLen = 20;
  27. //瑕疵暂停跳过几张图
  28. public static int defectPauseSkipPhotoCount=5;
  29. //DB
  30. //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
  31. //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
  32. //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
  33. public static string DBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  34. public static string ErpDBConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  35. public static string ErpSql = "select top 1 a,b,c from tableA where code=@code order by id desc";
  36. //LOG
  37. public static string LogPath;
  38. //DEV
  39. public static bool StopCodeScanner = false;
  40. public static bool StopIO = false;
  41. public static bool StopPLC=true;
  42. public static bool StopLight = true;
  43. public static string PlcIPAdrees;
  44. public static short PlcRackN=0, PlcSolt=1;
  45. public static string Carmer1ConfigFilePath,Carmer2ConfigFilePath;
  46. public static string IOCard_DeviceNum = "PCI-1730,BID#0";
  47. public static bool ScannerReversalX = false;
  48. public static bool ScannerReversalY = false;
  49. public static string Light_PortName;//COM端口号
  50. public static LightDevNameEnum Light_Name = LightDevNameEnum.锐视;
  51. public static CamerDevNameEnum Camer_Name = CamerDevNameEnum.海康;
  52. //LIB
  53. public static string model_path = "";//./models/best_0805_bs8.onnx
  54. //public static string labels_path = "./models/hexin.names";
  55. public static int cm2px_x = 1;
  56. public static int cm2px_y = 1;
  57. //边缘孔洞宽(门幅计算包含,识别库去除)
  58. public static int MarginHoleWidth = 120, MiddleSuperposition;
  59. public static int expand_pixel=50;
  60. public static string ImagePath;
  61. public static bool IsSaveAllImage, IsSaveDefectSourceImage, IsSaveDefectCutImage;
  62. //材质Material 1
  63. public static string[] SuedeList1 = new string[0];
  64. //材质Material 2
  65. public static string[] SuedeList2 = new string[0];
  66. //材质Material 3
  67. public static string[] SuedeList3 = new string[0];
  68. //材质Material 4
  69. public static string[] SuedeList4 = new string[0];
  70. //材质Material 5
  71. public static string[] SuedeList5 = new string[0];
  72. //材质Material 6
  73. public static string[] SuedeList6 = new string[0];
  74. //忽略的等级判断项目
  75. public static string[] SkipLabelGrade = new string[0];
  76. //云端
  77. public static string cloud_ip, cloud_username, cloud_password, CloudThisName;
  78. public static int cloud_port, cloud_open;
  79. //传统算法
  80. public static bool OpenHalconDefect;
  81. public static string HalconParamPath;
  82. public static void LoadCloudConfig()
  83. {
  84. if (string.IsNullOrWhiteSpace(appBasePath))
  85. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  86. IniFile ini = new IniFile(appBasePath + "\\CloudConfig.ini");
  87. cloud_ip = ini.ReadString("Cloud", "cloud_ip", "");
  88. cloud_port = ini.ReadInt("Cloud", "cloud_port", 0);
  89. cloud_open = ini.ReadInt("Cloud", "cloud_open", 0);
  90. cloud_username = ini.ReadString("Cloud", "cloud_username", "");
  91. cloud_password = ini.ReadString("Cloud", "cloud_password", "");
  92. CloudThisName = ini.ReadString("Cloud", "CloudThisName", "");
  93. }
  94. public static void LoadAllConfig()
  95. {
  96. if (string.IsNullOrWhiteSpace(appBasePath))
  97. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  98. LoadDefectItemList();
  99. LoadColorNameList();
  100. LoadMaterialNameList();
  101. //----
  102. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  103. if (!Directory.Exists(lsCmdPath))
  104. Directory.CreateDirectory(lsCmdPath);
  105. string fileName;
  106. CMDProcess = new Dictionary<CMDName, JObject>();
  107. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  108. {
  109. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  110. fileName = lsCmdPath + item + ".json";
  111. if (File.Exists(fileName))
  112. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  113. //else
  114. // CMDProcess.Add((CMDName)item, null);
  115. }
  116. // ----
  117. IniFile ini = new IniFile(appBasePath + "\\SysConfig.ini");
  118. //[DB]
  119. DBConStr = ini.ReadString("DB", "DBConStr", "");
  120. //[Erp]
  121. ErpDBConStr = ini.ReadString("ErpDB", "ErpDBConStr", "");
  122. ErpSql = ini.ReadString("ErpDB", "ErpSql", "");
  123. //[LOG]
  124. LogPath = ini.ReadString("LOG", "LogPath", "");
  125. //[CONTROL]
  126. defectPauseSkipPhotoCount = ini.ReadInt("CONTROL", "DefectPauseSkipPhotoCount", 0);
  127. //[DEV]
  128. StopCodeScanner = ini.ReadBool("DEV", "StopCodeScanner", false);
  129. StopIO = ini.ReadBool("DEV", "StopIO", false);
  130. StopPLC = ini.ReadBool("DEV", "StopPLC", false);
  131. PlcIPAdrees = ini.ReadString("DEV", "PlcIPAdrees", "");
  132. PlcRackN = ini.ReadShort("DEV", "PlcRackN", PlcRackN);
  133. PlcSolt = ini.ReadShort("DEV", "PlcSolt", PlcSolt);
  134. StopLight = ini.ReadBool("DEV", "StopLight", false);
  135. Carmer1ConfigFilePath = ini.ReadString("DEV", "Carmer1ConfigFilePath", "");
  136. Carmer2ConfigFilePath = ini.ReadString("DEV", "Carmer2ConfigFilePath", "");
  137. IOCard_DeviceNum = ini.ReadString("DEV", "IOCard_DeviceNum", "");
  138. Light_Name = (LightDevNameEnum)ini.ReadInt("DEV", "Light_Name");
  139. Light_PortName = ini.ReadString("DEV", "Light_PortName", "");
  140. Camer_Name = (CamerDevNameEnum)ini.ReadInt("DEV", "Camer_Name");
  141. ScannerReversalX = ini.ReadBool("DEV", "ScannerReversalX", false);
  142. ScannerReversalY = ini.ReadBool("DEV", "ScannerReversalY", false);
  143. //[LIB]
  144. model_path = ini.ReadString("LIB", "model_path", "");
  145. //labels_path = ini.ReadString("LIB", "labels_path", "");
  146. cm2px_x = ini.ReadInt("LIB", "cm2px_x", 1);
  147. cm2px_y = ini.ReadInt("LIB", "cm2px_y", 1);
  148. MarginHoleWidth = ini.ReadInt("LIB", "MarginHoleWidth", 0);
  149. MiddleSuperposition = ini.ReadInt("LIB", "MiddleSuperposition", 0);
  150. expand_pixel=ini.ReadInt("LIB", "expand_pixel", 50);
  151. ImagePath = ini.ReadString("LIB", "ImagePath", "");
  152. IsSaveAllImage = ini.ReadBool("LIB", "IsSaveAllImage", false);
  153. IsSaveDefectSourceImage = ini.ReadBool("LIB", "IsSaveDefectSourceImage", false);
  154. IsSaveDefectCutImage = ini.ReadBool("LIB", "IsSaveDefectCutImage", false);
  155. //
  156. string lsTmp = ini.ReadString("Material", "SuedeList", "").Trim();
  157. if (!string.IsNullOrWhiteSpace(lsTmp))
  158. SuedeList1 = lsTmp.Split(new char[] { ',', ';' });
  159. else
  160. SuedeList1 = new string[1] { "" };
  161. lsTmp = ini.ReadString("Material", "SuedeList2", "").Trim();
  162. if (!string.IsNullOrWhiteSpace(lsTmp))
  163. SuedeList2 = lsTmp.Split(new char[] { ',', ';' });
  164. else
  165. SuedeList2 = new string[1] { "" };
  166. lsTmp = ini.ReadString("Material", "SuedeList3", "").Trim();
  167. if (!string.IsNullOrWhiteSpace(lsTmp))
  168. SuedeList3 = lsTmp.Split(new char[] { ',', ';' });
  169. else
  170. SuedeList3 = new string[1] { "" };
  171. lsTmp = ini.ReadString("Material", "SuedeList4", "").Trim();
  172. if (!string.IsNullOrWhiteSpace(lsTmp))
  173. SuedeList4 = lsTmp.Split(new char[] { ',', ';' });
  174. else
  175. SuedeList4 = new string[1] { "" };
  176. lsTmp = ini.ReadString("Material", "SuedeList5", "").Trim();
  177. if (!string.IsNullOrWhiteSpace(lsTmp))
  178. SuedeList5 = lsTmp.Split(new char[] { ',', ';' });
  179. else
  180. SuedeList5 = new string[1] { "" };
  181. lsTmp = ini.ReadString("Material", "SuedeList6", "").Trim();
  182. if (!string.IsNullOrWhiteSpace(lsTmp))
  183. SuedeList6 = lsTmp.Split(new char[] { ',', ';' });
  184. else
  185. SuedeList6 = new string[1] { "" };
  186. lsTmp = ini.ReadString("SkipLabelGrade", "LabelGradeList", "").Trim();
  187. if (!string.IsNullOrWhiteSpace(lsTmp))
  188. SkipLabelGrade = lsTmp.Split(new char[] { ',', ';' });
  189. else
  190. SkipLabelGrade = new string[1] { "" };
  191. //传统参数
  192. OpenHalconDefect = ini.ReadBool("Halcon", "OpenHalconDefect");
  193. lsTmp = ini.ReadString("Halcon", "HalconParamPath", "").Trim();
  194. if (!string.IsNullOrWhiteSpace(lsTmp))
  195. HalconParamPath = lsTmp;
  196. else
  197. HalconParamPath = appBasePath;
  198. }
  199. #region defectItemList <=> DefectItemList.json
  200. public static void LoadDefectItemList()
  201. {
  202. if (string.IsNullOrWhiteSpace(appBasePath))
  203. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  204. string configPath = appBasePath + "\\DefectItemList.json";
  205. string lsTmp = File.ReadAllText(configPath);
  206. defectItemList = JArray.Parse(lsTmp);
  207. }
  208. public static void SaveDefectItemList(JArray newValue)
  209. {
  210. if (string.IsNullOrWhiteSpace(appBasePath))
  211. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  212. string configPath = appBasePath + "\\DefectItemList.json";
  213. File.WriteAllText(configPath, newValue.ToString());
  214. }
  215. public static JObject getDefectItem(string code)
  216. {
  217. try
  218. {
  219. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
  220. if (item == null)
  221. return null;
  222. return (JObject)item;
  223. }
  224. catch { return null; }
  225. }
  226. public static JObject getDefectItem(int id)
  227. {
  228. try
  229. {
  230. if (id == -99)
  231. {
  232. JObject obj = new JObject();
  233. obj.Add("id", 0);
  234. obj.Add("code", "ng");
  235. obj.Add("name", "NG");
  236. obj.Add("color", "Red");
  237. return obj;
  238. }
  239. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  240. if (item == null)
  241. return null;
  242. return (JObject)item;
  243. }
  244. catch { return null; }
  245. }
  246. public static string getDefectCode(int id)
  247. {
  248. try
  249. {
  250. var item = Config.defectItemList.FirstOrDefault(m => m.Value<int>("id") == id);
  251. if (item == null)
  252. return "";
  253. return ((JObject)item).Value<string>("code");
  254. }
  255. catch { return ""; }
  256. }
  257. public static string getDefectName(string code)
  258. {
  259. try {
  260. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("code") == code);
  261. if (item == null)
  262. return "";
  263. return ((JObject)item).Value<string>("name");
  264. }
  265. catch { return ""; }
  266. }
  267. public static string getDefectCode(string name)
  268. {
  269. try {
  270. var item = Config.defectItemList.FirstOrDefault(m => m.Value<string>("name") == name);
  271. if (item == null)
  272. return "";
  273. return ((JObject)item).Value<string>("code");
  274. }
  275. catch { return ""; }
  276. }
  277. #endregion
  278. #region colorNameList <=> ColorNameList.json
  279. public static void LoadColorNameList()
  280. {
  281. if (string.IsNullOrWhiteSpace(appBasePath))
  282. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  283. string configPath = appBasePath + "\\ColorNameList.json";
  284. string lsTmp = File.ReadAllText(configPath);
  285. colorNameList = JArray.Parse(lsTmp);
  286. }
  287. public static JObject getColorItem(int code)
  288. {
  289. var item = Config.colorNameList.FirstOrDefault(m => m.Value<int>("code") == code);
  290. if (item == null)
  291. return null;
  292. return (JObject)item;
  293. }
  294. public static void LoadMaterialNameList()
  295. {
  296. if (string.IsNullOrWhiteSpace(appBasePath))
  297. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  298. string configPath = appBasePath + "\\MaterialName.json";
  299. string lsTmp = File.ReadAllText(configPath);
  300. materialNameList = JArray.Parse(lsTmp);
  301. }
  302. //public static JObject getMaterialItem(string code)
  303. //{
  304. // var item = Config.materialNameList.FirstOrDefault(m => m.Value<string>("code") == code);
  305. // if (item == null)
  306. // return null;
  307. // return (JObject)item;
  308. //}
  309. #endregion
  310. }
  311. }