KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bom_settings.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Mike Williams <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <json_common.h>
24#include <wx/translation.h>
25
26
27// Implementations for BOM_FMT_PRESET
28bool BOM_FIELD::operator==( const BOM_FIELD& rhs ) const
29{
30 return this->name == rhs.name && this->label == rhs.label && this->show == rhs.show
31 && this->groupBy == rhs.groupBy;
32}
33
34
35bool operator!=( const BOM_FIELD& lhs, const BOM_FIELD& rhs )
36{
37 return !( lhs == rhs );
38}
39
40
41bool operator<( const BOM_FIELD& lhs, const BOM_FIELD& rhs )
42{
43 return lhs.name < rhs.name;
44}
45
46
47void to_json( nlohmann::json& j, const BOM_FIELD& f )
48{
49 j = nlohmann::json{
50 { "name", f.name }, { "label", f.label }, { "show", f.show }, { "group_by", f.groupBy }
51 };
52}
53
54
55void from_json( const nlohmann::json& j, BOM_FIELD& f )
56{
57 j.at( "name" ).get_to( f.name );
58 j.at( "label" ).get_to( f.label );
59 j.at( "show" ).get_to( f.show );
60 j.at( "group_by" ).get_to( f.groupBy );
61}
62
63
64bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs )
65{
66 return !( lhs == rhs );
67}
68
69
70bool operator<( const BOM_PRESET& lhs, const BOM_PRESET& rhs )
71{
72 return lhs.name < rhs.name;
73}
74
75
76void to_json( nlohmann::json& j, const BOM_PRESET& p )
77{
78 j = nlohmann::json{
79 { "name", p.name },
80 { "sort_field", p.sortField },
81 { "sort_asc", p.sortAsc },
82 { "filter_string", p.filterString },
83 { "filter_scope", p.filterScope },
84 { "group_symbols", p.groupSymbols },
85 { "exclude_dnp", p.excludeDNP },
86 { "include_excluded_from_bom", p.includeExcludedFromBOM },
87 };
88
89 if( p.fieldsOrdered.size() > 0 )
90 j["fields_ordered"] = p.fieldsOrdered;
91}
92
93
94void from_json( const nlohmann::json& j, BOM_PRESET& f )
95{
96 j.at( "name" ).get_to( f.name );
97 j.at( "fields_ordered" ).get_to( f.fieldsOrdered );
98 j.at( "sort_field" ).get_to( f.sortField );
99 j.at( "sort_asc" ).get_to( f.sortAsc );
100 j.at( "filter_string" ).get_to( f.filterString );
101 f.filterScope = j.value( "filter_scope", BOM_FILTER_SCOPE::REFERENCE );
102 j.at( "group_symbols" ).get_to( f.groupSymbols );
103 j.at( "exclude_dnp" ).get_to( f.excludeDNP );
104
105 // Was not present in initial BOM settings in 8.0, so default to false if not found
106 f.includeExcludedFromBOM = j.value( "include_excluded_from_bom", false );
107}
108
109
110// Implementations for BOM_PRESET
111bool BOM_PRESET::operator==( const BOM_PRESET& rhs ) const
112{
113 return this->name == rhs.name
114 && this->readOnly == rhs.readOnly
115 && this->fieldsOrdered == rhs.fieldsOrdered
116 && this->sortField == rhs.sortField
117 && this->sortAsc == rhs.sortAsc
118 && this->filterString == rhs.filterString
119 && this->filterScope == rhs.filterScope
120 && this->groupSymbols == rhs.groupSymbols
121 && this->excludeDNP == rhs.excludeDNP
122 && this->includeExcludedFromBOM == rhs.includeExcludedFromBOM;
123}
124
125
126BOM_PRESET BOM_PRESET::DefaultEditing()
127{
128 BOM_PRESET p{
129 _HKI( "Default Editing" ), true, {}, _( "Reference" ), true, "", BOM_FILTER_SCOPE::REFERENCE,
130 true, false, true
131 };
132
133 p.fieldsOrdered = std::vector<BOM_FIELD>{
134 { "Reference", "Reference", true, false },
135 { "${QUANTITY}", "Qty", true, false },
136 { "Value", "Value", true, true },
137 { "${DNP}", "DNP", true, true },
138 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, true },
139 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, true },
140 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, true },
141 { "${EXCLUDE_FROM_POS_FILES}", "Exclude from Position Files", true, true },
142 { "Footprint", "Footprint", true, true },
143 { "Datasheet", "Datasheet", true, false },
144 };
145
146 return p;
147}
148
149
150BOM_PRESET BOM_PRESET::GroupedByValue()
151{
152 BOM_PRESET p{
153 _HKI( "Grouped By Value" ), true, {}, _( "Reference" ), true, "", BOM_FILTER_SCOPE::REFERENCE,
154 true, false, false
155 };
156
157 p.fieldsOrdered = std::vector<BOM_FIELD>{
158 { "Reference", "Reference", true, false },
159 { "Value", "Value", true, true },
160 { "Datasheet", "Datasheet", true, false },
161 { "Footprint", "Footprint", true, false },
162 { "${QUANTITY}", "Qty", true, false },
163 { "${DNP}", "DNP", true, true },
164 };
165
166 return p;
167}
168
169
170BOM_PRESET BOM_PRESET::GroupedByValueFootprint()
171{
172 BOM_PRESET p{
173 _HKI( "Grouped By Value and Footprint" ), true, {}, _( "Reference" ), true, "",
174 BOM_FILTER_SCOPE::REFERENCE, true, false, false
175 };
176
177 p.fieldsOrdered = std::vector<BOM_FIELD>{
178 { "Reference", "Reference", true, false },
179 { "Value", "Value", true, true },
180 { "Datasheet", "Datasheet", true, false },
181 { "Footprint", "Footprint", true, true },
182 { "${QUANTITY}", "Qty", true, false },
183 { "${DNP}", "DNP", true, true },
184 };
185
186 return p;
187}
188
189
190BOM_PRESET BOM_PRESET::Attributes()
191{
192 BOM_PRESET p{
193 _HKI( "Attributes" ), true, {}, _( "Reference" ), true, "", BOM_FILTER_SCOPE::REFERENCE,
194 true, false, true
195 };
196
197 p.fieldsOrdered = std::vector<BOM_FIELD>{
198 { "Reference", "Reference", true, false },
199 { "Value", "Value", true, true },
200 { "Datasheet", "Datasheet", false, false },
201 { "Footprint", "Footprint", false, true },
202 { "${DNP}", "Do Not Place", true, false },
203 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
204 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
205 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
206 { "${EXCLUDE_FROM_POS_FILES}", "Exclude from Position Files", true, false },
207 };
208
209 return p;
210}
211
212
213std::vector<BOM_PRESET> BOM_PRESET::BuiltInPresets()
214{
215 return { BOM_PRESET::DefaultEditing(), BOM_PRESET::GroupedByValue(),
216 BOM_PRESET::GroupedByValueFootprint(), BOM_PRESET::Attributes() };
217}
218
219
220//Implementations for BOM_FMT_PRESET
222{
223 return this->name == rhs.name && this->readOnly == rhs.readOnly
224 && this->fieldDelimiter == rhs.fieldDelimiter
225 && this->stringDelimiter == rhs.stringDelimiter && this->refDelimiter == rhs.refDelimiter
226 && this->refRangeDelimiter == rhs.refRangeDelimiter && this->keepTabs == rhs.keepTabs
227 && this->keepLineBreaks == rhs.keepLineBreaks
229}
230
231
232bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
233{
234 return !( lhs == rhs );
235}
236
237
238bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
239{
240 return lhs.name < rhs.name;
241}
242
243
244void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p )
245{
246 j = nlohmann::json{ { "name", p.name },
247 { "field_delimiter", p.fieldDelimiter },
248 { "string_delimiter", p.stringDelimiter },
249 { "ref_delimiter", p.refDelimiter },
250 { "ref_range_delimiter", p.refRangeDelimiter },
251 { "keep_tabs", p.keepTabs },
252 { "keep_line_breaks", p.keepLineBreaks },
253 { "include_byte_order_mark", p.includeByteOrderMark } };
254}
255
256
257void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f )
258{
259 j.at( "name" ).get_to( f.name );
260 j.at( "field_delimiter" ).get_to( f.fieldDelimiter );
261 j.at( "string_delimiter" ).get_to( f.stringDelimiter );
262 j.at( "ref_delimiter" ).get_to( f.refDelimiter );
263 j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter );
264 j.at( "keep_tabs" ).get_to( f.keepTabs );
265 j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks );
266 // Added after the other options, so may not be present in old settings
267 f.includeByteOrderMark = j.value( "include_byte_order_mark", false );
268}
269
270
272{
273 return { _HKI( "CSV" ), true, wxS( "," ), wxT( "\"" ), wxT( "," ), wxT( "" ), false, false, false };
274}
275
276
278{
279 return { _HKI( "TSV" ), true, wxS( "\t" ), wxT( "" ), wxT( "," ), wxT( "" ), false, false, false };
280}
281
282
284{
285 return {
286 _HKI( "Semicolons" ), true, wxS( ";" ), wxT( "'" ), wxT( "," ), wxT( "" ), false, false, false
287 };
288}
289
290
291std::vector<BOM_FMT_PRESET> BOM_FMT_PRESET::BuiltInPresets()
292{
294}
295
296
297#if !defined( __MINGW32__ )
300#endif
const char * name
void to_json(nlohmann::json &j, const BOM_FIELD &f)
bool operator<(const BOM_FIELD &lhs, const BOM_FIELD &rhs)
void from_json(const nlohmann::json &j, BOM_FIELD &f)
bool operator!=(const BOM_FIELD &lhs, const BOM_FIELD &rhs)
#define _(s)
#define KICOMMON_API
Definition kicommon.h:27
#define _HKI(x)
Definition page_info.cpp:40
wxString label
bool operator==(const BOM_FIELD &rhs) const
wxString name
bool operator==(const BOM_FMT_PRESET &rhs) const
wxString fieldDelimiter
bool includeByteOrderMark
static BOM_FMT_PRESET CSV()
static std::vector< BOM_FMT_PRESET > BuiltInPresets()
wxString stringDelimiter
static BOM_FMT_PRESET TSV()
wxString refRangeDelimiter
static BOM_FMT_PRESET Semicolons()
wxString refDelimiter