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 { "group_symbols", p.groupSymbols },
84 { "exclude_dnp", p.excludeDNP },
85 { "include_excluded_from_bom", p.includeExcludedFromBOM },
86 };
87
88 if( p.fieldsOrdered.size() > 0 )
89 j["fields_ordered"] = p.fieldsOrdered;
90}
91
92
93void from_json( const nlohmann::json& j, BOM_PRESET& f )
94{
95 j.at( "name" ).get_to( f.name );
96 j.at( "fields_ordered" ).get_to( f.fieldsOrdered );
97 j.at( "sort_field" ).get_to( f.sortField );
98 j.at( "sort_asc" ).get_to( f.sortAsc );
99 j.at( "filter_string" ).get_to( f.filterString );
100 j.at( "group_symbols" ).get_to( f.groupSymbols );
101 j.at( "exclude_dnp" ).get_to( f.excludeDNP );
102
103 // Was not present in initial BOM settings in 8.0, so default to false if not found
104 f.includeExcludedFromBOM = j.value( "include_excluded_from_bom", false );
105}
106
107
108// Implementations for BOM_PRESET
109bool BOM_PRESET::operator==( const BOM_PRESET& rhs ) const
110{
111 return this->name == rhs.name
112 && this->readOnly == rhs.readOnly
113 && this->fieldsOrdered == rhs.fieldsOrdered
114 && this->sortField == rhs.sortField
115 && this->sortAsc == rhs.sortAsc
116 && this->filterString == rhs.filterString
117 && this->groupSymbols == rhs.groupSymbols
118 && this->excludeDNP == rhs.excludeDNP
120}
121
122
124{
125 BOM_PRESET p{
126 _HKI( "Default Editing" ), true, {}, _( "Reference" ), true, "", true, false, true
127 };
128
129 p.fieldsOrdered = std::vector<BOM_FIELD>{
130 { "Reference", "Reference", true, false },
131 { "${QUANTITY}", "Qty", true, false },
132 { "Value", "Value", true, true },
133 { "${DNP}", "DNP", true, true },
134 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, true },
135 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, true },
136 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, true },
137 { "${EXCLUDE_FROM_POS_FILES}", "Exclude from Position Files", true, true },
138 { "Footprint", "Footprint", true, true },
139 { "Datasheet", "Datasheet", true, false },
140 };
141
142 return p;
143}
144
145
147{
148 BOM_PRESET p{
149 _HKI( "Grouped By Value" ), true, {}, _( "Reference" ), true, "", true, false, false
150 };
151
152 p.fieldsOrdered = std::vector<BOM_FIELD>{
153 { "Reference", "Reference", true, false },
154 { "Value", "Value", true, true },
155 { "Datasheet", "Datasheet", true, false },
156 { "Footprint", "Footprint", true, false },
157 { "${QUANTITY}", "Qty", true, false },
158 { "${DNP}", "DNP", true, true },
159 };
160
161 return p;
162}
163
164
166{
167 BOM_PRESET p{
168 _HKI( "Grouped By Value and Footprint" ), true, {}, _( "Reference" ), true, "",
169 true, false, false
170 };
171
172 p.fieldsOrdered = std::vector<BOM_FIELD>{
173 { "Reference", "Reference", true, false },
174 { "Value", "Value", true, true },
175 { "Datasheet", "Datasheet", true, false },
176 { "Footprint", "Footprint", true, true },
177 { "${QUANTITY}", "Qty", true, false },
178 { "${DNP}", "DNP", true, true },
179 };
180
181 return p;
182}
183
184
186{
187 BOM_PRESET p{
188 _HKI( "Attributes" ), true, {}, _( "Reference" ), true, "", true, false, true
189 };
190
191 p.fieldsOrdered = std::vector<BOM_FIELD>{
192 { "Reference", "Reference", true, false },
193 { "Value", "Value", true, true },
194 { "Datasheet", "Datasheet", false, false },
195 { "Footprint", "Footprint", false, true },
196 { "${DNP}", "Do Not Place", true, false },
197 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
198 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
199 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
200 { "${EXCLUDE_FROM_POS_FILES}", "Exclude from Position Files", true, false },
201 };
202
203 return p;
204}
205
206
212
213
214//Implementations for BOM_FMT_PRESET
216{
217 return this->name == rhs.name && this->readOnly == rhs.readOnly
218 && this->fieldDelimiter == rhs.fieldDelimiter
219 && this->stringDelimiter == rhs.stringDelimiter && this->refDelimiter == rhs.refDelimiter
220 && this->refRangeDelimiter == rhs.refRangeDelimiter && this->keepTabs == rhs.keepTabs
221 && this->keepLineBreaks == rhs.keepLineBreaks;
222}
223
224
225bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
226{
227 return !( lhs == rhs );
228}
229
230
231bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
232{
233 return lhs.name < rhs.name;
234}
235
236
237void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p )
238{
239 j = nlohmann::json{ { "name", p.name },
240 { "field_delimiter", p.fieldDelimiter },
241 { "string_delimiter", p.stringDelimiter },
242 { "ref_delimiter", p.refDelimiter },
243 { "ref_range_delimiter", p.refRangeDelimiter },
244 { "keep_tabs", p.keepTabs },
245 { "keep_line_breaks", p.keepLineBreaks } };
246}
247
248
249void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f )
250{
251 j.at( "name" ).get_to( f.name );
252 j.at( "field_delimiter" ).get_to( f.fieldDelimiter );
253 j.at( "string_delimiter" ).get_to( f.stringDelimiter );
254 j.at( "ref_delimiter" ).get_to( f.refDelimiter );
255 j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter );
256 j.at( "keep_tabs" ).get_to( f.keepTabs );
257 j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks );
258}
259
260
262{
263 return { _HKI( "CSV" ), true, wxS( "," ), wxT( "\"" ), wxT( "," ), wxT( "" ), false, false };
264}
265
266
268{
269 return { _HKI( "TSV" ), true, wxS( "\t" ), wxT( "" ), wxT( "," ), wxT( "" ), false, false };
270}
271
272
274{
275 return {
276 _HKI( "Semicolons" ), true, wxS( ";" ), wxT( "'" ), wxT( "," ), wxT( "" ), false, false
277 };
278}
279
280
281std::vector<BOM_FMT_PRESET> BOM_FMT_PRESET::BuiltInPresets()
282{
284}
285
286
287#if !defined( __MINGW32__ )
290#endif
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
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
wxString name
bool operator==(const BOM_PRESET &rhs) const
static BOM_PRESET DefaultEditing()
wxString sortField
bool groupSymbols
std::vector< BOM_FIELD > fieldsOrdered
static BOM_PRESET GroupedByValue()
bool includeExcludedFromBOM
static std::vector< BOM_PRESET > BuiltInPresets()
bool excludeDNP
static BOM_PRESET GroupedByValueFootprint()
static BOM_PRESET Attributes()
wxString filterString