1 using CommunityToolkit.Mvvm.ComponentModel;
2 using CommunityToolkit.Mvvm.Input;
3 using CommunityToolkit.Mvvm.Messaging;
4 using System;
5 using System.Collections.Generic;
6 using System.ComponentModel;
7 using System.Diagnostics;
8 using System.Runtime.CompilerServices;
9 using System.Windows.Input;
10 using WpfApp1.Entities;
11 using WpfApp1.Views;
12
13 namespace WpfApp1
14 {
15 public partial class MainViewModel
16 {
17
18 public MainViewModel()
19 {
20
21 LeftTubes3 = CreateCircularTubes(12, 18, 110, 50);
22
23 //IsActive = true;
24 }
25
26 #region 左侧板栈UI
27
28 public List<BoxPosition> LeftTubes3 { get; set; } = [];
29
30 private static List<BoxPosition> CreateCircularTubes(int count, int tubs, double outerRadius, double innerRadius)
31 {
32 var positions = new List<BoxPosition>();
33 double centerX = outerRadius;
34 double centerY = outerRadius;
35
36 for (int i = 0; i < count; i++)
37 {
38 // 计算角度 (360度均匀分布)
39 double angleDeg = 360.0 * i / count;
40 double angleRad = angleDeg * Math.PI / 180.0;
41
42 // 计算位置 (在内外半径之间)
43 double radius = (outerRadius + innerRadius) / 2;
44 double x = centerX + radius * Math.Cos(angleRad) - 17; // 25是料盒宽度的一半
45 double y = centerY + radius * Math.Sin(angleRad) - 25; // 35是料盒高度的一半
46
47 // 行数和列数
48 var rows = 2;
49 var cols = 3;
50 var margin = 2;
51 var width = 10;
52 var height = 10;
53 switch (tubs)
54 {
55 case 3:
56 rows = 1;
57 cols = 3;
58 margin = 2;
59 width = 10;
60 height = 10;
61 break;
62 //case 6:
63 // rows = 2;
64 // cols = 3;
65 // break;
66 case 12:
67 rows = 3;
68 cols = 4;
69 margin = 1;
70 width = 5;
71 height = 5;
72 break;
73 case 18:
74 rows = 3;
75 cols = 6;
76 margin = 1;
77 width = 4;
78 height = 4;
79 break;
80 case 96:
81 rows = 8;
82 cols = 12;
83 margin = 0;
84 width = 1;
85 height = 1;
86 break;
87 }
88
89 // 创建6个料管
90 var tubes = new List<Tube>();
91 for (int j = 0; j < tubs; j++)
92 {
93 tubes.Add(new Tube
94 {
95 Margin = margin,
96 Width = width,
97 Height = height,
98 });
99 }
100
101 positions.Add(new BoxPosition
102 {
103 Index = i + 1,
104 X = x,
105 Y = y,
106 Rows = rows,
107 Cols = cols,
108 Angle = angleDeg + 90, // 旋转角度等于位置角度
109 Tubes = tubes
110 });
111 }
112
113 return positions;
114 }
115
116
117 #endregion
118
119 }
120 }