Full_Screen_View.xaml.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. using Newtonsoft.Json;
  16. using Newtonsoft.Json.Linq;
  17. namespace AIRS
  18. {
  19. /// <summary>
  20. /// Full_Screen_View.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class Full_Screen_View : Window
  23. {
  24. private Boolean isDown = false;
  25. Point ptDown = new Point();
  26. public String cir_rect = "";
  27. public double zoom_key = 1;
  28. public double rect_left = 0;
  29. public double rect_top = 0;
  30. public Boolean[] feild_change;
  31. public Full_Screen_View()
  32. {
  33. InitializeComponent();
  34. }
  35. ScaleTransform st;
  36. TranslateTransform tt;
  37. TransformGroup group;
  38. bool isDrag = false;
  39. Point startPoint;
  40. public string ProcessFileName = "AI";//传来的文件夹名
  41. public int ProcessOrInitial = 1;//调用本页时查看分析过程图时参数为1,图片放大缩小时为0
  42. public int cureent = 0;//默认选中第一个图片
  43. List<string> picList = new List<string>();//图片列表
  44. public int selectindex = 0;//将来会被弃用
  45. public Dictionary<string, List<string>> imglist = new Dictionary<string, List<string>>();
  46. public List<string> ImgAnalysisList = new List<string>();//list测试完的图片名分析过程图只是传过来一张
  47. bool isyuantudingwei = true;
  48. private void pdisyuan()
  49. {
  50. if (ProcessOrInitial == 0)
  51. {
  52. isyuantudingwei = true;
  53. }
  54. if (ProcessOrInitial == 1)
  55. {
  56. isyuantudingwei = false;
  57. }
  58. }
  59. /// <summary>
  60. /// 按键响应
  61. /// </summary>
  62. /// <param name="sender"></param>
  63. /// <param name="e"></param>
  64. private void MainWindows_Keydown(object sender, System.Windows.Input.KeyEventArgs e)
  65. {
  66. if (Keyboard.IsKeyDown(Key.Left))
  67. {
  68. e.Handled = true;
  69. if (cureent > 0)
  70. {
  71. cureent--;
  72. select_picture_index_path(cureent, picList);
  73. ShowImagesAnalysis(cureent, ImgAnalysisList);
  74. }
  75. //MessageBox.Show("按下了左键!");
  76. }
  77. if (Keyboard.IsKeyDown(Key.Right))
  78. {
  79. e.Handled = true;
  80. if (cureent < picList.Count - 1)
  81. {
  82. cureent++;
  83. select_picture_index_path(cureent, picList);
  84. ShowImagesAnalysis(cureent, ImgAnalysisList);
  85. }
  86. //MessageBox.Show("按下了右键!");
  87. }
  88. if (Keyboard.IsKeyDown(Key.Escape))
  89. {
  90. e.Handled = true;
  91. this.Close();
  92. //MessageBox.Show("按下了右键!");
  93. }
  94. }
  95. private void Window_Loaded(object sender, RoutedEventArgs e)
  96. {
  97. this.img_l_f.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Button_Previous_Click);
  98. this.img_r_f.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Button_Next_Click);
  99. //ShowImg(selectindex, imglist["imgList"]);
  100. cureent = selectindex;
  101. showProjects();
  102. pdisyuan();
  103. Console.WriteLine("传来的"+ProcessOrInitial);
  104. //ShowImagesAnalysis(cureent,ImgAnalysisList);//检验名称信息列表
  105. //ShowImagesAnalysis(selectindex,ImgAnalysisList);//检验名称信息列表
  106. //ShowCheckBoxTextAndCheck();
  107. group = (TransformGroup)grdMap.RenderTransform;
  108. st = group.Children[0] as ScaleTransform;
  109. tt = group.Children[3] as TranslateTransform;
  110. for(int i=0;i<feild_change.Length;i++)
  111. {
  112. feild_change[i] = false;
  113. }
  114. }
  115. /// <summary>
  116. /// 定位原图
  117. /// </summary>
  118. /// <param name="sender"></param>
  119. /// <param name="e"></param>
  120. private void Menu_Click_Positionimage(object sender, RoutedEventArgs e)
  121. {
  122. // MainWindow mainWindow = new MainWindow();
  123. if (isyuantudingwei == true)
  124. {
  125. if (File.Exists(imglist["imgList"][cureent]))
  126. {
  127. // MessageBox.Show("有原图" + ProcessOrInitial + isyuan + imglist["imgList"][cureent]);
  128. //mainWindow.OpenFolderAndSelectFile(imglist["imgList"][cureent]);
  129. Common.locateFile(imglist["imgList"][cureent]);
  130. }
  131. }
  132. else
  133. {
  134. if (File.Exists(ListImagesPathParsingProcess(imglist["imgList"])[cureent]))
  135. {
  136. Common.locateFile(ListImagesPathParsingProcess(imglist["imgList"])[cureent]);
  137. //mainWindow.OpenFolderAndSelectFile(ListImagesPathParsingProcess(imglist["imgList"])[cureent]);
  138. // MessageBox.Show("分析过程路径" + ProcessOrInitial + isyuan + ListImagesPathParsingProcess(imglist["imgList"])[cureent]);
  139. }
  140. }
  141. }
  142. /// <summary>
  143. /// 显示原图或分析过程
  144. /// </summary>
  145. /// <param name="sender"></param>
  146. /// <param name="e"></param>
  147. private void CheckBox_Click(object sender, RoutedEventArgs e)
  148. {
  149. isyuantudingwei = !isyuantudingwei;
  150. //MessageBox.Show("看卡" + isyuan);
  151. showProjects();
  152. //if (CheckBoxProcessOrInitial.IsChecked == true)
  153. //{
  154. // // ProcessOrInitial = 0;
  155. // showProjects();
  156. // //MessageBox.Show("按下了1键" +CheckBoxProcessOrInitial.IsChecked);
  157. //}
  158. //else
  159. //{
  160. // // ProcessOrInitial = 1;
  161. // showProjects();
  162. // //MessageBox.Show("按下了2键" +CheckBoxProcessOrInitial.IsChecked);
  163. //}
  164. //ShowCheckBoxTextAndCheck();
  165. //if (ProcessOrInitial == 0)
  166. //{
  167. // //ProcessOrInitial = 1;
  168. // //showProjects();
  169. // //MessageBox.Show("按下了右键" +CheckBoxProcessOrInitial.IsChecked);
  170. //}
  171. //if (ProcessOrInitial == 1)
  172. //{
  173. // // ProcessOrInitial = 0;
  174. // // showProjects();
  175. // //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
  176. //}
  177. }
  178. //private void checkboxzt()
  179. //{
  180. // if (ProcessOrInitial == 0)
  181. // {
  182. // CheckBoxProcessOrInitial.Visibility = Visibility.Hidden;
  183. // // CheckBoxProcessOrInitial.IsChecked = true;
  184. // }
  185. // if(ProcessOrInitial == 1)
  186. // {
  187. // CheckBoxProcessOrInitial.Visibility = Visibility.Visible;
  188. // CheckBoxProcessOrInitial.IsChecked = false;
  189. // }
  190. //}
  191. /// <summary>
  192. /// 根据传来的ProcessOrInitial的值 显示状态
  193. /// </summary>
  194. private void showProjects()
  195. {
  196. if (ProcessOrInitial == 0)
  197. {
  198. //CheckBoxProcessOrInitial.Content = "显示原图";
  199. //CheckBoxProcessOrInitial.IsChecked = true;
  200. //ShowImg(selectindex, imglist["imgList"]);
  201. ShowImagesAnalysis(cureent, ImgAnalysisList);
  202. ShowImg(cureent, imglist["imgList"]);
  203. CheckBoxProcessOrInitial.Visibility = Visibility.Hidden;
  204. //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
  205. }
  206. if (ProcessOrInitial == 1)
  207. {
  208. CheckBoxProcessOrInitial.Visibility = Visibility.Visible;
  209. // CheckBoxProcessOrInitial.IsChecked = false;
  210. if (CheckBoxProcessOrInitial.IsChecked == true)
  211. {
  212. ShowImagesAnalysis(cureent, ImgAnalysisList);
  213. ShowImg(cureent, imglist["imgList"]);
  214. }
  215. else
  216. {
  217. List<string> list = new List<string>();
  218. //CheckBoxProcessOrInitial.Content = "分析过程";
  219. //CheckBoxProcessOrInitial.IsChecked = true;
  220. list = ListImagesPathParsingProcess(imglist["imgList"]);
  221. //ShowImg(selectindex, imglist["imgList"]);
  222. ShowImagesAnalysis(cureent, ImgAnalysisList);
  223. ShowImg(cureent, list);
  224. }
  225. //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
  226. }
  227. //checkboxzt();
  228. }
  229. private void grdMap_MouseWheel(object sender, MouseWheelEventArgs e)
  230. {
  231. var point = e.GetPosition(grdRelative); // 实际点击的点
  232. var actualPoint = group.Inverse.Transform(point); // 想要缩放的点
  233. slider.Value = slider.Value + (double)e.Delta / 1000;
  234. tt.X = -((actualPoint.X * (slider.Value - 1))) + point.X - actualPoint.X;
  235. tt.Y = -((actualPoint.Y * (slider.Value - 1))) + point.Y - actualPoint.Y;
  236. }
  237. private void grdMap_MouseDown(object sender, MouseButtonEventArgs e)
  238. {
  239. isDrag = true;
  240. startPoint = e.GetPosition(grdRelative);
  241. }
  242. private void grdMap_MouseUp(object sender, MouseButtonEventArgs e)
  243. {
  244. isDrag = false;
  245. }
  246. private void grdMap_MouseLeave(object sender, MouseEventArgs e)
  247. {
  248. isDrag = false;
  249. }
  250. private void grdMap_MouseMove(object sender, MouseEventArgs e)
  251. {
  252. if (isDrag)
  253. {
  254. Point p = e.GetPosition(grdRelative);
  255. Point topPoint = grdMap.TranslatePoint(new Point(0, 0), grdRelative);
  256. Point bottomPoint = grdMap.TranslatePoint(new Point(grdMap.ActualWidth, grdMap.ActualHeight), grdRelative);
  257. double moveX = p.X - startPoint.X;
  258. double moveY = p.Y - startPoint.Y;
  259. //向上向下移动条件判断(会有一点点的小偏移,如果想更精确的控制,那么分向上和向下两种情况,并判断边距)
  260. if ((moveY < 0 && bottomPoint.Y > grdRelative.ActualHeight) || (moveY > 0 && topPoint.Y < 0))
  261. {
  262. tt.Y += (p.Y - startPoint.Y);
  263. startPoint.Y = p.Y;
  264. }
  265. //向左向右移动条件判断
  266. if ((moveX < 0 && bottomPoint.X > grdRelative.ActualWidth) || (moveX > 0 && topPoint.X < 0))
  267. {
  268. tt.X += (p.X - startPoint.X);
  269. startPoint.X = p.X;
  270. }
  271. }
  272. }
  273. /// <summary>
  274. /// 显示图片
  275. /// </summary>
  276. /// <param name="list"></param>
  277. public void ShowImg(int index,List<string> list)
  278. {
  279. try
  280. {
  281. if (index > -1 && list.Count > 0)
  282. {
  283. BitmapImage bi = new BitmapImage();
  284. bi.BeginInit();
  285. bi.CacheOption = BitmapCacheOption.OnLoad;
  286. picList = list;
  287. cureent = index;
  288. if (!File.Exists(picList[index]))
  289. {
  290. // Console.WriteLine(picList[index]);
  291. // MessageBox.Show("图片不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
  292. if (!File.Exists(imglist["imgList"][index]))
  293. {
  294. MessageBox.Show("原图片与分析图片都不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
  295. return;
  296. }
  297. bi.UriSource = new Uri(imglist["imgList"][index]);
  298. bi.EndInit();
  299. // target.Source = new BitmapImage(new Uri(listPics[index]));
  300. target.Source = bi;
  301. showLeftAndRight();
  302. this.show.Text = "未能分析";
  303. return;
  304. }
  305. Uri uri = new Uri(picList[index], UriKind.Absolute);
  306. //bi.BeginInit();
  307. //bi.CacheOption = BitmapCacheOption.OnLoad;
  308. bi.UriSource = uri;
  309. bi.EndInit();
  310. // BitmapImage source = new BitmapImage(uri);
  311. target.Source = bi;
  312. //计算缩放比
  313. int iw = bi.PixelWidth;
  314. int ih = bi.PixelHeight;
  315. double vw = target.Width;
  316. double vh = target.Height;
  317. double propw = iw / vw;
  318. double proph = ih / vh;
  319. if (propw > proph)
  320. {
  321. zoom_key = propw;
  322. rect_top = (vh - ih / propw) / 2;
  323. rect_left = 0;
  324. }
  325. else
  326. {
  327. zoom_key = proph;
  328. rect_top = 0;
  329. rect_left = (vw - iw / proph) / 2;
  330. }
  331. //检测是否有视场文件
  332. if (isyuantudingwei)
  333. {
  334. String field = System.IO.Path.GetDirectoryName(picList[index]) + "\\AI\\";
  335. field = field + System.IO.Path.GetFileNameWithoutExtension(picList[index]) + ".fld";
  336. if (File.Exists(field))
  337. {
  338. StreamReader file = new StreamReader(field);
  339. using (JsonTextReader reader = new JsonTextReader(file))
  340. {
  341. JObject o = (JObject)JToken.ReadFrom(reader);
  342. JObject param = JObject.Parse(o["viewport"].ToString());
  343. string c_r = param["type"].ToString();
  344. if (c_r.ToString() == "C")
  345. {
  346. double r = Convert.ToDouble(param["w"].ToString()) / 2;
  347. double x = Convert.ToDouble(param["x"].ToString()) + r;
  348. double y = Convert.ToDouble(param["y"].ToString()) + r;
  349. this.circle.RadiusX = r / zoom_key;
  350. this.circle.RadiusY = r / this.zoom_key;
  351. this.circle.Center = new Point(x / this.zoom_key + this.rect_left, y / this.zoom_key + this.rect_top);
  352. this.field.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
  353. this.fieldr.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
  354. this.field.Visibility = Visibility.Visible;
  355. this.fieldr.Visibility = Visibility.Hidden;
  356. }
  357. else
  358. {
  359. double _left = Convert.ToDouble(param["x"].ToString());
  360. double _top = Convert.ToDouble(param["y"].ToString());
  361. double _width = Convert.ToDouble(param["w"].ToString());
  362. double _height = Convert.ToDouble(param["h"].ToString());
  363. this.rectrr.Rect = new Rect(_left / this.zoom_key + this.rect_left, _top / zoom_key + this.rect_top, _width / this.zoom_key, _height / this.zoom_key);
  364. this.field.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
  365. this.fieldr.Fill = new SolidColorBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
  366. this.field.Visibility = Visibility.Hidden;
  367. this.fieldr.Visibility = Visibility.Visible;
  368. }
  369. reader.Close();
  370. file.Close();
  371. file.Dispose();
  372. }
  373. }
  374. }
  375. }
  376. else
  377. {
  378. MessageBox.Show("图片在来的路上?", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
  379. }
  380. }
  381. catch (Exception e)
  382. {
  383. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  384. }
  385. //for(int i = 0; i < picList.Count; i++)
  386. //{
  387. // Uri uri = new Uri(picList[i], UriKind.Absolute);
  388. // BitmapImage source = new BitmapImage(uri);
  389. // target.Source = source;
  390. // // this.show.Text = source.PixelWidth.ToString();
  391. //}
  392. }
  393. /// <summary>
  394. /// 显示图片分析数据
  395. ///
  396. /// </summary>
  397. /// <param name="index"></param>
  398. /// <param name="listPics"></param>
  399. public void ShowImagesAnalysis(int index, List<string> listAnalysis)
  400. {
  401. try
  402. {
  403. show.Text = listAnalysis[index];
  404. showLeftAndRight();
  405. }
  406. catch (Exception e)
  407. {
  408. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  409. }
  410. }
  411. /// <summary>
  412. /// 上一页
  413. /// </summary>
  414. /// <param name="sender"></param>
  415. /// <param name="e"></param>
  416. private void Button_Previous_Click(object sender, RoutedEventArgs e)
  417. {
  418. if (cureent > 0)
  419. {
  420. cureent--;
  421. ShowImagesAnalysis(cureent, ImgAnalysisList);
  422. select_picture_index_path(cureent, picList);
  423. }
  424. }
  425. /// <summary>
  426. /// 下一页
  427. /// </summary>
  428. /// <param name="sender"></param>
  429. /// <param name="e"></param>
  430. private void Button_Next_Click(object sender, RoutedEventArgs e)
  431. {
  432. if (cureent < picList.Count - 1)
  433. {
  434. cureent++;
  435. ShowImagesAnalysis(cureent, ImgAnalysisList);
  436. select_picture_index_path(cureent, picList);
  437. }
  438. }
  439. /// <summary>
  440. /// 显示图片//显示分析图片用到了
  441. ///
  442. /// </summary>
  443. /// <param name="index"></param>
  444. /// <param name="listPics"></param>
  445. public void select_picture_index_path(int index, List<string> listPics)
  446. {
  447. try
  448. {
  449. BitmapImage bi = new BitmapImage();
  450. bi.BeginInit();
  451. bi.CacheOption = BitmapCacheOption.OnLoad;
  452. if (!File.Exists(picList[index]))
  453. {
  454. // Console.WriteLine(picList[index]);
  455. // MessageBox.Show("图片不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
  456. if (!File.Exists(imglist["imgList"][index]))
  457. {
  458. MessageBox.Show("原图片与分析图片都不存在!", "提示您", MessageBoxButton.OK, MessageBoxImage.Warning);
  459. return;
  460. }
  461. bi.UriSource = new Uri(imglist["imgList"][index]);
  462. bi.EndInit();
  463. // target.Source = new BitmapImage(new Uri(listPics[index]));
  464. target.Source = bi;
  465. show.Text = "未能分析";
  466. showLeftAndRight();
  467. return;
  468. }
  469. bi.UriSource = new Uri(listPics[index]);
  470. bi.EndInit();
  471. // target.Source = new BitmapImage(new Uri(listPics[index]));
  472. target.Source = bi;
  473. //计算缩放比
  474. int iw = bi.PixelWidth;
  475. int ih = bi.PixelHeight;
  476. double vw = target.Width;
  477. double vh = target.Height;
  478. double propw = iw / vw;
  479. double proph = ih / vh;
  480. if (propw > proph)
  481. {
  482. zoom_key = propw;
  483. rect_top = (vh - ih / propw) / 2;
  484. rect_left = 0;
  485. }
  486. else
  487. {
  488. zoom_key = proph;
  489. rect_top = 0;
  490. rect_left = (vw - iw / proph) / 2;
  491. }
  492. //检测是否有视场文件
  493. if (isyuantudingwei)
  494. {
  495. String field = System.IO.Path.GetDirectoryName(picList[index]) + "\\AI\\";
  496. field = field + System.IO.Path.GetFileNameWithoutExtension(listPics[index]) + ".fld";
  497. if (File.Exists(field))
  498. {
  499. StreamReader file = new StreamReader(field);
  500. using (JsonTextReader reader = new JsonTextReader(file))
  501. {
  502. JObject o = (JObject)JToken.ReadFrom(reader);
  503. JToken c_r = o["Circle_Rect"];
  504. cir_rect = c_r.ToString();
  505. if (c_r.ToString() == "Circle")
  506. {
  507. JObject circle = JObject.Parse(o["Circle"].ToString());
  508. double r = Convert.ToDouble(circle["Radius"].ToString());
  509. double x = Convert.ToDouble(circle["Center_X"].ToString());
  510. double y = Convert.ToDouble(circle["Center_Y"].ToString());
  511. this.circle.RadiusX = r / zoom_key;
  512. this.circle.RadiusY = r / zoom_key;
  513. this.circle.Center = new Point(x / zoom_key + rect_left, y / zoom_key + rect_top);
  514. this.field.Visibility = Visibility.Visible;
  515. fieldr.Visibility = Visibility.Hidden;
  516. }
  517. else
  518. {
  519. JObject recta = JObject.Parse(o["Rectangle"].ToString());
  520. double _left = Convert.ToDouble(recta["Left"].ToString());
  521. double _top = Convert.ToDouble(recta["Top"].ToString());
  522. double _width = Convert.ToDouble(recta["Width"].ToString());
  523. double _height = Convert.ToDouble(recta["Height"].ToString());
  524. rectrr.Rect = new Rect(_left / zoom_key + rect_left, _top / zoom_key + rect_top, _width / zoom_key, _height / zoom_key);
  525. this.field.Visibility = Visibility.Hidden;
  526. this.fieldr.Visibility = Visibility.Visible;
  527. }
  528. reader.Close();
  529. file.Close();
  530. file.Dispose();
  531. }
  532. }
  533. }
  534. showLeftAndRight();
  535. }
  536. catch (Exception e)
  537. {
  538. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  539. }
  540. }
  541. /// <summary>
  542. /// 移动鼠标时是否显示翻页图标
  543. /// </summary>
  544. /// <param name="sender"></param>
  545. /// <param name="e"></param>
  546. private void MouseMove_Border(object sender, System.Windows.Input.MouseEventArgs e)
  547. {
  548. Point p = e.GetPosition(this);
  549. double X = p.X;
  550. double Y = p.Y;
  551. double one_four = this.ActualWidth / 4;
  552. if (X > one_four && X < this.grid.ActualWidth - one_four)
  553. {
  554. HiddenLeftAndRight();
  555. //this.btn_close.Visibility = Visibility.Hidden;
  556. //this.img_l_f.Visibility = Visibility.Hidden;
  557. //this.img_r_f.Visibility = Visibility.Hidden;
  558. }
  559. else
  560. {
  561. //this.img_l_f.Visibility = Visibility.Visible;
  562. //this.img_r_f.Visibility = Visibility.Visible;
  563. showLeftAndRight();
  564. // this.btn_close.Visibility = Visibility.Visible;
  565. }
  566. }
  567. /// <summary>
  568. /// 隐藏上一页下一页
  569. /// </summary>
  570. public void HiddenLeftAndRight()
  571. {
  572. this.img_l_f.Visibility = Visibility.Hidden;
  573. this.img_r_f.Visibility = Visibility.Hidden;
  574. }
  575. /// <summary>
  576. /// 显示上一页下一页
  577. /// </summary>
  578. public void showLeftAndRight()
  579. {
  580. if (picList.Count > 0)
  581. {
  582. if (picList.Count == 1)
  583. {
  584. HiddenLeftAndRight();
  585. }
  586. else
  587. {
  588. if (cureent == 0)
  589. {
  590. this.img_l_f.Visibility = Visibility.Hidden;
  591. this.img_r_f.Visibility = Visibility.Visible;
  592. }
  593. else if (cureent == picList.Count - 1)
  594. {
  595. this.img_l_f.Visibility = Visibility.Visible;
  596. this.img_r_f.Visibility = Visibility.Hidden;
  597. }
  598. else
  599. {
  600. this.img_l_f.Visibility = Visibility.Visible;
  601. this.img_r_f.Visibility = Visibility.Visible;
  602. }
  603. }
  604. }
  605. }
  606. /// 关闭窗口
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. private void button_close(object sender, RoutedEventArgs e)
  611. {
  612. this.Close();
  613. }
  614. /// <summary>
  615. /// 上一张 鼠标移动时发生移动时发生
  616. /// </summary>
  617. /// <param name="sender"></param>
  618. /// <param name="e"></param>
  619. private void Last_Img_MouseMove(object sender, MouseEventArgs e)
  620. {
  621. lasttimgellipse.Fill = new SolidColorBrush(Color.FromRgb(50, 150, 250));
  622. //Uri uri = new Uri("img/u71.png", UriKind.Relative);
  623. //BitmapImage img = new BitmapImage(uri);
  624. //img_l.Source = img;
  625. }
  626. /// <summary>
  627. /// 上一张 鼠标移除后发生
  628. /// </summary>
  629. /// <param name="sender"></param>
  630. /// <param name="e"></param>
  631. private void Last_Img_MouseLeave(object sender, MouseEventArgs e)
  632. {
  633. lasttimgellipse.Fill = new SolidColorBrush(Color.FromRgb(16, 133, 250));
  634. //Uri uri = new Uri("img/u7.png",UriKind.Relative);
  635. //BitmapImage img = new BitmapImage(uri);
  636. //img_l.Source = img;
  637. //lasttimgellipse.ReleaseMouseCapture();
  638. }
  639. /// <summary>
  640. /// 下一张 鼠标移动时发生移动时发生
  641. /// </summary>
  642. /// <param name="sender"></param>
  643. /// <param name="e"></param>
  644. private void Next_Img_MouseMove(object sender, MouseEventArgs e)
  645. {
  646. nextimgellipse.Fill = new SolidColorBrush(Color.FromRgb(50, 150, 250));
  647. //Uri uri = new Uri("img/u91.png", UriKind.Relative);
  648. //BitmapImage img = new BitmapImage(uri);
  649. //img_r.Source = img;
  650. }
  651. /// <summary>
  652. /// 上一张 鼠标移除后发生
  653. /// </summary>
  654. /// <param name="sender"></param>
  655. /// <param name="e"></param>
  656. private void Next_Img_MouseLeave(object sender, MouseEventArgs e)
  657. {
  658. nextimgellipse.Fill = new SolidColorBrush(Color.FromRgb(16, 133, 250));
  659. //Uri uri = new Uri("img/u9.png", UriKind.Relative);
  660. //BitmapImage img = new BitmapImage(uri);
  661. //img_r.Source = img;
  662. }
  663. /// <summary>
  664. /// 关闭 鼠标移动时发生移动时发生
  665. /// </summary>
  666. /// <param name="sender"></param>
  667. /// <param name="e"></param>
  668. private void btn_MouseEnter(object sender, MouseEventArgs e)
  669. {
  670. btn_close.Foreground =new SolidColorBrush(Colors.Black);
  671. }
  672. /// <summary>
  673. /// 关闭 鼠标移除后发生
  674. /// </summary>
  675. /// <param name="sender"></param>
  676. /// <param name="e"></param>
  677. private void btn_MouseLeave(object sender, MouseEventArgs e)
  678. {
  679. btn_close.Foreground = new SolidColorBrush(Colors.White);
  680. }
  681. /// <summary>
  682. /// 显示checkbox文本以及选中状态
  683. /// </summary>
  684. //private void ShowCheckBoxTextAndCheck()
  685. //{
  686. // if (ProcessOrInitial == 0)
  687. // {
  688. // // ProcessOrInitial = 1;
  689. // CheckBoxProcessOrInitial.Content = "显示原图";
  690. // CheckBoxProcessOrInitial.IsChecked = true;
  691. // //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
  692. // }
  693. // if (ProcessOrInitial == 1)
  694. // {
  695. // // ProcessOrInitial = 0;
  696. // CheckBoxProcessOrInitial.Content = "分析过程";
  697. // CheckBoxProcessOrInitial.IsChecked = true;
  698. // //MessageBox.Show("按下了右键" + CheckBoxProcessOrInitial.IsChecked);
  699. // }
  700. //}
  701. /// <summary>
  702. /// 分析过程的图片列表
  703. /// </summary>
  704. private List<string> ListImagesPathParsingProcess(List<string> list)
  705. {
  706. List<string> fxlist = new List<string>();
  707. try
  708. {
  709. if (list.Count > 0)
  710. {
  711. DirectoryInfo root = new DirectoryInfo(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(list[0]), ProcessFileName));
  712. if (Directory.Exists(root.ToString()))
  713. {
  714. FileInfo[] files = root.GetFiles();
  715. //if (files.Length > 0)
  716. //{
  717. // foreach (FileInfo li in files)
  718. // {
  719. // fxlist.Add(li.FullName);
  720. // //Console.WriteLine("111 " + li.FullName);//路径加图片名
  721. // }
  722. //}
  723. //else
  724. //{
  725. // MessageBox.Show("没有任何文件!");
  726. //}
  727. for (int i = 0; i < list.Count; i++)
  728. {
  729. string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(list[i]), ProcessFileName, System.IO.Path.GetFileName(list[i]));
  730. fxlist.Add(path);
  731. //Console.WriteLine(path);
  732. }
  733. }
  734. else
  735. {
  736. DirectoryInfo directoryInfo = new DirectoryInfo(root.ToString());
  737. directoryInfo.Create();
  738. for (int i = 0; i < list.Count; i++)
  739. {
  740. string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(list[i]), ProcessFileName, System.IO.Path.GetFileName(list[i]));
  741. fxlist.Add(path);
  742. //Console.WriteLine(path);
  743. }
  744. //MessageBox.Show(root.ToString()+"文件夹不存在!");
  745. }
  746. }
  747. }
  748. catch (Exception e)
  749. {
  750. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  751. }
  752. return fxlist;
  753. }
  754. private void can_tar_MouseDown(object sender, MouseButtonEventArgs e)
  755. {
  756. ptDown = e.GetPosition((IInputElement)sender);
  757. if (cir_rect == "Circle")
  758. {
  759. double liner = Math.Pow(ptDown.X - circle.Center.X, 2.0) + Math.Pow(ptDown.Y - circle.Center.Y, 2.0);
  760. if (liner > Math.Pow(circle.RadiusX, 2.0))
  761. {
  762. return;
  763. }
  764. }
  765. else
  766. {
  767. if (ptDown.X < rectrr.Rect.X || ptDown.X > (rectrr.Rect.X + rectrr.Rect.Width) ||
  768. ptDown.Y < rectrr.Rect.Y || ptDown.Y > (rectrr.Rect.Y + rectrr.Rect.Height))
  769. {
  770. return;
  771. }
  772. }
  773. this.Cursor = System.Windows.Input.Cursors.Hand;
  774. isDown = true;
  775. }
  776. private void can_tar_MouseMove(object sender, MouseEventArgs e)
  777. {
  778. if (isDown)
  779. {
  780. this.Cursor = System.Windows.Input.Cursors.ScrollAll;
  781. if (cir_rect == "Circle")
  782. {
  783. Point pt = e.GetPosition((IInputElement)sender);
  784. double x = pt.X - ptDown.X;
  785. double y = pt.Y - ptDown.Y;
  786. Point ptm = circle.Center;
  787. ptm.X = ptm.X + x;
  788. ptm.Y = ptm.Y + y;
  789. ptDown = new Point(ptDown.X + x, ptDown.Y + y);
  790. circle.Center = new Point(circle.Center.X + x, circle.Center.Y + y);
  791. //判断圆是否出图像
  792. if ((circle.Center.X - circle.RadiusX) < rect_left)
  793. {
  794. circle.Center = new Point(circle.RadiusX + rect_left, circle.Center.Y);
  795. }
  796. if ((circle.Center.Y - circle.RadiusY) < rect_top)
  797. {
  798. circle.Center = new Point(circle.Center.X, circle.RadiusY + rect_top);
  799. }
  800. if ((circle.Center.X + circle.RadiusX) > (target.Width - rect_left))
  801. {
  802. circle.Center = new Point(target.Width - rect_left - circle.RadiusX, circle.Center.Y);
  803. }
  804. if ((circle.Center.Y + circle.RadiusY) > (target.Height - rect_top))
  805. {
  806. circle.Center = new Point(circle.Center.X, target.Height - rect_top - circle.RadiusY);
  807. }
  808. }
  809. else
  810. {
  811. Point pt = e.GetPosition((IInputElement)sender);
  812. double x = pt.X - ptDown.X;
  813. double y = pt.Y - ptDown.Y;
  814. Rect rtm = rectrr.Rect;
  815. rtm.X = rtm.X + x;
  816. rtm.Y = rtm.Y + y;
  817. ptDown = new Point(ptDown.X + x, ptDown.Y + y);
  818. rectrr.Rect = rtm;
  819. if (rectrr.Rect.X < rect_left)
  820. {
  821. rtm.X = rect_left;
  822. rectrr.Rect = rtm;
  823. }
  824. if (rectrr.Rect.Y < rect_top)
  825. {
  826. rtm.Y = rect_top;
  827. rectrr.Rect = rtm;
  828. }
  829. if ((rectrr.Rect.X + rectrr.Rect.Width) > (target.Width - rect_left))
  830. {
  831. rtm.X = target.Width - rect_left - rectrr.Rect.Width;
  832. rectrr.Rect = rtm;
  833. }
  834. if ((rectrr.Rect.Y + rectrr.Rect.Height) > (target.Height - rect_top))
  835. {
  836. rtm.Y = target.Height - rect_top - rectrr.Rect.Height;
  837. rectrr.Rect = rtm;
  838. }
  839. }
  840. }
  841. }
  842. private void can_tar_MouseUp(object sender, MouseButtonEventArgs e)
  843. {
  844. if (isDown == true)
  845. {
  846. isDown = false;
  847. feild_change[cureent] = true;
  848. this.Cursor = System.Windows.Input.Cursors.Arrow;
  849. }
  850. }
  851. private void can_tar_MouseLeave(object sender, MouseEventArgs e)
  852. {
  853. if (isDown == true)
  854. {
  855. isDown = false;
  856. feild_change[cureent] = true;
  857. this.Cursor = System.Windows.Input.Cursors.Arrow;
  858. }
  859. }
  860. }
  861. }