-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Window_Eto.vb
276 lines (207 loc) · 14 KB
/
Window_Eto.vb
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
Imports System.IO
Imports Eto.Drawing
Imports Eto.Forms
Imports c = DWSIM.UI.Shared.Common
Public Class Window_Eto
Public Shared Function GetInspectorWindow() As TableLayout
'Layout
Dim content As New TableLayout With {.Padding = New Padding(5, 5, 5, 5), .Spacing = New Size(10, 10)}
Dim InspectorLabel = New Label With {.Text = " Solution Inspector", .Font = SystemFonts.Bold(), .VerticalAlignment = VerticalAlignment.Bottom, .TextColor = Colors.White, .Height = 20}
InspectorLabel.Font = New Font(SystemFont.Bold, DWSIM.UI.Shared.Common.GetEditorFontSize())
Dim InspectorDescription = New Label With {.Text = " The Solution Inspector brings a human-readable, hierarchized view of all model calculations in a Flowsheet Solver run.", .VerticalAlignment = VerticalAlignment.Bottom, .TextColor = Colors.White, .Height = 20}
InspectorDescription.Font = New Font(SystemFont.Default, DWSIM.UI.Shared.Common.GetEditorFontSize())
content.Rows.Add(New TableRow(InspectorLabel))
content.Rows.Add(New TableRow(InspectorDescription))
content.BackgroundColor = New Color(0.051F, 0.447F, 0.651F)
Dim SetsBox As New ListBox With {.Height = 100}
Dim SetsLabel = New Label With {.VerticalAlignment = VerticalAlignment.Center, .Text = "Available Solution Report Sets", .Font = SystemFonts.Bold(), .TextColor = Colors.White, .Height = 20}
SetsLabel.Font = New Font(SystemFont.Bold, DWSIM.UI.Shared.Common.GetEditorFontSize())
Dim leftcontainer, rightcontainer As New TableLayout
leftcontainer.Rows.Add(New TableRow(SetsLabel))
leftcontainer.Rows.Add(New TableRow(SetsBox))
leftcontainer.Rows.Add(New Label With {.VerticalAlignment = VerticalAlignment.Center, .Text = "Reports", .Font = New Font(SystemFont.Bold, DWSIM.UI.Shared.Common.GetEditorFontSize()), .TextColor = Colors.White})
leftcontainer.Padding = New Padding(5, 5, 5, 5)
leftcontainer.Spacing = New Size(10, 10)
leftcontainer.Width = 350
Dim itemSelector As New TreeGridView()
itemSelector.ShowHeader = False
itemSelector.AllowMultipleSelection = False
itemSelector.Columns.Add(New GridColumn With {.DataCell = New TextBoxCell(0)})
leftcontainer.Rows.Add(itemSelector)
rightcontainer.Padding = New Padding(5, 5, 5, 5)
rightcontainer.Spacing = New Size(10, 10)
Dim currentItemViewer As New WebView With {.BrowserContextMenuEnabled = True}
Dim lblTools As New Label() With {.VerticalAlignment = VerticalAlignment.Center, .Text = "Selected Report", .Font = New Font(SystemFont.Bold, DWSIM.UI.Shared.Common.GetEditorFontSize()), .TextColor = Colors.White}
Dim btnExportHTML As New Button() With {.Text = "Export to HTML File"}
AddHandler btnExportHTML.Click, Sub()
Dim Dialog As New SaveFileDialog()
Dialog.Title = "Export HTML Page"
Dialog.Filters.Add(New FileFilter("HTML File", {".htm"}))
Dialog.CurrentFilterIndex = 0
If Dialog.ShowDialog(content.ParentWindow) = DialogResult.Ok Then
Dim nesteditems = GetItems(Host.Items.ToList)
Dim sitem = nesteditems.Where(Function(x) x.ID = DirectCast(itemSelector.SelectedItem, TreeGridItem).Tag.ToString).FirstOrDefault
File.WriteAllText(Dialog.FileName, sitem.GetHTML)
End If
End Sub
'Dim btnPerfAn As New Button() With {.Text = "Performance Analyzer"}
'AddHandler btnPerfAn.Click, Sub()
'Dim f = c.GetDefaultEditorForm("DWSIM - Solution Inspector / Performance Analyzer", 1024, 768, PerfAn.GetPerfAnWindow(SetsBox.SelectedKey), False)
'f.WindowState = WindowState.Maximized
'f.Show()
'End Sub
Dim l1 As New TableLayout(New TableRow(lblTools, Nothing, btnExportHTML))
'Dim l1 As New TableLayout(New TableRow(lblTools, Nothing, btnPerfAn, btnExportHTML))
l1.Spacing = New Size(10, 10)
rightcontainer.Rows.Add(New TableRow(l1))
rightcontainer.Rows.Add(New TableRow(currentItemViewer))
rightcontainer.Rows(1).ScaleHeight = True
Dim splitterpanel As New Splitter()
splitterpanel.Panel1 = leftcontainer
splitterpanel.Panel2 = rightcontainer
splitterpanel.Orientation = Orientation.Horizontal
splitterpanel.SplitterWidth = 1
content.Rows.Add(splitterpanel)
'Events
Dim avsol As List(Of String) = Host.Items.Select(Of String)(Function(x) x.SolutionID).Distinct().ToList
For Each item In avsol
If item <> "" Then SetsBox.Items.Add(New ListItem() With {.Text = Date.FromBinary(item).ToString(), .Key = item})
Next
AddHandler SetsBox.SelectedIndexChanged,
Sub(sender, e)
Dim f As New Eto.Forms.Form
Dim loadingtext As Label
Dim progressSpinner As ProgressBar
Dim btnCancel As Button
With f
.Topmost = True
.Title = "Loading Inspector Reports"
progressSpinner = New ProgressBar With {.Width = 350, .Height = 20, .Enabled = True}
loadingtext = New Label With {.Text = "Loading reports..."}
loadingtext.VerticalAlignment = VerticalAlignment.Center
loadingtext.TextAlignment = TextAlignment.Center
btnCancel = New Button With {.Text = "Cancel"}
Dim row1 = New TableLayout
row1.Rows.Add(New TableRow(New TableCell() {Nothing, progressSpinner, Nothing}))
Dim row3 = New TableLayout
row3.Rows.Add(New TableRow(New TableCell() {loadingtext, Nothing, btnCancel}))
Dim Container = New TableLayout With {.Spacing = New Size(5, 5), .Padding = New Padding(25, 10, 25, 10)}
Container.Rows.Add(row1)
Container.Rows.Add(row3)
Container.Rows.Add(Nothing)
.Content = Container
.WindowStyle = Eto.Forms.WindowStyle.Default
.ShowInTaskbar = False
.Maximizable = False
.Minimizable = False
Dim w = 400
Dim h = 80
Dim center = Screen.PrimaryScreen.WorkingArea.Center
center.X -= w / 2
center.Y -= h / 2
.Location = New Point(center)
.ClientSize = New Size(w, h)
End With
'content.Enabled = False
f.Show()
Dim sitems = Host.Items.Where(Function(x) x.SolutionID = SetsBox.SelectedKey.ToString).ToList
Dim tvc As New TreeGridItemCollection()
Dim ct As New Threading.CancellationTokenSource
AddHandler btnCancel.Click, Sub()
ct.Cancel()
End Sub
Dim allitems As New List(Of InspectorItem)
Task.Factory.StartNew(Sub()
Application.Instance.Invoke(Sub()
allitems = GetItems(Host.Items.Where(Function(x) x.SolutionID = SetsBox.SelectedKey.ToString).ToList)
End Sub)
Dim i As Integer = 1
For Each item In sitems.Where(Function(x) x.ParentID = -1)
Dim timetaken = item.TimeTaken.TotalMilliseconds.ToString("N0") + " ms"
If timetaken = "0 ms" Then timetaken = (item.TimeTaken.TotalMilliseconds * 1000).ToString("N0") + " µs"
If timetaken = "0 µs" Then timetaken = (item.TimeTaken.TotalMilliseconds * 1000000).ToString("N0") + " ns"
Dim titem = New TreeGridItem() With {.Values = {item.Name + " (" + timetaken + ")"}, .Tag = item.ID}
tvc.Add(titem)
Application.Instance.Invoke(Sub()
loadingtext.Text = String.Format("Loading reports... ({0}/{1})", i, allitems.Count)
progressSpinner.Value = i / allitems.Count * 100
content.ParentWindow.Invalidate()
End Sub)
i += 1
Dim nesteditems = GetItems(item)
For Each item2 In nesteditems
Dim parent = GetAllTreeItems(tvc).Where(Function(x) DirectCast(x, TreeGridItem).Tag = item2.ParentID).FirstOrDefault
Dim timetaken2 = item2.TimeTaken.TotalMilliseconds.ToString("N0") + " ms"
If timetaken2 = "0 ms" Then timetaken2 = (item2.TimeTaken.TotalMilliseconds * 1000).ToString("N0") + " µs"
If timetaken2 = "0 µs" Then timetaken2 = (item2.TimeTaken.TotalMilliseconds * 1000000).ToString("N0") + " ns"
Dim titem2 = New TreeGridItem() With {.Values = {item2.Name + " (" + timetaken2 + ")"}, .Tag = item2.ID}
If parent Is Nothing Then
tvc.Add(titem2)
Else
DirectCast(parent, TreeGridItem).Children.Add(titem2)
End If
Application.Instance.Invoke(Sub()
loadingtext.Text = String.Format("Loading reports... ({0}/{1})", i, allitems.Count)
progressSpinner.Value = i / allitems.Count * 100
content.ParentWindow.Invalidate()
End Sub)
i += 1
If ct.IsCancellationRequested Then Throw New TaskCanceledException()
Next
Next
End Sub, ct.Token).ContinueWith(Sub()
Application.Instance.Invoke(Sub()
itemSelector.DataStore = tvc
'content.Enabled = True
f.Close()
End Sub)
End Sub)
End Sub
AddHandler itemSelector.SelectedItemChanged,
Sub(sender, e)
If itemSelector.SelectedItem IsNot Nothing Then
Dim nesteditems = GetItems(Host.Items.ToList)
Dim sitem = nesteditems.Where(Function(x) x.ID = DirectCast(itemSelector.SelectedItem, TreeGridItem).Tag.ToString).FirstOrDefault
If Not sitem Is Nothing Then
currentItemViewer.LoadHtml(sitem.GetHTML())
Else
MessageBox.Show("Selected report not found.")
End If
End If
End Sub
Return content
End Function
Public Shared Function GetItems(ByVal list As List(Of InspectorItem)) As List(Of InspectorItem)
Dim myItems As List(Of InspectorItem) = New List(Of InspectorItem)()
For Each i As InspectorItem In list
GetInspectorItems(i, myItems)
Next
Return myItems
End Function
Public Shared Function GetItems(ByVal iitem As InspectorItem) As List(Of InspectorItem)
Dim myItems As List(Of InspectorItem) = New List(Of InspectorItem)()
For Each i As InspectorItem In iitem.Items
GetInspectorItems(i, myItems)
Next
Return myItems
End Function
Private Shared Sub GetInspectorItems(ByVal item As InspectorItem, ByVal items As List(Of InspectorItem))
items.Add(item)
For Each i As InspectorItem In item.Items
GetInspectorItems(i, items)
Next
End Sub
Public Shared Function GetAllTreeItems(ByVal iitem As TreeGridItemCollection) As List(Of TreeGridItem)
Dim myItems As List(Of TreeGridItem) = New List(Of TreeGridItem)()
For Each i As TreeGridItem In iitem
GetTreeItems(i, myItems)
Next
Return myItems
End Function
Private Shared Sub GetTreeItems(ByVal item As TreeGridItem, ByVal items As List(Of TreeGridItem))
items.Add(item)
For Each i As TreeGridItem In item.Children
GetTreeItems(i, items)
Next
End Sub
End Class