This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
comp_table.cpp
278 lines (260 loc) · 6.47 KB
/
comp_table.cpp
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
#include "comp_table.h"
#include "project.h"
#include <algorithm>
enum ComponentColumns
{
COL_DESIGNATOR = 0,
COL_CAD_NAME,
COL_CAD_PATTERN,
COL_CAD_VALUE,
COL_FULL_NAME,
COL_LAYER,
COL_CAD_LOCATION_X,
COL_CAD_LOCATION_Y,
COL_CAD_ANGLE,
COL_ENABLED,
COL_PATTERN,
COL_PNP_NAME,
COL_PNP_PACKAGE,
COL_PNP_FOOTPRINT,
COL_PNP_LOCATION_X,
COL_PNP_LOCATION_Y,
COL_PNP_ANGLE,
COL_PNP_SUBPCB,
COL_PNP_ENABLED,
COUNT,
};
ComponentTable::ComponentTable(Project *project)
: wxGridTableBase()
, m_project(project)
, m_component(project->GetComponent())
{
wxGridCellAttrProvider *attrProvider = new wxGridCellAttrProvider;
SetAttrProvider (attrProvider);
wxGridCellAttr *ro_attr = new wxGridCellAttr();
ro_attr->SetReadOnly();
for (int col = 0; col < COUNT; col++)
SetColAttr(ro_attr, col);
}
ComponentTable::~ComponentTable()
{
}
int ComponentTable::GetNumberRows()
{
return m_component.size();
}
int ComponentTable::GetNumberCols()
{
return COUNT;
}
wxGridCellAttr *ComponentTable::GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind)
{
wxGridCellAttr *attr = GetAttrProvider()->GetAttr(row, col, kind);
Component& data = m_component[row];
if (!(data.enabled && data.pnp_enabled))
{
wxGridCellAttr *attrNew = attr->Clone();
attr->DecRef();
attr = attrNew;
attr->SetTextColour(*wxLIGHT_GREY);
}
return attr;
}
wxString ComponentTable::GetColLabelValue( int col )
{
wxString result = wxEmptyString;
switch (col)
{
case COL_DESIGNATOR:
result = "Des";
break;
case COL_CAD_NAME:
result = "Name";
break;
case COL_CAD_PATTERN:
result = "Pattern";
break;
case COL_CAD_VALUE:
result = "Value";
break;
case COL_FULL_NAME:
result = "ID";
break;
case COL_LAYER:
result = "Layer";
break;
case COL_CAD_LOCATION_X:
result = "X";
break;
case COL_CAD_LOCATION_Y:
result = "Y";
break;
case COL_CAD_ANGLE:
result = "Angle";
break;
case COL_ENABLED:
result = "To OUT";
break;
case COL_PATTERN:
result = "Patt";
break;
case COL_PNP_NAME:
result = "PNP Comp";
break;
case COL_PNP_PACKAGE:
result = "PNP Pack";
break;
case COL_PNP_FOOTPRINT:
result = "PNP Foot";
break;
case COL_PNP_LOCATION_X:
result = "PNP X";
break;
case COL_PNP_LOCATION_Y:
result = "PNP Y";
break;
case COL_PNP_ANGLE:
result = "PNP Angle";
break;
case COL_PNP_SUBPCB:
result = "PNP pcb";
break;
case COL_PNP_ENABLED:
result = "To OUT";
break;
}
return result;
}
wxString ComponentTable::GetValue( int row, int col )
{
wxString result = wxEmptyString;
Component& data = m_component[row];
switch (col)
{
case COL_DESIGNATOR:
result = data.designator;
break;
case COL_CAD_NAME:
result = data.cad_name;
break;
case COL_CAD_PATTERN:
result = data.cad_pattern;
break;
case COL_CAD_VALUE:
result = data.cad_value;
break;
case COL_FULL_NAME:
result = data.full_name;
break;
case COL_LAYER:
result = data.layer;
break;
case COL_CAD_LOCATION_X:
result = wxString::Format("%.3f", data.cad_location_x);
break;
case COL_CAD_LOCATION_Y:
result = wxString::Format("%.3f", data.cad_location_y);
break;
case COL_CAD_ANGLE:
result = wxString::Format("%.1f", data.cad_angle);
break;
case COL_ENABLED:
result = wxString::Format("%d", data.enabled);
break;
case COL_PATTERN:
result = data.pattern;
break;
case COL_PNP_NAME:
result = data.pnp_name;
break;
case COL_PNP_PACKAGE:
result = data.pnp_package;
break;
case COL_PNP_FOOTPRINT:
result = data.pnp_footprint;
break;
case COL_PNP_LOCATION_X:
result = wxString::Format("%.3f", data.pnp_location_x);
break;
case COL_PNP_LOCATION_Y:
result = wxString::Format("%.3f", data.pnp_location_y);
break;
case COL_PNP_ANGLE:
result = wxString::Format("%.1f", data.pnp_angle);
break;
case COL_PNP_SUBPCB:
result = wxString::Format("%d", data.pnp_subpcb_index);
break;
case COL_PNP_ENABLED:
result = wxString::Format("%d", data.pnp_enabled);
break;
}
return result;
}
void ComponentTable::SetValue( int row, int col, const wxString& value )
{
}
void ComponentTable::Sort(int col)
{
switch (col)
{
case COL_DESIGNATOR:
std::sort(m_component.begin(), m_component.end());
break;
case COL_CAD_NAME:
std::sort(m_component.begin(), m_component.end(), Component::ByCadName);
break;
case COL_CAD_PATTERN:
std::sort(m_component.begin(), m_component.end(), Component::ByCadPattern);
break;
case COL_CAD_VALUE:
std::sort(m_component.begin(), m_component.end(), Component::ByCadValue);
break;
case COL_FULL_NAME:
std::sort(m_component.begin(), m_component.end(), Component::ByFullName);
break;
case COL_LAYER:
std::sort(m_component.begin(), m_component.end(), Component::ByLayer);
break;
case COL_CAD_LOCATION_X:
std::sort(m_component.begin(), m_component.end(), Component::ByCadLocationX);
break;
case COL_CAD_LOCATION_Y:
std::sort(m_component.begin(), m_component.end(), Component::ByCadLocationY);
break;
case COL_CAD_ANGLE:
std::sort(m_component.begin(), m_component.end(), Component::ByCadAngle);
break;
case COL_ENABLED:
std::sort(m_component.begin(), m_component.end(), Component::ByEnabled);
break;
case COL_PATTERN:
std::sort(m_component.begin(), m_component.end(), Component::ByPattern);
break;
case COL_PNP_NAME:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpName);
break;
case COL_PNP_PACKAGE:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpPackage);
break;
case COL_PNP_FOOTPRINT:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpFootprint);
break;
case COL_PNP_LOCATION_X:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpLocationX);
break;
case COL_PNP_LOCATION_Y:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpLocationY);
break;
case COL_PNP_ANGLE:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpAngle);
break;
case COL_PNP_SUBPCB:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpSubpcbIndex);
break;
case COL_PNP_ENABLED:
std::sort(m_component.begin(), m_component.end(), Component::ByPnpEnabled);
break;
}
}