-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLerAtributosForm.cs
More file actions
397 lines (341 loc) · 17.3 KB
/
Copy pathLerAtributosForm.cs
File metadata and controls
397 lines (341 loc) · 17.3 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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AutisAnalytics.NavisworksAtributos
{
public class LerAtributosForm : Form
{
// ── Cores ──────────────────────────────────────────────────────────────
private static readonly Color CorFundo = UITheme.Color.Background;
private static readonly Color CorPainel = UITheme.Color.Surface;
private static readonly Color CorAccent = UITheme.Color.Primary;
private static readonly Color CorTexto = UITheme.Color.TextPrimary;
private static readonly Color CorTextoClaro = UITheme.Color.TextSecondary;
private static readonly Color CorBorda = UITheme.Color.BorderLight;
private static readonly Color CorGridHeader = UITheme.Color.BackgroundSecondary;
private static readonly Color CorGridAlt = UITheme.Color.SurfaceHover;
// ── Fontes ─────────────────────────────────────────────────────────────
private static readonly Font FonteNormal = UITheme.Typography.Body;
private static readonly Font FonteSemi = UITheme.Typography.Label;
private static readonly Font FonteTitulo = UITheme.Typography.H3;
private static readonly Font FontePequena = UITheme.Typography.BodySmall;
private static readonly Font FonteGrid = UITheme.Typography.BodySmall;
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, string lParam);
private const int EM_SETCUEBANNER = 0x1501;
// ── Controles principais ───────────────────────────────────────────────
private TextBox txtBusca;
private DataGridView dgv;
private Label lblStatus;
private CheckedListBox clbCategorias;
// ── Dados ──────────────────────────────────────────────────────────────
private readonly string _nomeElemento;
private readonly int _qtdSelecionados;
private readonly List<AtributoCustom> _todos;
private readonly Dictionary<string, List<AtributoCustom>> _porCategoria;
// ──────────────────────────────────────────────────────────────────────
public LerAtributosForm(string nomeElemento, int qtdSelecionados,
List<AtributoCustom> propriedades)
{
_nomeElemento = nomeElemento;
_qtdSelecionados = qtdSelecionados;
_todos = propriedades ?? new List<AtributoCustom>();
_porCategoria = _todos
.GroupBy(p => p.Categoria ?? "")
.ToDictionary(g => g.Key, g => g.ToList());
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
Montar();
AtualizarGrid();
}
// ── MONTAGEM ──────────────────────────────────────────────────────────
private void Montar()
{
UITheme.ApplyForm(this, "Read properties");
ClientSize = new Size(1050, 660);
MinimumSize = new Size(800, 500);
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.Sizable;
MontarHeader();
MontarBusca();
MontarRodape();
MontarCorpo(); // Fill — fica por último
}
// ── HEADER ─────────────────────────────────────────────────────────────
private void MontarHeader()
{
Controls.Add(UITheme.CreateHeader(
"Read properties",
$"{_nomeElemento} • {_qtdSelecionados} element(s) • {_todos.Count} properties"));
}
// ── BUSCA ──────────────────────────────────────────────────────────────
private void MontarBusca()
{
var pnl = new Panel
{
Dock = DockStyle.Top,
Height = 46,
BackColor = CorPainel,
Padding = new Padding(12, 8, 12, 8)
};
pnl.Paint += (s, e) =>
e.Graphics.DrawLine(new Pen(CorBorda), 0, pnl.Height - 1, pnl.Width, pnl.Height - 1);
txtBusca = new TextBox
{
Dock = DockStyle.Fill,
Font = FonteNormal,
BorderStyle = BorderStyle.FixedSingle,
BackColor = CorFundo,
ForeColor = CorTexto
};
txtBusca.HandleCreated += (s, e) =>
SendMessage(txtBusca.Handle, EM_SETCUEBANNER, 0, "Search all properties...");
txtBusca.TextChanged += (s, e) => AtualizarGrid();
pnl.Controls.Add(txtBusca);
Controls.Add(pnl);
}
// ── RODAPÉ ─────────────────────────────────────────────────────────────
private void MontarRodape()
{
var pnl = new Panel { Dock = DockStyle.Bottom, Height = 48, BackColor = CorPainel };
pnl.Paint += (s, e) => e.Graphics.DrawLine(new Pen(CorBorda), 0, 0, pnl.Width, 0);
lblStatus = new Label
{
Font = FontePequena,
ForeColor = CorTextoClaro,
AutoSize = true,
Location = new Point(16, 16)
};
pnl.Controls.Add(lblStatus);
var btnFechar = new Button
{
Text = "Close",
Font = FonteNormal,
ForeColor = CorTextoClaro,
BackColor = CorFundo,
FlatStyle = FlatStyle.Flat,
Size = new Size(90, 30),
Cursor = Cursors.Hand
};
btnFechar.FlatAppearance.BorderColor = CorBorda;
btnFechar.Click += (s, e) => Close();
var btnCopiar = new Button
{
Text = "Copy All",
Font = FonteSemi,
ForeColor = Color.White,
BackColor = CorAccent,
FlatStyle = FlatStyle.Flat,
Size = new Size(120, 30),
Cursor = Cursors.Hand
};
btnCopiar.FlatAppearance.BorderSize = 0;
btnCopiar.Click += BtnCopiar_Click;
pnl.Controls.Add(btnFechar);
pnl.Controls.Add(btnCopiar);
pnl.Resize += (s, e) =>
{
btnCopiar.Location = new Point(pnl.Width - 132, 9);
btnFechar.Location = new Point(pnl.Width - 232, 9);
};
Controls.Add(pnl);
}
// ── CORPO (SplitContainer) ─────────────────────────────────────────────
private void MontarCorpo()
{
var splitter = new SplitContainer
{
Dock = DockStyle.Fill,
SplitterWidth = 5,
BackColor = CorBorda,
BorderStyle = BorderStyle.None,
FixedPanel = FixedPanel.Panel1
};
splitter.SplitterDistance = 280;
MontarPainelEsquerdo(splitter.Panel1);
MontarGrid(splitter.Panel2);
Controls.Add(splitter);
}
// ── PAINEL ESQUERDO (categorias) ──────────────────────────────────────
private void MontarPainelEsquerdo(SplitterPanel parent)
{
parent.BackColor = CorPainel;
var pnlCat = new Panel { Dock = DockStyle.Fill, BackColor = CorPainel, Padding = new Padding(8) };
parent.Controls.Add(pnlCat);
var lblTitulo = new Label
{
Text = "Categories",
Font = FonteTitulo,
ForeColor = CorTexto,
Dock = DockStyle.Top,
Height = 32
};
pnlCat.Controls.Add(lblTitulo);
// Select all / clear — FlowLayoutPanel evita overlap
var pnlLinks = new FlowLayoutPanel
{
Dock = DockStyle.Top,
Height = 30,
FlowDirection = FlowDirection.LeftToRight,
WrapContents = false,
AutoSize = false
};
var lnkTudo = new LinkLabel
{
Text = "Select all",
AutoSize = true,
Font = FontePequena,
Margin = new Padding(0, 4, 8, 0)
};
lnkTudo.Click += (s, e) =>
{
for (int i = 0; i < clbCategorias.Items.Count; i++)
clbCategorias.SetItemChecked(i, true);
};
var lnkLimpar = new LinkLabel
{
Text = "Clear",
AutoSize = true,
Font = FontePequena,
Margin = new Padding(0, 4, 0, 0)
};
lnkLimpar.Click += (s, e) =>
{
for (int i = 0; i < clbCategorias.Items.Count; i++)
clbCategorias.SetItemChecked(i, false);
};
pnlLinks.Controls.Add(lnkTudo);
pnlLinks.Controls.Add(lnkLimpar);
pnlCat.Controls.Add(pnlLinks);
pnlLinks.BringToFront();
clbCategorias = new CheckedListBox
{
Dock = DockStyle.Fill,
BorderStyle = BorderStyle.None,
Font = FonteNormal,
CheckOnClick = true,
IntegralHeight = false,
BackColor = CorPainel,
HorizontalScrollbar = true
};
foreach (var cat in _porCategoria.Keys.OrderBy(c => c))
clbCategorias.Items.Add(cat, true); // todas marcadas por padrão
// Calcular HorizontalExtent para mostrar nomes completos
clbCategorias.HandleCreated += (s, e) => AjustarHorizontalExtent(clbCategorias);
clbCategorias.ItemCheck += (s, e) =>
{
if (IsHandleCreated)
BeginInvoke((Action)AtualizarGrid);
};
pnlCat.Controls.Add(clbCategorias);
clbCategorias.BringToFront();
parent.Controls.Add(pnlCat);
}
// ── GRID (painel direito) ──────────────────────────────────────────────
private void MontarGrid(SplitterPanel parent)
{
parent.BackColor = CorPainel;
dgv = new DataGridView
{
Dock = DockStyle.Fill,
ReadOnly = true,
AllowUserToAddRows = false,
AllowUserToDeleteRows = false,
AllowUserToResizeRows = false,
ColumnHeadersHeight = 34,
RowHeadersVisible = false,
BackgroundColor = CorPainel,
GridColor = CorBorda,
BorderStyle = BorderStyle.None,
CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal,
Font = FonteGrid,
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None,
EnableHeadersVisualStyles = false
};
dgv.RowTemplate.Height = 28;
dgv.ColumnHeadersDefaultCellStyle.BackColor = CorGridHeader;
dgv.ColumnHeadersDefaultCellStyle.ForeColor = CorTexto;
dgv.ColumnHeadersDefaultCellStyle.Font = UITheme.Typography.Label;
dgv.ColumnHeadersDefaultCellStyle.SelectionBackColor = CorGridHeader;
dgv.DefaultCellStyle.BackColor = CorPainel;
dgv.DefaultCellStyle.ForeColor = CorTexto;
dgv.DefaultCellStyle.SelectionBackColor = UITheme.Color.PrimaryVeryLight;
dgv.DefaultCellStyle.SelectionForeColor = CorTexto;
dgv.AlternatingRowsDefaultCellStyle.BackColor = CorGridAlt;
dgv.RowTemplate.Height = 22;
dgv.Columns.Add(new DataGridViewTextBoxColumn
{ Name = "Categoria", HeaderText = "Category", Width = 160, MinimumWidth = 80 });
dgv.Columns.Add(new DataGridViewTextBoxColumn
{ Name = "Propriedade", HeaderText = "Property", Width = 210, MinimumWidth = 100 });
dgv.Columns.Add(new DataGridViewTextBoxColumn
{ Name = "Valor", HeaderText = "Value", Width = 300, MinimumWidth = 100,
AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill });
dgv.Columns.Add(new DataGridViewTextBoxColumn
{ Name = "Tipo", HeaderText = "Type", Width = 80, MinimumWidth = 60 });
parent.Controls.Add(dgv);
}
// ── ATUALIZAR GRID ─────────────────────────────────────────────────────
private void AtualizarGrid()
{
var catsMarcadas = new HashSet<string>(clbCategorias == null
? _porCategoria.Keys
: clbCategorias.CheckedItems.Cast<object>().Select(o => o.ToString()));
var filtro = txtBusca?.Text.Trim().ToLower() ?? "";
dgv.SuspendLayout();
dgv.Rows.Clear();
int count = 0;
foreach (var cat in _porCategoria.Keys.OrderBy(c => c))
{
if (!catsMarcadas.Contains(cat)) continue;
foreach (var prop in _porCategoria[cat])
{
if (!string.IsNullOrEmpty(filtro))
{
bool match = (prop.Categoria?.ToLower().Contains(filtro) == true)
|| (prop.Nome?.ToLower().Contains(filtro) == true)
|| (prop.Valor?.ToLower().Contains(filtro) == true);
if (!match) continue;
}
dgv.Rows.Add(prop.Categoria, prop.Nome, prop.Valor, prop.Tipo ?? "string");
count++;
}
}
dgv.ResumeLayout();
if (lblStatus != null)
lblStatus.Text = $"{count} property/properties | {catsMarcadas.Count} categories selected";
}
// ── HELPERS ───────────────────────────────────────────────────────────
private static void AjustarHorizontalExtent(CheckedListBox clb)
{
using (var g = clb.CreateGraphics())
{
int maxW = 0;
foreach (var item in clb.Items)
{
int w = (int)g.MeasureString(item.ToString(), clb.Font).Width + 28; // 28 = checkbox
if (w > maxW) maxW = w;
}
clb.HorizontalExtent = maxW + 4;
}
}
// ── COPIAR ─────────────────────────────────────────────────────────────
private void BtnCopiar_Click(object sender, EventArgs e)
{
var linhas = new List<string>();
foreach (DataGridViewRow row in dgv.Rows)
{
string cat = row.Cells["Categoria"].Value?.ToString() ?? "";
string prop = row.Cells["Propriedade"].Value?.ToString() ?? "";
string val = row.Cells["Valor"].Value?.ToString() ?? "";
linhas.Add($"{cat}\t{prop}\t{val}");
}
if (!linhas.Any()) return;
Clipboard.SetText(string.Join("\r\n", linhas));
MessageBox.Show($"{linhas.Count} properties copied to clipboard.",
"Autis 4D", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}