@@ -0,0 +1,167 @@ | |||||
using System; | |||||
using System.Windows; | |||||
using System.Windows.Controls; | |||||
namespace BPASmartClient.SCADAControl.Converters | |||||
{ | |||||
public class HoneycombPanel : Panel | |||||
{ | |||||
private double _unitLength; | |||||
private HoneycombStuffer _stuffer; | |||||
private static int GetXCount(int count) | |||||
{ | |||||
if (count == 0) return 0; | |||||
count -= 1; | |||||
var index = (int)Math.Floor(Math.Pow((12.0 * count + 25) / 36, 0.5) - 5.0 / 6); | |||||
var valeIndex = 3 * index * index + 5 * index; | |||||
var centerValue = valeIndex + 2; | |||||
return count >= centerValue | |||||
? 4 * index + 6 | |||||
: count > valeIndex | |||||
? 4 * index + 4 | |||||
: 4 * index + 2; | |||||
} | |||||
private static int GetYCount(int count) | |||||
{ | |||||
if (count == 0) return 0; | |||||
count -= 1; | |||||
var index = (int)Math.Floor(Math.Pow(count / 3.0 + 0.25, 0.5) - 0.5); | |||||
var valeIndex = 3 * index * index + 3 * index; | |||||
return count > valeIndex | |||||
? 2 * index + 2 | |||||
: 2 * index; | |||||
} | |||||
/* | |||||
* layout order | |||||
* | |||||
* ● ● | |||||
* (7) (8) | |||||
* | |||||
* ● ● ● | |||||
* (6) (1) (9) | |||||
* | |||||
* ● ● ● ... | |||||
* (5) (0) (2) | |||||
* | |||||
* ● ● ... | |||||
* (4) (3) | |||||
* | |||||
*/ | |||||
protected override Size MeasureOverride(Size availableSize) | |||||
{ | |||||
var maxSize = new Size(); | |||||
foreach (UIElement child in InternalChildren) | |||||
{ | |||||
if (child != null) | |||||
{ | |||||
child.Measure(availableSize); | |||||
maxSize.Width = Math.Max(maxSize.Width, child.DesiredSize.Width); | |||||
maxSize.Height = Math.Max(maxSize.Height, child.DesiredSize.Height); | |||||
} | |||||
} | |||||
_unitLength = Math.Max(maxSize.Width, maxSize.Height) / 2; | |||||
var xCount = GetXCount(InternalChildren.Count); | |||||
var yCount = GetYCount(InternalChildren.Count); | |||||
var availableWidth = xCount * _unitLength; | |||||
var availableHeight = yCount * Math.Pow(3, 0.5) * _unitLength + _unitLength * 2; | |||||
return new Size(availableWidth, availableHeight); | |||||
} | |||||
protected override Size ArrangeOverride(Size finalSize) | |||||
{ | |||||
var childLength = _unitLength * 2; | |||||
_stuffer = new HoneycombStuffer(new Rect(finalSize.Width / 2 - _unitLength, | |||||
finalSize.Height / 2 - _unitLength, childLength, childLength)); | |||||
foreach (UIElement child in InternalChildren) | |||||
{ | |||||
child.Arrange(_stuffer.Move()); | |||||
} | |||||
return finalSize; | |||||
} | |||||
private class HoneycombStuffer | |||||
{ | |||||
private int _turns; | |||||
private int _maxIndex; | |||||
private int _currentIndex = -1; | |||||
private readonly double _offsetX; | |||||
private readonly double _offsetY; | |||||
private Rect _childBounds; | |||||
private readonly double[] _offsetXArr; | |||||
private readonly double[] _offsetYArr; | |||||
public HoneycombStuffer(Rect childBounds) | |||||
{ | |||||
_childBounds = childBounds; | |||||
_offsetX = childBounds.Width / 2; | |||||
_offsetY = Math.Pow(3, 0.5) * _offsetX; | |||||
_offsetXArr = new[] | |||||
{ | |||||
2 * _offsetX, | |||||
_offsetX, | |||||
-_offsetX, | |||||
-2 * _offsetX, | |||||
-_offsetX, | |||||
_offsetX | |||||
}; | |||||
_offsetYArr = new[] | |||||
{ | |||||
0, | |||||
_offsetY, | |||||
_offsetY, | |||||
0, | |||||
-_offsetY, | |||||
-_offsetY | |||||
}; | |||||
} | |||||
public Rect Move() | |||||
{ | |||||
_currentIndex++; | |||||
if (_currentIndex > _maxIndex) | |||||
{ | |||||
_turns++; | |||||
_maxIndex = _turns * 6 - 1; | |||||
_currentIndex = 0; | |||||
_childBounds.Offset(_offsetX, -_offsetY); | |||||
return _childBounds; | |||||
} | |||||
if (_turns > 0) | |||||
{ | |||||
var index = _currentIndex / _turns; | |||||
_childBounds.Offset(_offsetXArr[index], _offsetYArr[index]); | |||||
} | |||||
return _childBounds; | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,87 @@ | |||||
<UserControl x:Class="BPASmartClient.SCADAControl.CustomerControls.TheWuLiaoControl" | |||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||||
xmlns:kj="clr-namespace:BPASmartClient.SCADAControl.Converters" | |||||
xmlns:local="clr-namespace:BPASmartClient.SCADAControl.CustomerControls" | |||||
mc:Ignorable="d" | |||||
x:Name="main" | |||||
Width="200" Height="200"> | |||||
<UserControl.Resources> | |||||
<Style x:Key="ListBoxItemCustom" TargetType="ListBoxItem"> | |||||
<Setter Property="SnapsToDevicePixels" Value="True" /> | |||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" /> | |||||
<Setter Property="Padding" Value="0" /> | |||||
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType=ItemsControl}}" /> | |||||
<Setter Property="VerticalContentAlignment" Value="Top" /> | |||||
<Setter Property="Background" Value="Transparent" /> | |||||
<Setter Property="BorderBrush" Value="Transparent" /> | |||||
<Setter Property="BorderThickness" Value="0" /> | |||||
<Setter Property="Template"> | |||||
<Setter.Value> | |||||
<ControlTemplate TargetType="ListBoxItem"> | |||||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> | |||||
</ControlTemplate> | |||||
</Setter.Value> | |||||
</Setter> | |||||
</Style> | |||||
<Style x:Key="ListBoxBaseStyle" TargetType="ListBox"> | |||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" /> | |||||
<Setter Property="BorderThickness" Value="1" /> | |||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /> | |||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> | |||||
<Setter Property="ScrollViewer.CanContentScroll" Value="true" /> | |||||
<Setter Property="ScrollViewer.PanningMode" Value="Both" /> | |||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False" /> | |||||
<Setter Property="VerticalContentAlignment" Value="Center" /> | |||||
<Setter Property="Padding" Value="2,2,2,0" /> | |||||
</Style> | |||||
<Style x:Key="ListBoxCustom" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"> | |||||
<Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemCustom}" /> | |||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> | |||||
</Style> | |||||
</UserControl.Resources> | |||||
<Grid> | |||||
<Ellipse Fill="Transparent" Stroke="{Binding Foreground, ElementName=main}" StrokeThickness="{Binding BorderThickness, ElementName=main}" Width="{Binding Width, ElementName=main}" Height="{Binding Width, ElementName=main}"/> | |||||
<Viewbox Width="auto" Height="auto" > | |||||
<Grid> | |||||
<ListBox Background="Transparent" Margin="30" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl},Path=vs}" Style="{DynamicResource ListBoxCustom}" BorderThickness="0" > | |||||
<ListBox.ItemsPanel> | |||||
<ItemsPanelTemplate> | |||||
<kj:HoneycombPanel /> | |||||
</ItemsPanelTemplate> | |||||
</ListBox.ItemsPanel> | |||||
<ListBox.ItemTemplate> | |||||
<DataTemplate> | |||||
<Grid Width="150" Height="150" Margin="10"> | |||||
<Ellipse Width="140" Height="140" Fill="Transparent" Stroke="{Binding Foreground, ElementName=main}" StrokeThickness="{Binding BorderThickness, ElementName=main}"/> | |||||
<TextBlock Text="一号料仓" Margin="0,-10,0,0" Foreground="{Binding Foreground, ElementName=main}" HorizontalAlignment="Center"></TextBlock> | |||||
<Viewbox Width="auto" Height="auto"> | |||||
<ListBox Background="Transparent" ItemsSource="{Binding dataModel}" Style="{DynamicResource ListBoxCustom}" BorderThickness="0" > | |||||
<ListBox.ItemsPanel> | |||||
<ItemsPanelTemplate> | |||||
<kj:HoneycombPanel /> | |||||
</ItemsPanelTemplate> | |||||
</ListBox.ItemsPanel> | |||||
<ListBox.ItemTemplate> | |||||
<DataTemplate> | |||||
<Grid> | |||||
<Ellipse Width="100" Height="100" Fill="Transparent" Stroke="{Binding Foreground, ElementName=main}" StrokeThickness="{Binding BorderThickness, ElementName=main}" Margin="10"/> | |||||
<TextBlock HorizontalAlignment="Center" Foreground="{Binding Foreground, ElementName=main}" VerticalAlignment="Center" FontSize="24" Text="味精"></TextBlock> | |||||
</Grid> | |||||
</DataTemplate> | |||||
</ListBox.ItemTemplate> | |||||
</ListBox> | |||||
</Viewbox> | |||||
</Grid> | |||||
</DataTemplate> | |||||
</ListBox.ItemTemplate> | |||||
</ListBox> | |||||
</Grid> | |||||
</Viewbox> | |||||
</Grid> | |||||
</UserControl> |
@@ -0,0 +1,119 @@ | |||||
using BPASmartClient.Compiler; | |||||
using BPASmartClient.DATABUS; | |||||
using BPASmartClient.MessageCommunication; | |||||
using BPASmartClient.MessageCommunication.MsgControl; | |||||
using BPASmartClient.MessageName; | |||||
using BPASmartClient.MessageName.EnumHelp; | |||||
using BPASmartClient.MessageName.发送消息Model; | |||||
using BPASmartClient.MessageName.接收消息Model; | |||||
using BPASmartClient.MessageName.接收消息Model.物料仓; | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
using System.Collections; | |||||
using System.Collections.Generic; | |||||
using System.Collections.ObjectModel; | |||||
using System.ComponentModel; | |||||
using System.Drawing.Design; | |||||
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.Documents; | |||||
using System.Windows.Input; | |||||
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 BPASmartClient.SCADAControl.CustomerControls | |||||
{ | |||||
/// <summary> | |||||
/// TheWuLiaoControl.xaml 的交互逻辑 | |||||
/// </summary> | |||||
public partial class TheWuLiaoControl : UserControl, IExecutable, IDisposable | |||||
{ | |||||
public TheWuLiaoControl() | |||||
{ | |||||
InitializeComponent(); | |||||
vs.Add(new shujuModel | |||||
{ | |||||
name = "", | |||||
dataModel = new ObservableCollection<string> { "", "" } | |||||
}); | |||||
vs.Add(new shujuModel | |||||
{ | |||||
name = "", | |||||
dataModel = new ObservableCollection<string> { "", "", "", "" } | |||||
}); | |||||
Width = 200; | |||||
Height = 200; | |||||
} | |||||
public string ControlType => "物料仓"; | |||||
private bool isExecuteState; | |||||
public bool IsExecuteState | |||||
{ | |||||
get { return isExecuteState; } | |||||
set | |||||
{ | |||||
isExecuteState = value; | |||||
if (IsExecuteState) | |||||
{ | |||||
IsEnabled = true; | |||||
Register(); | |||||
} | |||||
} | |||||
} | |||||
public event EventHandler PropertyChange; //声明一个事件 | |||||
/// <summary> | |||||
/// 数据模板 | |||||
/// </summary> | |||||
private ObservableCollection<shujuModel> vs | |||||
{ | |||||
get { return (ObservableCollection<shujuModel>)GetValue(vsProperty); } | |||||
set { SetValue(vsProperty, value); } | |||||
} | |||||
private static readonly DependencyProperty vsProperty = | |||||
DependencyProperty.Register("vs", typeof(ObservableCollection<shujuModel>), typeof(TheWuLiaoControl), new PropertyMetadata(new ObservableCollection<shujuModel>())); | |||||
/// <summary> | |||||
/// 数据模板 | |||||
/// </summary> | |||||
private Dictionary<string, object> DataModel | |||||
{ | |||||
get { return (Dictionary<string, object>)GetValue(DataModelProperty); } | |||||
set { SetValue(DataModelProperty, value); } | |||||
} | |||||
private static readonly DependencyProperty DataModelProperty = | |||||
DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheWuLiaoControl), new PropertyMetadata(new Dictionary<string, object>())); | |||||
public void Register() | |||||
{ | |||||
Class_DataBus.GetInstance().BindingAction += BindingActionHeader; | |||||
} | |||||
public void BindingActionHeader(object sender, EventArgs e) | |||||
{ | |||||
this.Dispatcher.Invoke((Action)(() => | |||||
{ | |||||
DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding; | |||||
PropertyChange?.Invoke(this, EventArgs.Empty); | |||||
})); | |||||
} | |||||
public void Dispose() | |||||
{ | |||||
} | |||||
} | |||||
public class shujuModel | |||||
{ | |||||
public string name { get; set; } | |||||
public ObservableCollection<string> dataModel { get; set; } | |||||
} | |||||
} |
@@ -2293,4 +2293,6 @@ | |||||
<GradientStop Offset="1" Color="#E3E3E3" /> | <GradientStop Offset="1" Color="#E3E3E3" /> | ||||
</LinearGradientBrush> | </LinearGradientBrush> | ||||
<!--#endregion--> | <!--#endregion--> | ||||
</ResourceDictionary> | </ResourceDictionary> |