-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAwpModelBuilderForm.cs
More file actions
645 lines (596 loc) · 26.7 KB
/
Copy pathAwpModelBuilderForm.cs
File metadata and controls
645 lines (596 loc) · 26.7 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
namespace AutisAnalytics.NavisworksAtributos
{
internal sealed class AwpModelBuilderForm : Form
{
private sealed class PropertyOptionItem
{
public SetNamePropertyOption Option { get; }
public string Label { get; }
public PropertyOptionItem(SetNamePropertyOption option, string label = null)
{
Option = option;
Label = label ?? $"{option.CategoriaNomeExibicao} — {option.PropriedadeNomeExibicao} | {option.OrigemDescricao}";
}
public override string ToString() => Label;
}
private readonly Document _document;
private readonly ModelItemCollection _scope;
private readonly List<SetNamePropertyOption> _options;
private readonly string _scopeDescription;
private AwpBuilderPreview _preview;
private TextBox _profileName;
private TextBox _projectId;
private TextBox _prefix;
private NumericUpDown _maxItems;
private ComboBox _cwa;
private ComboBox _discipline;
private ComboBox _cwp;
private ComboBox _iwp;
private CheckBox _uppercase;
private CheckBox _searchSets;
private CheckBox _snapshots;
private DataGridView _grid;
private Label _summary;
private Button _create;
public bool BuildCompleted { get; private set; }
public AwpModelBuilderForm(
Document document,
ModelItemCollection scope,
IEnumerable<SetNamePropertyOption> options,
string scopeDescription)
{
_document = document ?? throw new ArgumentNullException(nameof(document));
_scope = scope ?? new ModelItemCollection();
_options = (options ?? Enumerable.Empty<SetNamePropertyOption>()).ToList();
_scopeDescription = scopeDescription ?? "Model";
UITheme.ApplyForm(this, "AWP Model Builder");
StartPosition = FormStartPosition.CenterScreen;
Size = new Size(1220, 790);
MinimumSize = new Size(1020, 680);
AutoScaleMode = AutoScaleMode.Dpi;
Controls.Add(UITheme.CreateHeader(
"AWP Model Builder",
$"{_scope.Count} construction element(s) | {_scopeDescription} | Draft packages require planner review"));
var footer = CreateFooter();
Controls.Add(footer);
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, 266));
layout.RowStyles.Add(new RowStyle(SizeType.Absolute, 38));
layout.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
body.Controls.Add(layout);
layout.Controls.Add(CreateConfigurationCard(), 0, 0);
_summary = new Label
{
Dock = DockStyle.Fill,
Text = "Choose the source properties, then generate a preview.",
Font = UITheme.Typography.BodySmall,
ForeColor = UITheme.Color.TextSecondary,
TextAlign = ContentAlignment.MiddleLeft
};
layout.Controls.Add(_summary, 0, 1);
layout.Controls.Add(CreateGrid(), 0, 2);
FillPropertyCombos();
ApplyDefaultProfile();
}
private Control CreateConfigurationCard()
{
var card = UITheme.CreateCard();
card.Dock = DockStyle.Fill;
card.Padding = new Padding(16, 12, 16, 12);
var table = new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 4,
RowCount = 6,
BackColor = UITheme.Color.Surface
};
table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 132));
table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 142));
table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 32));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 37));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 37));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 37));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 37));
table.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
card.Controls.Add(table);
var title = new Label
{
Text = "Project profile and model mapping",
Font = UITheme.Typography.H3,
ForeColor = UITheme.Color.TextPrimary,
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleLeft
};
table.Controls.Add(title, 0, 0);
table.SetColumnSpan(title, 2);
var profileActions = new FlowLayoutPanel
{
Dock = DockStyle.Fill,
FlowDirection = FlowDirection.RightToLeft,
WrapContents = false,
Margin = new Padding(0)
};
var load = UITheme.CreateSecondaryButton("Load profile");
load.Size = new Size(108, 30);
load.Click += LoadProfile;
var save = UITheme.CreateSecondaryButton("Save profile");
save.Size = new Size(108, 30);
save.Click += SaveProfile;
profileActions.Controls.Add(load);
profileActions.Controls.Add(save);
table.Controls.Add(profileActions, 2, 0);
table.SetColumnSpan(profileActions, 2);
_profileName = AddTextField(table, "Profile name", 1, 0, "Default AWP profile");
_projectId = AddTextField(table, "Project ID", 1, 2, "PROJECT");
_prefix = AddTextField(table, "Package prefix", 2, 0, "AWP");
AddLabel(table, "Max items / IWP", 2, 2);
_maxItems = new NumericUpDown
{
Minimum = 1,
Maximum = 5000,
Value = 200,
Dock = DockStyle.Fill,
Margin = new Padding(0, 4, 0, 4),
Font = UITheme.Typography.Body
};
table.Controls.Add(_maxItems, 3, 2);
AddLabel(table, "CWA source *", 3, 0);
_cwa = AddCombo(table, 3, 1);
AddLabel(table, "Discipline source *", 3, 2);
_discipline = AddCombo(table, 3, 3);
AddLabel(table, "CWP source", 4, 0);
_cwp = AddCombo(table, 4, 1);
AddLabel(table, "IWP source", 4, 2);
_iwp = AddCombo(table, 4, 3);
var optionsPanel = new FlowLayoutPanel
{
Dock = DockStyle.Fill,
FlowDirection = FlowDirection.LeftToRight,
WrapContents = false,
Padding = new Padding(0, 7, 0, 0),
Margin = new Padding(0)
};
_uppercase = new CheckBox { Text = "Normalize codes to uppercase", AutoSize = true, Checked = true, Margin = new Padding(0, 3, 22, 0) };
_searchSets = new CheckBox { Text = "Create/update dynamic Search Sets", AutoSize = true, Checked = true, Margin = new Padding(0, 3, 22, 0) };
_snapshots = new CheckBox { Text = "Create IWP snapshot Selection Sets", AutoSize = true, Margin = new Padding(0, 3, 22, 0) };
optionsPanel.Controls.Add(_uppercase);
optionsPanel.Controls.Add(_searchSets);
optionsPanel.Controls.Add(_snapshots);
table.Controls.Add(optionsPanel, 0, 5);
table.SetColumnSpan(optionsPanel, 4);
return card;
}
private Panel CreateFooter()
{
var footer = UITheme.CreateFooter();
var actions = new FlowLayoutPanel
{
Dock = DockStyle.Right,
Width = 512,
FlowDirection = FlowDirection.RightToLeft,
WrapContents = false,
Padding = new Padding(0, 9, 16, 0),
BackColor = UITheme.Color.Surface
};
footer.Controls.Add(actions);
var preview = UITheme.CreatePrimaryButton("Generate preview");
preview.Size = new Size(142, 34);
preview.Margin = new Padding(0, 0, 10, 0);
preview.Click += GeneratePreview;
var export = UITheme.CreateSecondaryButton("Export preview");
export.Size = new Size(126, 34);
export.Margin = new Padding(0, 0, 10, 0);
export.Click += ExportPreview;
var cancel = UITheme.CreateSecondaryButton("Cancel");
cancel.Size = new Size(84, 34);
cancel.Margin = new Padding(0, 0, 10, 0);
cancel.Click += (sender, args) => Close();
_create = UITheme.CreateSuccessButton("Create AWP");
_create.Size = new Size(106, 34);
_create.Margin = new Padding(0);
_create.Enabled = false;
_create.Click += CreateAwp;
actions.Controls.Add(_create);
actions.Controls.Add(cancel);
actions.Controls.Add(export);
actions.Controls.Add(preview);
return footer;
}
private Control CreateGrid()
{
_grid = new DataGridView
{
Dock = DockStyle.Fill,
ReadOnly = true,
RowHeadersVisible = false,
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
BorderStyle = BorderStyle.FixedSingle
};
UITheme.StyleDataGridView(_grid);
_grid.Columns.Add("Level", "Level");
_grid.Columns.Add("Package", "Package ID");
_grid.Columns.Add("Parent", "Parent package");
_grid.Columns.Add("Discipline", "Discipline");
_grid.Columns.Add("Elements", "Elements");
_grid.Columns.Add("Source", "Definition");
_grid.Columns[0].FillWeight = 45;
_grid.Columns[1].FillWeight = 160;
_grid.Columns[2].FillWeight = 140;
_grid.Columns[3].FillWeight = 90;
_grid.Columns[4].FillWeight = 55;
_grid.Columns[5].FillWeight = 90;
return _grid;
}
private static TextBox AddTextField(
TableLayoutPanel table,
string label,
int row,
int labelColumn,
string value)
{
AddLabel(table, label, row, labelColumn);
var text = new TextBox
{
Text = value,
Dock = DockStyle.Fill,
Margin = new Padding(0, 4, 10, 4)
};
UITheme.StyleTextBox(text);
table.Controls.Add(text, labelColumn + 1, row);
return text;
}
private static void AddLabel(TableLayoutPanel table, string text, int row, int column)
{
table.Controls.Add(new Label
{
Text = text,
Dock = DockStyle.Fill,
Font = UITheme.Typography.Label,
ForeColor = UITheme.Color.TextPrimary,
TextAlign = ContentAlignment.MiddleLeft,
Margin = new Padding(0, 0, 8, 0)
}, column, row);
}
private static ComboBox AddCombo(TableLayoutPanel table, int row, int column)
{
var combo = new ComboBox
{
Dock = DockStyle.Fill,
DropDownStyle = ComboBoxStyle.DropDownList,
Font = UITheme.Typography.Body,
Margin = new Padding(0, 4, 10, 4),
MaxDropDownItems = 18
};
table.Controls.Add(combo, column, row);
return combo;
}
private void FillPropertyCombos()
{
foreach (var combo in new[] { _cwa, _discipline, _cwp, _iwp })
{
combo.BeginUpdate();
if (combo == _cwp || combo == _iwp)
combo.Items.Add(new PropertyOptionItem(null, "Derive automatically from the AWP hierarchy"));
foreach (var option in _options)
combo.Items.Add(new PropertyOptionItem(option));
combo.EndUpdate();
}
}
private void ApplyDefaultProfile()
{
SelectOption(_cwa, AwpDataService.AutoDetect(_options, AutisSchema.CwaId));
SelectOption(_discipline, AwpDataService.AutoDetect(_options, AutisSchema.Discipline));
SelectOption(_cwp, AwpDataService.AutoDetect(_options, AutisSchema.CwpId));
SelectOption(_iwp, AwpDataService.AutoDetect(_options, AutisSchema.IwpId));
if (_cwp.SelectedIndex < 0) _cwp.SelectedIndex = 0;
if (_iwp.SelectedIndex < 0) _iwp.SelectedIndex = 0;
}
private static void SelectOption(ComboBox combo, SetNamePropertyOption option)
{
if (option == null) return;
for (int index = 0; index < combo.Items.Count; index++)
{
if (combo.Items[index] is PropertyOptionItem item &&
ReferenceEquals(item.Option, option))
{
combo.SelectedIndex = index;
return;
}
}
}
private static SetNamePropertyOption SelectedOption(ComboBox combo)
{
return (combo.SelectedItem as PropertyOptionItem)?.Option;
}
private AwpProjectProfile ReadProfile()
{
return new AwpProjectProfile
{
ProfileName = _profileName.Text.Trim(),
ProjectId = _projectId.Text.Trim(),
PackagePrefix = _prefix.Text.Trim(),
MaxItemsPerIwp = (int)_maxItems.Value,
UppercaseCodes = _uppercase.Checked,
CreateSearchSets = _searchSets.Checked,
CreateSnapshots = _snapshots.Checked,
CwaMapping = AwpPropertyMapping.FromOption(SelectedOption(_cwa)),
DisciplineMapping = AwpPropertyMapping.FromOption(SelectedOption(_discipline)),
CwpMapping = AwpPropertyMapping.FromOption(SelectedOption(_cwp)),
IwpMapping = AwpPropertyMapping.FromOption(SelectedOption(_iwp))
};
}
private void ApplyProfile(AwpProjectProfile profile)
{
_profileName.Text = profile.ProfileName ?? "Default AWP profile";
_projectId.Text = profile.ProjectId ?? "PROJECT";
_prefix.Text = profile.PackagePrefix ?? "AWP";
_maxItems.Value = Math.Max(_maxItems.Minimum, Math.Min(_maxItems.Maximum, profile.MaxItemsPerIwp));
_uppercase.Checked = profile.UppercaseCodes;
_searchSets.Checked = profile.CreateSearchSets;
_snapshots.Checked = profile.CreateSnapshots;
SelectOption(_cwa, AwpDataService.FindOption(_options, profile.CwaMapping));
SelectOption(_discipline, AwpDataService.FindOption(_options, profile.DisciplineMapping));
SelectOption(_cwp, AwpDataService.FindOption(_options, profile.CwpMapping));
SelectOption(_iwp, AwpDataService.FindOption(_options, profile.IwpMapping));
if (!profile.CwpMapping?.IsConfigured ?? true) _cwp.SelectedIndex = 0;
if (!profile.IwpMapping?.IsConfigured ?? true) _iwp.SelectedIndex = 0;
_preview = null;
_create.Enabled = false;
}
private void GeneratePreview(object sender, EventArgs args)
{
try
{
Cursor = Cursors.WaitCursor;
var profile = ReadProfile();
ValidateProfile(profile);
_preview = AwpDataService.BuildPreview(
_scope,
profile,
SelectedOption(_cwa),
SelectedOption(_discipline),
SelectedOption(_cwp),
SelectedOption(_iwp));
PopulatePreview();
_create.Enabled = _preview.ValidCount > 0;
}
catch (Exception ex)
{
_preview = null;
_create.Enabled = false;
MessageBox.Show("Could not generate the AWP preview.\n\n" + ex.Message,
"Autis 4D — AWP Model Builder", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
Cursor = Cursors.Default;
}
}
private static void ValidateProfile(AwpProjectProfile profile)
{
if (string.IsNullOrWhiteSpace(profile.ProfileName))
throw new InvalidOperationException("Enter a profile name.");
if (string.IsNullOrWhiteSpace(profile.ProjectId))
throw new InvalidOperationException("Enter the Project ID.");
if (string.IsNullOrWhiteSpace(profile.PackagePrefix))
throw new InvalidOperationException("Enter the package prefix.");
if (profile.CwaMapping == null)
throw new InvalidOperationException("Choose the source property for CWA.");
if (profile.DisciplineMapping == null)
throw new InvalidOperationException("Choose the source property for discipline.");
}
private void PopulatePreview()
{
_grid.Rows.Clear();
foreach (var package in _preview.Packages
.OrderBy(item => item.Level)
.ThenBy(item => item.PackageId, StringComparer.OrdinalIgnoreCase))
{
_grid.Rows.Add(
package.Level,
package.PackageId,
package.ParentId,
package.Discipline,
package.Count,
package.Derived ? "Derived draft" : "Model property");
}
_summary.Text =
$"{_preview.Packages.Count} package(s) | {_preview.ValidCount} assigned element(s) | " +
$"{_preview.InvalidCount} unassigned | Search Sets stay synchronized when the model is updated";
}
private void CreateAwp(object sender, EventArgs args)
{
try
{
// Regera a prévia para capturar qualquer alteração feita depois
// do último clique em Generate preview.
var profile = ReadProfile();
ValidateProfile(profile);
_preview = AwpDataService.BuildPreview(
_scope, profile, SelectedOption(_cwa), SelectedOption(_discipline),
SelectedOption(_cwp), SelectedOption(_iwp));
PopulatePreview();
var confirmation =
"Create the draft AWP structure in the current model?\n\n" +
$"Elements to write: {_preview.ValidCount}\n" +
$"CWA/CWP/IWP packages: {_preview.Packages.Count}\n" +
$"Unassigned elements: {_preview.InvalidCount}\n\n" +
"The package status will be DRAFT. Release/readiness approval remains a planner decision.";
if (MessageBox.Show(confirmation, "Autis 4D — AWP Model Builder",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return;
Cursor = Cursors.WaitCursor;
Enabled = false;
var attributes = AwpDataService.CreateAttributes(_preview, profile);
var writeResult = AtributoService.GravarAtributosPorItem(attributes, AutisSchema.CategoriaAwp);
var result = new AwpBuildResult
{
ElementsWritten = writeResult.sucesso,
WriteErrors = writeResult.erros,
UnassignedCount = _preview.InvalidCount
};
if (writeResult.sucesso > 0)
{
// Um snapshot representa um marco congelado. Se algum item
// falhou na escrita, não criamos uma fotografia incompleta;
// os Search Sets ainda podem ser gerados com segurança.
bool snapshotsRequested = profile.CreateSnapshots;
if (writeResult.erros > 0) profile.CreateSnapshots = false;
try
{
AwpSetService.CreateOrUpdate(_document, _preview, profile, result);
}
finally
{
profile.CreateSnapshots = snapshotsRequested;
}
}
BuildCompleted = writeResult.sucesso > 0;
MessageBox.Show(
"AWP draft structure completed.\n\n" +
$"Elements written: {result.ElementsWritten}\n" +
$"Write errors: {result.WriteErrors}\n" +
$"Search Sets created: {result.SearchSetsCreated}\n" +
$"Search Sets updated: {result.SearchSetsUpdated}\n" +
$"IWP snapshots created: {result.SnapshotsCreated}\n" +
$"Unassigned elements: {result.UnassignedCount}\n" +
$"Set errors: {result.SetErrors}\n\n" +
"Review package boundaries and constraints before releasing any IWP.",
"Autis 4D — AWP Model Builder",
MessageBoxButtons.OK,
result.WriteErrors > 0 || result.SetErrors > 0 || result.UnassignedCount > 0
? MessageBoxIcon.Warning
: MessageBoxIcon.Information);
if (BuildCompleted)
{
DialogResult = DialogResult.OK;
Close();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"[Autis] Protected AWP Builder failure: {ex}");
MessageBox.Show(
"The AWP operation was stopped safely.\n\n" + ex.Message,
"Autis 4D — AWP Model Builder",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
Enabled = true;
Cursor = Cursors.Default;
}
}
private void SaveProfile(object sender, EventArgs args)
{
try
{
var profile = ReadProfile();
ValidateProfile(profile);
Directory.CreateDirectory(AwpProfileService.DefaultFolder);
using (var dialog = new SaveFileDialog
{
Title = "Save AWP profile",
Filter = "Autis AWP profile (*.awp.json)|*.awp.json|JSON file (*.json)|*.json",
InitialDirectory = AwpProfileService.DefaultFolder,
FileName = SafeProfileFileName(profile.ProfileName) + ".awp.json",
AddExtension = true
})
{
if (dialog.ShowDialog(this) != DialogResult.OK) return;
AwpProfileService.Save(dialog.FileName, profile);
}
}
catch (Exception ex)
{
MessageBox.Show("Could not save the AWP profile.\n\n" + ex.Message,
"Autis 4D — AWP Model Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadProfile(object sender, EventArgs args)
{
try
{
Directory.CreateDirectory(AwpProfileService.DefaultFolder);
using (var dialog = new OpenFileDialog
{
Title = "Load AWP profile",
Filter = "Autis AWP profile (*.awp.json)|*.awp.json|JSON file (*.json)|*.json",
InitialDirectory = AwpProfileService.DefaultFolder
})
{
if (dialog.ShowDialog(this) != DialogResult.OK) return;
ApplyProfile(AwpProfileService.Load(dialog.FileName));
}
}
catch (Exception ex)
{
MessageBox.Show("Could not load the AWP profile.\n\n" + ex.Message,
"Autis 4D — AWP Model Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ExportPreview(object sender, EventArgs args)
{
if (_preview == null || _grid.Rows.Count == 0)
{
MessageBox.Show("Generate the AWP preview before exporting.",
"Autis 4D — AWP Model Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
using (var dialog = new SaveFileDialog
{
Title = "Export AWP preview",
Filter = "Excel workbook (*.xlsx)|*.xlsx",
DefaultExt = "xlsx",
AddExtension = true,
FileName = $"Autis4D_AWP_Preview_{DateTime.Now:yyyyMMdd_HHmm}.xlsx"
})
{
if (dialog.ShowDialog(this) != DialogResult.OK) return;
try
{
ExcelGridExporter.Exportar(_grid, dialog.FileName, "AWP Preview");
MessageBox.Show("The AWP preview was exported to Excel.",
"Autis 4D — AWP Model Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Could not export the AWP preview.\n\n" + ex.Message,
"Autis 4D — AWP Model Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private static string SafeProfileFileName(string value)
{
var name = string.IsNullOrWhiteSpace(value) ? "AWP_Profile" : value.Trim();
foreach (var character in Path.GetInvalidFileNameChars())
name = name.Replace(character, '-');
return string.IsNullOrWhiteSpace(name) ? "AWP_Profile" : name;
}
}
}