@@ -102,10 +102,6 @@ | |||
<Resource Include="Images\光柱.png" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Folder Include="Helper\" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPASmart.Model\BPASmart.Model.csproj" /> | |||
<ProjectReference Include="..\BPASmartClient.SCADAControl\BPASmartClient.SCADAControl.csproj" /> | |||
@@ -123,4 +119,8 @@ | |||
</Reference> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Folder Include="Helper\" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,162 @@ | |||
using BPASmartClient.Compiler; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BeDesignerSCADA.Common | |||
{ | |||
/// <summary> | |||
/// 页面菜单属性 | |||
/// </summary> | |||
public class MenuModel : ObservableObject | |||
{ | |||
/// <summary> | |||
/// 是否显示菜单 | |||
/// </summary> | |||
private bool _IsVisibility; | |||
public bool IsVisibility | |||
{ | |||
get | |||
{ | |||
return _IsVisibility; | |||
} | |||
set | |||
{ | |||
_IsVisibility = value; | |||
OnPropertyChanged("IsVisibility"); | |||
} | |||
} | |||
/// <summary> | |||
/// 程序集名称 | |||
/// </summary> | |||
private string _Name; | |||
public string Name | |||
{ | |||
get | |||
{ | |||
return _Name; | |||
} | |||
set | |||
{ | |||
_Name = value; | |||
OnPropertyChanged("Name"); | |||
} | |||
} | |||
/// <summary> | |||
/// 菜单显示方向 | |||
/// </summary> | |||
private MenuAlignment _Alignment; | |||
public MenuAlignment Alignment | |||
{ | |||
get | |||
{ | |||
return _Alignment; | |||
} | |||
set | |||
{ | |||
_Alignment = value; | |||
OnPropertyChanged("Alignment"); | |||
} | |||
} | |||
/// <summary> | |||
/// 页面控件集合 | |||
/// </summary> | |||
public Dictionary<string, PageBase> PageChildren = new Dictionary<string, PageBase>(); | |||
} | |||
/// <summary> | |||
/// 菜单选择枚举 | |||
/// </summary> | |||
public enum MenuAlignment | |||
{ | |||
左边, | |||
顶部, | |||
右边, | |||
底部, | |||
} | |||
/// <summary> | |||
/// 页面Model | |||
/// </summary> | |||
public class PageModel : PageBase | |||
{ | |||
/// <summary> | |||
/// 页面控件集合 | |||
/// </summary> | |||
public CanvasPanel visual { get; set; } | |||
} | |||
/// <summary> | |||
/// 页面 | |||
/// </summary> | |||
public class PageBase : ObservableObject | |||
{ | |||
/// <summary> | |||
/// 是否首页 | |||
/// </summary> | |||
private bool _IsHome; | |||
public bool IsHome | |||
{ | |||
get | |||
{ | |||
return _IsHome; | |||
} | |||
set | |||
{ | |||
_IsHome = value; | |||
OnPropertyChanged("IsHome"); | |||
} | |||
} | |||
/// <summary> | |||
/// 排序 | |||
/// </summary> | |||
public int Sort { get; set; } | |||
/// <summary> | |||
/// 页面名称 | |||
/// </summary> | |||
private string _Name; | |||
public string Name | |||
{ | |||
get | |||
{ | |||
return _Name; | |||
} | |||
set | |||
{ | |||
_Name = value; | |||
OnPropertyChanged("Name"); | |||
} | |||
} | |||
/// <summary> | |||
/// 菜单名称 | |||
/// </summary> | |||
private string _MenuName; | |||
public string MenuName | |||
{ | |||
get | |||
{ | |||
return _MenuName; | |||
} | |||
set | |||
{ | |||
_MenuName = value; | |||
OnPropertyChanged("MenuName"); | |||
} | |||
} | |||
/// <summary> | |||
/// 页面ID | |||
/// </summary> | |||
public string Id { get; set; } | |||
/// <summary> | |||
/// 页面子控件集合 | |||
/// </summary> | |||
public List<string> ChildrenStr { get; set; } | |||
public PageBase() | |||
{ | |||
ChildrenStr = new List<string>(); | |||
Id = Guid.NewGuid().ToString(); | |||
} | |||
} | |||
} |
@@ -17,7 +17,6 @@ | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary Source="/BeDesignerSCADA;component/Themes/Styles.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.SCADAControl;component/Themes/Generic.xaml" /> | |||
</ResourceDictionary.MergedDictionaries> | |||
<!--#region Menu--> | |||
<SolidColorBrush x:Key="Menu.Static.Background" Color="#FFF0F0F0" /> | |||
@@ -157,7 +156,7 @@ | |||
Foreground="{TemplateBinding Foreground}" | |||
IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" | |||
Style="{StaticResource ExpanderDownHeaderStyle}" /> | |||
<ContentPresenter | |||
<ContentPresenter | |||
x:Name="ExpandSite" | |||
Margin="{TemplateBinding Padding}" | |||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" | |||
@@ -185,67 +184,81 @@ | |||
</UserControl.Resources> | |||
<Grid x:Name="grid"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="250"/> | |||
<ColumnDefinition Width="245"/> | |||
<ColumnDefinition/> | |||
<ColumnDefinition Width="320"/> | |||
</Grid.ColumnDefinitions> | |||
<!--左侧选择区域--> | |||
<Border x:Name="bordermain" BorderThickness="1" BorderBrush="{StaticResource AccentBrush}" Background="Transparent" Margin="4"> | |||
<Grid> | |||
<Grid.RowDefinitions > | |||
<RowDefinition Height="{Binding Height, ElementName=wapanl}"/> | |||
<RowDefinition Height="{Binding Height, ElementName=PageList}" MaxHeight="500"/> | |||
<RowDefinition Height="*"/> | |||
</Grid.RowDefinitions> | |||
<Expander Style="{DynamicResource expang_1}" x:Name="wapanl" Header="菜单布局" Grid.Row="0" IsExpanded="False"> | |||
<WrapPanel Margin="10,0,10,5" > | |||
<RadioButton Margin="10,0,0,0" FontSize="14">顶部水平</RadioButton> | |||
<RadioButton IsChecked="True" Margin="10,0,0,0" FontSize="14">左侧垂直</RadioButton> | |||
<RadioButton Margin="10,0,0,0" FontSize="14">右侧垂直</RadioButton> | |||
<RadioButton Margin="10,0,0,0" FontSize="14">底部水平</RadioButton> | |||
</WrapPanel> | |||
</Expander> | |||
<Expander Style="{DynamicResource expang_1}" x:Name="expander" Margin="0,-10,0,0" Header="页面编辑" Grid.Row="1" IsExpanded="True"> | |||
<ListBox x:Name="PageList" Background="Transparent" Margin="0,0,0,10" MaxHeight="460" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{DynamicResource PageBoxStyle}" FontSize="14" BorderThickness="0" > | |||
<ListBox.ContextMenu> | |||
<ContextMenu> | |||
<MenuItem Header="设置首页"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="HomeGarage" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="向上移动"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Upload" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="向下移动"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Download" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="编辑信息"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Edit" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="删除该页"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Delete" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
</ContextMenu> | |||
</ListBox.ContextMenu> | |||
</ListBox> | |||
</Expander> | |||
<icon:PackIconMaterial x:Name="icon" Width="24" Height="17" Grid.Row="1" Foreground="{StaticResource AccentBrush}" | |||
Margin="0,0,15,0" Cursor="Hand" HorizontalAlignment="Right" VerticalAlignment="Top" ToolTip="添加页" BorderThickness="1" Kind="HospitalBoxOutline" /> | |||
<Expander Style="{DynamicResource expang_1}" Margin="0,-10,0,10" Header="组件列表" Grid.Row="2" IsExpanded="True"/> | |||
<ListBox x:Name="CtlList" Grid.Row="2" Margin="0,30,0,0" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{DynamicResource ToolBoxStyle}" FontSize="14" BorderThickness="0" PreviewMouseMove="CtlList_PreviewMouseMove" /> | |||
</Grid> | |||
</Border> | |||
<TabControl SelectedIndex="0"> | |||
<TabItem Header="页面编辑"> | |||
<Border BorderThickness="1" BorderBrush="{StaticResource AccentBrush}" Background="Transparent" > | |||
<ListBox x:Name="PageList" Grid.Row="0" Margin="0,5,0,0" HorizontalAlignment="Center" SelectedItem="{Binding SelectPageModels,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding pageModels,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{DynamicResource PageBoxStyle}" FontSize="14" BorderThickness="0" > | |||
<ListBox.ContextMenu> | |||
<ContextMenu> | |||
<MenuItem Header="设置首页" Command="{Binding SetHomePageCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Home" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="向上移动" Command="{Binding SetTopPageCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Upload" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="向下移动" Command="{Binding SetBottomPageCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Download" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="删除该页" Command="{Binding DeletePageCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Delete" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="导出页面文件" Command="{Binding SaveAllPageCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="Save" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="加载页面文件" Command="{Binding LoadAllPageCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="DiskDownload" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
<MenuItem Header="加载变量文件" Command="{Binding LoadValuesCommand}"> | |||
<MenuItem.Icon> | |||
<icon:PackIconModern Width="10" HorizontalAlignment="Center" Kind="DiskDownload" /> | |||
</MenuItem.Icon> | |||
</MenuItem> | |||
</ContextMenu> | |||
</ListBox.ContextMenu> | |||
</ListBox> | |||
</Border> | |||
</TabItem> | |||
<TabItem Header="组件列表"> | |||
<Border BorderThickness="1" BorderBrush="{StaticResource AccentBrush}" Background="Transparent"> | |||
<ListBox x:Name="CtlList" Grid.Row="2" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{DynamicResource ToolBoxStyle}" FontSize="14" BorderThickness="0" PreviewMouseMove="CtlList_PreviewMouseMove" /> | |||
</Border> | |||
</TabItem> | |||
<TabItem Header="菜单布局"> | |||
<Border BorderThickness="1" BorderBrush="{StaticResource AccentBrush}" Background="Transparent"> | |||
<mypro:PropertyGrid Margin="10" ShowAdvancedOptions="True" ShowDescriptionByTooltip="True" | |||
FontSize="14" ShowTitle="False" ShowSortOptions="False" ShowSearchBox="False" | |||
AutoGenerateProperties="False" | |||
CategoryGroupHeaderTemplate="{DynamicResource Category}" SelectedObject="{Binding DataContext.MenuModel,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" > | |||
<mypro:PropertyGrid.PropertyDefinitions> | |||
<mypro:PropertyDefinition Name="FontSize" ></mypro:PropertyDefinition> | |||
<mypro:PropertyDefinition DisplayName="是否显示菜单" Category="菜单属性" DisplayOrder="1" Name="IsVisibility" Description="是否显示菜单"/> | |||
<mypro:PropertyDefinition DisplayName="菜单显示方向" Category="菜单属性" DisplayOrder="2" Name="Alignment" Description="菜单显示方向"/> | |||
<mypro:PropertyDefinition DisplayName="程序标题" Category="菜单属性" DisplayOrder="2" Name="Name" Description="程序集标题"/> | |||
</mypro:PropertyGrid.PropertyDefinitions> | |||
</mypro:PropertyGrid> | |||
</Border> | |||
</TabItem> | |||
</TabControl> | |||
<!--中间控制区域--> | |||
<DockPanel Grid.Column="1"> | |||
@@ -272,7 +285,6 @@ | |||
<Button Margin="4 0 0 0" Width="24" Padding="0" Click="VerticalLayoutBtn_Click" ToolTip="垂直分布"> | |||
<icon:PackIconModern Kind="BorderVertical"/> | |||
</Button> | |||
<ToggleButton IsChecked="{Binding UseAutoAlignment, ElementName=cav, Mode=TwoWay}" ToolTip="使用对齐网格" Margin="4 0 0 0" Width="24" Padding="0"> | |||
<icon:PackIconModern Kind="CellAlign"/> | |||
</ToggleButton> | |||
@@ -315,14 +327,12 @@ | |||
</Style> | |||
</Button.Style> | |||
</Button> | |||
<Button x:Name="Run1Btn" Margin="16 0 0 0" Padding="0" Click="MNRunBtn_Click"> | |||
<Button x:Name="Run1Btn" Margin="4 0 0 0" Padding="0" Click="MNRunBtn_Click"> | |||
<StackPanel Orientation="Horizontal" Margin="8 0"> | |||
<icon:PackIconModern Kind="ControlPlay" VerticalAlignment="Center" Foreground="#28B60F" Width="8"/> | |||
<TextBlock Text="模拟运行" Margin="4 0" VerticalAlignment="Center"/> | |||
</StackPanel> | |||
</Button> | |||
<Button x:Name="SaveBtn" Margin="16 0 0 0" Padding="0" Click="SaveBtn_Click"> | |||
<StackPanel Orientation="Horizontal" Margin="8 0"> | |||
<icon:PackIconModern Kind="Save" VerticalAlignment="Center" Width="12"/> | |||
@@ -336,11 +346,10 @@ | |||
<TextBlock Text="加载" Margin="4 0" VerticalAlignment="Center"/> | |||
</StackPanel> | |||
</Button> | |||
<Button x:Name="LoadBtnValue" Margin="4 0 0 0" Padding="0" Click="LoadBtnValue_Click"> | |||
<Button x:Name="SavePage" Margin="4 0 0 0" Padding="0" Click="SavePage_Click"> | |||
<StackPanel Orientation="Horizontal" Margin="8 0"> | |||
<icon:PackIconModern Kind="DiskDownload" VerticalAlignment="Center" Width="14"/> | |||
<TextBlock Text="变量管理" Margin="4 0" VerticalAlignment="Center"/> | |||
<icon:PackIconModern Kind="Save" VerticalAlignment="Center" Width="12"/> | |||
<TextBlock Text="同步" Margin="4 0" VerticalAlignment="Center"/> | |||
</StackPanel> | |||
</Button> | |||
@@ -348,9 +357,9 @@ | |||
<icon:Material Kind="FileCode"/> | |||
</ToggleButton> | |||
<!--<Slider DockPanel.Dock="Right" x:Name="slikl" Width="100" Maximum="16" Minimum="1" Margin="4 0 0 0" | |||
HorizontalContentAlignment="Center" Value="{Binding ElementName=cav,Path=GridPxiel}" />--> | |||
<!--<TextBlock DockPanel.Dock="Right" Text="对齐:" VerticalAlignment="Center" Margin="16 0 0 0"/>--> | |||
<Slider DockPanel.Dock="Right" x:Name="slikl" Width="100" Maximum="16" Minimum="1" Margin="4 0 0 0" | |||
HorizontalContentAlignment="Center" Value="{Binding ElementName=cav,Path=GridPxiel}" /> | |||
<TextBlock DockPanel.Dock="Right" Text="对齐:" VerticalAlignment="Center" Margin="16 0 0 0"/> | |||
<CheckBox x:Name="IsYSSX" Content="原生属性" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="0 0 0 0"></CheckBox> | |||
@@ -373,7 +382,7 @@ | |||
<Compiler:CanvasPanel.Background> | |||
<VisualBrush TileMode="Tile" Viewport="0,0,20,20" ViewportUnits="Absolute"> | |||
<VisualBrush.Visual> | |||
<Rectangle Width="20" Height="20" StrokeDashArray="4,2" StrokeThickness="0.5" Stroke="#CBCBCB"> | |||
<Rectangle Width="20" Height="20" StrokeDashArray="5,5" StrokeThickness="0.4" Stroke="#CBCBCB"> | |||
<Rectangle.Style> | |||
<Style TargetType="{x:Type Rectangle}"> | |||
<Style.Triggers> | |||
@@ -390,7 +399,6 @@ | |||
</VisualBrush.Visual> | |||
</VisualBrush> | |||
</Compiler:CanvasPanel.Background> | |||
<Compiler:CanvasPanel.RenderTransform> | |||
<TransformGroup> | |||
<TranslateTransform x:Name="CanvasTranslate"/> | |||
@@ -400,7 +408,9 @@ | |||
<ctl:RunCanvas x:Name="runCanvas" Visibility="{Binding RunCanvasVisibility}" /> | |||
</Grid> | |||
</ScrollViewer> | |||
<avae:TextEditor x:Name="codeEditor" ShowLineNumbers="True" Padding="4" WordWrap="True" IsReadOnly="True" SyntaxHighlighting="XML" BorderThickness="1 0 0 0" BorderBrush="{StaticResource ControlBorderBrush}" Grid.Column="1" Width="480" Visibility="{Binding ElementName=showCode, Path=IsChecked, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"/> | |||
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,20,20" FontSize="16" Foreground="Red">分辨率:1920×1080</TextBlock> | |||
</Grid> | |||
</Border> | |||
@@ -411,6 +421,18 @@ | |||
<!--右侧属性栏--> | |||
<Grid Grid.Column="2"> | |||
<TabControl SelectedIndex="0"> | |||
<TabItem Header="页面设置"> | |||
<mypro:PropertyGrid Margin="10" ShowAdvancedOptions="True" ShowDescriptionByTooltip="True" | |||
FontSize="14" ShowTitle="False" ShowSortOptions="False" ShowSearchBox="False" | |||
AutoGenerateProperties="False" | |||
CategoryGroupHeaderTemplate="{DynamicResource Category}" SelectedObject="{Binding SelectedItem,ElementName=PageList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" > | |||
<mypro:PropertyGrid.PropertyDefinitions> | |||
<mypro:PropertyDefinition Name="FontSize" ></mypro:PropertyDefinition> | |||
<mypro:PropertyDefinition DisplayName="页面名称" Category="页面属性" DisplayOrder="1" Name="Name" Description="页面名称"/> | |||
<mypro:PropertyDefinition DisplayName="菜单名称" Category="页面属性" DisplayOrder="2" Name="MenuName" Description="菜单名称"/> | |||
</mypro:PropertyGrid.PropertyDefinitions> | |||
</mypro:PropertyGrid> | |||
</TabItem> | |||
<TabItem Header="属性设置"> | |||
<mypro:PropertyGrid Margin="10" ShowAdvancedOptions="True" ShowDescriptionByTooltip="True" | |||
FontSize="14" ShowTitle="False" ShowSortOptions="False" ShowSearchBox="False" | |||
@@ -652,8 +674,8 @@ | |||
<mypro:PropertyGrid Margin="10" ShowAdvancedOptions="True" ShowDescriptionByTooltip="True" | |||
FontSize="14" ShowTitle="False" ShowSortOptions="False" ShowSearchBox="False" | |||
CategoryGroupHeaderTemplate="{DynamicResource Category}" SelectedObject="{Binding SelectedItem,ElementName=cav,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> | |||
</TabItem> | |||
</TabControl> | |||
</Grid> | |||
</Grid> | |||
@@ -34,39 +34,22 @@ namespace BeDesignerSCADA.Controls | |||
/// </summary> | |||
public partial class CanvasPanelNew : System.Windows.Controls.UserControl | |||
{ | |||
/// <summary> | |||
/// 布局文件路径 | |||
/// </summary> | |||
public string Path = string.Empty; | |||
MainViewModelNew viewModel = new MainViewModelNew(); | |||
ObservableCollection<PageModel> pageModels = new ObservableCollection<PageModel>(); | |||
public MainViewModelNew viewModel = new MainViewModelNew(); | |||
public CanvasPanelNew(string _Path) | |||
{ | |||
InitializeComponent(); | |||
EditorHelper.Register<BindingExpression, BindingConvertor>(); | |||
Path = _Path; | |||
viewModel.LayoutsPath = Path; | |||
viewModel.LayoutsPath = _Path; | |||
this.DataContext = viewModel; | |||
viewModel.Loaded(cav, runCanvas); | |||
//控件加载 | |||
Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly(); | |||
CtlList.ItemsSource = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name)?.ToList(); | |||
pageModels.Add(new PageModel { Name="首页面", PathName="首页面", visual= cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
pageModels.Add(new PageModel { Name = "第二页面", PathName = "首页面", visual = cav }); | |||
PageList.ItemsSource = pageModels; | |||
//读取文件 | |||
FileRead(_Path); | |||
} | |||
#region 位置调整 | |||
/// <summary> | |||
/// 左对齐 | |||
@@ -133,75 +116,28 @@ namespace BeDesignerSCADA.Controls | |||
} | |||
#endregion | |||
#region 其他事件操作 | |||
#region 外部调用事件 | |||
/// <summary> | |||
/// 传入变量管理器地址 | |||
/// </summary> | |||
/// <param name="path"></param> | |||
private void LoadBtnValue_Click(object sender, RoutedEventArgs e) | |||
public void VariableManagerPath(string path) | |||
{ | |||
OpenFileDialog ofd = new OpenFileDialog(); | |||
ofd.Filter = "变量管理器文件|*.json"; | |||
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) | |||
try | |||
{ | |||
viewModel.VariablePath = ofd.FileName; | |||
bool isSucess = DataBusModel.GetInstance().RefreshVariableManager(ofd.FileName); | |||
System.Windows.MessageBox.Show(isSucess ? "加载成功!" : "加载失败!"); | |||
viewModel.VariablePath = path; | |||
} | |||
} | |||
/// <summary> | |||
/// 运行 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void RunBtn_Click(object sender, RoutedEventArgs e) | |||
{ | |||
if (sender is System.Windows.Controls.Button btn) | |||
catch (Exception ex) | |||
{ | |||
if (btn.Tag.ToString() == "运行") | |||
{ | |||
cav.ClearSelection(); | |||
runCanvas.Run(cav.Generator()); | |||
} | |||
else if (btn.Tag.ToString() == "停止") | |||
{ | |||
runCanvas.Destory(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 模拟运行 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void MNRunBtn_Click(object sender, RoutedEventArgs e) | |||
{ | |||
cav.ClearSelection(); | |||
RunWindows runWindows = new RunWindows(); | |||
runWindows.LoadingData(cav.Generator()); | |||
runWindows.Show(); | |||
} | |||
/// <summary> | |||
/// 加载 | |||
/// 保存文件流 布局文件 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void LoadBtn_Click(object sender, RoutedEventArgs e) | |||
public void FileSave() | |||
{ | |||
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); | |||
SaveBtn_Click(null, null); | |||
} | |||
/// <summary> | |||
/// 读取文件 | |||
@@ -248,7 +184,6 @@ namespace BeDesignerSCADA.Controls | |||
catch (Exception ex) | |||
{ | |||
throw; | |||
} | |||
} | |||
/// <summary> | |||
@@ -267,28 +202,6 @@ namespace BeDesignerSCADA.Controls | |||
return frameworks; | |||
} | |||
/// <summary> | |||
/// 保存文件 | |||
/// </summary> | |||
public void FileSave() | |||
{ | |||
SaveBtn_Click(null, null); | |||
} | |||
/// <summary> | |||
/// 传入变量管理器地址 | |||
/// </summary> | |||
/// <param name="path"></param> | |||
public void VariableManagerPath(string path) | |||
{ | |||
try | |||
{ | |||
viewModel.VariablePath = path; | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 运行程序 | |||
/// </summary> | |||
public void Run() | |||
@@ -318,6 +231,63 @@ namespace BeDesignerSCADA.Controls | |||
throw; | |||
} | |||
} | |||
#endregion | |||
#region 执行操作事件 | |||
/// <summary> | |||
/// 运行 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
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(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 模拟运行 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void MNRunBtn_Click(object sender, RoutedEventArgs e) | |||
{ | |||
cav.ClearSelection(); | |||
RunWindows runWindows = new RunWindows(); | |||
runWindows.LoadingData(cav.Generator()); | |||
runWindows.Show(); | |||
} | |||
/// <summary> | |||
/// 加载 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
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); | |||
} | |||
/// <summary> | |||
/// 保存 | |||
/// </summary> | |||
@@ -325,10 +295,10 @@ namespace BeDesignerSCADA.Controls | |||
/// <param name="e"></param> | |||
private void SaveBtn_Click(object sender, RoutedEventArgs e) | |||
{ | |||
if (File.Exists(Path)) | |||
if (File.Exists(viewModel.LayoutsPath)) | |||
{ | |||
string str = cav.Save(); | |||
File.WriteAllText(Path, str, Encoding.Unicode); | |||
File.WriteAllText(viewModel.LayoutsPath, str, Encoding.Unicode); | |||
} | |||
else | |||
{ | |||
@@ -343,13 +313,22 @@ namespace BeDesignerSCADA.Controls | |||
} | |||
} | |||
/// <summary> | |||
/// 模拟消息发送 | |||
/// 保存页面 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void MNBtn_Click(object sender, RoutedEventArgs e) | |||
private void SavePage_Click(object sender, RoutedEventArgs e) | |||
{ | |||
if (viewModel.SelectPageModels == null) | |||
viewModel.SelectPageModels = viewModel.pageModels[0]; | |||
viewModel.SelectPageModels.visual.Children.Clear(); | |||
foreach (FrameworkElement element in cav.Children) | |||
{ | |||
string xamlText = XamlWriter.Save(element); | |||
FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; | |||
viewModel.SelectPageModels.visual.Children.Add(item); | |||
} | |||
viewModel.UpdatePageBase(viewModel.SelectPageModels); | |||
} | |||
#endregion | |||
@@ -524,20 +503,4 @@ namespace BeDesignerSCADA.Controls | |||
} | |||
#endregion | |||
} | |||
public class PageModel | |||
{ | |||
/// <summary> | |||
/// 页面名称 | |||
/// </summary> | |||
public string Name { get; set; } | |||
/// <summary> | |||
/// 路径名称 | |||
/// </summary> | |||
public string PathName { get; set; } | |||
/// <summary> | |||
/// 页面 | |||
/// </summary> | |||
public object visual { get; set; } | |||
} | |||
} |
@@ -0,0 +1,53 @@ | |||
<UserControl x:Class="BeDesignerSCADA.Controls.MenuRunCanvas" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:con="clr-namespace:BeDesignerSCADA.Converters" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BeDesignerSCADA.Controls" | |||
mc:Ignorable="d" | |||
d:DesignHeight="450" d:DesignWidth="800"> | |||
<UserControl.Resources> | |||
<con:ZoomConverter x:Key="ZoomX" IsHeight="False" /> | |||
<con:ZoomConverter x:Key="ZoomY" IsHeight="True" /> | |||
</UserControl.Resources> | |||
<Grid ClipToBounds="True"> | |||
<Grid> | |||
</Grid> | |||
<Grid> | |||
<Canvas | |||
x:Name="RootCanvas" | |||
Background="Transparent" | |||
ClipToBounds="True" | |||
MouseLeftButtonDown="RootCanvas_MouseLeftButtoDown" | |||
MouseLeftButtonUp="RootCanvas_MouseLeftButtonUp" | |||
MouseMove="RootCanvas_MouseMove" | |||
MouseWheel="RootCanvas_MouseWheel"> | |||
<Canvas.RenderTransform> | |||
<TransformGroup> | |||
<ScaleTransform x:Name="Scale" /> | |||
<TranslateTransform x:Name="Translate" /> | |||
</TransformGroup> | |||
</Canvas.RenderTransform> | |||
</Canvas> | |||
</Grid> | |||
<Grid VerticalAlignment="Bottom" Background="#4B959595"> | |||
<StackPanel | |||
Margin="8,0" | |||
HorizontalAlignment="Right" | |||
Orientation="Horizontal"> | |||
<CheckBox | |||
x:Name="DragEnable" | |||
Margin="4" | |||
Content="拖动" /> | |||
<CheckBox | |||
x:Name="ZoomEnable" | |||
Margin="4" | |||
Content="缩放" /> | |||
</StackPanel> | |||
</Grid> | |||
</Grid> | |||
</UserControl> |
@@ -0,0 +1,274 @@ | |||
using BeDesignerSCADA.Common; | |||
using BPASmartClient.Compiler; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.IO; | |||
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.Markup; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
namespace BeDesignerSCADA.Controls | |||
{ | |||
/// <summary> | |||
/// MenuRunCanvas.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class MenuRunCanvas : UserControl | |||
{ | |||
MenuRunCanvasModel menuRunCanvasModel = null; | |||
public MenuRunCanvas() | |||
{ | |||
InitializeComponent(); | |||
menuRunCanvasModel=new MenuRunCanvasModel(); | |||
this.DataContext=menuRunCanvasModel; | |||
Unloaded += (s, e) => Destory(); | |||
} | |||
/// <summary> | |||
/// 停止 | |||
/// </summary> | |||
public void Destory() | |||
{ | |||
foreach (var item in RootCanvas.Children) | |||
{ | |||
if (item is IDisposable disposable) | |||
{ | |||
disposable.Dispose(); | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 根据路径运行程序 | |||
/// </summary> | |||
public void LoadingData(string path) | |||
{ | |||
menuRunCanvasModel.MenuModel = BinaryFile.ReadBinary<MenuModel>(path) as MenuModel; | |||
menuRunCanvasModel.pageModels.Clear(); | |||
menuRunCanvasModel.MenuModel?.PageChildren?.ToList().ForEach(par => | |||
{ | |||
PageModel page = new PageModel | |||
{ | |||
Id = par.Value.Id, | |||
ChildrenStr = par.Value.ChildrenStr, | |||
IsHome = par.Value.IsHome, | |||
MenuName = par.Value.MenuName, | |||
Name = par.Value.Name, | |||
Sort = par.Value.Sort, | |||
}; | |||
page.visual = new CanvasPanel(); | |||
par.Value?.ChildrenStr?.ForEach(k => | |||
{ | |||
FrameworkElement item = XamlReader.Parse(k) as FrameworkElement; | |||
page.visual.Children.Add(item); | |||
}); | |||
menuRunCanvasModel.pageModels.Add(page); | |||
}); | |||
if (menuRunCanvasModel.pageModels.Count > 0) | |||
{ | |||
menuRunCanvasModel.SelectPageModels = menuRunCanvasModel.pageModels[0]; | |||
} | |||
//try | |||
//{ | |||
// SelectPageModels = obj as PageModel; | |||
// try | |||
// { | |||
// canvasPanel.Children.Clear(); | |||
// foreach (FrameworkElement element in (SelectPageModels?.visual as CanvasPanel).Children) | |||
// { | |||
// string xamlText = XamlWriter.Save(element); | |||
// FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; | |||
// canvasPanel.Children.Add(item); | |||
// } | |||
// canvasPanel.SelectedItems?.Clear(); | |||
// } | |||
// catch (Exception ex) | |||
// { | |||
// } | |||
//} | |||
//catch (Exception ex) | |||
//{ | |||
//} | |||
////加载控件 | |||
//List<FrameworkElement> Children = new List<FrameworkElement>(); | |||
//FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | |||
//using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Unicode)) | |||
//{ | |||
// while (sr.Peek() > -1) | |||
// { | |||
// string str = sr.ReadLine(); | |||
// var ele = XamlReader.Parse(str) as FrameworkElement; | |||
// Children.Add(ele); | |||
// } | |||
//} | |||
//if (Children.Count > 0) | |||
//{ | |||
// Run(Children); | |||
//} | |||
} | |||
/// <summary> | |||
/// 运行 | |||
/// </summary> | |||
/// <param name="canvas"></param> | |||
public void Run(List<FrameworkElement> canvas) | |||
{ | |||
RootCanvas.Children.Clear(); | |||
foreach (FrameworkElement element in canvas) | |||
{ | |||
if (element is IExecutable executable) | |||
executable.IsExecuteState = true; | |||
RootCanvas.Children.Add(element); | |||
RegisterJsName(element); | |||
} | |||
} | |||
#region 拖动与缩放 | |||
// 注册名称到Js | |||
static void RegisterJsName(FrameworkElement element) | |||
{ | |||
Config.GetInstance().SetVariable(element.Name, element); | |||
if (element is Panel panel) | |||
{ | |||
foreach (var item in panel.Children) | |||
{ | |||
RegisterJsName(item as FrameworkElement); | |||
} | |||
} | |||
} | |||
private void RootCanvas_MouseMove(object sender, MouseEventArgs e) | |||
{ | |||
if (DragEnable.IsChecked == false) | |||
{ | |||
return; | |||
} | |||
if (e.LeftButton == MouseButtonState.Pressed && isPressed) | |||
{ | |||
Point point = e.GetPosition(this); | |||
var movex = (point.X - last.X); | |||
var movey = (point.Y - last.Y); | |||
Translate.X += movex; | |||
Translate.Y += movey; | |||
last = point; | |||
} | |||
} | |||
bool isPressed = false; | |||
Point last;//记录上次鼠标坐标位置 | |||
private void RootCanvas_MouseLeftButtoDown(object sender, MouseButtonEventArgs e) | |||
{ | |||
last = e.GetPosition(this); | |||
isPressed = true; | |||
} | |||
private void RootCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) | |||
{ | |||
isPressed = false; | |||
} | |||
// 缩放 | |||
private void RootCanvas_MouseWheel(object sender, MouseWheelEventArgs e) | |||
{ | |||
if (ZoomEnable.IsChecked == false) | |||
{ | |||
return; | |||
} | |||
var zoomS = (e.Delta / 960d); | |||
var zoom = zoomS + Scale.ScaleX; | |||
if (zoom > 3 || zoom < 0.8) | |||
{ | |||
return; | |||
} | |||
Scale.ScaleX = Scale.ScaleY = zoom; | |||
Point mouse = e.GetPosition(RootCanvas); | |||
Point newMouse = new Point(mouse.X * zoomS, mouse.Y * zoomS); | |||
Translate.X -= newMouse.X; | |||
Translate.Y -= newMouse.Y; | |||
} | |||
#endregion | |||
} | |||
public class MenuRunCanvasModel : ObservableObject | |||
{ | |||
/// <summary> | |||
/// 菜单Model | |||
/// </summary> | |||
private MenuModel _MenuModel; | |||
public MenuModel MenuModel | |||
{ | |||
get | |||
{ | |||
return _MenuModel; | |||
} | |||
set | |||
{ | |||
_MenuModel = value; | |||
OnPropertyChanged("MenuModel"); | |||
} | |||
} | |||
/// <summary> | |||
/// 选中页面 | |||
/// </summary> | |||
private PageModel _SelectPageModels; | |||
public PageModel SelectPageModels | |||
{ | |||
get | |||
{ | |||
return _SelectPageModels; | |||
} | |||
set | |||
{ | |||
_SelectPageModels = value; | |||
OnPropertyChanged("SelectPageModels"); | |||
} | |||
} | |||
/// <summary> | |||
/// 页面Model | |||
/// </summary> | |||
private ObservableCollection<PageModel> _pageModels; | |||
public ObservableCollection<PageModel> pageModels | |||
{ | |||
get | |||
{ | |||
return _pageModels; | |||
} | |||
set | |||
{ | |||
_pageModels = value; | |||
OnPropertyChanged("pageModels"); | |||
} | |||
} | |||
public MenuRunCanvasModel() | |||
{ | |||
MenuModel = new MenuModel(); | |||
pageModels = new ObservableCollection<PageModel>(); | |||
pageModels.Add(new PageModel { Name = "首页面", visual = new CanvasPanel(), Sort = 0 }); | |||
SelectPageModels = pageModels[0]; | |||
} | |||
} | |||
} |
@@ -198,8 +198,8 @@ | |||
<!--#region 其他--> | |||
<DataTemplate x:Key="PageBoxStyle"> | |||
<Grid x:Name="mains" Margin="2,5,0,5" Background="Transparent"> | |||
<Grid> | |||
<Button x:Name="dsd" Background="Transparent" BorderBrush="DarkBlue" CommandParameter="{Binding .}" Command="{Binding DataContext.SelectPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"> | |||
<Grid x:Name="mains" Margin="2"> | |||
<Grid.Background> | |||
<ImageBrush ImageSource="../Images/bj.png" Stretch="UniformToFill"/> | |||
</Grid.Background> | |||
@@ -212,16 +212,44 @@ | |||
<VisualBrush Visual="{Binding visual,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> | |||
</Rectangle.Fill> | |||
</Rectangle> | |||
<TextBlock Grid.Row="1" FontWeight="Bold" Margin="5,0,0,0" FontSize="14" Foreground="#FFFFA500" | |||
<StackPanel Grid.Row="1" Orientation="Horizontal"> | |||
<icon:PackIconModern x:Name="Sort" Width="10" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0,5,0" Foreground="#FFFFA500" Kind="Page" /> | |||
<TextBlock FontWeight="Bold" Margin="5,0,0,0" FontSize="14" Foreground="#FFFFA500" | |||
x:Name="txt" | |||
Grid.Column="1" | |||
HorizontalAlignment="Left" | |||
VerticalAlignment="Bottom" | |||
Text="{Binding Name}" /> | |||
Text="{Binding Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> | |||
</StackPanel> | |||
<StackPanel x:Name="stack" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,10,0"> | |||
<Button Width="24" Cursor="Hand" BorderBrush="Transparent" Background="Transparent" CommandParameter="{Binding .}" Command="{Binding DataContext.AddPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" Padding="0" Margin="0,0,0,0" ToolTip="增加页"> | |||
<icon:PackIconModern ToolTip="增加页" Width="10" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FFFFA500" Kind="Add" /> | |||
</Button> | |||
<Button Width="24" Cursor="Hand" BorderBrush="Transparent" Background="Transparent" CommandParameter="{Binding .}" Command="{Binding DataContext.DeletePageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" VerticalAlignment="Center" Padding="0" ToolTip="删除页"> | |||
<icon:PackIconModern ToolTip="删除页" Width="10" HorizontalAlignment="Center" Foreground="#FFFFA500" Kind="Delete" /> | |||
</Button> | |||
</StackPanel> | |||
</Grid> | |||
</Grid> | |||
</Button> | |||
<DataTemplate.Triggers> | |||
<Trigger Property="IsMouseOver" Value="True"> | |||
<Setter Property="Visibility" Value="Visible" TargetName="stack"></Setter> | |||
</Trigger> | |||
<Trigger Property="IsMouseOver" Value="false"> | |||
<Setter Property="Visibility" Value="Collapsed" TargetName="stack"></Setter> | |||
</Trigger> | |||
<!--<Trigger Property="IsSelected" Value="True"> | |||
<Setter Property="BorderBrush" Value="Red" TargetName="dsd"></Setter> | |||
</Trigger>--> | |||
<DataTrigger Binding="{Binding IsHome,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="True"> | |||
<Setter TargetName="Sort" Property="Kind" Value="Home" /> | |||
</DataTrigger> | |||
<DataTrigger Binding="{Binding IsHome,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="False"> | |||
<Setter TargetName="Sort" Property="Kind" Value="Page" /> | |||
</DataTrigger> | |||
</DataTemplate.Triggers> | |||
</DataTemplate> | |||
<DataTemplate x:Key="ToolBoxStyle"> | |||
@@ -1,29 +1,20 @@ | |||
using BeDesignerSCADA.Common; | |||
using BeDesignerSCADA.Controls; | |||
using BeDesignerSCADA.View; | |||
using BPASmart.Model; | |||
using BPASmartClient.Compiler; | |||
using BPASmartClient.DATABUS; | |||
using BPASmartClient.SCADAControl.Converters; | |||
using ICSharpCode.AvalonEdit; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
using Microsoft.Win32; | |||
using System; | |||
using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
using System.Collections.ObjectModel; | |||
using System.ComponentModel; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Controls; | |||
using System.Windows.Data; | |||
using System.Windows.Input; | |||
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; | |||
using System.Windows.Markup; | |||
namespace BeDesignerSCADA.ViewModel | |||
{ | |||
@@ -32,6 +23,7 @@ namespace BeDesignerSCADA.ViewModel | |||
public MainViewModelNew() | |||
{ | |||
IsRunning = false; | |||
//启动 或者 停止 | |||
RunUiCommand = new RelayCommand(() => | |||
{ | |||
@@ -74,7 +66,6 @@ namespace BeDesignerSCADA.ViewModel | |||
OnPropertyChanged("IsRunning"); | |||
} | |||
} | |||
/// <summary> | |||
/// 画布是否显示 | |||
/// </summary> | |||
@@ -93,7 +84,6 @@ namespace BeDesignerSCADA.ViewModel | |||
OnPropertyChanged("CanvasPanelVisibility"); | |||
} | |||
} | |||
/// <summary> | |||
/// 运行代码是否显示 | |||
/// </summary> | |||
@@ -112,7 +102,6 @@ namespace BeDesignerSCADA.ViewModel | |||
OnPropertyChanged("RunCanvasVisibility"); | |||
} | |||
} | |||
/// <summary> | |||
/// 当前代码Xaml | |||
/// </summary> | |||
@@ -131,7 +120,6 @@ namespace BeDesignerSCADA.ViewModel | |||
OnPropertyChanged("XamlCode"); | |||
} | |||
} | |||
/// <summary> | |||
/// 选中控件 | |||
/// </summary> | |||
@@ -150,38 +138,52 @@ namespace BeDesignerSCADA.ViewModel | |||
OnPropertyChanged("CanSelectedItem"); | |||
} | |||
} | |||
/// <summary> | |||
/// 设备名称集合 | |||
/// 菜单Model | |||
/// </summary> | |||
private ObservableCollection<string> _DevNameList; | |||
public ObservableCollection<string> DevNameList | |||
private MenuModel _MenuModel; | |||
public MenuModel MenuModel | |||
{ | |||
get | |||
{ | |||
return _DevNameList; | |||
return _MenuModel; | |||
} | |||
set | |||
{ | |||
_DevNameList = value; | |||
OnPropertyChanged("DevNameList"); | |||
_MenuModel = value; | |||
OnPropertyChanged("MenuModel"); | |||
} | |||
} | |||
/// <summary> | |||
/// 设备变量集合 | |||
/// 选中页面 | |||
/// </summary> | |||
private ObservableCollection<string> _DevValueList; | |||
public ObservableCollection<string> DevValueList | |||
private PageModel _SelectPageModels; | |||
public PageModel SelectPageModels | |||
{ | |||
get | |||
{ | |||
return _DevValueList; | |||
return _SelectPageModels; | |||
} | |||
set | |||
{ | |||
_DevValueList = value; | |||
OnPropertyChanged("DevValueList"); | |||
_SelectPageModels = value; | |||
OnPropertyChanged("SelectPageModels"); | |||
} | |||
} | |||
/// <summary> | |||
/// 页面Model | |||
/// </summary> | |||
private ObservableCollection<PageModel> _pageModels; | |||
public ObservableCollection<PageModel> pageModels | |||
{ | |||
get | |||
{ | |||
return _pageModels; | |||
} | |||
set | |||
{ | |||
_pageModels = value; | |||
OnPropertyChanged("pageModels"); | |||
} | |||
} | |||
#endregion | |||
@@ -205,6 +207,35 @@ namespace BeDesignerSCADA.ViewModel | |||
{ | |||
textEditor.Text = canvasPanel.Save(); | |||
} | |||
/// <summary> | |||
/// 更新页面 | |||
/// </summary> | |||
public void UpdatePageBase(PageModel _pageModel) | |||
{ | |||
try | |||
{ | |||
List<string> ChildrenStr = new List<string>(); | |||
foreach (FrameworkElement element in _pageModel.visual.Children) | |||
{ | |||
string xamlText = XamlWriter.Save(element); | |||
ChildrenStr.Add(xamlText); | |||
} | |||
PageBase page = new PageBase() | |||
{ | |||
ChildrenStr = ChildrenStr, | |||
Id = _pageModel.Id, | |||
IsHome = _pageModel.IsHome, | |||
MenuName = _pageModel.MenuName, | |||
Name = _pageModel.Name, | |||
Sort = _pageModel.Sort, | |||
}; | |||
MenuModel.PageChildren[_pageModel.Id] = page; | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
#endregion | |||
#region 脚本编辑数据 | |||
@@ -216,7 +247,6 @@ namespace BeDesignerSCADA.ViewModel | |||
/// 当前运行界面 | |||
/// </summary> | |||
public RunCanvas runCanvas; | |||
/// <summary> | |||
/// 加载 | |||
/// </summary> | |||
@@ -226,8 +256,9 @@ namespace BeDesignerSCADA.ViewModel | |||
canvasPanel = objCan as CanvasPanel; | |||
runCanvas = objRun as RunCanvas; | |||
} | |||
InitCommand(); | |||
} | |||
/// <summary> | |||
/// 编辑 | |||
/// </summary> | |||
@@ -237,7 +268,6 @@ namespace BeDesignerSCADA.ViewModel | |||
string result = JsEditWindow.ShowEdit(((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value?.ToString(), canvasPanel.GetAllExecChildren()); | |||
((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value = result; | |||
} | |||
/// <summary> | |||
/// 子控件编辑 | |||
/// </summary> | |||
@@ -247,7 +277,6 @@ namespace BeDesignerSCADA.ViewModel | |||
string xml = ChildEditWindow.ShowEdit(((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value?.ToString()); | |||
((Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem)obj).Value = xml; | |||
} | |||
/// <summary> | |||
/// 绑定编辑 | |||
/// </summary> | |||
@@ -287,7 +316,6 @@ namespace BeDesignerSCADA.ViewModel | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 清除绑定 | |||
/// </summary> | |||
@@ -312,7 +340,6 @@ namespace BeDesignerSCADA.ViewModel | |||
BindingOperations.ClearBinding((selectControl as FrameworkElement), dependencyProperty); | |||
} | |||
} | |||
/// <summary> | |||
/// 图片选择路径 | |||
/// </summary> | |||
@@ -351,7 +378,6 @@ namespace BeDesignerSCADA.ViewModel | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 选择路径 | |||
/// </summary> | |||
@@ -367,6 +393,299 @@ namespace BeDesignerSCADA.ViewModel | |||
} | |||
#endregion | |||
#region 命令事件,页面编辑 Command | |||
/// <summary> | |||
/// 设置首页 | |||
/// </summary> | |||
public RelayCommand SetHomePageCommand { get; set; } | |||
/// <summary> | |||
/// 向上移动 | |||
/// </summary> | |||
public RelayCommand SetTopPageCommand { get; set; } | |||
/// <summary> | |||
/// 向下移动 | |||
/// </summary> | |||
public RelayCommand SetBottomPageCommand { get; set; } | |||
/// <summary> | |||
/// 增加页-该项下增加 | |||
/// </summary> | |||
public RelayCommand<object> AddPageCommand { get; set; } | |||
/// <summary> | |||
/// 删除该页 | |||
/// </summary> | |||
public RelayCommand<object> DeletePageCommand { get; set; } | |||
/// <summary> | |||
/// 选中该页 | |||
/// </summary> | |||
public RelayCommand<object> SelectPageCommand { get; set; } | |||
/// <summary> | |||
/// 导出页面文件 | |||
/// </summary> | |||
public RelayCommand SaveAllPageCommand { get; set; } | |||
/// <summary> | |||
/// 加载页面文件 | |||
/// </summary> | |||
public RelayCommand LoadAllPageCommand { get; set; } | |||
/// <summary> | |||
/// 加载变量文件 | |||
/// </summary> | |||
public RelayCommand LoadValuesCommand { get; set; } | |||
/// <summary> | |||
/// 初始化命令 | |||
/// </summary> | |||
public void InitCommand() | |||
{ | |||
SetHomePageCommand = new RelayCommand(new Action(SetHomePageHeader)); | |||
SetTopPageCommand = new RelayCommand(new Action(SetTopPageHeader)); | |||
SetBottomPageCommand = new RelayCommand(new Action(SetBottomPageHeader)); | |||
AddPageCommand = new RelayCommand<object>(new Action<object?>(AddPageHeader)); | |||
DeletePageCommand = new RelayCommand<object>(new Action<object?>(DeletePageHeader)); | |||
SelectPageCommand = new RelayCommand<object>(new Action<object?>(SelectPageHeader)); | |||
SaveAllPageCommand = new RelayCommand(new Action(SaveAllPageHeader)); | |||
LoadAllPageCommand = new RelayCommand(new Action(LoadAllPageHeader)); | |||
LoadValuesCommand = new RelayCommand(new Action(LoadValuesHeader)); | |||
MenuModel = new MenuModel(); | |||
pageModels = new ObservableCollection<PageModel>(); | |||
pageModels.Add(new PageModel { Name = "首页面", visual = new CanvasPanel(), Sort = 0 }); | |||
SelectPageModels = pageModels[0]; | |||
GxSortTarget(); | |||
} | |||
/// <summary> | |||
/// 刷新排序 | |||
/// </summary> | |||
public void GxSortTarget() | |||
{ | |||
MenuModel.PageChildren.Clear(); | |||
for (int i = 0; i < pageModels.Count; i++) | |||
{ | |||
pageModels[i].Sort = i; | |||
if(i==0) | |||
pageModels[i].IsHome = true; | |||
else | |||
pageModels[i].IsHome = false; | |||
UpdatePageBase(pageModels[i]); | |||
} | |||
} | |||
/// <summary> | |||
/// 设置首页 | |||
/// </summary> | |||
public void SetHomePageHeader() | |||
{ | |||
try | |||
{ | |||
if (SelectPageModels != null) | |||
{ | |||
PageModel mode = SelectPageModels; | |||
pageModels.Remove(mode); | |||
pageModels.Insert(0,mode); | |||
GxSortTarget(); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 向上移动 | |||
/// </summary> | |||
public void SetTopPageHeader() | |||
{ | |||
try | |||
{ | |||
if (SelectPageModels != null) | |||
{ | |||
PageModel mode = SelectPageModels; | |||
if (mode.Sort > 0) | |||
{ | |||
pageModels.Remove(mode); | |||
pageModels.Insert(mode.Sort - 1, mode); | |||
GxSortTarget(); | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 向下移动 | |||
/// </summary> | |||
public void SetBottomPageHeader() | |||
{ | |||
try | |||
{ | |||
if (SelectPageModels != null) | |||
{ | |||
PageModel mode = SelectPageModels; | |||
if (mode.Sort > 0 && mode.Sort+1< pageModels.Count) | |||
{ | |||
pageModels.Remove(mode); | |||
pageModels.Insert(mode.Sort + 1, mode); | |||
GxSortTarget(); | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 增加页-该项下增加 | |||
/// </summary> | |||
public void AddPageHeader(object obj) | |||
{ | |||
try | |||
{ | |||
if (obj != null && obj is PageModel mode) | |||
{ | |||
if (mode.Sort >= 0 && mode.Sort + 1 < pageModels.Count) | |||
{ | |||
pageModels.Insert(mode.Sort + 1,new PageModel { Name = "页面"+ pageModels.Count, MenuName = "页面" + pageModels.Count, visual = new CanvasPanel(), Sort = pageModels.Count }); | |||
GxSortTarget(); | |||
} | |||
else if (mode.Sort + 1 == pageModels.Count) | |||
{ | |||
pageModels.Add(new PageModel { Name = "页面" + pageModels.Count, MenuName= "页面" + pageModels.Count,visual = new CanvasPanel(), Sort = pageModels.Count }); | |||
GxSortTarget(); | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 删除该页 | |||
/// </summary> | |||
public void DeletePageHeader(object obj) | |||
{ | |||
try | |||
{ | |||
if (obj != null && obj is PageModel page) | |||
{ | |||
pageModels.Remove(page); | |||
GxSortTarget(); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 选中该页 | |||
/// </summary> | |||
/// <param name="obj"></param> | |||
public void SelectPageHeader(object obj) | |||
{ | |||
try | |||
{ | |||
SelectPageModels = obj as PageModel; | |||
try | |||
{ | |||
canvasPanel.Children.Clear(); | |||
foreach (FrameworkElement element in (SelectPageModels?.visual as CanvasPanel).Children) | |||
{ | |||
string xamlText = XamlWriter.Save(element); | |||
FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; | |||
canvasPanel.Children.Add(item); | |||
} | |||
canvasPanel.SelectedItems?.Clear(); | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 导出页面文件 | |||
/// </summary> | |||
public void SaveAllPageHeader() | |||
{ | |||
try | |||
{ | |||
SaveFileDialog sfd = new SaveFileDialog(); | |||
sfd.Filter = "页面布局|*.yf"; | |||
if (sfd.ShowDialog() == true) | |||
{ | |||
BinaryFile.SaveBinary(MenuModel, sfd.FileName); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 加载页面文件 | |||
/// </summary> | |||
public void LoadAllPageHeader() | |||
{ | |||
try | |||
{ | |||
OpenFileDialog ofd = new OpenFileDialog(); | |||
ofd.Filter = "页面布局|*.yf"; | |||
if (ofd.ShowDialog() == true) | |||
{ | |||
MenuModel obj = BinaryFile.ReadBinary<MenuModel>(ofd.FileName) as MenuModel; | |||
MenuModel = obj; | |||
pageModels.Clear(); | |||
MenuModel?.PageChildren?.ToList().ForEach(par => | |||
{ | |||
PageModel page = new PageModel | |||
{ | |||
Id = par.Value.Id, | |||
ChildrenStr = par.Value.ChildrenStr, | |||
IsHome = par.Value.IsHome, | |||
MenuName = par.Value.MenuName, | |||
Name = par.Value.Name, | |||
Sort = par.Value.Sort, | |||
}; | |||
page.visual = new CanvasPanel(); | |||
par.Value?.ChildrenStr?.ForEach(k => | |||
{ | |||
FrameworkElement item = XamlReader.Parse(k) as FrameworkElement; | |||
page.visual.Children.Add(item); | |||
}); | |||
pageModels.Add(page); | |||
}); | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 加载变量文件 | |||
/// </summary> | |||
public void LoadValuesHeader() | |||
{ | |||
OpenFileDialog ofd = new OpenFileDialog(); | |||
ofd.Filter = "变量管理器文件|*.json"; | |||
if (ofd.ShowDialog() == true) | |||
{ | |||
VariablePath = ofd.FileName; | |||
bool isSucess = DataBusModel.GetInstance().RefreshVariableManager(ofd.FileName); | |||
System.Windows.MessageBox.Show(isSucess ? "加载成功!" : "加载失败!"); | |||
} | |||
} | |||
#endregion | |||
} | |||
} |