using DataEntity; using DataEntity.Share; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; using XCommon.Log; using XHandler.Class; using XHandler.Class.DataEx; using XImagingXhandler.XDAL; namespace XHandler.View.BacteriaPickResult { /// /// 挑选菌落详情页面 /// public partial class BacteriaPickDetails : UserControl { #region 变量 /// /// 挑菌拍照基本信息 /// private ExperimentRunChoiceBacteraModel m_expRunChoiceBactera = null; private ObservableCollection m_bacteriaChoiceDetailList = null; public event EventHandler closeEvent = null; #endregion #region 初始化 /// /// 构造函数 /// /// 挑菌拍照基本信息 public BacteriaPickDetails(ExperimentRunChoiceBacteraModel expRunChoiceBactera) { InitializeComponent(); m_expRunChoiceBactera = expRunChoiceBactera; this.DataContext = m_expRunChoiceBactera; if (expRunChoiceBactera != null) { // 获取挑选详细信息 m_bacteriaChoiceDetailList = GetBacteriaCoordinateList(expRunChoiceBactera.UpdateJsonPath); dgPickData.ItemsSource = m_bacteriaChoiceDetailList; } // 菌落来源 List sourceList = new List(); sourceList.Add(Properties.Resources.strPlsSelect); sourceList.Add(Properties.Resources.strImagingSystem); sourceList.Add(Properties.Resources.strManualAdded); comboxBacteriaSource.ItemsSource = sourceList; comboxBacteriaSource.SelectedIndex = 0; } /// /// 初始化 /// /// /// private void UserControl_Loaded(object sender, RoutedEventArgs e) { //Storyboard storyboard = new Storyboard(); //DoubleAnimation doubleAnimation = new DoubleAnimation(0, 1300, new Duration(TimeSpan.FromSeconds(0.25))); //Storyboard.SetTarget(doubleAnimation, border);//Target对象 //Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性 //storyboard.Children.Add(doubleAnimation); //ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames(); //showAnimation.BeginTime = TimeSpan.FromSeconds(0); //Storyboard.SetTarget(showAnimation, this); //Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)")); //DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromSeconds(0.01)); //showAnimation.KeyFrames.Add(closeKeyFrame); //storyboard.Children.Add(showAnimation); //storyboard.Begin(); this.Width = Shared.Config.DisplaySizeW; this.Height = Shared.Config.DisplaySizeH; } /// /// 获取挑选详细信息 /// /// /// private ObservableCollection GetBacteriaCoordinateList(string jsonFile = "") { ObservableCollection list = new ObservableCollection(); if (string.IsNullOrEmpty(jsonFile)) { LoggerHelper.ErrorLog("[GetBacteriaCoordinateList]: json File is null"); return list; } if (!File.Exists(jsonFile)) { LoggerHelper.ErrorLog(string.Format("[GetBacteriaCoordinateList]:jsonFile is not exist. jsonFile = {0}", jsonFile)); return list; } try { string jsonData = File.ReadAllText(jsonFile); jsonData = jsonData.Replace("#!HxSEP!#", ""); JObject job = JObject.Parse(jsonData); JArray jArray = (JArray)job["germlist"]; foreach (JToken jt in jArray) { BacteriaCoordinate bacteriaCoordinate = new BacteriaCoordinate(); bacteriaCoordinate.bacteriacoordinate_id = jt["index"].ToString(); string coordinate3D = string.Empty; string coordinate3Dx = jt["coordinate3D"]["x"].ToString(); string coordinate3Dy = jt["coordinate3D"]["y"].ToString(); string coordinate3Dz = jt["coordinate3D"]["z"].ToString(); coordinate3D = jt["coordinate3D"]["x"].ToString() + "," + jt["coordinate3D"]["y"].ToString() + "," + jt["coordinate3D"]["z"].ToString(); bacteriaCoordinate.coordinate_machine = coordinate3D; string coordinatePixel = string.Empty; string pixelx = jt["coordinatePixel"]["x"].ToString(); string pixely = jt["coordinatePixel"]["y"].ToString(); coordinatePixel = jt["coordinatePixel"]["x"].ToString() + "," + jt["coordinatePixel"]["y"].ToString(); bacteriaCoordinate.coordinate_pixel = coordinatePixel; BacteriaCoordinateEx ex = new BacteriaCoordinateEx(bacteriaCoordinate); ex.diameter = jt["diameterSize"].ToString(); double pixelX = double.Parse(pixelx); double pixelY = double.Parse(pixely); ex.pixelPoint = new Point(pixelX, pixelY); double p3DX = double.Parse(coordinate3Dx); double p3DY = double.Parse(coordinate3Dy); double p3DZ = double.Parse(coordinate3Dz); ex.machinePoint = new Point3D(p3DX, p3DY, p3DZ); ex.bacteria_type = "";//bacteriaChoiceResultData.bacteria_name; ex.bacteria_shape = jt["shape"].ToString();//bacteriaChoiceResultData.bacteria_shape_name; ex.bacteria_color = jt["color"].ToString();// bacteriaChoiceResultData.bacteria_color_name; ex.bacteria_edge = jt["edge"].ToString();// bacteriaChoiceResultData.bacteria_edge_name; ex.isManualPick = (jt["manualPick"].ToString() == "true") ? true : false; list.Add(ex); } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } return list; } #endregion #region 窗口关闭 /// /// 窗口关闭 /// /// /// private void btnClose_Click(object sender, RoutedEventArgs e) { if (EventResponseController.Instance.CanExecute() == false) return; //Storyboard storyboard = new Storyboard(); //DoubleAnimation doubleAnimation = new DoubleAnimation(1300, 0, new Duration(TimeSpan.FromSeconds(0.25))); //Storyboard.SetTarget(doubleAnimation, border);//Target对象 //Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性 //storyboard.Children.Add(doubleAnimation); //ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames(); //showAnimation.BeginTime = TimeSpan.FromSeconds(0); //Storyboard.SetTarget(showAnimation, this); //Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)")); //DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Collapsed, TimeSpan.FromSeconds(0.26)); //showAnimation.KeyFrames.Add(closeKeyFrame); //storyboard.Children.Add(showAnimation); //storyboard.Completed += delegate { closeEvent?.Invoke(this, EventArgs.Empty); }; //storyboard.Begin(); closeEvent?.Invoke(this, EventArgs.Empty); } #endregion #region 菌落来源选择变更 /// /// 菌落来源选择变更 /// /// /// private void comboxBacteriaSource_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (comboxBacteriaSource.SelectedIndex == 0) { dgPickData.ItemsSource = m_bacteriaChoiceDetailList; } else if (comboxBacteriaSource.SelectedIndex == 1) { var result = m_bacteriaChoiceDetailList.Where(s => s.isManualPick.Equals(false)); dgPickData.ItemsSource = result; } else if (comboxBacteriaSource.SelectedIndex == 2) { var result = m_bacteriaChoiceDetailList.Where(s => s.isManualPick.Equals(true)); dgPickData.ItemsSource = result; } } #endregion #region 原图预览 /// /// 原图预览 /// /// /// private void Image_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount > 1) { ImagePreview imagePreview = new ImagePreview(m_expRunChoiceBactera.UpdateImagePath); imagePreview.closeEvent += ImagePreview_closeEvent; Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); parent.Children.Add(imagePreview); } } /// /// 预览窗口关闭 /// /// /// private void ImagePreview_closeEvent(object sender, EventArgs e) { // 移除元素 UIElement element = sender as UIElement; Utilities.RemoveChild(element); } #endregion #region 挑菌后的图片预览 /// /// 挑菌后的图片预览 /// /// /// private void SrcImage_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount > 1) { ImagePreview imagePreview = new ImagePreview(m_expRunChoiceBactera.SourceImagePath); imagePreview.closeEvent += ImagePreview_closeEvent; Window wnd = Application.Current.MainWindow; Grid parent = Utilities.FindVisualChild(wnd); parent.Children.Add(imagePreview); } } #endregion #region Del //private void comboxPickMode_SelectionChanged(object sender, SelectionChangedEventArgs e) //{ // if (comboxPickMode.SelectedIndex == 0) // { // dgPickData.ItemsSource = bacteriaCoordinateExList; // } // else if (comboxPickMode.SelectedIndex == 1) // { // var result = bacteriaCoordinateExList.Where(s => s.isManualPick.Equals(true)); // dgPickData.ItemsSource = result; // } // else if (comboxPickMode.SelectedIndex == 2) // { // var result = bacteriaCoordinateExList.Where(s => s.isManualPick.Equals(false)); // dgPickData.ItemsSource = result; // } //} #endregion } }