using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using XHandler.Class;
using XHandler.Class.DataEx;
using XImagingXhandler.XDAL;
using System.Collections.ObjectModel;
namespace XHandler.Controls
{
public class ControlLabware : Grid
{
private double tipRatio = 16 * 1.0 / 104;
private double plateRatio = 8 * 1.0 / 104;
//private SolidColorBrush tipsValidBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x4F, 0x4F, 0x4F));
private SolidColorBrush ValidBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x0E, 0x81, 0xEC)); //(0xFF, 0x67, 0xDC, 0xFF));
//private SolidColorBrush InValidBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xBC, 0xBC, 0xBC));
//private SolidColorBrush runningBrush = Brushes.LightGreen;// new SolidColorBrush(Color.FromArgb(0xFF, 0x16, 0x5D, 0xFF));
private SolidColorBrush defaultBrush = Brushes.White;
private SolidColorBrush disableBrush = Brushes.Gray;
///
/// 有效孔位
///
private List validWellList = new List();
///
/// 正在更新的孔位
///
private List updateWellList = new List();
///
/// 耗材的孔位数据
///
public ObservableCollection labwareWellInfoList
{
get { return (ObservableCollection)GetValue(LabwareWellInfoProperty); }
set { SetValue(LabwareWellInfoProperty, value); }
}
public static readonly DependencyProperty LabwareWellInfoProperty =
DependencyProperty.Register("labwareWellInfoList", typeof(ObservableCollection), typeof(ControlLabware), new PropertyMetadata(null));
///
/// 耗材的实际长
///
public double LabwareRealLength
{
get { return (double)GetValue(LabwareRealLengthProperty); }
set { SetValue(LabwareRealLengthProperty, value); }
}
public static readonly DependencyProperty LabwareRealLengthProperty =
DependencyProperty.Register("LabwareRealLength", typeof(double), typeof(ControlLabware), new PropertyMetadata(null));// Double.NaN, OnLabwareRealSizeChanged));
///
/// 耗材的实际宽
///
public double LabwareRealWidth
{
get { return (double)GetValue(LabwareRealWidthProperty); }
set { SetValue(LabwareRealWidthProperty, value); }
}
public static readonly DependencyProperty LabwareRealWidthProperty =
DependencyProperty.Register("LabwareRealWidth", typeof(double), typeof(ControlLabware), new PropertyMetadata(Double.NaN, OnLabwareRealSizeChanged));
public static void OnLabwareRealSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
if (control.LabwareType == (int)ConsumableTypeEnum.Shelf)
{
control.Children.Clear();
control.DrawContentForShelf();
}
else if (control.LabwareType == (int)ConsumableTypeEnum.Electrophoto)
{
control.Children.Clear();
control.DrawElectrophoto();
}
}
}
///
/// 耗材的长
///
public double LabwareWidth
{
get { return (double)GetValue(LabwareWidthProperty); }
set { SetValue(LabwareWidthProperty, value); }
}
public static readonly DependencyProperty LabwareWidthProperty =
DependencyProperty.Register("LabwareWidth", typeof(double), typeof(ControlLabware), new PropertyMetadata(Double.NaN));
///
/// 耗材的宽
///
public double LabwareHeight
{
get { return (double)GetValue(LabwareHeightProperty); }
set { SetValue(LabwareHeightProperty, value); }
}
public static readonly DependencyProperty LabwareHeightProperty =
DependencyProperty.Register("LabwareHeight", typeof(double), typeof(ControlLabware), new PropertyMetadata(Double.NaN, OnLabwareSizeChanged));
public static void OnLabwareSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
double height = (double)e.NewValue;
control.Width = control.LabwareWidth + control.LabwareDeep;
control.Height = height + control.LabwareDeep;
}
}
///
/// 耗材的高度
///
public double LabwareDeep
{
get { return (double)GetValue(LabwareDeepProperty); }
set { SetValue(LabwareDeepProperty, value); }
}
public static readonly DependencyProperty LabwareDeepProperty =
DependencyProperty.Register("LabwareDeep", typeof(double), typeof(ControlLabware), new PropertyMetadata((double)8));
///
/// 耗材左边面板颜色
///
public Color LeftSideColor
{
get { return (Color)GetValue(LeftSideColorProperty); }
set { SetValue(LeftSideColorProperty, value); }
}
public static readonly DependencyProperty LeftSideColorProperty =
DependencyProperty.Register("LeftSideColor", typeof(Color), typeof(ControlLabware), new PropertyMetadata(Colors.White, OnLeftSideColorChanged));
public static void OnLeftSideColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
Color color = (Color)e.NewValue;
control.SetSideColor(color);
}
}
///
/// 耗材前面面板颜色
///
public Color FrontColor
{
get { return (Color)GetValue(FrontColorProperty); }
set { SetValue(FrontColorProperty, value); }
}
public static readonly DependencyProperty FrontColorProperty =
DependencyProperty.Register("FrontColor", typeof(Color), typeof(ControlLabware), new PropertyMetadata(Colors.White, OnFrontColorChanged));
public static void OnFrontColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
Color color = (Color)e.NewValue;
control.SetFrontColor(color);
}
}
///
/// 耗材上面面板颜色
///
public Color TopColor
{
get { return (Color)GetValue(TopColorProperty); }
set { SetValue(TopColorProperty, value); }
}
public static readonly DependencyProperty TopColorProperty =
DependencyProperty.Register("TopColor", typeof(Color), typeof(ControlLabware), new PropertyMetadata(Colors.White, OnTopColorChanged));
public static void OnTopColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
Color color = (Color)e.NewValue;
control.SetTopColor(color);
}
}
///
/// 耗材边框颜色
///
public Color BorderColor
{
get { return (Color)GetValue(BorderColorProperty); }
set { SetValue(BorderColorProperty, value); }
}
public static readonly DependencyProperty BorderColorProperty =
DependencyProperty.Register("BorderColor", typeof(Color), typeof(ControlLabware), new PropertyMetadata(Colors.White, OnBorderColorChanged));
public static void OnBorderColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
Color color = (Color)e.NewValue;
control.SetBorderColor(color);
}
}
///
/// 耗材孔的颜色
///
public Color WellColor
{
get { return (Color)GetValue(WellColorProperty); }
set { SetValue(WellColorProperty, value); }
}
public static readonly DependencyProperty WellColorProperty =
DependencyProperty.Register("WellColor", typeof(Color), typeof(ControlLabware), new PropertyMetadata(Colors.White));
///
/// 耗材行数
///
public int Rows
{
get { return (int)GetValue(RowsProperty); }
set { SetValue(RowsProperty, value); }
}
public static readonly DependencyProperty RowsProperty =
DependencyProperty.Register("Rows", typeof(int), typeof(ControlLabware), new PropertyMetadata(1));
///
/// 耗材列数
///
public int Columns
{
get { return (int)GetValue(ColumnsProperty); }
set { SetValue(ColumnsProperty, value); }
}
public static readonly DependencyProperty ColumnsProperty =
DependencyProperty.Register("Columns", typeof(int), typeof(ControlLabware), new PropertyMetadata(1));
///
/// 耗材孔是否填充颜色
///
public bool IsFill
{
get { return (bool)GetValue(IsFillProperty); }
set { SetValue(IsFillProperty, value); }
}
public static readonly DependencyProperty IsFillProperty =
DependencyProperty.Register("IsFill", typeof(bool), typeof(ControlLabware), new PropertyMetadata(false));
///
/// 垃圾桶
///
public bool IsTrash
{
get { return (bool)GetValue(IsTrashProperty); }
set { SetValue(IsTrashProperty, value); }
}
public static readonly DependencyProperty IsTrashProperty =
DependencyProperty.Register("IsTrash", typeof(bool), typeof(ControlLabware), new PropertyMetadata(false));
///
/// 是否选中
///
public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}
public static readonly DependencyProperty IsSelectedProperty =
DependencyProperty.Register("IsSelected", typeof(bool), typeof(ControlLabware), new PropertyMetadata(false, IsSelectedChanged));
public static void IsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
bool? isSelect = e.NewValue as bool?;
if (isSelect == true)
control.SetSelection();
else
control.ClearSelection();
}
}
///
/// label
///
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
public static readonly DependencyProperty LabelProperty =
DependencyProperty.Register("Label", typeof(string), typeof(ControlLabware), new PropertyMetadata("", OnLabelChanged));
public static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
string label = e.NewValue as string;
control.SetLabel(label);
}
}
///
/// barcode
///
public string Barcode
{
get { return (string)GetValue(BarcodeProperty); }
set { SetValue(BarcodeProperty, value); }
}
public static readonly DependencyProperty BarcodeProperty =
DependencyProperty.Register("Barcode", typeof(string), typeof(ControlLabware), new PropertyMetadata("", OnBarcodeChanged));
public static void OnBarcodeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
//string label = e.NewValue as string;
//control.SetLabel(label);
}
}
///
/// LabwareName
///
public string LabwareName
{
get { return (string)GetValue(LabwareNameProperty); }
set { SetValue(LabwareNameProperty, value); }
}
public static readonly DependencyProperty LabwareNameProperty =
DependencyProperty.Register("LabwareName", typeof(string), typeof(ControlLabware), new PropertyMetadata("", OnLabwareNameChanged));
public static void OnLabwareNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
string label = e.NewValue as string;
control.SetLabwareName(label);
}
}
///
/// 有效的孔位
///
public string ValidWells
{
get { return (string)GetValue(ValidWellsProperty); }
set { SetValue(ValidWellsProperty, value); }
}
public static readonly DependencyProperty ValidWellsProperty = DependencyProperty.Register("ValidWells", typeof(string), typeof(ControlLabware),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnValidWellsChanged), null));
private static void OnValidWellsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
string val = (string)e.NewValue;
control.SetValidWells(val);
}
}
///
/// 耗材类型
///
public int LabwareType
{
get { return (int)GetValue(LabwareTypeProperty); }
set { SetValue(LabwareTypeProperty, value); }
}
public static readonly DependencyProperty LabwareTypeProperty =
DependencyProperty.Register("LabwareType", typeof(int), typeof(ControlLabware), new PropertyMetadata(0, OnLabwareTypeChanged));
public static void OnLabwareTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlLabware control = (ControlLabware)d;
if (control != null)
{
int type = (int)e.NewValue;
if (type == (int)ConsumableTypeEnum.Plate)
{
control.LabwareDeep = control.LabwareWidth * control.plateRatio;
control.Width = control.LabwareWidth + control.LabwareDeep;
control.Height = control.LabwareHeight + control.LabwareDeep;
}
else if ((type == (int)ConsumableTypeEnum.Tips) || (type == (int)ConsumableTypeEnum.TipsBox)|| (type == (int)ConsumableTypeEnum.Centrifugal) || (type == (int)ConsumableTypeEnum.Electrophoto))
{
control.LabwareDeep = control.LabwareWidth * control.tipRatio;
control.Width = control.LabwareWidth + control.LabwareDeep;
control.Height = control.LabwareHeight + control.LabwareDeep;
}
else if (type == (int)ConsumableTypeEnum.CircularDish)
{
control.Width = control.LabwareWidth + 4;// control.LabwareDeep;
control.Height = control.LabwareHeight + 4;// control.LabwareDeep;
}
else
{
control.LabwareDeep = control.LabwareWidth * control.plateRatio;
control.Width = control.LabwareWidth + control.LabwareDeep;
control.Height = control.LabwareHeight + control.LabwareDeep;
}
}
}
private Grid _gridContent = new Grid();
private Border borderLabel;
private ToolTip tooltip;//鼠标悬停至标签提示文本
private ToolTip tooltipLabware;//鼠标悬停至耗材提示文本
private Path frontPath;
private Path leftSidePath; // 左边
private Path topPath;
private Rectangle dishRect;
private string updateWells;
public ControlLabware()
{
this.SnapsToDevicePixels = true;
this.UseLayoutRounding = true;
//this.AllowDrop = true;
InitializeComponent();
//this.Drop += ControlLabware_Drop;
//this.PreviewDrop += ControlLabware_Drop;
}
void InitializeComponent()
{
if (!IsTrash)
{
this.Children.Add(_gridContent);
_gridContent.SizeChanged += _gridContent_SizeChanged;
tooltip = new ToolTip();
tooltip.Placement = PlacementMode.Right;
tooltip.PlacementRectangle = new Rect(0, 0, 0, 0);
tooltip.HorizontalOffset = 30;
tooltip.VerticalOffset = -20;
tooltipLabware = new ToolTip();
tooltipLabware.Placement = PlacementMode.Right;
tooltipLabware.PlacementRectangle = new Rect(0, 0, 0, 0);
tooltipLabware.HorizontalOffset = 30;
tooltipLabware.VerticalOffset = -20;
}
this.SizeChanged += ControlLabware_SizeChanged;
}
private void _gridContent_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (LabwareType == (int)ConsumableTypeEnum.CircularDish || IsTrash || LabwareType == (int)ConsumableTypeEnum.Rounddishlid||LabwareType==(int)ConsumableTypeEnum.Electrophoto)
return;
_gridContent.ColumnDefinitions.Clear();
_gridContent.RowDefinitions.Clear();
_gridContent.Children.Clear();
if (LabwareType == (int)ConsumableTypeEnum.Through)
{
AddThrough();
}
else if (LabwareType == (int)ConsumableTypeEnum.Tube)
{
AddWellsCircle();
}
else
{
AddWells();
}
if (!string.IsNullOrEmpty(ValidWells))
SetValidWells(ValidWells);
}
private void ControlLabware_SizeChanged(object sender, SizeChangedEventArgs e)
{
//this.Width = LabwareWidth + LabwareDeep;
//this.Height = LabwareWidth * nBaseHeight / nBaseWidth + LabwareDeep;
if (this.ActualWidth == double.NaN || this.ActualWidth <= 0)
return;
this.Children.Clear();
if (!IsTrash)
{
this.ColumnDefinitions.Clear();
this.RowDefinitions.Clear();
_gridContent.ColumnDefinitions.Clear();
_gridContent.RowDefinitions.Clear();
_gridContent.Children.Clear();
this.Children.Add(_gridContent);
// 圆形皿
// 圆形皿盖子
if (LabwareType == (int)ConsumableTypeEnum.CircularDish ||
LabwareType == (int)ConsumableTypeEnum.Rounddishlid)
{
_gridContent.Margin = new Thickness(0);
DrawCircularDish();
}
else if (LabwareType == (int)ConsumableTypeEnum.Tips)
{
_gridContent.Margin = new Thickness(0);
DrawTip();
}
else if (LabwareType == (int)ConsumableTypeEnum.Centrifugal)//离心管
{
_gridContent.Margin = new Thickness(0);
DrawCentrifugal();
}
else if (LabwareType == (int)ConsumableTypeEnum.Electrophoto)//电泳槽
{
_gridContent.Margin = new Thickness(0);
DrawElectrophoto();
}
else if (LabwareType == (int)ConsumableTypeEnum.Tube)//管架
{
_gridContent.Margin = new Thickness(3);
DrawContent();
//多加一个孔外圈
AddWellsCircle();
}
else if(LabwareType == (int)ConsumableTypeEnum.Shelf)//板位
{
DrawContentForShelf();
}
else
{
_gridContent.Margin = new Thickness(3);
DrawContent();
}
}
else
{
DrawTrash();
if (this.ActualWidth <= 50)
{
SetFont();
}
}
AddLabel();
if (IsSelected)
SetSelection();
else
ClearSelection();
}
public void SetFont()
{
Children.Clear();
TextBlock tb = new TextBlock();
tb.Text = Properties.Resources.strTrash;
tb.FontSize = 14;
tb.Foreground = Brushes.Black;
tb.VerticalAlignment = VerticalAlignment.Center;
tb.HorizontalAlignment = HorizontalAlignment.Center;
Border border = new Border()
{
Name = "Trash",
Background = Brushes.DarkGray,
CornerRadius = new CornerRadius(5),
Child = tb,
};
Children.Add(border);
}
private void DrawCircularDish()
{
dishRect = new Rectangle();
dishRect.Width = LabwareWidth;
dishRect.Height = LabwareHeight;
dishRect.Fill = new SolidColorBrush(TopColor);
dishRect.Stroke = Brushes.Gray;
dishRect.RadiusX = LabwareWidth / 2;
dishRect.RadiusY = 20;
dishRect.VerticalAlignment = VerticalAlignment.Bottom;
_gridContent.Children.Add(dishRect);
Ellipse ellipse = new Ellipse();
ellipse.HorizontalAlignment = HorizontalAlignment.Center;
ellipse.VerticalAlignment = VerticalAlignment.Top;
ellipse.Fill = Brushes.White;
ellipse.Width = LabwareWidth;
ellipse.Height = LabwareHeight * 40 / 50;
ellipse.Opacity = 0.5;
ellipse.Stroke = Brushes.Gray;
_gridContent.Children.Add(ellipse);
GradientStopCollection gradientStops = new GradientStopCollection();
GradientStop gs = new GradientStop()
{ Color = Colors.LightGray, };
gradientStops.Add(gs);
gs = new GradientStop()
{
Color = Colors.Transparent,
Offset = 1,
};
gradientStops.Add(gs);
gs = new GradientStop()
{
Color = Color.FromArgb(0x31, 0x00, 0x00, 0x00),
Offset = 0.6,
};
gradientStops.Add(gs);
LinearGradientBrush brush = new LinearGradientBrush(gradientStops, new Point(0, 0.5), new Point(1, 1.5));
Rectangle rectangle = new Rectangle();
rectangle.Width = LabwareWidth;
rectangle.Height = LabwareHeight;
rectangle.Opacity = 0.5;
rectangle.RadiusX = 40;
rectangle.RadiusY = 20;
rectangle.Fill = brush;
rectangle.VerticalAlignment = VerticalAlignment.Bottom;
_gridContent.Children.Add(rectangle);
}
private void DrawTip()
{
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(64, GridUnitType.Star) });
//this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(LabwareDeep, GridUnitType.Pixel) });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(104, GridUnitType.Pixel) });
//this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"../../../Assets/Consumables/tip.png", UriKind.Relative));
this.Children.Add(img);
Grid.SetColumn(_gridContent, 0);
Grid.SetColumnSpan(_gridContent, 2);
Grid.SetRow(_gridContent, 0);
img.Stretch = Stretch.Fill;
Panel.SetZIndex(_gridContent, 1);
}
#region 画离心管
private void DrawCentrifugal()
{
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(64, GridUnitType.Star) });
//this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(LabwareDeep, GridUnitType.Pixel) });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(104, GridUnitType.Pixel) });
//this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"../../../Assets/Consumables/centrifugal.png", UriKind.Relative));
this.Children.Add(img);
Grid.SetColumn(_gridContent, 0);
Grid.SetColumnSpan(_gridContent, 2);
Grid.SetRow(_gridContent, 0);
img.Stretch = Stretch.Fill;
Panel.SetZIndex(_gridContent, 1);
}
#endregion
#region 画电泳槽
private void DrawElectrophoto()
{
double realHeight = LabwareRealWidth/1.5;//LabwareHeight;
double realWidth = LabwareRealLength/1.5;//LabwareWidth;
//this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(realHeight, GridUnitType.Pixel) });
//this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(LabwareDeep, GridUnitType.Pixel) });
RowDefinition rowDefinition = new RowDefinition();
rowDefinition.Height = new GridLength(realHeight); // 设置固定高度
this.RowDefinitions.Add(rowDefinition);
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(realWidth, GridUnitType.Pixel) });
//this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"../../../Assets/Consumables/电泳.png", UriKind.Relative));
img.Width = realWidth;
img.Height = realHeight;
this.Children.Add(img);
Grid.SetColumn(_gridContent, 0);
Grid.SetColumnSpan(_gridContent, 2);
Grid.SetRow(_gridContent, 0);
Grid.SetRowSpan(_gridContent, 2);
img.Stretch = Stretch.Fill;
rowDefinition.Height=new GridLength(realHeight); // 设置固定高度
_gridContent.Height= realHeight;
Panel.SetZIndex(_gridContent, 1);
}
#endregion
private void DrawContent()
{
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
this.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(LabwareDeep, GridUnitType.Pixel) });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(LabwareDeep, GridUnitType.Pixel) });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
Grid.SetColumn(_gridContent, 1);
Grid.SetRow(_gridContent, 0);
Panel.SetZIndex(_gridContent, 1);
DrawLeftSide();
DrawFront();
DrawTop();
}
#region 左侧面板
///
/// 左侧面板
///
private void DrawLeftSide()
{
if (LabwareType == (int)ConsumableTypeEnum.Tube)
{
leftSidePath = new Path()
{
Fill = new SolidColorBrush(LeftSideColor),
Stroke = new SolidColorBrush(BorderColor),
StrokeThickness = 1,
Opacity = 0.3
};
}
else
{
leftSidePath = new Path()
{
Fill = new SolidColorBrush(LeftSideColor),
Stroke = new SolidColorBrush(BorderColor),
StrokeThickness = 1
};
}
Point pt1 = new Point();
pt1.X = 0;
pt1.Y = LabwareDeep;
Point pt2 = new Point();
pt2.X = LabwareDeep;
pt2.Y = 0;
Point pt3 = new Point();
pt3.X = LabwareDeep;
pt3.Y = this.ActualHeight - LabwareDeep;// * nBaseHeight / nBaseWidth;
Point pt4 = new Point();
pt4.X = 0;
pt4.Y = this.ActualHeight;
string strData = string.Format("M{0},{1} L{2},{3} L{4},{5} L{6},{7}Z", pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
var converter = TypeDescriptor.GetConverter(typeof(Geometry));
leftSidePath.Data = (Geometry)(converter.ConvertFrom(strData));
this.Children.Add(leftSidePath);
Grid.SetColumn(leftSidePath, 0);
Grid.SetRow(leftSidePath, 0);
Grid.SetRowSpan(leftSidePath, 2);
}
#endregion
#region 前面板
///
/// 前面板
///
private void DrawFront()
{
if (LabwareType == (int)ConsumableTypeEnum.Tube)
{
frontPath = new Path()
{
Fill = new SolidColorBrush(FrontColor),
Stroke = new SolidColorBrush(BorderColor),
StrokeThickness = 1,
Opacity=0.3
};
}
else
{
frontPath = new Path()
{
Fill = new SolidColorBrush(FrontColor),
Stroke = new SolidColorBrush(BorderColor),
StrokeThickness = 1
};
}
Point pt1 = new Point();
pt1.X = 0;
pt1.Y = this.LabwareDeep;
Point pt2 = new Point();
pt2.X = LabwareDeep;
pt2.Y = 0;
Point pt3 = new Point();
pt3.X = this.ActualWidth;
pt3.Y = 0;
Point pt4 = new Point();
pt4.X = this.ActualWidth - LabwareDeep;
pt4.Y = LabwareDeep;
string strData = string.Format("M{0},{1} L{2},{3} L{4},{5} L{6},{7}Z", pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
var converter = TypeDescriptor.GetConverter(typeof(Geometry));
frontPath.Data = (Geometry)(converter.ConvertFrom(strData));
this.Children.Add(frontPath);
Grid.SetColumn(frontPath, 0);
Grid.SetRow(frontPath, 1);
Grid.SetColumnSpan(frontPath, 2);
}
#endregion
#region 顶面板
///
/// 顶面板
///
private void DrawTop()
{
if (LabwareType == (int)ConsumableTypeEnum.Tube)
{
topPath = new Path()
{
Fill = new SolidColorBrush(TopColor),
Stroke = new SolidColorBrush(BorderColor),
StrokeThickness = 1,
Opacity = 0.3
};
}
else
{
topPath = new Path()
{
Fill = new SolidColorBrush(TopColor),
Stroke = new SolidColorBrush(BorderColor),
StrokeThickness = 1
};
}
Point pt1 = new Point();
pt1.X = 0;
pt1.Y = 0;
Point pt2 = new Point();
pt2.X = this.ActualWidth - LabwareDeep - 0.5;
pt2.Y = 0;
Point pt3 = new Point();
pt3.X = pt2.X;
pt3.Y = this.ActualHeight - LabwareDeep;
Point pt4 = new Point();
pt4.X = 0;
pt4.Y = pt3.Y;
string strData = string.Format("M{0},{1} L{2},{3} L{4},{5} L{6},{7}Z", pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
var converter = TypeDescriptor.GetConverter(typeof(Geometry));
topPath.Data = (Geometry)(converter.ConvertFrom(strData));
this.Children.Add(topPath);
//topPath.Drop += ControlLabware_Drop;
Grid.SetColumn(topPath, 1);
Grid.SetRow(topPath, 0);
}
#endregion
#region 画板位
private void DrawContentForShelf()
{
Path path = new Path()
{
Stroke = Brushes.Gray,//FindResource("blueBrush") as SolidColorBrush,
StrokeThickness = 1,
Fill = Brushes.DarkGray//FindResource("lightBlueBrush") as SolidColorBrush,
};
string strData = GetPathData();
path.Data = Geometry.Parse(strData);
this.Children.Add(path);
}
#endregion
#region 画板位图数据Path
private string GetPathData()
{
string ret = "";
double W = LabwareRealLength;
double H = LabwareRealWidth;
ret = string.Format("M0,0 L{0},0 L{1},{2} L0,{3}Z", W, W, H, H);
return ret;
}
#endregion
private void ControlLabware_Drop(object sender, DragEventArgs e)
{
// If an element in the panel has already handled the drop,
// the panel should not also handle it.
if (e.Handled == false)
{
Panel _panel = (Panel)sender;
UIElement _element = (UIElement)e.Data.GetData("ControlLabware");
if (_panel != null && _element != null)
{
// Get the panel that the element currently belongs to,
// then remove it from that panel and add it the Children of
// the panel that its been dropped on.
Panel _parent = (Panel)VisualTreeHelper.GetParent(_element);
if (_parent != null)
{
if (e.KeyStates == DragDropKeyStates.ControlKey &&
e.AllowedEffects.HasFlag(DragDropEffects.Copy))
{
ControlLabware _circle = (ControlLabware)_element;
_circle.Margin = new Thickness(50, 0, 0, 0);
_panel.Children.Add(_circle);
// set the value to return to the DoDragDrop call
e.Effects = DragDropEffects.Copy;
}
else if (e.AllowedEffects.HasFlag(DragDropEffects.Move))
{
ControlLabware _circle = (ControlLabware)_element;
_parent.Children.Remove(_element);
_circle.Margin = new Thickness(50, 0, 0, 0);
_panel.Children.Add(_element);
// set the value to return to the DoDragDrop call
e.Effects = DragDropEffects.Move;
}
}
}
e.Handled = true;
}
}
#region 试剂槽
private void AddThrough()
{
if (Rows <= 0 || Columns <= 0)
return;
if (_gridContent.ActualWidth <= 0)
return;
for (int i = 0; i < Columns; i++)
_gridContent.ColumnDefinitions.Add(new ColumnDefinition());
for (int i = 0; i < Rows; i++)
_gridContent.RowDefinitions.Add(new RowDefinition());
//double well = 2;
//int count = Columns * Rows;
//if (count <= 96)
//{
// double w = (_gridContent.ActualWidth - 6) / Columns - 2;
// double h = (_gridContent.ActualHeight - 6) / Rows - 2;
// well = Math.Min(w, h);
// if (well < 2)
// well = 1;
//}
for (int i = 0; i < Columns; i++)
{
for (int j = 0; j < Rows; j++)
{
Rectangle rectangle = new Rectangle();
rectangle.Name = ChangePosToString(j, i);
rectangle.Margin = new Thickness(2);
rectangle.HorizontalAlignment = HorizontalAlignment.Stretch;
rectangle.VerticalAlignment = VerticalAlignment.Stretch;
if (IsFill)
{
rectangle.Fill = new SolidColorBrush(WellColor);
}
else
{
rectangle.Stroke = new SolidColorBrush(WellColor);
rectangle.StrokeThickness = 1;
}
_gridContent.Children.Add(rectangle);
Grid.SetColumn(rectangle, i);
Grid.SetRow(rectangle, j);
}
}
}
#endregion
private void AddWells()
{
if (Rows <= 0 || Columns <= 0)
return;
if (_gridContent.ActualWidth <= 0)
return;
for (int i = 0; i < Columns; i++)
_gridContent.ColumnDefinitions.Add(new ColumnDefinition());
for (int i = 0; i < Rows; i++)
_gridContent.RowDefinitions.Add(new RowDefinition());
double well = 1;
int count = Columns * Rows;
if (count <= 96)
{
double w = (_gridContent.ActualWidth - 6) / Columns - 2;
double h = (_gridContent.ActualHeight - 6) / Rows - 2;
well = Math.Min(w, h);
if (well < 1)
well = 1;
}
for (int i = 0; i < Columns; i++)
{
for (int j = 0; j < Rows; j++)
{
Ellipse ellipse = new Ellipse();
ellipse.Name = ChangePosToString(j, i);
ellipse.Width = well;
ellipse.Height = well;
ellipse.HorizontalAlignment = HorizontalAlignment.Center;
ellipse.VerticalAlignment = VerticalAlignment.Center;
if (IsFill)
{
ellipse.Fill = new SolidColorBrush(WellColor);
}
else
{
ellipse.Stroke = new SolidColorBrush(WellColor);
ellipse.StrokeThickness = 1;
}
_gridContent.Children.Add(ellipse);
Grid.SetColumn(ellipse, i);
Grid.SetRow(ellipse, j);
}
}
}
///
/// 增加管架孔圈
///
private void AddWellsCircle()
{
//根据labwareName 获取该耗材内部孔位数据
if (labwareWellInfoList != null)
{
//先计算出版面比例
double labwareFaceHeight = _gridContent.ActualHeight;
double labwareFaceWidth= _gridContent.ActualWidth;
double realHeight = LabwareRealWidth;//LabwareHeight;
double realWidth = LabwareRealLength;//LabwareWidth;
double widthScale = (double)labwareFaceWidth / realWidth;
double heightScale = (double)labwareFaceHeight / realHeight;
if (labwareWellInfoList.Count == 0)
{
AddWells();
}
else
{
foreach (LabwareWellInfo l in labwareWellInfoList)
{
Ellipse ellipse = new Ellipse();
ellipse.Name = l.labware_well_name;
double diameterVal = l.well_max_length * widthScale;
ellipse.Width = diameterVal;
ellipse.Height = diameterVal;
//ellipse.HorizontalAlignment = HorizontalAlignment.Center;
//ellipse.VerticalAlignment = VerticalAlignment.Center;
ellipse.Stroke = Brushes.Black;
ellipse.StrokeThickness = 1;
if (IsFill)
{
ellipse.Fill = new SolidColorBrush(WellColor);
}
else
{
ellipse.Stroke = new SolidColorBrush(WellColor);
ellipse.StrokeThickness = 1;
}
double labwareEllipsePixelx = l.labware_well_center_x * widthScale;
double labwareEllipsePixely = l.labware_well_center_y * heightScale;
ellipse.Tag = (labwareEllipsePixelx - diameterVal / (double)2).ToString() + "," + (labwareEllipsePixely - diameterVal / (double)2).ToString();
ellipse.Loaded += Ellipse_Loaded;
_gridContent.Children.Add(ellipse);
//ellipse.Margin = new Thickness(20,20, 0, 0);
//Grid.SetColumn(ellipse, i);
//Grid.SetRow(ellipse, j);
}
}
}
else
{
AddWells();
}
/*
if (Rows <= 0 || Columns <= 0)
return;
if (_gridContent.ActualWidth <= 0)
return;
for (int i = 0; i < Columns; i++)
_gridContent.ColumnDefinitions.Add(new ColumnDefinition());
for (int i = 0; i < Rows; i++)
_gridContent.RowDefinitions.Add(new RowDefinition());
double well = 1;
int count = Columns * Rows;
if (count <= 96)
{
double w = (_gridContent.ActualWidth - 1) / Columns - 1;
double h = (_gridContent.ActualHeight - 1) / Rows - 1;
well = Math.Min(w, h);
if (well < 1)
well = 1;
}
double wellIn = 1;
if (count <= 96)
{
double w = (_gridContent.ActualWidth - 6) / Columns - 4;
double h = (_gridContent.ActualHeight - 6) / Rows - 4;
wellIn = Math.Min(w, h);
if (wellIn < 1)
wellIn = 1;
}
for (int i = 0; i < Columns; i++)
{
for (int j = 0; j < Rows; j++)
{
Ellipse ellipse = new Ellipse();
ellipse.Name = ChangePosToString(j, i);
ellipse.Width = well;
ellipse.Height = well;
ellipse.HorizontalAlignment = HorizontalAlignment.Center;
ellipse.VerticalAlignment = VerticalAlignment.Center;
ellipse.Stroke = Brushes.Black;
ellipse.StrokeThickness = 0.3;
_gridContent.Children.Add(ellipse);
Grid.SetColumn(ellipse, i);
Grid.SetRow(ellipse, j);
ellipse = new Ellipse();
ellipse.Name = ChangePosToString(j, i);
ellipse.Width = wellIn;
ellipse.Height = wellIn;
ellipse.HorizontalAlignment = HorizontalAlignment.Center;
ellipse.VerticalAlignment = VerticalAlignment.Center;
if (IsFill)
{
ellipse.Fill = new SolidColorBrush(WellColor);
}
else
{
ellipse.Stroke = new SolidColorBrush(WellColor);
ellipse.StrokeThickness = 1;
}
_gridContent.Children.Add(ellipse);
Grid.SetColumn(ellipse, i);
Grid.SetRow(ellipse, j);
}
}*/
}
private void Ellipse_Loaded(object sender, RoutedEventArgs e)
{
Ellipse ellipse = sender as Ellipse;
ellipse.HorizontalAlignment = HorizontalAlignment.Left;
ellipse.VerticalAlignment = VerticalAlignment.Top;
string[] strPixels = Convert.ToString(ellipse.Tag).Split(',');
ellipse.Margin = new Thickness(Convert.ToDouble(strPixels[0]), Convert.ToDouble(strPixels[1]), 0, 0);
}
private string ChangePosToString(int row, int col)
{
string ret = "";
char ch = (char)('A' + row);
string strRow = ch.ToString();
ret = strRow + (col + 1).ToString();
return ret;
}
private void AddLabel()
{
tooltip.Content = new TextBlock()
{
Text = Label,
};
TextBlock tb = new TextBlock();
tb.Text = Label;
tb.Margin = new Thickness(2);
tb.Foreground = Brushes.White;
tb.TextWrapping = TextWrapping.Wrap;
tb.ToolTip = tooltip;
tooltipLabware.Content = new TextBlock()
{
Text = LabwareName,
};
this.ToolTip = tooltipLabware;
borderLabel = new Border()
{
Name = "borderLabel",
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Left,
Background = new SolidColorBrush(Color.FromArgb(180, 34, 106, 255)),
Width = this.ActualWidth,
Height = 20,
Child = tb,
};
if (string.IsNullOrEmpty(Label))
borderLabel.Visibility = Visibility.Collapsed;
else
borderLabel.Visibility = Visibility.Visible;
this.Children.Add(borderLabel);
Panel.SetZIndex(borderLabel, 5);
Grid.SetColumn(borderLabel, 0);
Grid.SetColumnSpan(borderLabel, 2);
Grid.SetRow(borderLabel, 0);
Grid.SetRowSpan(borderLabel, 2);
}
public void SetSelection()
{
if (IsTrash)
return;
Border bd = new Border()
{
Name = "borderSelection",
Background = new SolidColorBrush(Color.FromArgb(0x20, 0xFF, 0xFF, 0xFF)),
BorderThickness = new Thickness(2, 2, 2, 2),
CornerRadius = new CornerRadius(5),
BorderBrush = FindResource("blueBrush") as SolidColorBrush,
};
this.Children.Add(bd);
Grid.SetColumn(bd, 0);
Grid.SetRow(bd, 0);
Grid.SetRowSpan(bd, 2);
Grid.SetColumnSpan(bd, 2);
}
public void ClearSelection()
{
if (IsTrash)
return;
int count = this.Children.Count;
if (this.Children[count - 1] is Border)
{
Border bd = this.Children[count - 1] as Border;
if (bd.Name == "borderSelection")
this.Children.RemoveAt(count - 1);
}
}
public void SetLabel(string text)
{
if (IsTrash)
return;
if (borderLabel == null)
return;
TextBlock tb = Utilities.FindVisualChild(borderLabel);
if (tb != null)
{
tb.Text = text;
}
if (string.IsNullOrEmpty(text))
borderLabel.Visibility = Visibility.Collapsed;
else
{
borderLabel.Visibility = Visibility.Visible;
((ToolTip)(tb.ToolTip)).Content = new TextBlock()
{
Text = Label,
};
}
}
public void SetLabwareName(string text)
{
if (IsTrash)
return;
this.ToolTip = tooltipLabware;
}
private void DrawTrash()
{
TextBlock tb = new TextBlock();
tb.Text = Properties.Resources.strTrash;
//tb.Text = string.Format("垃{0}圾{0}桶", Environment.NewLine);
tb.FontSize = 18;
tb.Foreground = Brushes.Black;
tb.VerticalAlignment = VerticalAlignment.Center;
tb.HorizontalAlignment = HorizontalAlignment.Center;
Border border = new Border()
{
Name = "Trash",
Background = Brushes.DarkGray,
CornerRadius = new CornerRadius(5),
Child = tb,
};
Children.Add(border);
}
public void SetValidWells(string validWells)
{
if (LabwareType == (int)ConsumableTypeEnum.CircularDish)
return;
if (validWells == null)
return;
validWellList.Clear();
string[] ary = validWells.Split(',');
foreach (string w in ary)
{
if (string.IsNullOrEmpty(w))
break;
if (!validWellList.Contains(w))
validWellList.Add(w);
}
RefreshWells();
}
public void RefreshWells()
{
if (LabwareType == (int)ConsumableTypeEnum.CircularDish)
return;
// 试剂槽
if (LabwareType == (int)ConsumableTypeEnum.Through)
{
foreach (Rectangle rectangle in _gridContent.Children)
{
if (validWellList.Contains(rectangle.Name))
rectangle.Fill = ValidBrush;
else
rectangle.Fill = defaultBrush;
}
}
// 孔板
else
{
foreach (Ellipse ellipse in _gridContent.Children)
{
if (validWellList.Contains(ellipse.Name))
ellipse.Fill = ValidBrush;
else
ellipse.Fill = defaultBrush;
}
}
}
///
/// 更新孔颜色
///
/// 孔: A1,A2,A3,....
/// 颜色
public void UpdateWells(string wells, Color color)
{
if (LabwareType == (int)ConsumableTypeEnum.CircularDish)
return;
updateWells = wells;
if (string.IsNullOrEmpty(wells))
return;
string[] ary = wells.Split(',');
updateWellList.Clear();
foreach (string w in ary)
{
if (!updateWellList.Contains(w))
updateWellList.Add(w);
}
if (updateWellList.Count == 0)
return;
SolidColorBrush brush = new SolidColorBrush(color);
if (LabwareType == (int)ConsumableTypeEnum.Through)
{
foreach (Rectangle rectangle in _gridContent.Children)
{
if (updateWellList.Contains(rectangle.Name))
rectangle.Fill = brush;
}
}
else
{
foreach (Ellipse ellipse in _gridContent.Children)
{
if (updateWellList.Contains(ellipse.Name))
ellipse.Fill = brush;
}
}
}
public void SetTopColor(Color color)
{
if (LabwareType == (int)ConsumableTypeEnum.CircularDish)
{
if (dishRect == null)
return;
SolidColorBrush brush = new SolidColorBrush(color);
dishRect.Fill = brush;
}
else
{
if (topPath == null)
return;
SolidColorBrush brush = new SolidColorBrush(color);
topPath.Fill = brush;
}
}
public void SetSideColor(Color color)
{
if (leftSidePath == null)
return;
SolidColorBrush brush = new SolidColorBrush(color);
leftSidePath.Fill = brush;
}
public void SetFrontColor(Color color)
{
if (frontPath == null)
return;
SolidColorBrush brush = new SolidColorBrush(color);
frontPath.Fill = brush;
}
public void SetBorderColor(Color color)
{
SolidColorBrush brush = new SolidColorBrush(color);
if (frontPath != null)
frontPath.Stroke = brush;
if (leftSidePath != null)
leftSidePath.Stroke = brush;
if (topPath != null)
topPath.Stroke = brush;
}
#region 叠放耗材相关事件
bool isStartMove = false;
//protected override void OnMouseMove(MouseEventArgs e)
//{
// base.OnMouseMove(e);
// if (e.LeftButton == MouseButtonState.Pressed)
// {
// if(isStartMove)
// {
// return;
// }
// // Package the data.
// DataObject data = new DataObject();
// data.SetData("Object", this);
// // Initiate the drag-and-drop operation.
// DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move);
// isStartMove = true;
// }
//}
protected override void OnGiveFeedback(GiveFeedbackEventArgs e)
{
base.OnGiveFeedback(e);
// These Effects values are set in the drop target's
// DragOver event handler.
if (e.Effects.HasFlag(DragDropEffects.Copy))
{
Mouse.SetCursor(Cursors.Cross);
}
else if (e.Effects.HasFlag(DragDropEffects.Move))
{
Mouse.SetCursor(Cursors.Pen);
}
else
{
Mouse.SetCursor(Cursors.No);
}
e.Handled = true;
}
//protected override void OnDrop(DragEventArgs e)
//{
// base.OnDrop(e);
// // If the DataObject contains string data, extract it.
// if (e.Data.GetDataPresent("Object"))
// {
// ControlLabware srcControlLabware = (ControlLabware)e.Data.GetData("Object");//来源对象
// this.Children.Add(srcControlLabware);
// // If the string can be converted into a Brush,
// // convert it and apply it to the ellipse.
// //BrushConverter converter = new BrushConverter();
// //if (converter.IsValid(dataString))
// //{
// // Brush newFill = (Brush)converter.ConvertFromString(dataString);
// // circleUI.Fill = newFill;
// // // Set Effects to notify the drag source what effect
// // // the drag-and-drop operation had.
// // // (Copy if CTRL is pressed; otherwise, move.)
// // if (e.KeyStates.HasFlag(DragDropKeyStates.ControlKey))
// // {
// // e.Effects = DragDropEffects.Copy;
// // }
// // else
// // {
// // e.Effects = DragDropEffects.Move;
// // }
// //}
// }
// e.Handled = true;
//}
#endregion
}
}