@@ -8,8 +8,8 @@ | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:vm="clr-namespace:BPASmartClient.CustomResource.Pages.ViewModel" | |||
Title="LoginView" | |||
Width="1920" | |||
Height="1080" | |||
Width="1366" | |||
Height="768" | |||
AllowsTransparency="True" | |||
Background="{x:Null}" | |||
Topmost="False" | |||
@@ -194,7 +194,7 @@ | |||
<!--#region 操作按钮样式--> | |||
<Style x:Key="ButtonStyle" TargetType="Button"> | |||
<Setter Property="Margin" Value="20,20" /> | |||
<Setter Property="Margin" Value="20,0" /> | |||
<Setter Property="Background" Value="#cc009DFF" /> | |||
<Setter Property="BorderThickness" Value="0" /> | |||
<Setter Property="FontSize" Value="30" /> | |||
@@ -236,9 +236,24 @@ | |||
VerticalAlignment="Center" | |||
LoadedBehavior="Manual" />--> | |||
<Grid x:Name="grid" Margin="400,180"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="0.4*" /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition Width="0.4*" /> | |||
</Grid.ColumnDefinitions> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="0.25*" /> | |||
<RowDefinition /> | |||
<RowDefinition Height="0.25*" /> | |||
</Grid.RowDefinitions> | |||
<!-- Margin="400,180" --> | |||
<Grid | |||
x:Name="grid" | |||
Grid.Row="1" | |||
Grid.Column="1"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition /> | |||
<RowDefinition Height="0.8*"/> | |||
<RowDefinition /> | |||
<RowDefinition /> | |||
<RowDefinition /> | |||
@@ -300,7 +315,7 @@ | |||
Text="请输入账号密码" | |||
Visibility="Visible" /> | |||
<Grid Grid.Row="3"> | |||
<Grid Margin="0 20" Grid.Row="3"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
@@ -123,7 +123,7 @@ | |||
<ContentPresenter | |||
x:Name="ContentSite" | |||
Margin="3,3,0,3" | |||
HorizontalAlignment="Center" | |||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" | |||
VerticalAlignment="Center" | |||
Content="{TemplateBinding SelectionBoxItem}" | |||
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" | |||
@@ -9,6 +9,7 @@ | |||
<ItemGroup> | |||
<None Remove="Fonts\ds-digib.ttf" /> | |||
<None Remove="Images\03.png" /> | |||
<None Remove="Images\2609.png" /> | |||
<None Remove="Images\api.png" /> | |||
<None Remove="Images\biogebj.png" /> | |||
@@ -25,6 +26,7 @@ | |||
<None Remove="Images\mqttrun.png" /> | |||
<None Remove="Images\mqttstop.png" /> | |||
<None Remove="Images\nbbj.png" /> | |||
<None Remove="Images\Pop_bg.png" /> | |||
<None Remove="Images\redis.png" /> | |||
<None Remove="Images\redisrun.png" /> | |||
<None Remove="Images\redisstop.png" /> | |||
@@ -42,7 +44,15 @@ | |||
<None Remove="Images\上箭头.png" /> | |||
<None Remove="Images\借出.png" /> | |||
<None Remove="Images\光柱.png" /> | |||
<None Remove="Images\右1.png" /> | |||
<None Remove="Images\右2.png" /> | |||
<None Remove="Images\左1.png" /> | |||
<None Remove="Images\左2.png" /> | |||
<None Remove="Images\拉出.png" /> | |||
<None Remove="Images\收缩.png" /> | |||
<None Remove="Images\矩形边框.png" /> | |||
<None Remove="Images\矩形边框1.png" /> | |||
<None Remove="Images\系统名称.png" /> | |||
<None Remove="Images\退出.png" /> | |||
<None Remove="Images\顶部线条.png" /> | |||
</ItemGroup> | |||
@@ -75,6 +85,9 @@ | |||
<ItemGroup> | |||
<Resource Include="Fonts\ds-digib.ttf" /> | |||
<Resource Include="Images\03.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\2609.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
@@ -114,6 +127,9 @@ | |||
<Resource Include="Images\nbbj.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\Pop_bg.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\redis.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
@@ -174,9 +190,33 @@ | |||
<Resource Include="Images\button2.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\右1.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\右2.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\左1.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\左2.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\拉出.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\收缩.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\矩形边框.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\矩形边框1.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\系统名称.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
<Resource Include="Images\退出.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
@@ -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" /> | |||
@@ -3030,7 +3064,7 @@ | |||
</Style> | |||
<DataTemplate x:Key="X_PageBoxStyle"> | |||
<Button x:Name="dsd" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" CommandParameter="{Binding .}" Command="{Binding DataContext.MenSelectPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"> | |||
<Button x:Name="dsd" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" CommandParameter="{Binding .}" Command="{Binding DataContext.MenSelectPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"> | |||
<Grid > | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="auto"/> | |||
@@ -3053,6 +3087,12 @@ | |||
HorizontalAlignment="Left" | |||
VerticalAlignment="Bottom" | |||
Text="{Binding Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> | |||
<TextBlock FontWeight="Bold" Margin="5,0,5,0" FontSize="14" Foreground="#FFFFA500" | |||
Grid.Row="2" | |||
HorizontalAlignment="Right" | |||
VerticalAlignment="Bottom" | |||
Text="{Binding Sort,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> | |||
</Grid> | |||
</Button> | |||
@@ -3073,15 +3113,86 @@ | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image系统名称" TargetType="Image"> | |||
<Style.Setters> | |||
<Setter Property="VerticalAlignment" Value="Stretch" /> | |||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | |||
<Setter Property="Source" Value="../Images/系统名称.png" /> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image矩阵框1" TargetType="WrapPanel"> | |||
<Style.Setters> | |||
<Setter Property="Background"> | |||
<Setter.Value> | |||
<ImageBrush ImageSource="../Images/矩形边框.png" Stretch="UniformToFill" ></ImageBrush> | |||
<ImageBrush ImageSource="../Images/Pop_bg.png" Stretch="Fill" Opacity="1" ></ImageBrush> | |||
</Setter.Value> | |||
</Setter> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="imageTextBlock" TargetType="TextBlock"> | |||
<Style.Setters> | |||
<Setter Property="Background"> | |||
<Setter.Value> | |||
<ImageBrush ImageSource="../Images/系统名称.png" Stretch="Fill" ></ImageBrush> | |||
</Setter.Value> | |||
</Setter> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image拉出" TargetType="Grid"> | |||
<Style.Setters> | |||
<Setter Property="Background"> | |||
<Setter.Value> | |||
<ImageBrush ImageSource="../Images/拉出.png" Stretch="Fill" ></ImageBrush> | |||
</Setter.Value> | |||
</Setter> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image收缩" TargetType="Grid"> | |||
<Style.Setters> | |||
<Setter Property="Background"> | |||
<Setter.Value> | |||
<ImageBrush ImageSource="../Images/收缩.png" Stretch="Fill" ></ImageBrush> | |||
</Setter.Value> | |||
</Setter> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image右1" TargetType="Image"> | |||
<Style.Setters> | |||
<Setter Property="VerticalAlignment" Value="Stretch" /> | |||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | |||
<Setter Property="Source" Value="../Images/右1.png" /> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image右2" TargetType="Image"> | |||
<Style.Setters> | |||
<Setter Property="VerticalAlignment" Value="Stretch" /> | |||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | |||
<Setter Property="Source" Value="../Images/右2.png" /> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image左1" TargetType="Image"> | |||
<Style.Setters> | |||
<Setter Property="VerticalAlignment" Value="Stretch" /> | |||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | |||
<Setter Property="Source" Value="../Images/左1.png" /> | |||
</Style.Setters> | |||
</Style> | |||
<Style x:Key="image左2" TargetType="Image"> | |||
<Style.Setters> | |||
<Setter Property="VerticalAlignment" Value="Stretch" /> | |||
<Setter Property="HorizontalAlignment" Value="Stretch" /> | |||
<Setter Property="Source" Value="../Images/左2.png" /> | |||
</Style.Setters> | |||
</Style> | |||
</ResourceDictionary> |
@@ -21,7 +21,9 @@ namespace BPASmartClient.SmallBatchingSystem | |||
public static Window MainWindow; | |||
protected override void OnStartup(StartupEventArgs e) | |||
{ | |||
//1366*768 | |||
base.OnStartup(e); | |||
BPASmartClient.Helper.SystemHelper.GetInstance.CreateDesktopShortcut(); | |||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | |||
Json<ConfigInfoModel>.Read(); | |||
Json<CommunicationPar>.Read(); | |||
@@ -29,16 +31,16 @@ namespace BPASmartClient.SmallBatchingSystem | |||
MainView mv = new MainView(); | |||
Control.GetInstance.Init(); | |||
mv.TitleName = "黑菠萝自动化配料系统"; | |||
mv.Show(); | |||
//LoginView lv = new LoginView(); | |||
//var res = lv.ShowDialog(); | |||
//if (res != null && res == true) | |||
//{ | |||
// Control.GetInstance.OperationLog("用户登录"); | |||
// mv.Show(); | |||
//} | |||
//else | |||
// mv.Close(); | |||
//mv.Show(); | |||
LoginView lv = new LoginView(); | |||
var res = lv.ShowDialog(); | |||
if (res != null && res == true) | |||
{ | |||
Control.GetInstance.OperationLog("用户登录"); | |||
mv.Show(); | |||
} | |||
else | |||
mv.Close(); | |||
MainWindow = mv; | |||
} | |||
@@ -8,8 +8,8 @@ namespace BPASmartClient.SmallBatchingSystem | |||
{ | |||
public class CommunicationPar | |||
{ | |||
//public string Host { get; set; } = "192.168.6.100"; | |||
public string Host { get; set; } = "127.0.0.1"; | |||
public string Host { get; set; } = "192.168.6.100"; | |||
//public string Host { get; set; } = "127.0.0.1"; | |||
public int Port { get; set; } = 502; | |||
} | |||
@@ -1,4 +1,6 @@ | |||
using BPA.Helper; | |||
#define test | |||
using BPA.Helper; | |||
using BPASmartClient.SmallBatchingSystem; | |||
using System; | |||
using System.Collections.Concurrent; | |||
@@ -36,86 +38,236 @@ namespace BPASmartClient.SmallBatchingSystem | |||
{ | |||
if (MakeOrderQueue.TryDequeue(out RecipeInfo recipeInfo)) | |||
{ | |||
IsCancel = false; | |||
List<int> OutletInfo = new List<int>(); | |||
recipeInfo.SiloInfoModels.ToList()?.ForEach(item => | |||
{ | |||
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); | |||
if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); | |||
}); | |||
foreach (var temp in OutletInfo) | |||
//ProcessOne(recipeInfo); | |||
ProcessTwo(recipeInfo); | |||
} | |||
} | |||
Thread.Sleep(10); | |||
}), "配方流程控制"); | |||
} | |||
private void ProcessOne(RecipeInfo recipeInfo) | |||
{ | |||
IsCancel = false; | |||
List<int> OutletInfo = new List<int>(); | |||
recipeInfo.SiloInfoModels.ToList()?.ForEach(item => | |||
{ | |||
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); | |||
if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); | |||
}); | |||
foreach (var temp in OutletInfo) | |||
{ | |||
PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 | |||
PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 | |||
RunLog($"启动定位,出料口位置:{temp}"); | |||
int index = temp - 1; | |||
if (index >= 0) | |||
{ | |||
RunLog("等待定位完成"); | |||
while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 | |||
if (IsCancel) break; | |||
RunLog("定位完成"); | |||
PlcServer.GetInstance.WriteData("M20.0", false); | |||
while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); | |||
if (IsCancel) break; | |||
RunLog("定位完成,复位成功"); | |||
foreach (var temp1 in recipeInfo.SiloInfoModels) | |||
{ | |||
var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); | |||
if (rest != null && rest.OutletLoc == temp) | |||
{ | |||
PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 | |||
PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 | |||
RunLog($"启动定位,出料口位置:{temp}"); | |||
int index = temp - 1; | |||
if (index >= 0) | |||
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); | |||
if (res != null) | |||
{ | |||
RunLog("等待定位完成"); | |||
while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 | |||
StatusNotify(res.SiloName, Status.正在配料); | |||
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}"); | |||
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)temp1.SiloWeight); | |||
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); | |||
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); | |||
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 | |||
if (IsCancel) break; | |||
RunLog("定位完成"); | |||
PlcServer.GetInstance.WriteData("M20.0", false); | |||
while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); | |||
RunLog("出料完成,复位出料完成状态"); | |||
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 | |||
while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 | |||
if (IsCancel) break; | |||
RunLog("定位完成,复位成功"); | |||
foreach (var temp1 in recipeInfo.SiloInfoModels) | |||
{ | |||
var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); | |||
if (rest != null && rest.OutletLoc == temp) | |||
{ | |||
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); | |||
if (res != null) | |||
{ | |||
StatusNotify(res.SiloName, Status.正在配料); | |||
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}"); | |||
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)temp1.SiloWeight); | |||
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); | |||
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); | |||
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 | |||
if (IsCancel) break; | |||
RunLog("出料完成,复位出料完成状态"); | |||
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 | |||
while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 | |||
if (IsCancel) break; | |||
RunLog("出料完成复位成功"); | |||
StatusNotify(res.SiloName, Status.配料完成); | |||
} | |||
} | |||
} | |||
if (IsCancel) return; | |||
RunLog("出料完成复位成功"); | |||
StatusNotify(res.SiloName, Status.配料完成); | |||
} | |||
} | |||
} | |||
if (IsCancel) return; | |||
} | |||
} | |||
if (!IsCancel) | |||
{ | |||
RunLog($"写入配方执行完成信号"); | |||
PlcServer.GetInstance.WriteData("M10.4", true); | |||
RunLog("等待配方执行完成"); | |||
while (!PlcDataModel.RecipeBatchingComplete && !IsCancel) Thread.Sleep(1); | |||
if (IsCancel) return; | |||
RunLog($"【{recipeInfo.RecipeName}】配方执行完成"); | |||
ActionManage.GetInstance.Send("GrindArenaceousCancel"); | |||
} | |||
} | |||
if (!IsCancel) | |||
/// <summary> | |||
/// 计时配料 | |||
/// </summary> | |||
/// <param name="recipeInfo"></param> | |||
private void ProcessTwo(RecipeInfo recipeInfo) | |||
{ | |||
IsCancel = false; | |||
Dictionary<int, List<int>> DeviceSoilInfo = new Dictionary<int, List<int>>(); | |||
List<int> OutletInfo = new List<int>(); | |||
recipeInfo.SiloInfoModels.ToList()?.ForEach(item => | |||
{ | |||
var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s == item.SiloName) != null); | |||
if (res != null) | |||
{ | |||
var soliInfo = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == item.SiloName); | |||
if (soliInfo != null) | |||
{ | |||
if (!DeviceSoilInfo.ContainsKey(res.OutletLoc)) | |||
{ | |||
DeviceSoilInfo.Add(res.OutletLoc, new List<int>()); | |||
DeviceSoilInfo[res.OutletLoc].Add(soliInfo.SiloLoc); | |||
} | |||
else | |||
{ | |||
RunLog($"写入配方执行完成信号"); | |||
PlcServer.GetInstance.WriteData("M10.4", true); | |||
RunLog("等待配方执行完成"); | |||
while (!PlcDataModel.RecipeBatchingComplete && !IsCancel) Thread.Sleep(1); | |||
if (IsCancel) break; | |||
RunLog($"【{recipeInfo.RecipeName}】配方执行完成"); | |||
ActionManage.GetInstance.Send("GrindArenaceousCancel"); | |||
DeviceSoilInfo[res.OutletLoc].Add(soliInfo.SiloLoc); | |||
} | |||
} | |||
} | |||
Thread.Sleep(10); | |||
}), "配方流程控制"); | |||
} | |||
}); | |||
private bool Wait(ref bool Targger, bool IsCancel = false) | |||
{ | |||
bool a = Targger; | |||
while (!IsCancel) | |||
foreach (var temp in DeviceSoilInfo) | |||
{ | |||
if (a) | |||
Thread.Sleep(1); | |||
PlcServer.GetInstance.WriteData("VW302", (ushort)temp.Key);//设置出料口位置 | |||
//PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 | |||
PlcServer.GetInstance.WriteData("M10.4", true);//定位启动 | |||
RunLog($"启动定位,出料口位置:{temp}"); | |||
int index = temp.Key - 1; | |||
if (index >= 0) | |||
{ | |||
RunLog("等待定位完成"); | |||
while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 | |||
if (IsCancel) break; | |||
RunLog("定位完成"); | |||
PlcServer.GetInstance.WriteData("M20.0", false); | |||
while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); | |||
if (IsCancel) break; | |||
RunLog("定位完成,复位成功"); | |||
foreach (var temp1 in temp.Value) | |||
{ | |||
//var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); | |||
//if (rest != null && rest.OutletLoc == temp) | |||
//{ | |||
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloLoc == temp1); | |||
if (res != null) | |||
{ | |||
var tempRecipe = recipeInfo.SiloInfoModels.FirstOrDefault(p => p.SiloName == res.SiloName); | |||
if (tempRecipe != null) | |||
{ | |||
StatusNotify(res.SiloName, Status.正在配料); | |||
RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{tempRecipe.SiloWeight}"); | |||
PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)(tempRecipe.SiloWeight * 10)); | |||
RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); | |||
PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); | |||
while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 | |||
if (IsCancel) break; | |||
RunLog("出料完成,复位出料完成状态"); | |||
#if test | |||
PlcServer.GetInstance.WriteData("M10.0", false);//复位出料完成信号 | |||
#else | |||
PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 | |||
#endif | |||
while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 | |||
if (IsCancel) break; | |||
RunLog("出料完成复位成功"); | |||
StatusNotify(res.SiloName, Status.配料完成); | |||
} | |||
} | |||
//} | |||
} | |||
if (IsCancel) return; | |||
} | |||
} | |||
return !IsCancel; | |||
} | |||
//IsCancel = false; | |||
//List<int> OutletInfo = new List<int>(); | |||
//recipeInfo.SiloInfoModels.ToList()?.ForEach(item => | |||
//{ | |||
// var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); | |||
// if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); | |||
//}); | |||
//foreach (var temp in OutletInfo) | |||
//{ | |||
// PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 | |||
// //PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 | |||
// PlcServer.GetInstance.WriteData("M10.4", true);//定位启动 | |||
// RunLog($"启动定位,出料口位置:{temp}"); | |||
// int index = temp - 1; | |||
// if (index >= 0) | |||
// { | |||
// RunLog("等待定位完成"); | |||
// while (!PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1);//等待定位反馈 | |||
// if (IsCancel) break; | |||
// RunLog("定位完成"); | |||
// PlcServer.GetInstance.WriteData("M20.0", false); | |||
// while (PlcDataModel.TargetLocComplete && !IsCancel) Thread.Sleep(1); | |||
// if (IsCancel) break; | |||
// RunLog("定位完成,复位成功"); | |||
// foreach (var temp1 in recipeInfo.SiloInfoModels) | |||
// { | |||
// var rest = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(temp1.SiloName)) != null); | |||
// if (rest != null && rest.OutletLoc == temp) | |||
// { | |||
// var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); | |||
// if (res != null) | |||
// { | |||
// StatusNotify(res.SiloName, Status.正在配料); | |||
// RunLog($"写重量地址:{GetWeightAdd(res.SiloLoc)},重量:{temp1.SiloWeight}"); | |||
// PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)(temp1.SiloWeight * 10)); | |||
// RunLog($"写启动信号地址:{GetStartSingleAdd(res.SiloLoc)}"); | |||
// PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); | |||
// while (!PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成 | |||
// if (IsCancel) break; | |||
// RunLog("出料完成,复位出料完成状态"); | |||
//#if test | |||
// PlcServer.GetInstance.WriteData("M10.0", false);//复位出料完成信号 | |||
//#else | |||
//PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 | |||
//#endif | |||
// while (PlcDataModel.BatchingCompleted && !IsCancel) Thread.Sleep(1);//等待出料完成信号复位成功 | |||
// if (IsCancel) break; | |||
// RunLog("出料完成复位成功"); | |||
// StatusNotify(res.SiloName, Status.配料完成); | |||
// } | |||
// } | |||
// } | |||
// if (IsCancel) return; | |||
// } | |||
//} | |||
if (!IsCancel) | |||
{ | |||
RunLog($"写入配方执行完成信号"); | |||
//PlcServer.GetInstance.WriteData("M10.4", true); | |||
PlcServer.GetInstance.WriteData("M10.5", true); | |||
RunLog("等待配方执行完成"); | |||
while (!PlcDataModel.RecipeBatchingComplete && !IsCancel) Thread.Sleep(1); | |||
if (IsCancel) return; | |||
RunLog($"【{recipeInfo.RecipeName}】配方执行完成"); | |||
ActionManage.GetInstance.Send("GrindArenaceousCancel"); | |||
} | |||
} | |||
/// <summary> | |||
/// 获取重量设置地址 | |||
/// </summary> | |||
@@ -123,10 +275,22 @@ namespace BPASmartClient.SmallBatchingSystem | |||
/// <returns></returns> | |||
private string GetWeightAdd(int num) | |||
{ | |||
#if test | |||
if (num > 0) | |||
{ | |||
int add = 0; | |||
if (num >= 1 && num <= 8) | |||
if (num >= 1 && num <= 18) | |||
{ | |||
add = 200 + (num - 1) * 2; | |||
} | |||
return $"VW{add}"; | |||
} | |||
return default; | |||
#else | |||
if (num > 0) | |||
{ | |||
int add = 0; | |||
if (num >= 1 && num <= 18) | |||
{ | |||
add = 100 + (num - 1) * 2; | |||
} | |||
@@ -137,6 +301,8 @@ namespace BPASmartClient.SmallBatchingSystem | |||
return $"VW{add}"; | |||
} | |||
return default; | |||
#endif | |||
} | |||
private void StatusNotify(string SiloName, Status Status) | |||
@@ -176,6 +342,7 @@ namespace BPASmartClient.SmallBatchingSystem | |||
/// <returns></returns> | |||
private string GetStartSingleAdd(int num) | |||
{ | |||
#if test | |||
if (num > 0) | |||
{ | |||
string Add = string.Empty; | |||
@@ -187,10 +354,28 @@ namespace BPASmartClient.SmallBatchingSystem | |||
c = 7; | |||
} | |||
else c--; | |||
Add = $"M{ t}.{c}"; | |||
Add = $"M{t + 4}.{c}"; | |||
return Add; | |||
} | |||
return default; | |||
#else | |||
if (num > 0) | |||
{ | |||
string Add = string.Empty; | |||
var t = num / 8; | |||
var c = (num % 8); | |||
if (c == 0) | |||
{ | |||
t--; | |||
c = 7; | |||
} | |||
else c--; | |||
Add = $"M{t}.{c}"; | |||
return Add; | |||
} | |||
return default; | |||
#endif | |||
} | |||
} | |||
@@ -27,13 +27,33 @@ namespace BPASmartClient.SmallBatchingSystem | |||
MessageLog.GetInstance.Show("设备连接成功"); | |||
ThreadManage.GetInstance().StartLong(new Action(() => | |||
{ | |||
//带称程序 | |||
//var res = ReadData("M20.0", 1);//到达目标位置信号 | |||
//if (res != null && res is bool[] bools && bools.Length == 1) | |||
//{ | |||
// PlcDataModel.TargetLocComplete = bools[0]; | |||
//} | |||
//var res1 = ReadData("M4.0", 1);//通道出料完成 | |||
//if (res1 != null && res1 is bool[] bools1 && bools1.Length == 1) | |||
//{ | |||
// PlcDataModel.BatchingCompleted = bools1[0]; | |||
//} | |||
//var res2 = ReadData("M13.3", 1);//配方配料完成,托盘在放碗或取碗位置 | |||
//if (res2 != null && res2 is bool[] bools2 && bools2.Length == 1) | |||
//{ | |||
// PlcDataModel.RecipeBatchingComplete = bools2[0]; | |||
//} | |||
//定时程序 | |||
var res = ReadData("M20.0", 1);//到达目标位置信号 | |||
if (res != null && res is bool[] bools && bools.Length == 1) | |||
{ | |||
PlcDataModel.TargetLocComplete = bools[0]; | |||
} | |||
var res1 = ReadData("M4.0", 1);//通道出料完成 | |||
var res1 = ReadData("M10.0", 1);//通道出料完成 | |||
if (res1 != null && res1 is bool[] bools1 && bools1.Length == 1) | |||
{ | |||
PlcDataModel.BatchingCompleted = bools1[0]; | |||
@@ -15,7 +15,7 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels | |||
{ | |||
public NewOutletViewModel() | |||
{ | |||
Json<ConfigInfoModel>.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); | |||
Json<ConfigInfoModel>.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add($"{item.SiloName}"); }); | |||
ActionManage.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
if (o != null && o is OutletInfoModel tempOutletInfo) | |||
@@ -24,7 +24,7 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels | |||
OutletLoc = tempOutletInfo.OutletLoc; | |||
tempOutletInfo.SiloInfos?.ToList()?.ForEach((item => | |||
{ | |||
int tempIndex = Array.FindIndex(SileName.ToArray(), p => p.Contains(item)); | |||
int tempIndex = Array.FindIndex(SileName.ToArray(), p => p == item); | |||
SiloInfos.Add(new RawMaterialInfo() { RawMaterialName = item, SelectIndex = tempIndex }); | |||
})); | |||
Index = Array.FindIndex(Json<ConfigInfoModel>.Data.OutletInfoModels.ToArray(), p => p.OutletName == tempOutletInfo.OutletName); | |||
@@ -40,6 +40,11 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels | |||
{ | |||
Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).OutletName = OutletName; | |||
Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).OutletLoc = OutletLoc; | |||
Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos.Clear(); | |||
//SileNames.ToList()?.ForEach(temp => | |||
//{ | |||
// Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos.Add(temp); | |||
//}); | |||
Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos = SileNames; | |||
Control.GetInstance.OperationLog($"{OutletName} 编辑完成"); | |||
} | |||
@@ -16,6 +16,20 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels | |||
CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("SiloClose"); }); | |||
SaveCommand = new RelayCommand(() => | |||
{ | |||
var res = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == SiloInfoModelObj.SiloName); | |||
if (res != null) | |||
{ | |||
ErrorInfo = "料仓名称已经存在!"; | |||
return; | |||
} | |||
var temp = Json<ConfigInfoModel>.Data.SiloInfoModels.FirstOrDefault(p => p.SiloLoc == SiloInfoModelObj.SiloLoc); | |||
if (temp != null) | |||
{ | |||
ErrorInfo = "料仓位置已存在!"; | |||
return; | |||
} | |||
if (Index >= 0 && Index < Json<ConfigInfoModel>.Data.SiloInfoModels.Count) | |||
{ | |||
Json<ConfigInfoModel>.Data.SiloInfoModels.ElementAt(Index).SiloName = SiloInfoModelObj.SiloName; | |||
@@ -29,13 +29,16 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels | |||
int index = Array.FindIndex(Json<ConfigInfoModel>.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); | |||
if (index >= 0 && index < Json<ConfigInfoModel>.Data.Recipes.Count) | |||
{ | |||
var data = Json<ConfigInfoModel>.Data.Recipes.ElementAt(index); | |||
Control.GetInstance.RunLog($"下发配方:{data.RecipeName}"); | |||
GrindArenaceousView grindArenaceousView = new GrindArenaceousView(); | |||
ActionManage.GetInstance.Send("OpenRecipeStatusMotion", data); | |||
Control.GetInstance.MakeOrderQueue.Enqueue(data); | |||
Control.GetInstance.NotifyPrompt("配方下发成功!"); | |||
grindArenaceousView.ShowDialog(); | |||
App.Current.Dispatcher.Invoke(() => | |||
{ | |||
var data = Json<ConfigInfoModel>.Data.Recipes.ElementAt(index); | |||
Control.GetInstance.RunLog($"下发配方:{data.RecipeName}"); | |||
GrindArenaceousView grindArenaceousView = new GrindArenaceousView(); | |||
ActionManage.GetInstance.Send("OpenRecipeStatusMotion", data); | |||
Control.GetInstance.MakeOrderQueue.Enqueue(data); | |||
Control.GetInstance.NotifyPrompt("配方下发成功!"); | |||
grindArenaceousView.ShowDialog(); | |||
}); | |||
} | |||
} | |||
} | |||
@@ -12,6 +12,7 @@ | |||
Height="400" | |||
AllowsTransparency="True" | |||
Background="{x:Null}" | |||
Topmost="True" | |||
WindowStartupLocation="CenterScreen" | |||
WindowStyle="None" | |||
mc:Ignorable="d"> | |||
@@ -123,7 +124,7 @@ | |||
Style="{StaticResource ImageButtonStyle}" /> | |||
</StackPanel> | |||
<Grid Grid.Row="2" Margin="15,0,10,0"> | |||
<Grid Grid.Row="2" Margin="15,0,10,10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="35" /> | |||
@@ -181,6 +182,7 @@ | |||
Grid.Column="0" | |||
Height="{Binding ElementName=gr, Path=ActualHeight}" | |||
VerticalAlignment="Center" | |||
HorizontalContentAlignment="Left" | |||
BorderBrush="#FF074B92" | |||
BorderThickness="1" | |||
FontFamily="楷体" | |||
@@ -10,6 +10,7 @@ | |||
Title="NewPfView" | |||
Width="500" | |||
Height="300" | |||
Topmost="True" | |||
AllowsTransparency="True" | |||
Background="{x:Null}" | |||
WindowStartupLocation="CenterScreen" | |||
@@ -93,7 +94,7 @@ | |||
Style="{StaticResource ImageButtonStyle}" /> | |||
</StackPanel> | |||
<Grid Grid.Row="2" Margin="15,0,10,0"> | |||
<Grid Grid.Row="2" Margin="15,0,10,10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="35" /> | |||
@@ -11,6 +11,7 @@ | |||
Height="300" | |||
AllowsTransparency="True" | |||
Background="{x:Null}" | |||
Topmost="True" | |||
WindowStartupLocation="CenterScreen" | |||
WindowStyle="None" | |||
mc:Ignorable="d"> | |||
@@ -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>(); | |||
@@ -77,7 +77,10 @@ | |||
<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" /> | |||
<ListBox x:Name="CtlList" Grid.Row="2" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Auto" | |||
ItemTemplate="{DynamicResource ToolBoxStyle}" FontSize="14" BorderThickness="0" | |||
PreviewMouseMove="CtlList_PreviewMouseMove" | |||
/> | |||
</Border> | |||
</TabItem> | |||
@@ -27,6 +27,7 @@ using System.Windows.Media.Animation; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
using System.Windows.Media.Effects; | |||
namespace BeDesignerSCADA.Controls | |||
{ | |||
@@ -49,6 +50,8 @@ namespace BeDesignerSCADA.Controls | |||
CtlList.ItemsSource = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name)?.ToList(); | |||
//读取文件 | |||
FileRead(_Path); | |||
//this.MouseLeftButtonUp += CanvasPanelNew_MouseLeftButtonUp; | |||
//this.MouseMove += CanvasPanelNew_MouseMove; | |||
} | |||
#region 位置调整 | |||
@@ -341,6 +344,84 @@ namespace BeDesignerSCADA.Controls | |||
#region 左侧控件栏移动 | |||
/// <summary> | |||
/// 当前拖动子控件流 | |||
/// </summary> | |||
private UIElement ChildElement; | |||
/// <summary> | |||
/// 是否已经按下 | |||
/// </summary> | |||
private bool isDown = false; | |||
/// <summary> | |||
/// 当前拖动的Pop窗体 | |||
/// </summary> | |||
private Popup DropPopup = null; | |||
/// <summary> | |||
/// 移动 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void CanvasPanelNew_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) | |||
{ | |||
try | |||
{ | |||
if (isDown == false) return; | |||
Point ptLeftUp = new Point(0, 0); | |||
Point ptRightDown = new Point(this.ActualWidth, this.ActualHeight); | |||
ptLeftUp = this.PointToScreen(ptLeftUp); | |||
ptRightDown = this.PointToScreen(ptRightDown); | |||
double y = e.GetPosition(CtlList).Y; | |||
double x = e.GetPosition(CtlList).X; | |||
if (DropPopup != null) | |||
{ | |||
//下面两句是设置Popup控件的位置除以2是想让鼠标在它的中心 | |||
DropPopup.HorizontalOffset = ptLeftUp.X + x - ((FrameworkElement)ChildElement).ActualWidth / 2; | |||
DropPopup.VerticalOffset = ptLeftUp.Y + y - ((FrameworkElement)ChildElement).ActualHeight / 2; | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 鼠标抬起事件 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void CanvasPanelNew_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) | |||
{ | |||
try | |||
{ | |||
//鼠标未按下返回 | |||
if (!isDown) return; | |||
isDown = false; | |||
//关闭Pop窗体 | |||
if (this.DropPopup != null) | |||
{ | |||
this.DropPopup.IsOpen = false; | |||
this.DropPopup.Child = null; | |||
this.DropPopup = null; | |||
} | |||
//蒙层关闭 | |||
ChildElement.ReleaseMouseCapture();//当控件具有鼠标捕获的话,则释放该捕获。 | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 移动到右侧 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
@@ -351,9 +432,70 @@ namespace BeDesignerSCADA.Controls | |||
{ | |||
DragDrop.DoDragDrop(CtlList, CtlList.SelectedItem, System.Windows.DragDropEffects.Copy); | |||
codeEditor.Text = cav.Save(); | |||
try | |||
{ | |||
//var control = Activator.CreateInstance(CtlList.SelectedItem as Type) as FrameworkElement; | |||
//string str = XamlWriter.Save(control); | |||
//ChildElement = (UIElement)XamlReader.Parse(str); | |||
//ChildElement.CaptureMouse();//设置了鼠标捕获,这样它可以不受到其它控件的影响。 | |||
////加蒙层,表明已经开始拖动 | |||
////暂时未加 | |||
//CreatePopup(ChildElement, null); | |||
//isDown = true; | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
} | |||
/// <summary> | |||
/// 创建浮动窗口 | |||
/// </summary> | |||
/// <param name="dragElement"></param> | |||
/// <param name="e"></param> | |||
private void CreatePopup(Visual dragElement, MouseButtonEventArgs e) | |||
{ | |||
//使用PointToScreen函数可以将点转换为屏幕坐标 | |||
//首先获取当前窗体的左上角和右下角两点的坐标 | |||
Point ptLeftUp = new Point(0, 0); | |||
//转换获取到这个窗口相对于屏幕两个坐标 | |||
ptLeftUp = this.PointToScreen(ptLeftUp); | |||
//获取myGrid的实际宽高 | |||
double y = 0;//e.GetPosition(CtlList).Y; | |||
double x = 0;// e.GetPosition(CtlList).X; | |||
this.DropPopup = new Popup(); | |||
Border border = new Border(); | |||
border.Margin = new Thickness(0, 0, 8, 8); | |||
DropShadowEffect effect = new DropShadowEffect(); | |||
effect.Opacity = 1; | |||
effect.ShadowDepth = -14; | |||
effect.BlurRadius = 9; | |||
effect.Color = Color.FromArgb(100, 0, 0, 0); | |||
border.Effect = effect; | |||
Rectangle r = new Rectangle(); | |||
r.Width = ((FrameworkElement)dragElement).ActualWidth; | |||
r.Height = ((FrameworkElement)dragElement).ActualHeight; | |||
r.Fill = new VisualBrush(dragElement); | |||
border.Child = r; | |||
this.DropPopup.Child = border; | |||
DropPopup.AllowsTransparency = true; | |||
DropPopup.HorizontalOffset = ptLeftUp.X + x - ((FrameworkElement)dragElement).ActualWidth / 2; | |||
DropPopup.VerticalOffset = ptLeftUp.Y + y - ((FrameworkElement)dragElement).ActualHeight / 2; | |||
this.DropPopup.IsOpen = true; | |||
} | |||
/// <summary> | |||
/// 显示代码 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
@@ -509,5 +651,7 @@ namespace BeDesignerSCADA.Controls | |||
} | |||
} | |||
#endregion | |||
} | |||
} |
@@ -12,61 +12,28 @@ | |||
<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> | |||
<WrapPanel x:Name="wrapanl_main" Orientation="Vertical" Style="{DynamicResource image矩阵框1}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Margin="0,5,0,25"> | |||
<Grid> | |||
<Border x:Name="main" > | |||
</Border> | |||
<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" | |||
<StackPanel x:Name="waibustack" Orientation="Horizontal" MouseMove="wrapanl_main_MouseMove" MouseLeave="wrapanl_main_MouseLeave" > | |||
<WrapPanel Style="{DynamicResource image矩阵框1}" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Stretch" x:Name="wrapanl_main" Orientation="Vertical"> | |||
<TextBlock x:Name="TitleName" Style="{DynamicResource imageTextBlock}" Padding="10" Foreground="#FFFFA500" FontSize="18" TextWrapping="Wrap" MaxWidth="118" 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}" | |||
ItemsSource="{Binding MenuModel.pageModels,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" | |||
Background="Transparent" | |||
ScrollViewer.VerticalScrollBarVisibility="Auto" | |||
ScrollViewer.HorizontalScrollBarVisibility="Auto" | |||
ItemTemplate="{DynamicResource X_PageBoxStyle}" FontSize="14" BorderThickness="0" > | |||
</ListBox> | |||
</WrapPanel> | |||
</ListBox> | |||
</WrapPanel> | |||
<Border x:Name="lachu" Background="Transparent" Width="30" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,0,0,25" BorderBrush="Aqua" BorderThickness="0,0,1,0"> | |||
<Image x:Name="lachuStyle" Style="{DynamicResource image右1}" Width="70" Height="30"></Image> | |||
</Border> | |||
</StackPanel> | |||
</Grid> | |||
</UserControl> |
@@ -16,9 +16,11 @@ using System.Windows.Documents; | |||
using System.Windows.Input; | |||
using System.Windows.Markup; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Animation; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
using System.Windows.Threading; | |||
namespace BeDesignerSCADA.Controls | |||
{ | |||
@@ -28,27 +30,52 @@ namespace BeDesignerSCADA.Controls | |||
public partial class MenuRunCanvas : UserControl | |||
{ | |||
MenuRunCanvasModel menuRunCanvasModel = null; | |||
ResourceDictionary languageResDic = new ResourceDictionary(); | |||
DispatcherTimer timer1;//控制菜单显示隐藏功能 | |||
public MenuRunCanvas() | |||
{ | |||
InitializeComponent(); | |||
menuRunCanvasModel=new MenuRunCanvasModel(); | |||
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute); | |||
menuRunCanvasModel =new MenuRunCanvasModel(); | |||
this.DataContext=menuRunCanvasModel; | |||
Unloaded += (s, e) => Destory(); | |||
timer1 = new DispatcherTimer(); | |||
timer1.Tick += new System.EventHandler(timer1_Tick); | |||
timer1.Interval = new TimeSpan(0, 0, 0, 0, 1000); | |||
timer1.Start(); | |||
this.Loaded += MenuRunCanvas_Loaded; | |||
} | |||
/// <summary> | |||
/// 停止 | |||
/// </summary> | |||
public void Destory() | |||
private void MenuRunCanvas_Loaded(object sender, RoutedEventArgs e) | |||
{ | |||
foreach (var item in RootCanvas.Children) | |||
if (menuRunCanvasModel.MenuModel != null) | |||
{ | |||
if (item is IDisposable disposable) | |||
switch (menuRunCanvasModel.MenuModel.Alignment) | |||
{ | |||
disposable.Dispose(); | |||
case MenuAlignment.左边: | |||
menuWidth = wrapanl_main.ActualWidth; | |||
break; | |||
case MenuAlignment.顶部: | |||
menuWidth = wrapanl_main.ActualHeight; | |||
break; | |||
case MenuAlignment.右边: | |||
menuWidth = wrapanl_main.ActualWidth; | |||
break; | |||
case MenuAlignment.底部: | |||
menuWidth = wrapanl_main.ActualHeight; | |||
break; | |||
default: | |||
break; | |||
} | |||
MenuSmall(); | |||
} | |||
} | |||
private void timer1_Tick(object sender, EventArgs e) | |||
{ | |||
times += 1; | |||
} | |||
/// <summary> | |||
/// 根据路径运行程序 | |||
/// </summary> | |||
@@ -74,7 +101,13 @@ namespace BeDesignerSCADA.Controls | |||
wrapanl_main.Orientation = Orientation.Vertical; | |||
wrapanl_main.HorizontalAlignment = HorizontalAlignment.Left; | |||
wrapanl_main.VerticalAlignment = VerticalAlignment.Stretch; | |||
wrapanl_main.Margin = new Thickness(0, 0, 0, 25); | |||
TitleName.Margin = new Thickness(0, 10, 0, 10); | |||
waibustack.Orientation = Orientation.Horizontal; | |||
waibustack.HorizontalAlignment = HorizontalAlignment.Left; | |||
lachu.HorizontalAlignment = HorizontalAlignment.Left; | |||
lachu.VerticalAlignment = VerticalAlignment.Stretch; | |||
lachu.BorderThickness = new Thickness(1, 0, 0, 0); | |||
break; | |||
case MenuAlignment.顶部: | |||
PageList.HorizontalAlignment = HorizontalAlignment.Left; | |||
@@ -83,8 +116,15 @@ namespace BeDesignerSCADA.Controls | |||
wrapanl_main.Orientation = Orientation.Horizontal; | |||
wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch; | |||
wrapanl_main.VerticalAlignment = VerticalAlignment.Top; | |||
TitleName.LayoutTransform = new RotateTransform(){ Angle = 270 }; | |||
wrapanl_main.Margin = new Thickness(0, 0, 0, 0); | |||
TitleName.LayoutTransform = new RotateTransform(){ Angle = 0 }; | |||
TitleName.Margin = new Thickness(10, 0,10, 0); | |||
waibustack.Orientation = Orientation.Vertical; | |||
waibustack.VerticalAlignment = VerticalAlignment.Top; | |||
lachu.HorizontalAlignment = HorizontalAlignment.Stretch; | |||
lachu.VerticalAlignment = VerticalAlignment.Top; | |||
lachu.LayoutTransform = new RotateTransform() { Angle = 270 }; | |||
lachu.BorderThickness = new Thickness(0, 0, 1, 0); | |||
break; | |||
case MenuAlignment.右边: | |||
PageList.HorizontalAlignment = HorizontalAlignment.Right; | |||
@@ -93,7 +133,14 @@ namespace BeDesignerSCADA.Controls | |||
wrapanl_main.Orientation = Orientation.Vertical; | |||
wrapanl_main.HorizontalAlignment = HorizontalAlignment.Right; | |||
wrapanl_main.VerticalAlignment = VerticalAlignment.Stretch; | |||
wrapanl_main.Margin = new Thickness(0, 0, 0, 25); | |||
TitleName.Margin = new Thickness(0, 10, 0, 10); | |||
menuWidth = wrapanl_main.ActualWidth; | |||
waibustack.Orientation = Orientation.Horizontal; | |||
waibustack.HorizontalAlignment = HorizontalAlignment.Right; | |||
lachu.HorizontalAlignment = HorizontalAlignment.Right; | |||
lachu.VerticalAlignment = VerticalAlignment.Stretch; | |||
lachu.BorderThickness = new Thickness(0, 0,0, 0); | |||
break; | |||
case MenuAlignment.底部: | |||
PageList.HorizontalAlignment = HorizontalAlignment.Left; | |||
@@ -102,167 +149,140 @@ namespace BeDesignerSCADA.Controls | |||
wrapanl_main.Orientation = Orientation.Horizontal; | |||
wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch; | |||
wrapanl_main.VerticalAlignment = VerticalAlignment.Bottom; | |||
TitleName.LayoutTransform = new RotateTransform() { Angle = 270 }; | |||
wrapanl_main.Margin = new Thickness(0, 0, 0, 0); | |||
TitleName.LayoutTransform = new RotateTransform() { Angle = 0 }; | |||
TitleName.Margin = new Thickness(10, 0, 10, 0); | |||
menuWidth = wrapanl_main.ActualHeight; | |||
waibustack.Orientation = Orientation.Vertical; | |||
waibustack.VerticalAlignment = VerticalAlignment.Bottom; | |||
lachu.HorizontalAlignment = HorizontalAlignment.Stretch; | |||
lachu.VerticalAlignment = VerticalAlignment.Bottom; | |||
lachu.LayoutTransform = new RotateTransform() { Angle = 270 }; | |||
lachu.BorderThickness= new Thickness(0, 0, 0, 0); | |||
break; | |||
default: | |||
break; | |||
} | |||
if(canvas.IsVisibility) | |||
wrapanl_main.Visibility = Visibility.Visible; | |||
waibustack.Visibility = Visibility.Visible; | |||
else | |||
wrapanl_main.Visibility = Visibility.Collapsed; | |||
waibustack.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; | |||
main.Child = menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas; | |||
menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas.RunSelect(); | |||
} | |||
SelectMenu(); | |||
} | |||
bool ismove = true; | |||
int times = 0; | |||
/// <summary> | |||
/// 选中菜单 | |||
/// 鼠标移动 | |||
/// </summary> | |||
public void SelectMenu() | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void wrapanl_main_MouseMove(object sender, MouseEventArgs e) | |||
{ | |||
try | |||
if (times < 1) | |||
{ | |||
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); | |||
return; | |||
} | |||
catch (Exception ex) | |||
if (ismove) | |||
{ | |||
ismove = false; | |||
MenuBig(); | |||
} | |||
times = 0; | |||
} | |||
/// <summary> | |||
/// 运行 | |||
/// 鼠标离开 | |||
/// </summary> | |||
/// <param name="canvas"></param> | |||
public void Run(List<FrameworkElement> canvas) | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void wrapanl_main_MouseLeave(object sender, MouseEventArgs e) | |||
{ | |||
Config.GetInstance().Reset(); | |||
RootCanvas.Children.Clear(); | |||
foreach (FrameworkElement element in canvas) | |||
menuWidthDefault = 0; | |||
if (!ismove) | |||
{ | |||
if (element is IExecutable executable) | |||
executable.IsExecuteState = true; | |||
RootCanvas.Children.Add(element); | |||
RegisterJsName(element); | |||
ismove = true; | |||
MenuSmall(); | |||
} | |||
times = 0; | |||
} | |||
#region 拖动与缩放 | |||
// 注册名称到Js | |||
static void RegisterJsName(FrameworkElement element) | |||
private int menuWidthDefault = 0; | |||
private double menuWidth = 86; | |||
private void MenuBig() | |||
{ | |||
Config.GetInstance().SetVariable(element.Name, element); | |||
if (element is Panel panel) | |||
DoubleAnimation da = new DoubleAnimation(); | |||
da.From = menuWidthDefault; | |||
da.To = menuWidth; | |||
da.Duration = TimeSpan.FromSeconds(0.5); | |||
if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边) | |||
{ | |||
foreach (var item in panel.Children) | |||
{ | |||
RegisterJsName(item as FrameworkElement); | |||
} | |||
wrapanl_main.BeginAnimation(WidthProperty, da); | |||
if (languageResDic.Contains("image左1")) | |||
lachuStyle.Style = languageResDic["image左1"] as Style; | |||
} | |||
} | |||
private void RootCanvas_MouseMove(object sender, MouseEventArgs e) | |||
{ | |||
if (DragEnable.IsChecked == false) | |||
else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部) | |||
{ | |||
return; | |||
wrapanl_main.BeginAnimation(HeightProperty, da); | |||
if (languageResDic.Contains("image右1")) | |||
lachuStyle.Style = languageResDic["image右1"] as Style; | |||
} | |||
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) | |||
private void MenuSmall() | |||
{ | |||
if (ZoomEnable.IsChecked == false) | |||
DoubleAnimation da = new DoubleAnimation(); | |||
da.From = menuWidth; | |||
da.To = menuWidthDefault; | |||
da.Duration = TimeSpan.FromSeconds(0.5); | |||
if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边) | |||
{ | |||
return; | |||
if (languageResDic.Contains("image右1")) | |||
lachuStyle.Style = languageResDic["image右1"] as Style; | |||
wrapanl_main.BeginAnimation(WidthProperty, da); | |||
} | |||
var zoomS = (e.Delta / 960d); | |||
var zoom = zoomS + Scale.ScaleX; | |||
if (zoom > 3 || zoom < 0.8) | |||
else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部) | |||
{ | |||
return; | |||
wrapanl_main.BeginAnimation(HeightProperty, da); | |||
if (languageResDic.Contains("image左1")) | |||
lachuStyle.Style = languageResDic["image左1"] as Style; | |||
} | |||
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 | |||
} | |||
/// <summary> | |||
/// 运行Model | |||
/// </summary> | |||
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 +300,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 +317,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(); | |||
@@ -239,10 +239,6 @@ | |||
<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> | |||
@@ -3,6 +3,6 @@ | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:local="clr-namespace:WPFDemo" | |||
StartupUri="Window1.xaml"> | |||
StartupUri="Window2.xaml"> | |||
<Application.Resources /> | |||
</Application> |
@@ -8,6 +8,7 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<None Remove="bj.png" /> | |||
<None Remove="device.png" /> | |||
</ItemGroup> | |||
@@ -25,6 +26,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Resource Include="bj.png" /> | |||
<Resource Include="device.png"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</Resource> | |||
@@ -0,0 +1,36 @@ | |||
<Window x:Class="WPFDemo.Window2" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:local="clr-namespace:WPFDemo" | |||
mc:Ignorable="d" | |||
Title="Window2" Height="450" Width="800"> | |||
<Grid> | |||
<Grid.Background> | |||
<ImageBrush ImageSource="/bj.png"/> | |||
</Grid.Background> | |||
<ListView x:Name="lisbox" ItemsSource="{Binding ViewItems,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" | |||
Background="{x:Null}" Foreground="White" | |||
PreviewMouseMove="ListView_PreviewMouseMove" | |||
PreviewMouseLeftButtonUp="lisbox_PreviewMouseLeftButtonUp"> | |||
<ListBox.ItemTemplate> | |||
<ItemContainerTemplate> | |||
<Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown" > | |||
<Border BorderBrush="Aquamarine" BorderThickness="1" Padding="5"> | |||
<Grid> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition/> | |||
<ColumnDefinition/> | |||
</Grid.ColumnDefinitions> | |||
<TextBlock Grid.Column="0" Text="{Binding Name,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"></TextBlock> | |||
<TextBlock Grid.Column="1" Text="{Binding Ph,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"></TextBlock> | |||
</Grid> | |||
</Border> | |||
</Grid> | |||
</ItemContainerTemplate> | |||
</ListBox.ItemTemplate> | |||
</ListView> | |||
</Grid> | |||
</Window> |
@@ -0,0 +1,329 @@ | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
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; | |||
using System.Windows.Controls.Primitives; | |||
using System.Windows.Data; | |||
using System.Windows.Documents; | |||
using System.Windows.Input; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Effects; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Shapes; | |||
namespace WPFDemo | |||
{ | |||
/// <summary> | |||
/// Window2.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class Window2 : Window | |||
{ | |||
TestModel testModel=new TestModel(); | |||
public Window2() | |||
{ | |||
InitializeComponent(); | |||
this.DataContext = testModel; | |||
testModel.ViewItems.Add(new PageModel {Name="张三", Ph="125486545" }); | |||
testModel.ViewItems.Add(new PageModel { Name = "李四", Ph = "125486545" }); | |||
testModel.ViewItems.Add(new PageModel { Name = "王麻子", Ph = "125486545" }); | |||
testModel.ViewItems.Add(new PageModel { Name = "二货", Ph = "125486545" }); | |||
} | |||
#region 移动事件 | |||
/// <summary> | |||
/// 当前拖动子控件流 | |||
/// </summary> | |||
private UIElement ChildElement; | |||
/// <summary> | |||
/// 是否已经按下 | |||
/// </summary> | |||
private bool isDown = false; | |||
/// <summary> | |||
/// 按下记录初始鼠标点位 | |||
/// 鼠标相对与拖动子控件的位置(偏移量) | |||
/// </summary> | |||
private Point InitPoint; | |||
/// <summary> | |||
/// 当前拖动的Pop窗体 | |||
/// </summary> | |||
private Popup DropPopup = null; | |||
/// <summary> | |||
/// 鼠标按下事件 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) | |||
{ | |||
try | |||
{ | |||
//isDown变量是防止多次操作。 | |||
if (isDown) | |||
{ | |||
isDown = false; | |||
return; | |||
} | |||
ChildElement = (UIElement)sender; | |||
ChildElement.CaptureMouse();//设置了鼠标捕获,这样它可以不受到其它控件的影响。 | |||
InitPoint= new Point(e.GetPosition(ChildElement).X, e.GetPosition(ChildElement).Y); | |||
//加蒙层,表明已经开始拖动 | |||
//暂时未加 | |||
CreatePopup(ChildElement, e); | |||
isDown = true; | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 鼠标抬起事件 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void lisbox_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) | |||
{ | |||
try | |||
{ | |||
//鼠标未按下返回 | |||
if (!isDown) return; | |||
isDown = false; | |||
//关闭Pop窗体 | |||
if (this.DropPopup != null) | |||
{ | |||
this.DropPopup.IsOpen = false; | |||
this.DropPopup.Child = null; | |||
this.DropPopup = null; | |||
} | |||
//蒙层关闭 | |||
ChildElement.ReleaseMouseCapture();//当控件具有鼠标捕获的话,则释放该捕获。 | |||
//double y = e.GetPosition(this).Y;//获取鼠标抬起时的控件的位置 Y值 | |||
//double start = 0.0; | |||
//int row = 0; | |||
//foreach (RowDefinition rd in myGrid.RowDefinitions) | |||
//{ | |||
// start += rd.ActualHeight; | |||
// if (y < start) | |||
// { | |||
// break; | |||
// } | |||
// row++; | |||
//} | |||
//double x = e.GetPosition(myGrid).X;//获取鼠标抬起时的控件的位置 X值 | |||
//double cstart = 0.0; | |||
//int column = 0; | |||
//foreach (ColumnDefinition cd in myGrid.ColumnDefinitions) | |||
//{ | |||
// cstart += cd.ActualWidth; | |||
// if (x < cstart) | |||
// { | |||
// break; | |||
// } | |||
// column++; | |||
//} | |||
//var initRow = Grid.GetRow(ultUE);//找到控件所在的行 | |||
//var initCol = Grid.GetColumn(ultUE);//找到控件所在的列 | |||
//UIElement uIElement = null; | |||
//if (row != initRow || column != initCol) | |||
//{ | |||
// uIElement = GetChildren(myGrid, row, column); | |||
//} | |||
//if (uIElement != null) | |||
//{ | |||
// //下面是交换两个控件的位置 (需要先移除再加载) | |||
// myGrid.Children.Remove(uIElement); | |||
// Grid.SetColumn(ultUE, column);//指定控件在grid中哪行哪例 | |||
// Grid.SetRow(ultUE, row); | |||
// myGrid.Children.Add(uIElement); | |||
// Grid.SetColumn(uIElement, initCol); | |||
// Grid.SetRow(uIElement, initRow); | |||
//} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 鼠标移动事件 | |||
/// </summary> | |||
/// <param name="sender"></param> | |||
/// <param name="e"></param> | |||
private void ListView_PreviewMouseMove(object sender, MouseEventArgs e) | |||
{ | |||
try | |||
{ | |||
if (isDown == false) return; | |||
Point ptLeftUp = new Point(0, 0); | |||
Point ptRightDown = new Point(this.ActualWidth, this.ActualHeight); | |||
ptLeftUp = this.PointToScreen(ptLeftUp); | |||
ptRightDown = this.PointToScreen(ptRightDown); | |||
double y = e.GetPosition(lisbox).Y; | |||
double x = e.GetPosition(lisbox).X; | |||
if (DropPopup != null) | |||
{ | |||
//下面两句是设置Popup控件的位置除以2是想让鼠标在它的中心 | |||
DropPopup.HorizontalOffset = ptLeftUp.X + x - ((FrameworkElement)ChildElement).ActualWidth / 2; | |||
DropPopup.VerticalOffset = ptLeftUp.Y + y - ((FrameworkElement)ChildElement).ActualHeight / 2; | |||
} | |||
//double start = 0.0; | |||
//int row = 0; | |||
//foreach (RowDefinition rd in myGrid.RowDefinitions) | |||
//{ | |||
// start += rd.ActualHeight; | |||
// if (y < start) | |||
// { | |||
// break; | |||
// } | |||
// row++; | |||
//} | |||
//double cstart = 0.0; | |||
//int column = 0; | |||
//foreach (ColumnDefinition cd in myGrid.ColumnDefinitions) | |||
//{ | |||
// cstart += cd.ActualWidth; | |||
// if (x < cstart) | |||
// { | |||
// break; | |||
// } | |||
// column++; | |||
//} | |||
////下面的代码是当鼠标移动到哪个格子哪个格子就会亮起来。 | |||
//UIElement uIElement = GetChildren(myGrid, row, column); | |||
//foreach (UIElement element in myGrid.Children) | |||
//{ | |||
// if (element != ultUE && element != uIElement) | |||
// { | |||
// element.Opacity = moveOpacity; | |||
// } | |||
// else | |||
// { | |||
// element.Opacity = 1; | |||
// } | |||
//} | |||
} | |||
catch (Exception ex) | |||
{ | |||
} | |||
} | |||
/// <summary> | |||
/// 创建浮动窗口 | |||
/// </summary> | |||
/// <param name="dragElement"></param> | |||
/// <param name="e"></param> | |||
private void CreatePopup(Visual dragElement, MouseButtonEventArgs e) | |||
{ | |||
//使用PointToScreen函数可以将点转换为屏幕坐标 | |||
//首先获取当前窗体的左上角和右下角两点的坐标 | |||
Point ptLeftUp = new Point(0, 0); | |||
//转换获取到这个窗口相对于屏幕两个坐标 | |||
ptLeftUp = this.PointToScreen(ptLeftUp); | |||
//获取myGrid的实际宽高 | |||
double y = e.GetPosition(this).Y; | |||
double x = e.GetPosition(this).X; | |||
this.DropPopup = new Popup(); | |||
Border border = new Border(); | |||
border.Margin = new Thickness(0, 0, 8, 8); | |||
DropShadowEffect effect = new DropShadowEffect(); | |||
effect.Opacity = 1; | |||
effect.ShadowDepth = -14; | |||
effect.BlurRadius = 9; | |||
effect.Color = Color.FromArgb(100, 0, 0, 0); | |||
border.Effect = effect; | |||
Rectangle r = new Rectangle(); | |||
r.Width = ((FrameworkElement)dragElement).ActualWidth; | |||
r.Height = ((FrameworkElement)dragElement).ActualHeight; | |||
r.Fill = new VisualBrush(dragElement); | |||
border.Child = r; | |||
this.DropPopup.Child = border; | |||
DropPopup.AllowsTransparency = true; | |||
DropPopup.HorizontalOffset = ptLeftUp.X + x - ((FrameworkElement)dragElement).ActualWidth / 2; | |||
DropPopup.VerticalOffset = ptLeftUp.Y + y - ((FrameworkElement)dragElement).ActualHeight / 2; | |||
this.DropPopup.IsOpen = true; | |||
} | |||
#endregion | |||
} | |||
public class TestModel : ObservableObject | |||
{ | |||
private ObservableCollection<PageModel> _pageModels; | |||
public ObservableCollection<PageModel> ViewItems | |||
{ | |||
get | |||
{ | |||
return _pageModels; | |||
} | |||
set | |||
{ | |||
_pageModels = value; | |||
OnPropertyChanged("ViewItems"); | |||
} | |||
} | |||
public TestModel() | |||
{ | |||
ViewItems=new ObservableCollection<PageModel>(); | |||
} | |||
} | |||
public class PageModel : ObservableObject | |||
{ | |||
private string _Name; | |||
public string Name | |||
{ | |||
get | |||
{ | |||
return _Name; | |||
} | |||
set | |||
{ | |||
_Name = value; | |||
OnPropertyChanged("Name"); | |||
} | |||
} | |||
private string _Ph; | |||
public string Ph | |||
{ | |||
get | |||
{ | |||
return _Ph; | |||
} | |||
set | |||
{ | |||
_Ph = value; | |||
OnPropertyChanged("Ph"); | |||
} | |||
} | |||
} | |||
} |