@@ -35,6 +35,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
public SwitchButton() | |||
{ | |||
ResourceDictionary languageResDic = new ResourceDictionary(); | |||
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute); | |||
this.Resources.MergedDictionaries.Add(languageResDic); | |||
SetCurrentValue(WidthProperty, 120d); | |||
SetCurrentValue(HeightProperty, 40d); | |||
} | |||
@@ -100,7 +103,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
public static readonly DependencyProperty DKColorProperty = | |||
DependencyProperty.Register("DKColor", typeof(Brush), typeof(SwitchButton), new PropertyMetadata(new SolidColorBrush(Colors.Transparent))); | |||
TranslateTransform transX; | |||
Ellipse ellipse; | |||
public Ellipse ellipse; | |||
public override void OnApplyTemplate() | |||
{ | |||
base.OnApplyTemplate(); | |||
@@ -119,6 +122,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
} | |||
void Refresh() | |||
{ | |||
if (ellipse == null) | |||
{ | |||
return; | |||
@@ -160,6 +164,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls | |||
{ | |||
Class_DataBus.GetInstance().BindingAction += BindingActionHeader; | |||
this.Click += SwitchButton_Click; | |||
if (this.IsChecked == true) Config.GetInstance().RunJsScipt(CheckedExec); | |||
else Config.GetInstance().RunJsScipt(UnCheckedExec); | |||
Refresh(); | |||
} | |||
public void BindingActionHeader(object sender, EventArgs e) | |||
{ | |||
@@ -197,6 +197,40 @@ | |||
</Setter> | |||
</Style> | |||
<Style x:Key="swith_button" TargetType="{x:Type ctrl:SwitchButton}"> | |||
<Setter Property="Background" Value="{StaticResource ControlBackground}" /> | |||
<Setter Property="BorderBrush" Value="LightGray" /> | |||
<Setter Property="Foreground" Value="Gray" /> | |||
<Setter Property="BorderThickness" Value="0" /> | |||
<Setter Property="Template"> | |||
<Setter.Value> | |||
<ControlTemplate TargetType="ctrl:SwitchButton"> | |||
<Border | |||
Background="{TemplateBinding Background}" | |||
BorderBrush="{TemplateBinding BorderBrush}" | |||
BorderThickness="{TemplateBinding BorderThickness}" | |||
CornerRadius="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ActualHeight, Converter={StaticResource HalfNumber}}"> | |||
<Grid> | |||
<Ellipse | |||
x:Name="ELLIPSE" | |||
HorizontalAlignment="Left" | |||
VerticalAlignment="Center" | |||
Fill="Gray" | |||
RenderTransformOrigin="0.5,0.5" | |||
Stroke="{StaticResource ControlBorderBrush}" | |||
StrokeThickness="1"> | |||
<Ellipse.RenderTransform> | |||
<TransformGroup> | |||
<TranslateTransform x:Name="TranslateX" X="2" /> | |||
</TransformGroup> | |||
</Ellipse.RenderTransform> | |||
</Ellipse> | |||
</Grid> | |||
</Border> | |||
</ControlTemplate> | |||
</Setter.Value> | |||
</Setter> | |||
</Style> | |||
<Style TargetType="ctrl:DigitalNumber"> | |||
<Setter Property="Background" Value="#FF1A1E22" /> | |||
<Setter Property="Foreground" Value="#FF0AA74D" /> | |||
@@ -1,4 +1,5 @@ | |||
using BPASmartClient.Compiler; | |||
using BeDesignerSCADA.Controls; | |||
using BPASmartClient.Compiler; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -205,6 +206,11 @@ namespace BeDesignerSCADA.Common | |||
OnPropertyChanged("visual"); | |||
} | |||
} | |||
/// <summary> | |||
/// 运行Canvas | |||
/// </summary> | |||
[Newtonsoft.Json.JsonIgnore] | |||
public RunCanvas runCanvas { get; set; } | |||
public PageModel() | |||
{ | |||
ChildrenStr = new List<string>(); | |||
@@ -12,50 +12,14 @@ | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary Source="/BPASmartClient.SCADAControl;component/Themes/Generic.xaml" /> | |||
</ResourceDictionary.MergedDictionaries> | |||
<con:ZoomConverter x:Key="ZoomX" IsHeight="False" /> | |||
<con:ZoomConverter x:Key="ZoomY" IsHeight="True" /> | |||
</ResourceDictionary> | |||
</UserControl.Resources> | |||
<Grid ClipToBounds="True"> | |||
<Grid> | |||
<Canvas | |||
Tag="{Binding SelectId,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" | |||
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> | |||
<Border x:Name="main" > | |||
</Border> | |||
<WrapPanel x:Name="wrapanl_main" Orientation="Vertical" Style="{DynamicResource image矩阵框1}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="0,5,0,25"> | |||
<TextBlock x:Name="TitleName" Foreground="#FFFFA500" FontSize="18" Width="100" TextWrapping="Wrap" MaxHeight="20" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding MenuModel.Name}" FontFamily="{DynamicResource Digital}"></TextBlock> | |||
<ListBox x:Name="PageList" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Bottom" | |||
SelectedItem="{Binding MenuModel.SelectPageModels,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" | |||
@@ -65,8 +29,6 @@ | |||
ScrollViewer.HorizontalScrollBarVisibility="Auto" | |||
ItemTemplate="{DynamicResource X_PageBoxStyle}" FontSize="14" BorderThickness="0" > | |||
</ListBox> | |||
</WrapPanel> | |||
</Grid> | |||
</UserControl> |
@@ -33,21 +33,6 @@ namespace BeDesignerSCADA.Controls | |||
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> | |||
/// 根据路径运行程序 | |||
@@ -114,155 +99,34 @@ namespace BeDesignerSCADA.Controls | |||
wrapanl_main.Visibility = Visibility.Collapsed; | |||
itemsPanelTemplate.VisualTree = _StackPanel; | |||
PageList.ItemsPanel = itemsPanelTemplate; | |||
menuRunCanvasModel.canvas1 = RootCanvas; | |||
menuRunCanvasModel.MenuModel = canvas; | |||
menuRunCanvasModel.MenuModel = canvas; | |||
menuRunCanvasModel.border = main; | |||
menuRunCanvasModel.MenuModel?.pageModels?.ToList().ForEach(par => | |||
{ | |||
List<FrameworkElement> Children = new List<FrameworkElement>(); | |||
par.visual = new CanvasPanel(); | |||
par?.ChildrenStr?.ForEach(k => | |||
{ | |||
FrameworkElement item = XamlReader.Parse(k) as FrameworkElement; | |||
par.visual.Children.Add(item); | |||
FrameworkElement item1 = XamlReader.Parse(k) as FrameworkElement; | |||
Children.Add(item1); | |||
}); | |||
RunCanvas runCanvas = new RunCanvas(); | |||
runCanvas.Init(Children); | |||
par.runCanvas = runCanvas; | |||
}); | |||
if (menuRunCanvasModel.MenuModel.pageModels.Count > 0) | |||
{ | |||
menuRunCanvasModel.MenuModel.SelectPageModels = menuRunCanvasModel.MenuModel.pageModels[0]; | |||
menuRunCanvasModel.SelectId = menuRunCanvasModel.MenuModel.pageModels[0].Id; | |||
} | |||
SelectMenu(); | |||
} | |||
/// <summary> | |||
/// 选中菜单 | |||
/// </summary> | |||
public void SelectMenu() | |||
{ | |||
try | |||
{ | |||
List<FrameworkElement> Children = new List<FrameworkElement>(); | |||
if (menuRunCanvasModel.MenuModel.SelectPageModels != null) | |||
{ | |||
foreach (FrameworkElement element in (menuRunCanvasModel?.MenuModel.SelectPageModels?.visual as CanvasPanel).Children) | |||
{ | |||
string xamlText = XamlWriter.Save(element); | |||
FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; | |||
Children.Add(item); | |||
} | |||
} | |||
Run(Children); | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 运行 | |||
/// </summary> | |||
/// <param name="canvas"></param> | |||
public void Run(List<FrameworkElement> canvas) | |||
{ | |||
Config.GetInstance().Reset(); | |||
RootCanvas.Children.Clear(); | |||
foreach (FrameworkElement element in canvas) | |||
{ | |||
if (element is IExecutable executable) | |||
executable.IsExecuteState = true; | |||
RootCanvas.Children.Add(element); | |||
RegisterJsName(element); | |||
main.Child = menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas; | |||
menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas.RunSelect(); | |||
} | |||
} | |||
#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> | |||
/// 选中ID | |||
/// </summary> | |||
private string _SelectId; | |||
public string SelectId | |||
{ | |||
get | |||
{ | |||
return _SelectId; | |||
} | |||
set | |||
{ | |||
_SelectId = value; | |||
OnPropertyChanged("SelectId"); | |||
} | |||
} | |||
/// <summary> | |||
/// 菜单Model | |||
/// </summary> | |||
@@ -280,7 +144,7 @@ namespace BeDesignerSCADA.Controls | |||
} | |||
} | |||
public RelayCommand<object> MenSelectPageCommand { get; set; } | |||
public Canvas canvas1; | |||
public Border border { get; set; } | |||
public MenuRunCanvasModel() | |||
{ | |||
MenuModel = new MenuModel(); | |||
@@ -297,61 +161,15 @@ namespace BeDesignerSCADA.Controls | |||
{ | |||
try | |||
{ | |||
Rx(SelectId); | |||
//MenuModel.SelectPageModels.runCanvas.Destory(); | |||
MenuModel.SelectPageModels = obj as PageModel; | |||
SelectId = MenuModel.SelectPageModels.Id; | |||
List<FrameworkElement> Children = new List<FrameworkElement>(); | |||
if (MenuModel.SelectPageModels != null) | |||
{ | |||
foreach (FrameworkElement element in (MenuModel.SelectPageModels?.visual as CanvasPanel).Children) | |||
{ | |||
string xamlText = XamlWriter.Save(element); | |||
FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; | |||
Children.Add(item); | |||
} | |||
} | |||
Run(Children); | |||
border.Child = MenuModel.SelectPageModels.runCanvas; | |||
MenuModel.SelectPageModels.runCanvas.RunSelect(); | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
public void Rx(string id) | |||
{ | |||
//(MenuModel?.pageModels?.ToList().Find(par => par.Id == id).visual as CanvasPanel).Children.Clear(); | |||
//foreach (FrameworkElement element in canvas1.Children) | |||
//{ | |||
// string xamlText = XamlWriter.Save(element); | |||
// FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement; | |||
// (MenuModel?.pageModels?.ToList().Find(par => par.Id == id).visual as CanvasPanel).Children.Add(item); | |||
//} | |||
} | |||
public void Run(List<FrameworkElement> canvas) | |||
{ | |||
Config.GetInstance().Reset(); | |||
canvas1.Children.Clear(); | |||
foreach (FrameworkElement element in canvas) | |||
{ | |||
if (element is IExecutable executable) | |||
executable.IsExecuteState = true; | |||
canvas1.Children.Add(element); | |||
RegisterJsName(element); | |||
} | |||
} | |||
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); | |||
} | |||
} | |||
} | |||
} | |||
} |
@@ -66,9 +66,36 @@ namespace BeDesignerSCADA.Controls | |||
{ | |||
Run(Children); | |||
} | |||
} | |||
/// <summary> | |||
/// 初始化 | |||
/// </summary> | |||
/// <param name="canvas"></param> | |||
public void Init(List<FrameworkElement> canvas) | |||
{ | |||
RootCanvas.Children.Clear(); | |||
foreach (FrameworkElement element in canvas) | |||
{ | |||
RootCanvas.Children.Add(element); | |||
} | |||
} | |||
public void RunSelect() | |||
{ | |||
Config.GetInstance().Reset(); | |||
foreach (FrameworkElement element in RootCanvas.Children) | |||
{ | |||
RegisterJsName(element);//注册rejs | |||
} | |||
foreach (FrameworkElement element in RootCanvas.Children) | |||
{ | |||
if (element is IExecutable executable) | |||
executable.IsExecuteState = true; | |||
} | |||
} | |||
public void Run(List<FrameworkElement> canvas) | |||
{ | |||
RootCanvas.Children.Clear(); | |||