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
31 && this->label == rhs.label
32 && this->show == rhs.show
33 && this->groupBy == rhs.groupBy;
34}
35
36
37bool operator!=( const BOM_FIELD& lhs, const BOM_FIELD& rhs )
38{
39 return !( lhs == rhs );
40}
41
42
43bool operator<( const BOM_FIELD& lhs, const BOM_FIELD& rhs )
44{
45 return lhs.name < rhs.name;
46}
47
48
49void to_json( nlohmann::json& j, const BOM_FIELD& f )
50{
51 j = nlohmann::json{
52 { "name", f.name },
53 { "label", f.label },
54 { "show", f.show },
55 { "group_by", f.groupBy }
56 };
57}
58
59
60void from_json( const nlohmann::json& j, BOM_FIELD& f )
61{
62 j.at( "name" ).get_to( f.name );
63 j.at( "label" ).get_to( f.label );
64 j.at( "show" ).get_to( f.show );
65 j.at( "group_by" ).get_to( f.groupBy );
66}
67
68
69bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs )
70{
71 return !( lhs == rhs );
72}
73
74
75bool operator<( const BOM_PRESET& lhs, const BOM_PRESET& rhs )
76{
77 return lhs.name < rhs.name;
78}
79
80
81void to_json( nlohmann::json& j, const BOM_PRESET& p )
82{
83 j = nlohmann::json{
84 { "name", p.name },
85 { "fields_ordered", p.fieldsOrdered },
86 { "sort_field", p.sortField },
87 { "sort_asc", p.sortAsc },
88 { "filter_string", p.filterString },
89 { "filter_scope", p.filterScope },
90 { "group_symbols", p.groupSymbols },
91 { "exclude_dnp", p.excludeDNP },
92 { "include_excluded_from_bom", p.includeExcludedFromBOM },
93 };
94}
95
96
97void from_json( const nlohmann::json& j, BOM_PRESET& f )
98{
99 j.at( "name" ).get_to( f.name );
100 f.fieldsOrdered = j.value( "fields_ordered", std::vector<BOM_FIELD>{} );
101 j.at( "sort_field" ).get_to( f.sortField );
102 j.at( "sort_asc" ).get_to( f.sortAsc );
103 j.at( "filter_string" ).get_to( f.filterString );
104 f.filterScope = j.value( "filter_scope", BOM_FILTER_SCOPE::REFERENCE );
105 j.at( "group_symbols" ).get_to( f.groupSymbols );
106 j.at( "exclude_dnp" ).get_to( f.excludeDNP );
107
108 // Was not present in initial BOM settings in 8.0, so default to false if not found
109 f.includeExcludedFromBOM = j.value( "include_excluded_from_bom", false );
110}
111
112
113// Implementations for BOM_PRESET
114bool BOM_PRESET::operator==( const BOM_PRESET& rhs ) const
115{
116 return this->name == rhs.name
117 && this->readOnly == rhs.readOnly
118 && this->fieldsOrdered == rhs.fieldsOrdered
119 && this->sortField == rhs.sortField
120 && this->sortAsc == rhs.sortAsc
121 && this->filterString == rhs.filterString
122 && this->filterScope == rhs.filterScope
123 && this->groupSymbols == rhs.groupSymbols
124 && this->excludeDNP == rhs.excludeDNP
125 && this->includeExcludedFromBOM == rhs.includeExcludedFromBOM;
126}
127
128
129BOM_PRESET BOM_PRESET::DefaultEditing()
130{
131 BOM_PRESET p{
132 _HKI( "Default Editing" ), true, {}, wxS( "Reference" ), true, "", BOM_FILTER_SCOPE::REFERENCE,
133 true, false, true
134 };
135
136 p.fieldsOrdered = std::vector<BOM_FIELD>{
137 { "Reference", "Reference", true, false },
138 { "${QUANTITY}", "Qty", true, false },
139 { "Value", "Value", true, true },
140 { "${DNP}", "DNP", true, true },
141 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, true },
142 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, true },
143 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, true },
144 { "${EXCLUDE_FROM_POS_FILES}", "Exclude from Position Files", true, true },
145 { "Footprint", "Footprint", true, true },
146 { "Datasheet", "Datasheet", true, false },
147 };
148
149 return p;
150}
151
152
153BOM_PRESET BOM_PRESET::GroupedByValue()
154{
155 BOM_PRESET p{
156 _HKI( "Grouped By Value" ), true, {}, wxS( "Reference" ), true, "", BOM_FILTER_SCOPE::REFERENCE,
157 true, false, false
158 };
159
160 p.fieldsOrdered = std::vector<BOM_FIELD>{
161 { "Reference", "Reference", true, false },
162 { "Value", "Value", true, true },
163 { "Datasheet", "Datasheet", true, false },
164 { "Footprint", "Footprint", true, false },
165 { "${QUANTITY}", "Qty", true, false },
166 { "${DNP}", "DNP", true, true },
167 };
168
169 return p;
170}
171
172
173BOM_PRESET BOM_PRESET::GroupedByValueFootprint()
174{
175 BOM_PRESET p{
176 _HKI( "Grouped By Value and Footprint" ), true, {}, wxS( "Reference" ), true, "",
177 BOM_FILTER_SCOPE::REFERENCE, true, false, false
178 };
179
180 p.fieldsOrdered = std::vector<BOM_FIELD>{
181 { "Reference", "Reference", true, false },
182 { "Value", "Value", true, true },
183 { "Datasheet", "Datasheet", true, false },
184 { "Footprint", "Footprint", true, true },
185 { "${QUANTITY}", "Qty", true, false },
186 { "${DNP}", "DNP", true, true },
187 };
188
189 return p;
190}
191
192
193BOM_PRESET BOM_PRESET::Attributes()
194{
195 BOM_PRESET p{
196 _HKI( "Attributes" ), true, {}, wxS( "Reference" ), true, "", BOM_FILTER_SCOPE::REFERENCE,
197 true, false, true
198 };
199
200 p.fieldsOrdered = std::vector<BOM_FIELD>{
201 { "Reference", "Reference", true, false },
202 { "Value", "Value", true, true },
203 { "Datasheet", "Datasheet", false, false },
204 { "Footprint", "Footprint", false, true },
205 { "${DNP}", "Do Not Place", true, false },
206 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
207 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
208 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
209 { "${EXCLUDE_FROM_POS_FILES}", "Exclude from Position Files", true, false },
210 };
211
212 return p;
213}
214
215
216std::vector<BOM_PRESET> BOM_PRESET::BuiltInPresets()
217{
218 return { BOM_PRESET::DefaultEditing(),
219 BOM_PRESET::GroupedByValue(),
220 BOM_PRESET::GroupedByValueFootprint(),
221 BOM_PRESET::Attributes() };
222}
223
224
225//Implementations for BOM_FMT_PRESET
227{
228 return this->name == rhs.name
229 && this->readOnly == rhs.readOnly
230 && this->fieldDelimiter == rhs.fieldDelimiter
231 && this->stringDelimiter == rhs.stringDelimiter
232 && this->refDelimiter == rhs.refDelimiter
234 && this->keepTabs == rhs.keepTabs
235 && this->keepLineBreaks == rhs.keepLineBreaks
237}
238
239
240bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
241{
242 return !( lhs == rhs );
243}
244
245
246bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
247{
248 return lhs.name < rhs.name;
249}
250
251
252void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p )
253{
254 j = nlohmann::json{ { "name", p.name },
255 { "field_delimiter", p.fieldDelimiter },
256 { "string_delimiter", p.stringDelimiter },
257 { "ref_delimiter", p.refDelimiter },
258 { "ref_range_delimiter", p.refRangeDelimiter },
259 { "keep_tabs", p.keepTabs },
260 { "keep_line_breaks", p.keepLineBreaks },
261 { "include_byte_order_mark", p.includeByteOrderMark } };
262}
263
264
265void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f )
266{
267 j.at( "name" ).get_to( f.name );
268 j.at( "field_delimiter" ).get_to( f.fieldDelimiter );
269 j.at( "string_delimiter" ).get_to( f.stringDelimiter );
270 j.at( "ref_delimiter" ).get_to( f.refDelimiter );
271 j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter );
272 j.at( "keep_tabs" ).get_to( f.keepTabs );
273 j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks );
274 // Added after the other options, so may not be present in old settings
275 f.includeByteOrderMark = j.value( "include_byte_order_mark", false );
276}
277
278
280{
281 return { _HKI( "CSV" ), true, wxS( "," ), wxT( "\"" ), wxT( "," ), wxT( "" ), false, false, false };
282}
283
284
286{
287 return { _HKI( "TSV" ), true, wxS( "\t" ), wxT( "" ), wxT( "," ), wxT( "" ), false, false, false };
288}
289
290
292{
293 return {
294 _HKI( "Semicolons" ), true, wxS( ";" ), wxT( "'" ), wxT( "," ), wxT( "" ), false, false, false
295 };
296}
297
298
299std::vector<BOM_FMT_PRESET> BOM_FMT_PRESET::BuiltInPresets()
300{
302}
303
304
305#if !defined( __MINGW32__ )
308#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 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