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_type_table.cpp
188 lines (171 loc) · 4.36 KB
/
comp_type_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
#include "comp_type_table.h"
#include "project.h"
#include <algorithm>
enum ComponentTypeColumns
{
COL_NAME = 0,
COL_PATTERN,
COL_PNP_NAME,
COL_OVR_NAME,
COL_COMP_COUNT,
COL_ENABLED,
COL_IS_NEW,
COUNT,
};
ComponentTypeTable::ComponentTypeTable(Project *project)
: wxGridTableBase()
, m_project(project)
, m_type(project->GetComponentType())
{
wxGridCellAttrProvider *attrProvider = new wxGridCellAttrProvider;
SetAttrProvider (attrProvider);
wxGridCellAttr *ro_attr = new wxGridCellAttr();
ro_attr->SetReadOnly();
SetColAttr (ro_attr, COL_NAME);
SetColAttr (ro_attr, COL_IS_NEW);
wxGridCellAttr *ro_num_attr = new wxGridCellAttr();
wxGridCellNumberRenderer *num_rend = new wxGridCellNumberRenderer();
ro_num_attr->SetRenderer(num_rend);
ro_num_attr->SetReadOnly();
SetColAttr (ro_num_attr, COL_COMP_COUNT);
wxGridCellAttr *bool_attr = new wxGridCellAttr();
wxGridCellBoolRenderer *bool_rend = new wxGridCellBoolRenderer();
bool_attr->SetRenderer(bool_rend);
wxGridCellBoolEditor *bool_edit = new wxGridCellBoolEditor();
bool_edit->UseStringValues("1", "0");
bool_attr->SetEditor(bool_edit);
SetColAttr (bool_attr, COL_ENABLED);
SetColAttr (bool_attr, COL_OVR_NAME);
// InsertColumn(COL_NAME, _T("Name"), wxLIST_FORMAT_LEFT, 120);
// InsertColumn(COL_PATTERN, _T("Patt"), wxLIST_FORMAT_LEFT, 70);
// InsertColumn(COL_PNP_NAME, _T("PNP Name"), wxLIST_FORMAT_LEFT, 110);
// InsertColumn(COL_COMP_COUNT, _T("Count"), wxLIST_FORMAT_LEFT, 50);
// InsertColumn(COL_ENABLED, _T("To OUT"), wxLIST_FORMAT_LEFT, 50);
// InsertColumn(COL_IS_NEW, _T("New"), wxLIST_FORMAT_LEFT, 50);
}
ComponentTypeTable::~ComponentTypeTable()
{
}
int ComponentTypeTable::GetNumberRows()
{
return m_type.size();
}
int ComponentTypeTable::GetNumberCols()
{
return COUNT;
}
wxString ComponentTypeTable::GetColLabelValue( int col )
{
wxString result = wxEmptyString;
switch (col)
{
case COL_NAME:
result = "Name";
break;
case COL_PATTERN:
result = "Pattern";
break;
case COL_PNP_NAME:
result = "Name in PnP";
break;
case COL_OVR_NAME:
result = "Override Name";
break;
case COL_COMP_COUNT:
result = "Count";
break;
case COL_ENABLED:
result = "To OUT";
break;
case COL_IS_NEW:
result = "New";
break;
}
return result;
}
wxString ComponentTypeTable::GetValue(int row, int col)
{
wxString result = wxEmptyString;
ComponentType& data = m_type[row];
switch (col)
{
case COL_NAME:
result = data.name;
break;
case COL_PATTERN:
result = data.pattern;
break;
case COL_PNP_NAME:
result = data.pnp_name;
break;
case COL_OVR_NAME:
result = wxString::Format("%d", data.override_name);
break;
case COL_COMP_COUNT:
result = wxString::Format("%d", data.comp_count);
break;
case COL_ENABLED:
result = wxString::Format("%d", data.enabled);
break;
case COL_IS_NEW:
result = wxString::Format("%d", data.is_new);
break;
}
return result;
}
void ComponentTypeTable::SetValue(int row, int col, const wxString& value)
{
long tmp_long;
if (value.IsEmpty())
return;
ComponentType& data = m_type[row];
switch (col)
{
case COL_PATTERN:
data.pattern = value;
break;
case COL_PNP_NAME:
data.pnp_name = value;
break;
case COL_OVR_NAME:
value.ToLong(&tmp_long);
data.override_name = tmp_long;
break;
case COL_ENABLED:
value.ToLong(&tmp_long);
data.enabled = tmp_long;
break;
}
//
// update project
//
m_project->UpdateComponents();
m_project->Notify(wxEVT_PROJECT_UPDATED);
}
void ComponentTypeTable::Sort(int col)
{
switch (col)
{
case COL_NAME:
std::sort(m_type.begin(), m_type.end());
break;
case COL_PATTERN:
std::sort(m_type.begin(), m_type.end(), ComponentType::ByPattern);
break;
case COL_PNP_NAME:
std::sort(m_type.begin(), m_type.end(), ComponentType::ByPnpName);
break;
case COL_OVR_NAME:
std::sort(m_type.begin(), m_type.end(), ComponentType::ByOverrideName);
break;
case COL_COMP_COUNT:
std::sort(m_type.begin(), m_type.end(), ComponentType::ByCompCount);
break;
case COL_ENABLED:
std::sort(m_type.begin(), m_type.end(), ComponentType::ByEnabled);
break;
case COL_IS_NEW:
std::sort(m_type.begin(), m_type.end(), ComponentType::ByIsNew);
break;
}
}