-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAwpHealthForm.cs
More file actions
300 lines (271 loc) · 11.8 KB
/
Copy pathAwpHealthForm.cs
File metadata and controls
300 lines (271 loc) · 11.8 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
namespace AutisAnalytics.NavisworksAtributos
{
internal sealed class AwpHealthForm : Form
{
private readonly Document _document;
private readonly AwpHealthReport _report;
private readonly DataGridView _grid;
private ComboBox _severityFilter;
private TextBox _search;
private readonly Label _status;
public AwpHealthForm(Document document, AwpHealthReport report)
{
_document = document ?? throw new ArgumentNullException(nameof(document));
_report = report ?? throw new ArgumentNullException(nameof(report));
UITheme.ApplyForm(this, "Model Health Check");
StartPosition = FormStartPosition.CenterScreen;
Size = new Size(1180, 760);
MinimumSize = new Size(940, 620);
AutoScaleMode = AutoScaleMode.Dpi;
Controls.Add(UITheme.CreateHeader(
"Model Health Check",
$"{_report.TotalElements} construction element(s) analyzed | {_report.ScopeDescription}"));
var footer = UITheme.CreateFooter();
Controls.Add(footer);
_status = new Label
{
AutoSize = true,
Font = UITheme.Typography.BodySmall,
ForeColor = UITheme.Color.TextSecondary,
Location = new Point(18, 18)
};
footer.Controls.Add(_status);
var actions = new FlowLayoutPanel
{
Dock = DockStyle.Right,
Width = 390,
FlowDirection = FlowDirection.RightToLeft,
WrapContents = false,
Padding = new Padding(0, 9, 16, 0),
BackColor = UITheme.Color.Surface
};
footer.Controls.Add(actions);
var close = UITheme.CreateSecondaryButton("Close");
close.Size = new Size(92, 34);
close.Margin = new Padding(0, 0, 0, 0);
close.Click += (sender, args) => Close();
actions.Controls.Add(close);
var export = UITheme.CreatePrimaryButton("Export Excel");
export.Size = new Size(124, 34);
export.Margin = new Padding(0, 0, 10, 0);
export.Click += ExportExcel;
actions.Controls.Add(export);
var select = UITheme.CreateSecondaryButton("Select issues");
select.Size = new Size(124, 34);
select.Margin = new Padding(0, 0, 10, 0);
select.Click += SelectVisibleIssues;
actions.Controls.Add(select);
var body = new Panel
{
Dock = DockStyle.Fill,
Padding = new Padding(16, 14, 16, 14),
BackColor = UITheme.Color.Background
};
Controls.Add(body);
body.BringToFront();
var layout = new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 1,
RowCount = 3,
BackColor = UITheme.Color.Background
};
layout.RowStyles.Add(new RowStyle(SizeType.Absolute, 78));
layout.RowStyles.Add(new RowStyle(SizeType.Absolute, 48));
layout.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
body.Controls.Add(layout);
layout.Controls.Add(CreateSummary(), 0, 0);
layout.Controls.Add(CreateFilters(), 0, 1);
_grid = new DataGridView
{
Dock = DockStyle.Fill,
ReadOnly = true,
RowHeadersVisible = false,
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
MultiSelect = true,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
BorderStyle = BorderStyle.FixedSingle
};
UITheme.StyleDataGridView(_grid);
_grid.Columns.Add("Severity", "Severity");
_grid.Columns.Add("Field", "AWP field");
_grid.Columns.Add("Element", "Element");
_grid.Columns.Add("Value", "Current value");
_grid.Columns.Add("Issue", "Issue");
_grid.Columns.Add("Recommendation", "Recommended action");
_grid.Columns[0].FillWeight = 55;
_grid.Columns[1].FillWeight = 65;
_grid.Columns[2].FillWeight = 110;
_grid.Columns[3].FillWeight = 90;
_grid.Columns[4].FillWeight = 155;
_grid.Columns[5].FillWeight = 180;
_grid.CellDoubleClick += GridCellDoubleClick;
layout.Controls.Add(_grid, 0, 2);
PopulateGrid();
}
private Control CreateSummary()
{
var panel = new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 4,
Padding = new Padding(0, 0, 0, 10)
};
for (int index = 0; index < 4; index++)
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
panel.Controls.Add(CreateMetric("Coverage", $"{_report.Coverage:0.0}%", UITheme.Color.Primary), 0, 0);
panel.Controls.Add(CreateMetric("Errors", _report.Errors.ToString(), UITheme.Color.Error), 1, 0);
panel.Controls.Add(CreateMetric("Warnings", _report.Warnings.ToString(), UITheme.Color.Warning), 2, 0);
panel.Controls.Add(CreateMetric("Ready for AWP", $"{_report.ValidElements} / {_report.TotalElements}", UITheme.Color.Success), 3, 0);
return panel;
}
private static Control CreateMetric(string label, string value, System.Drawing.Color accent)
{
var card = UITheme.CreateCard();
card.Dock = DockStyle.Fill;
card.Margin = new Padding(0, 0, 10, 0);
var marker = new Panel { Dock = DockStyle.Left, Width = 4, BackColor = accent };
card.Controls.Add(marker);
card.Controls.Add(new Label
{
Text = value,
Font = UITheme.Typography.H2,
ForeColor = UITheme.Color.TextPrimary,
AutoSize = true,
Location = new Point(18, 12)
});
card.Controls.Add(new Label
{
Text = label,
Font = UITheme.Typography.BodySmall,
ForeColor = UITheme.Color.TextSecondary,
AutoSize = true,
Location = new Point(18, 39)
});
return card;
}
private Control CreateFilters()
{
var panel = new Panel { Dock = DockStyle.Fill, BackColor = UITheme.Color.Background };
panel.Controls.Add(new Label
{
Text = "Show:",
AutoSize = true,
Font = UITheme.Typography.Label,
Location = new Point(0, 12)
});
_severityFilter = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
Location = new Point(52, 7),
Width = 150,
Font = UITheme.Typography.Body
};
_severityFilter.Items.AddRange(new object[] { "All issues", "Errors", "Warnings", "Information" });
_severityFilter.SelectedIndex = 0;
_severityFilter.SelectedIndexChanged += (sender, args) => PopulateGrid();
panel.Controls.Add(_severityFilter);
_search = new TextBox
{
Location = new Point(218, 7),
Width = 390,
Text = ""
};
UITheme.StyleTextBox(_search);
_search.TextChanged += (sender, args) => PopulateGrid();
panel.Controls.Add(_search);
return panel;
}
private void PopulateGrid()
{
if (_grid == null) return;
_grid.Rows.Clear();
var searchText = _search?.Text?.Trim() ?? "";
var filter = _severityFilter?.SelectedItem?.ToString() ?? "All issues";
foreach (var issue in _report.Issues.Where(item => MatchesSeverity(item, filter)))
{
var searchable = $"{issue.Field} {issue.ElementName} {issue.ElementUid} {issue.CurrentValue} {issue.Issue} {issue.Recommendation}";
if (!string.IsNullOrWhiteSpace(searchText) &&
searchable.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) < 0)
continue;
int index = _grid.Rows.Add(
issue.Severity.ToString(),
issue.Field,
issue.ElementName,
issue.CurrentValue,
issue.Issue,
issue.Recommendation);
var row = _grid.Rows[index];
row.Tag = issue;
row.Cells[0].Style.ForeColor = issue.Severity == AwpHealthSeverity.Error
? UITheme.Color.Error
: issue.Severity == AwpHealthSeverity.Warning
? UITheme.Color.Warning
: UITheme.Color.InfoText;
}
_status.Text = $"{_grid.Rows.Count} visible issue(s) | Double-click a row to locate the element";
}
private static bool MatchesSeverity(AwpHealthIssue issue, string filter)
{
if (filter == "Errors") return issue.Severity == AwpHealthSeverity.Error;
if (filter == "Warnings") return issue.Severity == AwpHealthSeverity.Warning;
if (filter == "Information") return issue.Severity == AwpHealthSeverity.Info;
return true;
}
private void GridCellDoubleClick(object sender, DataGridViewCellEventArgs args)
{
if (args.RowIndex < 0) return;
if (_grid.Rows[args.RowIndex].Tag is AwpHealthIssue issue && issue.Item != null)
SelectItems(new[] { issue.Item });
}
private void SelectVisibleIssues(object sender, EventArgs args)
{
var items = _grid.Rows.Cast<DataGridViewRow>()
.Select(row => row.Tag as AwpHealthIssue)
.Where(issue => issue?.Item != null)
.Select(issue => issue.Item)
.Distinct()
.ToList();
SelectItems(items);
}
private void SelectItems(IEnumerable<ModelItem> items)
{
var collection = new ModelItemCollection();
foreach (var item in items ?? Enumerable.Empty<ModelItem>())
collection.Add(item);
if (collection.Count > 0)
_document.CurrentSelection.CopyFrom(collection);
}
private void ExportExcel(object sender, EventArgs args)
{
using (var dialog = new SaveFileDialog
{
Title = "Export Model Health Check",
Filter = "Excel workbook (*.xlsx)|*.xlsx",
DefaultExt = "xlsx",
AddExtension = true,
FileName = $"Autis4D_ModelHealth_{DateTime.Now:yyyyMMdd_HHmm}.xlsx"
})
{
if (dialog.ShowDialog(this) != DialogResult.OK) return;
try
{
ExcelGridExporter.Exportar(_grid, dialog.FileName, "Model Health");
MessageBox.Show("The health report was exported to Excel.",
"Autis 4D — Model Health Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Could not export the health report.\n\n" + ex.Message,
"Autis 4D — Model Health Check", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}