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 };
86
87 if( p.fieldsOrdered.size() > 0 )
88 j["fields_ordered"] = p.fieldsOrdered;
89}
90
91
92void from_json( const nlohmann::json& j, BOM_PRESET& f )
93{
94 j.at( "name" ).get_to( f.name );
95 j.at( "fields_ordered" ).get_to( f.fieldsOrdered );
96 j.at( "sort_field" ).get_to( f.sortField );
97 j.at( "sort_asc" ).get_to( f.sortAsc );
98 j.at( "filter_string" ).get_to( f.filterString );
99 j.at( "group_symbols" ).get_to( f.groupSymbols );
100 j.at( "exclude_dnp" ).get_to( f.excludeDNP );
101}
102
103
104// Implementations for BOM_PRESET
105bool BOM_PRESET::operator==( const BOM_PRESET& rhs ) const
106{
107 return this->name == rhs.name
108 && this->readOnly == rhs.readOnly
109 && this->fieldsOrdered == rhs.fieldsOrdered
110 && this->sortField == rhs.sortField
111 && this->sortAsc == rhs.sortAsc
112 && this->groupSymbols == rhs.groupSymbols
113 && this->excludeDNP == rhs.excludeDNP;
114}
115
116
118{
119 BOM_PRESET p{ _HKI( "Grouped By Value" ), true, {}, _( "Reference" ), true, "", true, false };
120
121 p.fieldsOrdered = std::vector<BOM_FIELD>{
122 { "Reference", "Reference", true, false },
123 { "Value", "Value", true, true },
124 { "Datasheet", "Datasheet", true, false },
125 { "Footprint", "Footprint", true, false },
126 { "${QUANTITY}", "Qty", true, false },
127 { "${DNP}", "DNP", true, true },
128 };
129
130 return p;
131}
132
133
135{
136 BOM_PRESET p{
137 _HKI( "Grouped By Value and Footprint" ), true, {}, _( "Reference" ), true, "", true, false
138 };
139
140 p.fieldsOrdered = std::vector<BOM_FIELD>{
141 { "Reference", "Reference", true, false },
142 { "Value", "Value", true, true },
143 { "Datasheet", "Datasheet", true, false },
144 { "Footprint", "Footprint", true, true },
145 { "${QUANTITY}", "Qty", true, false },
146 { "${DNP}", "DNP", true, true },
147 };
148
149 return p;
150}
151
152
154{
155 BOM_PRESET p{
156 _HKI( "Attributes" ), true, {}, _( "Reference" ), true, "", true, false
157 };
158
159 p.fieldsOrdered = std::vector<BOM_FIELD>{
160 { "Reference", "Reference", true, false },
161 { "Value", "Value", true, true },
162 { "Datasheet", "Datasheet", false, false },
163 { "Footprint", "Footprint", false, true },
164 { "${DNP}", "Do Not Place", true, false },
165 { "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
166 { "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
167 { "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
168 };
169
170 return p;
171}
172
173std::vector<BOM_PRESET> BOM_PRESET::BuiltInPresets()
174{
177}
178
179//Implementations for BOM_FMT_PRESET
181{
182 return this->name == rhs.name && this->readOnly == rhs.readOnly
183 && this->fieldDelimiter == rhs.fieldDelimiter
184 && this->stringDelimiter == rhs.stringDelimiter && this->refDelimiter == rhs.refDelimiter
185 && this->refRangeDelimiter == rhs.refRangeDelimiter && this->keepTabs == rhs.keepTabs
186 && this->keepLineBreaks == rhs.keepLineBreaks;
187}
188
189
190bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
191{
192 return !( lhs == rhs );
193}
194
195
196bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs )
197{
198 return lhs.name < rhs.name;
199}
200
201
202void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p )
203{
204 j = nlohmann::json{ { "name", p.name },
205 { "field_delimiter", p.fieldDelimiter },
206 { "string_delimiter", p.stringDelimiter },
207 { "ref_delimiter", p.refDelimiter },
208 { "ref_range_delimiter", p.refRangeDelimiter },
209 { "keep_tabs", p.keepTabs },
210 { "keep_line_breaks", p.keepLineBreaks } };
211}
212
213
214void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f )
215{
216 j.at( "name" ).get_to( f.name );
217 j.at( "field_delimiter" ).get_to( f.fieldDelimiter );
218 j.at( "string_delimiter" ).get_to( f.stringDelimiter );
219 j.at( "ref_delimiter" ).get_to( f.refDelimiter );
220 j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter );
221 j.at( "keep_tabs" ).get_to( f.keepTabs );
222 j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks );
223}
224
225
227{
228 return { _HKI( "CSV" ), true, wxS( "," ), wxT( "\"" ), wxT( "," ), wxT( "" ), false, false };
229}
230
232{
233 return { _HKI( "TSV" ), true, wxS( "\t" ), wxT( "" ), wxT( "," ), wxT( "" ), false, false };
234}
235
237{
238 return {
239 _HKI( "Semicolons" ), true, wxS( ";" ), wxT( "'" ), wxT( "," ), wxT( "" ), false, false
240 };
241}
242
243std::vector<BOM_FMT_PRESET> BOM_FMT_PRESET::BuiltInPresets()
244{
246}
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)
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:81
wxString name
Definition: bom_settings.h:79
static BOM_FMT_PRESET CSV()
static std::vector< BOM_FMT_PRESET > BuiltInPresets()
wxString stringDelimiter
Definition: bom_settings.h:82
static BOM_FMT_PRESET TSV()
wxString refRangeDelimiter
Definition: bom_settings.h:84
static BOM_FMT_PRESET Semicolons()
wxString refDelimiter
Definition: bom_settings.h:83
wxString name
Definition: bom_settings.h:51
bool operator==(const BOM_PRESET &rhs) const
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 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