tx
8 天以前 e0b138b3e057de6f57021e6c8963868f5c5acc5a
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
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command; 
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; 
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using TProduct.ProcessDrawing.Components; 
using TProduct.ProcessDrawing.Models;
 
namespace TProduct.ProcessDrawing.ViewModels
{
    /// <summary>
    /// 对应窗口的业务逻辑
    /// </summary>
    public class DisplayViewModel : ViewModelBase
    {
        public ObservableCollection<DeviceItem4Display> DeviceList { get; set; } = new ObservableCollection<DeviceItem4Display>();
 
 
 
        private DeviceItem4Config _currentDevice;
        public DeviceItem4Config CurrentDevice
        {
            get => _currentDevice;
            set => Set(ref _currentDevice, value);
        }
 
        private string _saveFailedMessage; 
        public string SaveFailedMessage
        {
            get { return _saveFailedMessage; }
            set { Set(ref _saveFailedMessage, value); }
        }
 
 
 
        public RelayCommand<DeviceItem4Config> DeviceSelectedCommand { get; set; }
 
        int _pipelineID = -1;
        public void SetCurrentPipelineID(int PipelineID)
        {
            this._pipelineID = PipelineID;
            if (DeviceList == null)
                return;
            foreach (var d in DeviceList)
            {
                if (d.IsHavePipeIndex(PipelineID))
                {
                    //(d.UiComponent).IsShowFlowAnimation = 1;
 
                 
                         d.UiComponent .SetRunStatus(true );
                     
                }
                else
                {
                    d.UiComponent.SetRunStatus(false );
                }
            }
        }
        public void SetContaiterSize(int width, int height)
        {
            double left_x = (from x in DeviceList select x.X).Min();
            double right_x = (from x in DeviceList select x.X).Max();
 
            double top_y = (from x in DeviceList select x.Y).Min();
            double bottom_y = (from x in DeviceList select x.Y).Max();
 
            double offset_y = 0;
            if ( bottom_y    > height)
            {
                offset_y = 5 - top_y;
            }
            foreach (var d in DeviceList)
            {
                d.Y = d.Y + offset_y; 
            }
        }
 
        public DisplayViewModel()
        {
            if (!IsInDesignMode)
            { 
                // 初始化组态组件
                InititialDevices();
 
 
                //
                DeviceSelectedCommand = new RelayCommand<DeviceItem4Config>(model2 =>
                {
                    // 记录一个当前选中组件
                    // Model = DeviceItemModel
                    // 对当前组件进行选中
                    // 进行属性、点位编辑
                    if (CurrentDevice != null)
                        CurrentDevice.IsSelected = false;
                    if (model2 != null)
                    {
                        model2.IsSelected = true; 
                    }
 
                    CurrentDevice = model2;
                });
 
 
            }
        }
 
        //初始化组态组件
        private void InititialDevices()
        {
            if(DeviceList == null)
            {
                DeviceList = new ObservableCollection<DeviceItem4Display>();
            }
       
 
            List<TProduct.ProcessDrawing.Models.DeviceItem4Display> all_DeviceItemModels = null; 
            if (!ProcessDrawingConfigFileHelper.ReadFile(out all_DeviceItemModels))
            {
                return;
            }
 
 
            foreach (var dim in all_DeviceItemModels)
            { 
                DeviceList.Add(dim);
            }
        }
 
        public void InitialRunStatus()
        { 
            if (DeviceList == null)
                return;
            foreach (var d in DeviceList)
            {
                if (d.IsHavePipeIndex(_pipelineID))
                {
                   // d.UiComponent.StartAnimation();
 
                    d.UiComponent.SetRunStatus(true );
                }
                else
                {
 
                    d.UiComponent.SetRunStatus(false );
                }
            }
 
 
        }
 
 
 
 
 
    }
}