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->groupSymbols == rhs.groupSymbols
116 && this->excludeDNP == rhs.excludeDNP
118}
119
120
122{
123 BOM_PRESET p{
124 _HKI( "Default Editing" ), true, {}, _( "Reference" ), true, "", true, false, true
125 };
126
127 p.fieldsOrdered = std::vector<BOM_FIELD>{
128 { "Reference", "Reference", true, false },
129 { "${QUANTITY}", "Qty", true, false },
130 { "Value", "Value", true, true },
131 { "${DNP}", "DNP", true, true },
132 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, true },
133 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, true },
134 { "Footprint", "Footprint", true, true },
135 { "Datasheet", "Datasheet", true, false },
136 };
137
138 return p;
139}
140
141
143{
144 BOM_PRESET p{
145 _HKI( "Grouped By Value" ), true, {}, _( "Reference" ), true, "", true, false, false
146 };
147
148 p.fieldsOrdered = std::vector<BOM_FIELD>{
149 { "Reference", "Reference", true, false },
150 { "Value", "Value", true, true },
151 { "Datasheet", "Datasheet", true, false },
152 { "Footprint", "Footprint", true, false },
153 { "${QUANTITY}", "Qty", true, false },
154 { "${DNP}", "DNP", true, true },
155 };
156
157 return p;
158}
159
160
162{
163 BOM_PRESET p{
164 _HKI( "Grouped By Value and Footprint" ), true, {}, _( "Reference" ), true, "", true, false, false
165 };
166
167 p.fieldsOrdered = std::vector<BOM_FIELD>{
168 { "Reference", "Reference", true, false },
169 { "Value", "Value", true, true },
170 { "Datasheet", "Datasheet", true, false },
171 { "Footprint", "Footprint", true, true },
172 { "${QUANTITY}", "Qty", true, false },
173 { "${DNP}", "DNP", true, true },
174 };
175
176 return p;
177}
178
179
181{
182 BOM_PRESET p{
183 _HKI( "Attributes" ), true, {}, _( "Reference" ), true, "", true, false, true
184 };
185
186 p.fieldsOrdered = std::vector<BOM_FIELD>{
187 { "Reference", "Reference", true, false },
188 { "Value", "Value", true, true },
189 { "Datasheet", "Datasheet", false, false },
190 { "Footprint", "Footprint", false, true },
191 { "${DNP}", "Do Not Place", true, false },
192 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
193 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
194 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
195 };
196
197 return p;
198}
199
200std::vector<BOM_PRESET> BOM_PRESET::BuiltInPresets()
201{
204}
205
206//Implementations for BOM_FMT_PRESET
208{
209 return this->name == rhs.name && this->readOnly == rhs.readOnly
210 && this->fieldDelimiter == rhs.fieldDelimiter
211 && this->stringDelimiter == rhs.stringDelimiter && this->refDelimiter == rhs.refDelimiter
212 && this->refRangeDelimiter == rhs.refRangeDelimiter && this->keepTabs == rhs.keepTabs
213 && this->keepLineBreaks == rhs.keepLineBreaks;
214}
215
216
217bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
218{
219 return !( lhs == rhs );
220}
221
222
223bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
224{
225 return lhs.name < rhs.name;
226}
227
228
229void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p )
230{
231 j = nlohmann::json{ { "name", p.name },
232 { "field_delimiter", p.fieldDelimiter },
233 { "string_delimiter", p.stringDelimiter },
234 { "ref_delimiter", p.refDelimiter },
235 { "ref_range_delimiter", p.refRangeDelimiter },
236 { "keep_tabs", p.keepTabs },
237 { "keep_line_breaks", p.keepLineBreaks } };
238}
239
240
241void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f )
242{
243 j.at( "name" ).get_to( f.name );
244 j.at( "field_delimiter" ).get_to( f.fieldDelimiter );
245 j.at( "string_delimiter" ).get_to( f.stringDelimiter );
246 j.at( "ref_delimiter" ).get_to( f.refDelimiter );
247 j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter );
248 j.at( "keep_tabs" ).get_to( f.keepTabs );
249 j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks );
250}
251
252
254{
255 return { _HKI( "CSV" ), true, wxS( "," ), wxT( "\"" ), wxT( "," ), wxT( "" ), false, false };
256}
257
259{
260 return { _HKI( "TSV" ), true, wxS( "\t" ), wxT( "" ), wxT( "," ), wxT( "" ), false, false };
261}
262
264{
265 return {
266 _HKI( "Semicolons" ), true, wxS( ";" ), wxT( "'" ), wxT( "," ), wxT( "" ), false, false
267 };
268}
269
270std::vector<BOM_FMT_PRESET> BOM_FMT_PRESET::BuiltInPresets()
271{
273}
274
275#if !defined( __MINGW32__ )
278#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