ConfigItem.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace MeterVision.Config
  9. {
  10. public class ConfigItem2 : INotifyPropertyChanged
  11. {
  12. //全数字水表的List
  13. public static List<KeyValuePair<RulerDigitTypeEnum, string>> RulerDigitList =
  14. new List<KeyValuePair<RulerDigitTypeEnum, string>>()
  15. {
  16. new KeyValuePair<RulerDigitTypeEnum, string>(RulerDigitTypeEnum.MatchAllDigit,
  17. "匹配所有数字")
  18. //new KeyValuePair<RulerDigitTypeEnum, string>(RulerDigitTypeEnum.MatchAllDigitButLast,
  19. // "匹配所有数字,最后一位半字误差不大于1")
  20. };
  21. public static List<KeyValuePair<RulerDigitPointerTypeEnum, string>> RulerDigitPointerList =
  22. new List<KeyValuePair<RulerDigitPointerTypeEnum, string>>()
  23. {
  24. new KeyValuePair<RulerDigitPointerTypeEnum, string>(RulerDigitPointerTypeEnum.MatchAllDigitPointer,
  25. "匹配所有数字+所有指针"),
  26. new KeyValuePair<RulerDigitPointerTypeEnum, string>(RulerDigitPointerTypeEnum.MatchAllDigit,
  27. "匹配所有数字"),
  28. //new KeyValuePair<RulerDigitPointerTypeEnum, string>(RulerDigitPointerTypeEnum.MatchAllDigitButLast,
  29. // "匹配所有数字")
  30. };
  31. public static List<KeyValuePair<RulerPointerTypeEnum, string>> RulerPointerList =
  32. new List<KeyValuePair<RulerPointerTypeEnum, string>>()
  33. {
  34. new KeyValuePair<RulerPointerTypeEnum, string>(RulerPointerTypeEnum.MatchAllPointer,
  35. "匹配所有指针"),
  36. new KeyValuePair<RulerPointerTypeEnum, string>(RulerPointerTypeEnum.MatchAllIntegerPointer,
  37. "匹配整数指针")
  38. };
  39. public static bool IsValueInRulerDigitRange(int inputValue)
  40. {
  41. return RulerDigitList.Exists(item => (int)item.Key == inputValue);
  42. }
  43. public static bool IsValueInRulerDigitPointerRange(int inputValue)
  44. {
  45. return RulerDigitPointerList.Exists(item => (int)item.Key == inputValue);
  46. }
  47. public static bool IsValueInRulerPointerRange(int inputValue)
  48. {
  49. return RulerPointerList.Exists(item => (int)item.Key == inputValue);
  50. }
  51. public event EventHandler<PageSizeChangedEventArgs> OnStandPageSizeChanged;
  52. public event EventHandler<PageSizeChangedEventArgs> OnSinglePageSizeChanged;
  53. public event EventHandler<PageSizeChangedEventArgs> OnPatchPageSizeChanged;
  54. public event Action<int> OnStandCatalogPageSizeChanged;
  55. public event Action<int> OnPatchCatalogPageSizeChnaged;
  56. private string _onnxPath;
  57. public string OnnxPath
  58. {
  59. //get => _onnxPath;
  60. get
  61. {
  62. if (string.IsNullOrWhiteSpace(_onnxPath))
  63. {
  64. _onnxPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
  65. "onnx" , "N_I_RP_RGB_ns_5PB_5d0_63c_240701_x_29_t1.05_0.48_v1.04_0.52.onnx");
  66. //SaveOnnxPath(_onnxPath);
  67. }
  68. return _onnxPath;
  69. }
  70. set
  71. {
  72. //if(_onnxPath != value)
  73. {
  74. _onnxPath = value;
  75. OnPropertyChanged(nameof(OnnxPath));
  76. ConfigItem2.SaveOnnxPath(value);
  77. }
  78. }
  79. }
  80. private string _aiDll;
  81. public string AiDll
  82. {
  83. get
  84. {
  85. if (string.IsNullOrWhiteSpace(_aiDll))
  86. {
  87. _aiDll = "freeAI.dll";
  88. //SaveAiDll(_aiDll);
  89. }
  90. return _aiDll;
  91. }
  92. set
  93. {
  94. //if(_aiDll != value)
  95. {
  96. _aiDll = value;
  97. OnPropertyChanged(nameof(AiDll));
  98. ConfigItem2.SaveAiDll(value);
  99. }
  100. }
  101. }
  102. private string _dstImgPath;
  103. public string DstImgPath
  104. {
  105. get
  106. {
  107. if (string.IsNullOrWhiteSpace(_dstImgPath))
  108. {
  109. _dstImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dst_img");
  110. //SaveDstImgPath(_dstImgPath);
  111. }
  112. return _dstImgPath;
  113. }
  114. set
  115. {
  116. //if (_dstImgPath != value)
  117. {
  118. _dstImgPath = value;
  119. OnPropertyChanged(nameof(DstImgPath));
  120. ConfigItem2.SaveDstImgPath(value);
  121. }
  122. }
  123. }
  124. private string _transImgPath;
  125. public string TransImgPath
  126. {
  127. get
  128. {
  129. if (string.IsNullOrWhiteSpace(_transImgPath))
  130. {
  131. _transImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "trans_img");
  132. //SaveTransImgPath(_transImgPath);
  133. }
  134. return _transImgPath;
  135. }
  136. set
  137. {
  138. //if(_transImgPath != value)
  139. {
  140. _transImgPath = value;
  141. OnPropertyChanged(nameof(TransImgPath));
  142. ConfigItem2.SaveTransImgPath(value);
  143. }
  144. }
  145. }
  146. private string _aiLogPath;
  147. public string AiLogPath
  148. {
  149. get
  150. {
  151. if (string.IsNullOrWhiteSpace(_aiLogPath))
  152. {
  153. _aiLogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ai_log");
  154. //SaveAiLogPath(_aiLogPath);
  155. }
  156. return _aiLogPath;
  157. }
  158. set
  159. {
  160. //if (_aiLogPath != value)
  161. {
  162. _aiLogPath = value;
  163. OnPropertyChanged(nameof(AiLogPath));
  164. ConfigItem2.SaveAiLogPath(value);
  165. }
  166. }
  167. }
  168. private int _standPageSize;
  169. public int StandPageSize
  170. {
  171. get => _standPageSize;
  172. set
  173. {
  174. if (_standPageSize != value)
  175. {
  176. _standPageSize = value;
  177. OnPropertyChanged(nameof(StandPageSize));
  178. OnStandPageSizeChanged?.Invoke(this, new PageSizeChangedEventArgs(value));
  179. ConfigItem2.SaveStandPageSize(value);
  180. }
  181. }
  182. }
  183. private int _singlePageSize;
  184. public int SinglePageSize
  185. {
  186. get => _singlePageSize;
  187. set
  188. {
  189. if (_singlePageSize != value)
  190. {
  191. _singlePageSize = value;
  192. OnPropertyChanged(nameof(SinglePageSize));
  193. OnSinglePageSizeChanged?.Invoke(this, new PageSizeChangedEventArgs(value));
  194. ConfigItem2.SaveSinglePageSize(value);
  195. }
  196. }
  197. }
  198. private int _patchPageSize;
  199. public int PatchPageSize
  200. {
  201. get => _patchPageSize;
  202. set
  203. {
  204. if (_patchPageSize != value)
  205. {
  206. _patchPageSize = value;
  207. OnPropertyChanged(nameof(PatchPageSize));
  208. OnPatchPageSizeChanged?.Invoke(this, new PageSizeChangedEventArgs(value));
  209. ConfigItem2.SavePatchPageSize(value);
  210. }
  211. }
  212. }
  213. private int _catalogPageSize;
  214. public int CatalogPageSize
  215. {
  216. get => _catalogPageSize;
  217. set
  218. {
  219. if (_catalogPageSize != value)
  220. {
  221. _catalogPageSize = value;
  222. OnPropertyChanged(nameof(CatalogPageSize));
  223. }
  224. }
  225. }
  226. private int _standCatalogPageSize;
  227. public int StandCatalogPageSize
  228. {
  229. get => _standCatalogPageSize;
  230. set
  231. {
  232. if(_standCatalogPageSize != value)
  233. {
  234. _standCatalogPageSize = value;
  235. OnPropertyChanged(nameof(StandCatalogPageSize));
  236. OnStandCatalogPageSizeChanged?.Invoke(value);
  237. ConfigItem2.SaveStandCatalogPageSize(value);
  238. }
  239. }
  240. }
  241. private int _patchCatalogPageSize;
  242. public int PatchCatalogPageSize
  243. {
  244. get => _patchCatalogPageSize;
  245. set
  246. {
  247. if (_patchCatalogPageSize != value)
  248. {
  249. _patchCatalogPageSize = value;
  250. OnPropertyChanged(nameof(PatchCatalogPageSize));
  251. OnPatchCatalogPageSizeChnaged?.Invoke(value);
  252. ConfigItem2.SavePatchCatalogPageSize(value);
  253. }
  254. }
  255. }
  256. private int _rulerDigitType;
  257. public int RulerDigitType
  258. {
  259. get => _rulerDigitType;
  260. set
  261. {
  262. if(_rulerDigitType != value)
  263. {
  264. _rulerDigitType = value;
  265. OnPropertyChanged(nameof(RulerDigitType));
  266. }
  267. }
  268. }
  269. private int _rulerDigitPointerType;
  270. public int RulerDigitPointerType
  271. {
  272. get => _rulerDigitPointerType;
  273. set
  274. {
  275. if (_rulerDigitPointerType != value)
  276. {
  277. _rulerDigitPointerType = value;
  278. OnPropertyChanged(nameof(RulerDigitPointerType));
  279. }
  280. }
  281. }
  282. private int _rulerPointerType;
  283. public int RulerPointerType
  284. {
  285. get => _rulerPointerType;
  286. set
  287. {
  288. if (_rulerPointerType != value)
  289. {
  290. _rulerPointerType = value;
  291. OnPropertyChanged(nameof(RulerPointerType));
  292. }
  293. }
  294. }
  295. public ConfigItem2()
  296. {
  297. }
  298. private static ConfigItem2 _configItem;
  299. public event PropertyChangedEventHandler PropertyChanged;
  300. protected void OnPropertyChanged(string propertyName)
  301. {
  302. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  303. }
  304. public static ConfigItem2 GetConfigItem()
  305. {
  306. if(_configItem == null)
  307. {
  308. _configItem = new ConfigItem2();
  309. //string onnxPath = Properties.Settings.Default.onnx;
  310. int standPageSize = Properties.Settings.Default.stand_page_size;
  311. int singlePageSize = Properties.Settings.Default.single_page_size;
  312. int patchPageSize = Properties.Settings.Default.patch_page_size;
  313. int catalogPageSize = Properties.Settings.Default.catalog_page_size;
  314. _configItem.OnnxPath = Properties.Settings.Default.onnx; //onnxPath;
  315. _configItem.AiDll = Properties.Settings.Default.ai_dll;
  316. _configItem.DstImgPath = Properties.Settings.Default.dstimg_path;
  317. _configItem.AiLogPath = Properties.Settings.Default.ai_log_path;
  318. _configItem.TransImgPath = Properties.Settings.Default.transimg_path;
  319. _configItem.StandPageSize = standPageSize;
  320. _configItem.SinglePageSize = singlePageSize;
  321. _configItem.PatchPageSize = patchPageSize;
  322. _configItem.CatalogPageSize = catalogPageSize;
  323. _configItem.StandCatalogPageSize = Properties.Settings.Default.stand_catalog_page_size;
  324. _configItem.PatchCatalogPageSize = Properties.Settings.Default.patch_catalog_page_size;
  325. _configItem.RulerDigitType = Properties.Settings.Default.ruler_digit_type;
  326. _configItem.RulerDigitPointerType = Properties.Settings.Default.ruler_digitpointer_type;
  327. _configItem.RulerPointerType = Properties.Settings.Default.ruler_pointer_type;
  328. }
  329. return _configItem;
  330. }
  331. public static void SaveOnnxPath(string onnxPath)
  332. {
  333. Properties.Settings.Default.onnx = onnxPath;
  334. Properties.Settings.Default.Save();
  335. }
  336. public static void SaveAiDll(String aiDll)
  337. {
  338. Properties.Settings.Default.ai_dll = aiDll;
  339. Properties.Settings.Default.Save();
  340. }
  341. public static void SaveDstImgPath(string dstImgPath)
  342. {
  343. Properties.Settings.Default.dstimg_path = dstImgPath;
  344. Properties.Settings.Default.Save();
  345. }
  346. public static void SaveTransImgPath(string transImgPath)
  347. {
  348. Properties.Settings.Default.transimg_path = transImgPath;
  349. Properties.Settings.Default.Save();
  350. }
  351. public static void SaveAiLogPath(string aiLogPath)
  352. {
  353. Properties.Settings.Default.ai_log_path = aiLogPath;
  354. Properties.Settings.Default.Save();
  355. }
  356. public static void SaveStandPageSize(int pageSize)
  357. {
  358. Properties.Settings.Default.stand_page_size = pageSize;
  359. Properties.Settings.Default.Save();
  360. }
  361. public static void SaveSinglePageSize(int pageSize)
  362. {
  363. Properties.Settings.Default.single_page_size = pageSize;
  364. Properties.Settings.Default.Save();
  365. }
  366. public static void SavePatchPageSize(int pageSize)
  367. {
  368. Properties.Settings.Default.patch_page_size = pageSize;
  369. Properties.Settings.Default.Save();
  370. }
  371. public static void SaveCatalogPageSize(int pageSize)
  372. {
  373. Properties.Settings.Default.catalog_page_size = pageSize;
  374. Properties.Settings.Default.Save();
  375. }
  376. public static void SaveStandCatalogPageSize(int pageSize)
  377. {
  378. Properties.Settings.Default.stand_catalog_page_size = pageSize;
  379. Properties.Settings.Default.Save();
  380. }
  381. public static void SavePatchCatalogPageSize(int pageSize)
  382. {
  383. Properties.Settings.Default.patch_catalog_page_size = pageSize;
  384. Properties.Settings.Default.Save();
  385. }
  386. public static void SaveRulerDigitType(int type)
  387. {
  388. Properties.Settings.Default.ruler_digit_type = type;
  389. Properties.Settings.Default.Save();
  390. }
  391. public static void SaveRulerDigitPointerType(int type)
  392. {
  393. Properties.Settings.Default.ruler_digitpointer_type = type;
  394. Properties.Settings.Default.Save();
  395. }
  396. public static void SaveRulerPointerType(int type)
  397. {
  398. Properties.Settings.Default.ruler_pointer_type = type;
  399. Properties.Settings.Default.Save();
  400. }
  401. /////////////////////////////////////////
  402. }
  403. public class PageSizeChangedEventArgs : EventArgs
  404. {
  405. public int PageSize { get; }
  406. public PageSizeChangedEventArgs(int pageSize)
  407. {
  408. PageSize = pageSize;
  409. }
  410. }
  411. //全数字水表的枚举
  412. public enum RulerDigitTypeEnum
  413. {
  414. MatchAllDigit = 1, //全部数字相等
  415. //MatchAllDigitButLast = 2 //除了最后一位所有的数字相同(最后1位误差不能大于1)
  416. }
  417. //数字+指针水表的枚举
  418. public enum RulerDigitPointerTypeEnum
  419. {
  420. MatchAllDigitPointer = 1, //全部的数字和指针要相同
  421. MatchAllDigit = 2, //匹配所有的数字
  422. //MatchAllDigitButLast = 3 //除最后一位匹配所有数字(最后一位误差不大于1)
  423. }
  424. public enum RulerPointerTypeEnum
  425. {
  426. MatchAllPointer = 1, //匹配所有指针
  427. MatchAllIntegerPointer = 2 //匹配所有整数指针
  428. }
  429. }