schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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;
        }
 
    }
}