alielie
2025-08-25 c4a3f8db90530a727ffab77c3bb5bb7d782792bf
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using CommunityToolkit.Mvvm.ComponentModel;
using HMI.Base;
using HMI.UI.DpUtil;
using HMI.UI.MDI;
using System.ComponentModel;
using System.IO;
using System.Windows;
 
namespace Plugin.DODriverControl
{
    /// <summary>
    /// DOControl.xaml 的交互逻辑
    /// </summary>
    [ObservableObject]
    public partial class DOControl : SimpleMaskControl
    {
        public DOControl()
        {
            this.DataContext = this;
            InitializeComponent();
        }
 
        [ObservableProperty]
        private string workspaceSetting;
 
        public override void InitFinish()
        {
            WorkspaceSetting = Path.Combine(BaseFolder, "Workspace.xml");
            base.InitFinish();
        }
 
        private List<SingleControl> controls = new List<SingleControl>();
 
        private List<CanvasPosition> InitGridSize()
        {
            List<CanvasPosition> result = new List<CanvasPosition>();
            result.Add(new CanvasPosition
            {
                Left = 0,
                Top = 0,
                Width = 0.1 * ActualWidth,
                Height = 0.5 * ActualHeight
            });
            result.Add(new CanvasPosition
            {
                Left = 0.1 * ActualWidth + 2,
                Top = 0,
                Width = 0.5 * ActualWidth - 4,
                Height = ActualHeight,
            });
 
            result.Add(new CanvasPosition
            {
                Left = 0.6 * ActualWidth + 2,
                Top = 0,
                Width = 0.4 * ActualWidth - 2,
                Height = 0.5 * ActualHeight - 2
            });
 
            result.Add(new CanvasPosition
            {
                Left = 0,
                Top = 0.5 * ActualHeight + 2,
                Width = 0.1 * ActualWidth - 2,
                Height = 0.5 * ActualHeight - 2
            });
 
            result.Add(new CanvasPosition
            {
                Left = 0.6 * ActualWidth + 2,
                Top = 0.5 * ActualHeight + 2,
                Width = 0.4 * ActualWidth - 2,
                Height = 0.5 * ActualHeight - 2
            });
 
            return result;
        }
 
        public override void Active()
        {
            foreach (var control in controls)
            {
                control.Active();
            }
            base.Active();
        }
 
        public override void DeActive()
        {
            foreach (var control in controls)
            {
                control.DeActive();
            }
            base.DeActive();
        }
 
        public override void OnClose(object sender, CancelEventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                foreach (var control in controls)
                {
                    control.Close();
                }
            });
            base.DoClose(sender, e);
        }
 
        private void LoadSingleControl()
        {
            var ps = InitGridSize();
            var control = new SingleControl("DIO", BaseFolder)
            {
                log = log
            };
            controls.Add(control);
            workspace.AddInnerWindow(control.name, new InnerWindow()
            {
                Title = control.name,
                Content = control
            });
 
            //var control2 = new SingleControl("DIO2", BaseFolder)
            //{
            //    log = log
            //};
            //controls.Add(control2);
            //workspace.AddInnerWindow(control2.name, new InnerWindow()
            //{
            //    Title = control2.name,
            //    Content = control2
            //});
        }
 
        private void PluginMaskControl_Loaded(object sender, RoutedEventArgs e)
        {
            LoadSingleControl();
            Loaded -= PluginMaskControl_Loaded;
        }
    }
}