alielie
2025-03-03 1fca2167068e9ef2c079ec742f20313fc6697ab1
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using HMI.Base;
using log4net;
using WPFProject.Controls;
using WPFProject.Models;
using WPFProject.Utils;
 
namespace WPFProject.UI
{
    /// <summary>
    /// WorkControl.xaml 的交互逻辑
    /// </summary>
    public partial class WorkControl : PluginControl
    {
        private ILog log;
        public WorkControl()
        {
            InitializeComponent();
            Loaded += UserControl_Loaded;
        }
 
        private List<CanvasPosition> InitGridSize()
        {
            List<CanvasPosition> result = new List<CanvasPosition>();
            result.Add(new CanvasPosition
            {
                Left = 0,
                Top = 0,
                Width = 0.1 * ActualWidth - 2,
                Height = 0.5 * ActualHeight - 2
            });
            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;
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //List<CanvasPosition> pos = InitGridSize();
            //ProgramList programList = new ProgramList();
            //InnerWindow p = new InnerWindow(pos[0])
            //{
            //    Title = "程序列表",
            //    Content = programList
            //};
            //HandleInnerWindow(p);
 
            //InnerWindow p1 = new InnerWindow(pos[1])
            //{
            //    Title = "图片",
            //};
            //HandleInnerWindow(p1);
 
            //SequnceList sequnceList = new SequnceList();
            //programList.ProgramChanged += sequnceList.Selected_Program_Changed;
 
            //InnerWindow p2 = new InnerWindow(pos[2])
            //{
            //    Title = "序列",
            //    Content = sequnceList
            //};
            //HandleInnerWindow(p2);
 
            //FunctionSetting functionSetting = new FunctionSetting();
            //InnerWindow p3 = new InnerWindow(pos[3])
            //{
            //    Title = "函数",
            //    Content = functionSetting
            //};
            //HandleInnerWindow(p3);
 
            //StepSetting stepSetting = new StepSetting();
            //InnerWindow p4 = new InnerWindow(pos[4])
            //{
            //    Title = "单步设置",
            //    Content = stepSetting
            //};
            //HandleInnerWindow(p4);
 
 
            //SizeChanged += WorkControl_SizeChanged;
            Loaded -= UserControl_Loaded;
 
        }
 
        public int CanvasChildrenCount { get; private set; } = 0;
 
        #region InnerWindow操作逻辑
        /// <summary>
        /// 设置InnerWindow
        /// </summary>
        /// <param name="inner"></param>
        private void HandleInnerWindow(InnerWindow inner)
        {
            inner.MinEvent += InnerWindowMin;
            inner.MaxEvent += InnerWindowMax;
            inner.ZIndexEvent += Inner_ZIndexEvent;
            inner.GotFocus += Inner_GotFocus;
            inner.AttachToCanvas(WorkArea);
            inner.Zindex = CanvasChildrenCount++;
        }
 
        /// <summary>
        /// InnerWindow焦点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Inner_GotFocus(object sender, RoutedEventArgs e)
        {
            CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
        }
 
        /// <summary>
        /// InnerWindow ZIndex切换事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Inner_ZIndexEvent(object sender, EventArgs e)
        {
            CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
        }
 
        /// <summary>
        /// InnerWindow最小化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InnerWindowMin(object sender, System.EventArgs e)
        {
            InnerWindow inner = sender as InnerWindow;
            inner.Visibility = Visibility.Collapsed;
            HandleMinInnerWindow(inner);
        }
 
        /// <summary>
        /// InnerWindow最大化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InnerWindowMax(object sender, System.EventArgs e)
        {
            InnerWindow inner = sender as InnerWindow;
            if (inner.WindowState == WindowState.Maximized)
            {
                Canvas.SetLeft(inner, inner.canvasPosition.Left);
                Canvas.SetTop(inner, inner.canvasPosition.Top);
 
                inner.Width = inner.canvasPosition.Width;
                inner.Height = inner.canvasPosition.Height;
                inner.WindowState = WindowState.Normal;
            }
            else
            {
                Canvas.SetLeft(inner, 0);
                Canvas.SetTop(inner, 0);
                inner.Width = WorkArea.ActualWidth;
                inner.Height = WorkArea.ActualHeight;
                inner.WindowState = WindowState.Maximized;
            }
        }
 
        /// <summary>
        /// 重设大小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WorkControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            //Size newSize = e.NewSize;
            //Size previousSize = e.PreviousSize;
 
            //double xRate = newSize.Width / previousSize.Width;
            //double yRate = newSize.Height / previousSize.Height;
            //for (int i = 0; i < VisualTreeHelper.GetChildrenCount(WorkArea); i++)
            //{
            //    UIElement child = VisualTreeHelper.GetChild(WorkArea, i) as UIElement;
            //    Canvas.SetLeft(child, Canvas.GetLeft(child) * xRate);
            //    Canvas.SetTop(child, Canvas.GetTop(child) * yRate);
            //}
 
            //for (int i = 0; i < VisualTreeHelper.GetChildrenCount(WorkArea); i++)
            //{
            //    UIElement child = VisualTreeHelper.GetChild(WorkArea, i) as UIElement;
            //    if (Canvas.GetLeft(child) >= newSize.Width)
            //    {
            //        Canvas.SetLeft(child, Canvas.GetLeft(child) + newSize.Width - previousSize.Width);
            //    }
            //    if (Canvas.GetTop(child) >= newSize.Height)
            //    {
            //        Canvas.SetTop(child, Canvas.GetTop(child) + newSize.Height - previousSize.Height);
            //    }
            //}
        }
        #endregion
 
        #region 底部MinInnerWindow相关
        /// <summary>
        /// 底部MinInnerWindow处理
        /// </summary>
        /// <param name="inner"></param>
        private void HandleMinInnerWindow(InnerWindow inner)
        {
            MinInnerWindow min = new MinInnerWindow(inner);
            min.MaxEvent += MinInnerWindowMax;
            min.CloseEvent += MinInnerWindowClose;
            BottomBar.AddMinWindow(min);
        }
 
        /// <summary>
        /// 底部MinInnerWindow展开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MinInnerWindowMax(object sender, System.EventArgs e)
        {
            MinInnerWindow min = sender as MinInnerWindow;
            min.Inner.Visibility = Visibility.Visible;
            CanvasHelper.SetTopZIndex(min.Inner, WorkArea, typeof(InnerWindow));
            BottomBar.RemoveMinWindow(min);
        }
 
        /// <summary>
        /// 底部MinInnerWin关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MinInnerWindowClose(object sender, System.EventArgs e)
        {
            MinInnerWindow min = sender as MinInnerWindow;
            BottomBar.RemoveMinWindow(min);
        }
        #endregion
 
        public void OnTabChange(object sender, SelectionChangedEventArgs args)
        {
            if (args.AddedItems.Count > 0)
            {
                IconTabItem newTab = args.AddedItems[0] as IconTabItem;
                if (newTab != null && newTab.Content == this)
                {
 
                }
            }
 
            if (args.RemovedItems.Count > 0)
            {
                IconTabItem oldTab = args.RemovedItems[0] as IconTabItem;
                if (oldTab != null && oldTab.Content == this)
                {
 
                }
            }
        }
 
        public object Active()
        {
            return null;
        }
 
        public object DeActive()
        {
            return null;
        }
 
        public void OnTabChange(object sender, object args)
        {
 
        }
 
        public object Init()
        {
            return null;
        }
 
        public void SetLogger(ILog logger)
        {
            log = logger;
        }
    }
}