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 (C) 2023 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 along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <nlohmann/json.hpp>
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 // Was not present in initial BOM settings in 8.0, so default to false if not found
103 f.includeExcludedFromBOM = j.value( "include_excluded_from_bom", false );
104}
105
106
107// Implementations for BOM_PRESET
108bool BOM_PRESET::operator==( const BOM_PRESET& rhs ) const
109{
110 return this->name == rhs.name
111 && this->readOnly == rhs.readOnly
112 && this->fieldsOrdered == rhs.fieldsOrdered
113 && this->sortField == rhs.sortField
114 && this->sortAsc == rhs.sortAsc
115 && this->filterString == rhs.filterString
116 && this->groupSymbols == rhs.groupSymbols
117 && this->excludeDNP == rhs.excludeDNP
119}
120
121
123{
124 BOM_PRESET p{
125 _HKI( "Default Editing" ), true, {}, _( "Reference" ), true, "", true, false, true
126 };
127
128 p.fieldsOrdered = std::vector<BOM_FIELD>{
129 { "Reference", "Reference", true, false },
130 { "${QUANTITY}", "Qty", true, false },
131 { "Value", "Value", true, true },
132 { "${DNP}", "DNP", true, true },
133 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, true },
134 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, true },
135 { "Footprint", "Footprint", true, true },
136 { "Datasheet", "Datasheet", true, false },
137 };
138
139 return p;
140}
141
142
144{
145 BOM_PRESET p{
146 _HKI( "Grouped By Value" ), true, {}, _( "Reference" ), true, "", true, false, false
147 };
148
149 p.fieldsOrdered = std::vector<BOM_FIELD>{
150 { "Reference", "Reference", true, false },
151 { "Value", "Value", true, true },
152 { "Datasheet", "Datasheet", true, false },
153 { "Footprint", "Footprint", true, false },
154 { "${QUANTITY}", "Qty", true, false },
155 { "${DNP}", "DNP", true, true },
156 };
157
158 return p;
159}
160
161
163{
164 BOM_PRESET p{
165 _HKI( "Grouped By Value and Footprint" ), true, {}, _( "Reference" ), true, "", true, false, false
166 };
167
168 p.fieldsOrdered = std::vector<BOM_FIELD>{
169 { "Reference", "Reference", true, false },
170 { "Value", "Value", true, true },
171 { "Datasheet", "Datasheet", true, false },
172 { "Footprint", "Footprint", true, true },
173 { "${QUANTITY}", "Qty", true, false },
174 { "${DNP}", "DNP", true, true },
175 };
176
177 return p;
178}
179
180
182{
183 BOM_PRESET p{
184 _HKI( "Attributes" ), true, {}, _( "Reference" ), true, "", true, false, true
185 };
186
187 p.fieldsOrdered = std::vector<BOM_FIELD>{
188 { "Reference", "Reference", true, false },
189 { "Value", "Value", true, true },
190 { "Datasheet", "Datasheet", false, false },
191 { "Footprint", "Footprint", false, true },
192 { "${DNP}", "Do Not Place", true, false },
193 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
194 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
195 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
196 };
197
198 return p;
199}
200
201std::vector<BOM_PRESET> BOM_PRESET::BuiltInPresets()
202{
205}
206
207//Implementations for BOM_FMT_PRESET
209{
210 return this->name == rhs.name && this->readOnly == rhs.readOnly
211 && this->fieldDelimiter == rhs.fieldDelimiter
212 && this->stringDelimiter == rhs.stringDelimiter && this->refDelimiter == rhs.refDelimiter
213 && this->refRangeDelimiter == rhs.refRangeDelimiter && this->keepTabs == rhs.keepTabs
214 && this->keepLineBreaks == rhs.keepLineBreaks;
215}
216
217
218bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
219{
220 return !( lhs == rhs );
221}
222
223
224bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
225{
226 return lhs.name < rhs.name;
227}
228
229
230void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p )
231{
232 j = nlohmann::json{ { "name", p.name },
233 { "field_delimiter", p.fieldDelimiter },
234 { "string_delimiter", p.stringDelimiter },
235 { "ref_delimiter", p.refDelimiter },
236 { "ref_range_delimiter", p.refRangeDelimiter },
237 { "keep_tabs", p.keepTabs },
238 { "keep_line_breaks", p.keepLineBreaks } };
239}
240
241
242void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f )
243{
244 j.at( "name" ).get_to( f.name );
245 j.at( "field_delimiter" ).get_to( f.fieldDelimiter );
246 j.at( "string_delimiter" ).get_to( f.stringDelimiter );
247 j.at( "ref_delimiter" ).get_to( f.refDelimiter );
248 j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter );
249 j.at( "keep_tabs" ).get_to( f.keepTabs );
250 j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks );
251}
252
253
255{
256 return { _HKI( "CSV" ), true, wxS( "," ), wxT( "\"" ), wxT( "," ), wxT( "" ), false, false };
257}
258
260{
261 return { _HKI( "TSV" ), true, wxS( "\t" ), wxT( "" ), wxT( "," ), wxT( "" ), false, false };
262}
263
265{
266 return {
267 _HKI( "Semicolons" ), true, wxS( ";" ), wxT( "'" ), wxT( "," ), wxT( "" ), false, false
268 };
269}
270
271std::vector<BOM_FMT_PRESET> BOM_FMT_PRESET::BuiltInPresets()
272{
274}
275
276#if !defined( __MINGW32__ )
279#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 _HKI(x)
#define _(s)
#define KICOMMON_API
Definition: kicommon.h:28
wxString label
Definition: bom_settings.h:33
bool groupBy
Definition: bom_settings.h:35
bool operator==(const BOM_FIELD &rhs) const
wxString name
Definition: bom_settings.h:32
bool operator==(const BOM_FMT_PRESET &rhs) const
wxString fieldDelimiter
Definition: bom_settings.h:83
wxString name
Definition: bom_settings.h:81
static BOM_FMT_PRESET CSV()
static std::vector< BOM_FMT_PRESET > BuiltInPresets()
wxString stringDelimiter
Definition: bom_settings.h:84
static BOM_FMT_PRESET TSV()
wxString refRangeDelimiter
Definition: bom_settings.h:86
static BOM_FMT_PRESET Semicolons()
wxString refDelimiter
Definition: bom_settings.h:85
wxString name
Definition: bom_settings.h:51
bool operator==(const BOM_PRESET &rhs) const
static BOM_PRESET DefaultEditing()
wxString sortField
Definition: bom_settings.h:54
bool groupSymbols
Definition: bom_settings.h:57
std::vector< BOM_FIELD > fieldsOrdered
Definition: bom_settings.h:53
static BOM_PRESET GroupedByValue()
bool includeExcludedFromBOM
Definition: bom_settings.h:59
bool readOnly
Definition: bom_settings.h:52
static std::vector< BOM_PRESET > BuiltInPresets()
bool excludeDNP
Definition: bom_settings.h:58
bool sortAsc
Definition: bom_settings.h:55
static BOM_PRESET GroupedByValueFootprint()
static BOM_PRESET Attributes()
wxString filterString
Definition: bom_settings.h:56