-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserControl_visualize.xaml.cs
235 lines (196 loc) · 8.6 KB
/
UserControl_visualize.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BoyeoZoom
{
/// <summary>
/// UserControl_visualize.xaml에 대한 상호 작용 논리
/// </summary>
public partial class UserControl_visualize : UserControl
{
Parsing parsing = new Parsing();
public UserControl_visualize()
{
InitializeComponent();
}
public void init()
{
myVariable.Children.Clear();
myHeap.Children.Clear();
}
public void Draw_All(Trace step)
{
init();
Dictionary<string, UserControl_variableItem> dict = new Dictionary<string, UserControl_variableItem>();
// Global Variables
UserControl_funcPanel f1 = makeFuncPanel("Global Frame", step.Globals, dict);
myVariable.Children.Add(f1);
// Local Variables
List<List<C_VARIABLE>> stack = step.getLocals();
List<string> func_names = step.getFuncs();
for (int i = 0; i < stack.Count; i++)
{
UserControl_funcPanel f2 = makeFuncPanel(func_names[i], stack[i], dict);
myVariable.Children.Add(f2);
}
// Heap
List<C_VARIABLE> heap = step.Heap;
UserControl_funcPanel f3 = makeFuncPanel("Heap", heap, dict);
myHeap.Children.Add(f3);
// Pointer to Value
RandomColorGenerator rcg = new RandomColorGenerator();
foreach (var funcPanel in myVariable.Children) //VARIABLES PART
{
UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
pointerProcess(uc, dict, rcg);
}
foreach (var funcPanel in myHeap.Children) //HEAP PART
{
UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
pointerProcess(uc, dict, rcg);
}
}
//public Trace Draw_All(Visual visual, int run_current_count)
//{
// foreach (Trace step in visual.Trace)
// {
// if (run_current_count == step.Line)
// {
// init();
// Dictionary<string, UserControl_variableItem> dict = new Dictionary<string, UserControl_variableItem>();
// // Global Variables
// UserControl_funcPanel f1 = makeFuncPanel("Global Frame", step.Globals, dict);
// myVariable.Children.Add(f1);
// // Local Variables
// List<List<C_VARIABLE>> stack = step.getLocals();
// List<string> func_names = step.getFuncs();
// for (int i = 0; i < stack.Count; i++)
// {
// UserControl_funcPanel f2 = makeFuncPanel(func_names[i], stack[i], dict);
// myVariable.Children.Add(f2);
// }
// // Heap
// List<C_VARIABLE> heap = step.Heap;
// UserControl_funcPanel f3 = makeFuncPanel("Heap", heap, dict);
// myHeap.Children.Add(f3);
// // Pointer to Value
// RandomColorGenerator rcg = new RandomColorGenerator();
// foreach (var funcPanel in myVariable.Children) //VARIABLES PART
// {
// UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
// pointerProcess(uc, dict, rcg);
// }
// foreach (var funcPanel in myHeap.Children) //HEAP PART
// {
// UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
// pointerProcess(uc, dict, rcg);
// }
// return step;
// }
// else if (run_current_count == 0)
// {
// init();
// Dictionary<string, UserControl_variableItem> dict = new Dictionary<string, UserControl_variableItem>();
// // Global Variables
// UserControl_funcPanel f1 = makeFuncPanel("Global Frame", step.Globals, dict);
// myVariable.Children.Add(f1);
// // Heap
// List<C_VARIABLE> heap = step.Heap;
// UserControl_funcPanel f3 = makeFuncPanel("Heap", heap, dict);
// myHeap.Children.Add(f3);
// // Pointer to Value
// RandomColorGenerator rcg = new RandomColorGenerator();
// foreach (var funcPanel in myVariable.Children) //VARIABLES PART
// {
// UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
// pointerProcess(uc, dict, rcg);
// }
// foreach (var funcPanel in myHeap.Children) //HEAP PART
// {
// UserControl_funcPanel uc = funcPanel as UserControl_funcPanel;
// pointerProcess(uc, dict, rcg);
// }
// }
// }
// return null;
//}
private UserControl_funcPanel makeFuncPanel(string name, List<C_VARIABLE> vars, Dictionary<string, UserControl_variableItem> dict)
{
UserControl_funcPanel f = new UserControl_funcPanel();
f.setLabel(name);
foreach (var item in vars)
{
if (item is C_DATA) //primitive
{
UserControl_variable uc = new UserControl_variable();
C_DATA variable = item as C_DATA;
List<C_DATA> list = new List<C_DATA>();
list.Add(variable);
uc.AddValues(list, dict);
uc.setName(variable.Name);
f.Add(uc);
}
else
{
UserControl_variable uc = new UserControl_variable();
C_ARRAY ca = item as C_ARRAY;
uc.AddValues(ca.Values, dict);
uc.setName(ca.Name);
f.Add(uc);
}
}
return f;
}
private void pointerProcess(UserControl_funcPanel fPanel, Dictionary<string, UserControl_variableItem> dict, RandomColorGenerator rcg)
{
foreach (var item in fPanel.getPanelChildren())
{
if (item is UserControl_variable)
{
UserControl_variable arr = item as UserControl_variable;
List<C_DATA> dataChildren = arr.getArrayChildren();
if (dataChildren != null)
{
var panelChildren = arr.getPanelChildren();
int count = dataChildren.Count;
for (int i = 0; i < count; i++)
{
if (dataChildren[i].Type == "pointer")
{
UserControl_variableItem source = panelChildren[i] as UserControl_variableItem;
if (dict.ContainsKey(dataChildren[i].Value))
{
UserControl_variableItem target = dict[dataChildren[i].Value];
C_DATA data = target.Data;
if (source != null)
{
string val = StringFunc.toBeauty(data.Value, data.Type == "char");
source.setText(val);
SolidColorBrush scb = rcg.next();
target.val.Foreground = scb;
source.val.Foreground = scb;
}
}
else
{
source.setBackgroundNULL();
}
}
}
}
}
}
}
}
}