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 );
|
}
|
}
|
|
|
}
|
|
|
|
|
|
}
|
}
|