using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Reflection;
|
using System.Runtime.InteropServices.ComTypes;
|
using System.Security.Cryptography;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Media;
|
using System.Windows.Shapes;
|
|
namespace XHandler.Controls
|
{
|
public class GapLabware : Grid
|
{
|
public const int WN = 1;
|
public const int WS = 2;
|
public const int EN = 4;
|
public const int ES = 8;
|
|
private int nBaseWidth = 16;
|
private int nBaseHeight = 9;
|
/// <summary>
|
/// 耗材的长, 长宽比=3:2, 根据width可以算出height
|
/// </summary>
|
public double GapWidth
|
{
|
get { return (double)GetValue(GapWidthProperty); }
|
set { SetValue(GapWidthProperty, value); }
|
}
|
public static readonly DependencyProperty GapWidthProperty =
|
DependencyProperty.Register("GapWidth", typeof(double), typeof(GapLabware), new PropertyMetadata(Double.NaN));
|
|
/// <summary>
|
/// 缺角方向
|
/// </summary>
|
public int LabwareGap
|
{
|
get { return (int)GetValue(LabwareGapProperty); }
|
set { SetValue(LabwareGapProperty, value); }
|
}
|
public static readonly DependencyProperty LabwareGapProperty =
|
DependencyProperty.Register("LabwareGap", typeof(int), typeof(GapLabware), new PropertyMetadata(0));
|
|
|
|
public GapLabware()
|
{
|
this.SnapsToDevicePixels = true;
|
InitializeComponent();
|
}
|
|
void InitializeComponent()
|
{
|
this.SizeChanged += ControlLabware_SizeChanged;
|
}
|
|
private void ControlLabware_SizeChanged(object sender, SizeChangedEventArgs e)
|
{
|
if (this.ActualWidth == double.NaN || this.ActualWidth <= 0)
|
return;
|
|
this.Children.Clear();
|
|
DrawContent();
|
}
|
|
private void DrawContent()
|
{
|
|
Path path = new Path()
|
{
|
Stroke = FindResource("blueBrush") as SolidColorBrush,
|
StrokeThickness = 1,
|
Fill = FindResource("lightBlueBrush") as SolidColorBrush,
|
};
|
string strData = GetPathData(LabwareGap);
|
|
path.Data = Geometry.Parse(strData);
|
this.Children.Add(path);
|
}
|
|
private string GetPathData(int gap)
|
{
|
string ret = "";
|
double W = this.ActualWidth - 0.5;
|
double H = W * nBaseHeight / nBaseWidth;
|
|
if (gap == 0)
|
{
|
ret = string.Format("M0,0 L{0},0 L{1},{2} L0,{3}Z", W, W, H, H);
|
}
|
else
|
{
|
if ((gap & WN) == WN)
|
ret = string.Format("M{0},0 L{1},0 L0,{2} L0,{3} ", W/2, GapWidth, GapWidth, H/2);
|
else
|
ret = string.Format("M{0},0 L0,0 L0,{1} ", W/2, H/2);
|
|
if ((gap & WS) == WS)
|
ret += string.Format("L0,{0} L0,{1} L{2},{3} L{4},{5} ", H / 2, H - GapWidth, GapWidth, H, W/2, H);
|
else
|
ret += string.Format("L0,{0} L0,{1} L{2},{3} ", H / 2, H, W/2, H);
|
|
if ((gap & ES) == ES)
|
ret += string.Format("L{0},{1} L{2},{3} L{4},{5} L{6},{7} ", W/2,H,W-GapWidth,H,W,H-GapWidth,W, H/2);
|
else
|
ret += string.Format("L{0},{1} L{2},{3} L{4},{5} ", W/2,H,W,H,W,H/2);
|
|
if ((gap & EN) == EN)
|
ret += string.Format("L{0},{1} L{2},{3} L{4},0 L{5},0 Z", W,H/2,W,GapWidth,W-GapWidth,W/2);
|
else
|
ret += string.Format("L{0},{1} L{2},0 L{3},0 Z", W,H/2,W, W/2);
|
}
|
return ret;
|
}
|
|
}
|
}
|