From 017e40331e306f78f73d3de41847235f0ffcc8a2 Mon Sep 17 00:00:00 2001 From: fyf Date: Thu, 22 Sep 2022 16:04:50 +0800 Subject: [PATCH] 1 --- BeDesignerSCADA/Controls/MainCanvasPanel.xaml | 11 +- .../Controls/MainCanvasPanel.xaml.cs | 43 +- BeDesignerSCADA/MainTest.xaml | 13 - BeDesignerSCADA/MainTest.xaml.cs | 30 -- BeDesignerSCADA/MainWindow.xaml | 370 +----------------- BeDesignerSCADA/MainWindow.xaml.cs | 346 +--------------- 6 files changed, 46 insertions(+), 767 deletions(-) delete mode 100644 BeDesignerSCADA/MainTest.xaml delete mode 100644 BeDesignerSCADA/MainTest.xaml.cs diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml index 337a6529..d0906691 100644 --- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml +++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml @@ -119,12 +119,19 @@ - + + diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs index 9cb8c72c..be3aac10 100644 --- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs +++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml.cs @@ -50,16 +50,6 @@ namespace BeDesignerSCADA.Controls //读取文件 FileRead(_Path); } - //public MainCanvasPanel() - //{ - // InitializeComponent(); - // this.DataContext = viewModel; - // viewModel.Loaded(cav, runCanvas); - // //控件加载 - // Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly(); - // var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name); - // CtlList.ItemsSource = controls; - //} #region 位置调整 /// /// 左对齐 @@ -128,6 +118,21 @@ namespace BeDesignerSCADA.Controls #region 其他事件操作 /// + /// 传入变量管理器地址 + /// + /// + private void LoadBtnValue_Click(object sender, RoutedEventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "变量管理器文件|*.json"; + if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + viewModel.VariablePath = ofd.FileName; + bool isSucess= DataBusModel.GetInstance().RefreshVariableManager(ofd.FileName); + System.Windows.MessageBox.Show(isSucess ? "加载成功!" : "加载失败!"); + } + } + /// /// 运行 /// /// @@ -224,8 +229,22 @@ namespace BeDesignerSCADA.Controls /// private void SaveBtn_Click(object sender, RoutedEventArgs e) { - string str = cav.Save(); - File.WriteAllText(Path, str, Encoding.Unicode); + if (File.Exists(Path)) + { + string str = cav.Save(); + File.WriteAllText(Path, str, Encoding.Unicode); + } + else + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "布局文件|*.lay"; + + if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + string str = cav.Save(); + File.WriteAllText(sfd.FileName, str, Encoding.Unicode); + } + } } /// /// 模拟消息发送 diff --git a/BeDesignerSCADA/MainTest.xaml b/BeDesignerSCADA/MainTest.xaml deleted file mode 100644 index aabf5c5c..00000000 --- a/BeDesignerSCADA/MainTest.xaml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/BeDesignerSCADA/MainTest.xaml.cs b/BeDesignerSCADA/MainTest.xaml.cs deleted file mode 100644 index 5536bed8..00000000 --- a/BeDesignerSCADA/MainTest.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using BeDesignerSCADA.Controls; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace BeDesignerSCADA -{ - /// - /// MainTest.xaml 的交互逻辑 - /// - public partial class MainTest : Window - { - public MainTest() - { - InitializeComponent(); - MainCanvasPanel mainCanvas=new MainCanvasPanel(@"D:\fengyoufu\代码\Code\C#项目\新上位机代码\BPASmartClient.MinimalistUI\bin\Debug\net6.0-windows\LayoutFile\物料仓管理.lay"); - main.Children.Add(mainCanvas); - } - } -} diff --git a/BeDesignerSCADA/MainWindow.xaml b/BeDesignerSCADA/MainWindow.xaml index d80c9c2c..4b7cd71b 100644 --- a/BeDesignerSCADA/MainWindow.xaml +++ b/BeDesignerSCADA/MainWindow.xaml @@ -22,373 +22,7 @@ - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 绑定: - - - - - - - - - - - - - - - - - + diff --git a/BeDesignerSCADA/MainWindow.xaml.cs b/BeDesignerSCADA/MainWindow.xaml.cs index 8cd32c35..2bfaceb7 100644 --- a/BeDesignerSCADA/MainWindow.xaml.cs +++ b/BeDesignerSCADA/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using BeDesignerSCADA.ViewModel; +using BeDesignerSCADA.Controls; +using BeDesignerSCADA.ViewModel; using BPASmart.Model; using BPASmartClient.Compiler; using BPASmartClient.DATABUS; @@ -33,350 +34,11 @@ namespace BeDesignerSCADA /// public partial class MainWindow : Window { - - MainViewModelNew viewModel =new MainViewModelNew(); + MainCanvasPanel mainCanvas = new MainCanvasPanel(""); public MainWindow() { InitializeComponent(); - this.DataContext = viewModel; - viewModel.Loaded(cav, runCanvas); - Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly(); - var controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o=>o.Name); - CtlList.ItemsSource = controls; - } - - #region 位置调整 - /// - /// 左对齐 - /// - /// - /// - private void AglinLeftBtn_Click(object sender, RoutedEventArgs e) - { - cav.AlignLeft(); - } - /// - /// 底部对齐 - /// - /// - /// - private void AglinBottomBtn_Click(object sender, RoutedEventArgs e) - { - cav.AlignBottom(); - } - /// - /// 顶部对齐 - /// - /// - /// - private void AglinTopBtn_Click(object sender, RoutedEventArgs e) - { - cav.AlignTop(); - } - /// - /// 右对齐 - /// - /// - /// - private void AglinRightBtn_Click(object sender, RoutedEventArgs e) - { - cav.AlignRight(); - } - /// - /// 居中 - /// - /// - /// - private void AglinCenterBtn_Click(object sender, RoutedEventArgs e) - { - cav.AlignCenter(); - } - /// - /// 垂直分布 - /// - /// - /// - private void VerticalLayoutBtn_Click(object sender, RoutedEventArgs e) - { - cav.VertialLayout(); - } - /// - /// 水平分布 - /// - /// - /// - private void HorizontalLayoutBtn_Click(object sender, RoutedEventArgs e) - { - cav.HorizontalLayout(); - } - #endregion - - #region 其他事件操作 - /// - /// 传入变量管理器地址 - /// - /// - public void VariableManagerPath(string path) - { - try - { - viewModel.VariablePath = path; - DataBusModel.GetInstance().RefreshVariableManager(path); - } - catch (Exception ex) - { - - } - } - private void LoadBtnValue_Click(object sender, RoutedEventArgs e) - { - OpenFileDialog ofd = new OpenFileDialog(); - ofd.Filter = "变量管理器文件|*.json"; - if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) - { - viewModel.VariablePath = ofd.FileName; - bool isSucess= DataBusModel.GetInstance().RefreshVariableManager(ofd.FileName); - System.Windows.MessageBox.Show(isSucess ? "加载成功!" : "加载失败!"); - } - } - /// - /// 运行 - /// - /// - /// - private void RunBtn_Click(object sender, RoutedEventArgs e) - { - if (sender is System.Windows.Controls.Button btn) - { - if (btn.Tag.ToString() == "运行") - { - cav.ClearSelection(); - runCanvas.Run(cav.Generator()); - } - else if (btn.Tag.ToString() == "停止") - { - runCanvas.Destory(); - } - } - } - /// - /// 加载 - /// - /// - /// - private void LoadBtn_Click(object sender, RoutedEventArgs e) - { - OpenFileDialog ofd = new OpenFileDialog(); - ofd.Filter = "布局文件|*.lay"; - if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) - { - cav.Load(ofd.FileName); - } - - DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250))); - da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; - CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da); - - DoubleAnimation daop = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(250))); - daop.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }; - cav.BeginAnimation(OpacityProperty, daop); - } - /// - /// 保存 - /// - /// - /// - private void SaveBtn_Click(object sender, RoutedEventArgs e) - { - SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "布局文件|*.lay"; - - if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) - { - string str = cav.Save(); - File.WriteAllText(sfd.FileName, str, Encoding.Unicode); - } + grid.Child = mainCanvas; } - /// - /// 模拟消息发送 - /// - /// - /// - private void MNBtn_Click(object sender, RoutedEventArgs e) - { - - } - #endregion - - #region 左侧控件栏移动 - /// - /// 移动到右侧 - /// - /// - /// - private void CtlList_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) - { - if (CtlList.SelectedItem != null && e.LeftButton == MouseButtonState.Pressed) - { - DragDrop.DoDragDrop(CtlList, CtlList.SelectedItem, System.Windows.DragDropEffects.Copy); - codeEditor.Text = cav.Save(); - } - } - /// - /// 显示代码 - /// - /// - /// - private void showCode_Click(object sender, RoutedEventArgs e) - { - codeEditor.Text = cav.Save(); - } - /// - /// 编辑 - /// - /// - /// - private void ToggleButton_Click(object sender, RoutedEventArgs e) - { - try - { - if (sender is ToggleButton) - { - ToggleButton toggle = (ToggleButton)sender; - Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem; - if (propertyGridCommand != null) - { - viewModel.Edit(propertyGridCommand); - } - } - } - catch (Exception ex) - { - - } - } - /// - /// 路径资源选择 - /// - /// - /// - private void LJToggleButton_Click(object sender, RoutedEventArgs e) - { - try - { - if (sender is ToggleButton) - { - ToggleButton toggle = (ToggleButton)sender; - Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem; - if (propertyGridCommand != null) - { - viewModel.SelectPath(propertyGridCommand); - } - } - } - catch (Exception ex) - { - - } - } - /// - /// 变量选择 - /// - /// - /// - private void ComboBoxValue_TextChanged(object sender,TextChangedEventArgs e) - { - try - { - if (sender is System.Windows.Controls.ComboBox) - { - System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender; - Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem; - if (toggle.Tag != null && !string.IsNullOrEmpty(toggle.Text)) - propertyGridCommand.Value = "{" + $"Binding {toggle.Tag}.{toggle.Text}" + "}"; - } - } - catch (Exception ex) - { - - } - } - /// - /// 变量下拉框打开事件 - /// - /// - /// - private void valuebox_DropDownOpened(object sender,EventArgs e) - { - try - { - viewModel.DevValueList = new System.Collections.ObjectModel.ObservableCollection(); - if (sender is System.Windows.Controls.ComboBox) - { - System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender; - if (toggle.Tag == null) return; - - CommunicationPar communication = null; - if (DataBusModel.GetInstance().KeyValues.ContainsKey(viewModel.VariablePath)) - { - communication = DataBusModel.GetInstance().KeyValues[viewModel.VariablePath]; - } - CommunicationModel mode = communication?.CommunicationDevices?.ToList().Find(par => par.DeviceName == toggle.Tag.ToString()); - if (mode != null) - { - mode?.VarTableModels?.ToList().ForEach(par => { viewModel.DevValueList.Add(par.VarName); }); - } - } - } - catch (Exception ex) - { - - } - - } - /// - /// 设备名称选择 - /// - /// - /// - private void ComboBoxName_TextChanged(object sender,TextChangedEventArgs e) - { - try - { - if (sender is System.Windows.Controls.ComboBox) - { - System.Windows.Controls.ComboBox toggle = (System.Windows.Controls.ComboBox)sender; - Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem; - if(toggle.Tag!=null && !string.IsNullOrEmpty(toggle.Text)) - propertyGridCommand.Value = "{" + $"Binding {toggle.Text}.{toggle.Tag}" + "}"; - else if(!string.IsNullOrEmpty(toggle.Text)) - propertyGridCommand.Value = "{" + $"Binding {toggle.Text}." + "}"; - - } - } - catch (Exception ex) - { - - } - } - /// - /// 设备名称下拉框打开事件 - /// - /// - /// - private void namebox_DropDownOpened(object sender,EventArgs e) - { - viewModel.DevNameList = new System.Collections.ObjectModel.ObservableCollection(); - CommunicationPar communication = null; - if (DataBusModel.GetInstance().KeyValues.ContainsKey(viewModel.VariablePath)) - { - communication = DataBusModel.GetInstance().KeyValues[viewModel.VariablePath]; - } - communication?.CommunicationDevices?.ToList().ForEach(x => { viewModel.DevNameList.Add(x.DeviceName); }); - } - - #endregion - - } }