11 changed files with 474 additions and 169 deletions
-
1common/CMakeLists.txt
-
253common/settings/bom_settings.cpp
-
7common/settings/json_settings.cpp
-
4common/settings/parameters.cpp
-
100eeschema/dialogs/dialog_symbol_fields_table.cpp
-
24eeschema/eeschema_jobs_handler.cpp
-
39eeschema/fields_data_model.cpp
-
3eeschema/fields_data_model.h
-
43eeschema/schematic_settings.cpp
-
71eeschema/schematic_settings.h
-
98include/settings/bom_settings.h
@ -0,0 +1,253 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Mike Williams <mike@mikebwilliams.com> |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or (at your |
|||
* option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
* General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <settings/bom_settings.h>
|
|||
#include <nlohmann/json.hpp>
|
|||
#include <wx/translation.h>
|
|||
|
|||
namespace nlohmann |
|||
{ |
|||
template <> |
|||
struct adl_serializer<wxString> |
|||
{ |
|||
static void to_json( json& j, const wxString& s ) { j = s.ToUTF8(); } |
|||
|
|||
static void from_json( const json& j, wxString& s ) |
|||
{ |
|||
s = wxString::FromUTF8( j.get<std::string>().c_str() ); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
|
|||
// Implementations for BOM_FMT_PRESET
|
|||
bool BOM_FIELD::operator==( const BOM_FIELD& rhs ) const |
|||
{ |
|||
return this->name == rhs.name && this->label == rhs.label && this->show == rhs.show |
|||
&& this->groupBy == rhs.groupBy; |
|||
} |
|||
|
|||
|
|||
const bool operator!=( const BOM_FIELD& lhs, const BOM_FIELD& rhs ) |
|||
{ |
|||
return !( lhs == rhs ); |
|||
} |
|||
|
|||
|
|||
const bool operator<( const BOM_FIELD& lhs, const BOM_FIELD& rhs ) |
|||
{ |
|||
return lhs.name < rhs.name; |
|||
} |
|||
|
|||
|
|||
void to_json( nlohmann::json& j, const BOM_FIELD& f ) |
|||
{ |
|||
j = nlohmann::json{ |
|||
{ "name", f.name }, { "label", f.label }, { "show", f.show }, { "group_by", f.groupBy } |
|||
}; |
|||
} |
|||
|
|||
|
|||
void from_json( const nlohmann::json& j, BOM_FIELD& f ) |
|||
{ |
|||
j.at( "name" ).get_to( f.name ); |
|||
j.at( "label" ).get_to( f.label ); |
|||
j.at( "show" ).get_to( f.show ); |
|||
j.at( "group_by" ).get_to( f.groupBy ); |
|||
} |
|||
|
|||
|
|||
const bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs ) |
|||
{ |
|||
return !( lhs == rhs ); |
|||
} |
|||
|
|||
|
|||
const bool operator<( const BOM_PRESET& lhs, const BOM_PRESET& rhs ) |
|||
{ |
|||
return lhs.name < rhs.name; |
|||
} |
|||
|
|||
|
|||
void to_json( nlohmann::json& j, const BOM_PRESET& p ) |
|||
{ |
|||
j = nlohmann::json{ { "name", p.name }, |
|||
{ "sort_field", p.sortField }, |
|||
{ "sort_asc", p.sortAsc }, |
|||
{ "filter_string", p.filterString }, |
|||
{ "group_symbols", p.groupSymbols } }; |
|||
|
|||
if( p.fieldsOrdered.size() > 0 ) |
|||
j["fields_ordered"] = p.fieldsOrdered; |
|||
} |
|||
|
|||
|
|||
void from_json( const nlohmann::json& j, BOM_PRESET& f ) |
|||
{ |
|||
j.at( "name" ).get_to( f.name ); |
|||
j.at( "fields_ordered" ).get_to( f.fieldsOrdered ); |
|||
j.at( "sort_field" ).get_to( f.sortField ); |
|||
j.at( "sort_asc" ).get_to( f.sortAsc ); |
|||
j.at( "filter_string" ).get_to( f.filterString ); |
|||
j.at( "group_symbols" ).get_to( f.groupSymbols ); |
|||
} |
|||
|
|||
|
|||
// Implementations for BOM_PRESET
|
|||
bool BOM_PRESET::operator==( const BOM_PRESET& rhs ) const |
|||
{ |
|||
return this->name == rhs.name && this->readOnly == rhs.readOnly |
|||
&& this->fieldsOrdered == rhs.fieldsOrdered && this->sortField == rhs.sortField |
|||
&& this->sortAsc == rhs.sortAsc && this->groupSymbols == rhs.groupSymbols; |
|||
} |
|||
|
|||
|
|||
BOM_PRESET BOM_PRESET::GroupedByValue() |
|||
{ |
|||
BOM_PRESET p = { .name = _HKI( "Grouped By Value" ), |
|||
.readOnly = true, |
|||
.sortField = _( "Reference" ), |
|||
.sortAsc = true, |
|||
.groupSymbols = true }; |
|||
|
|||
p.fieldsOrdered = std::vector<BOM_FIELD>( { |
|||
( BOM_FIELD ){ |
|||
.name = "Reference", .label = "Reference", .show = true, .groupBy = false }, |
|||
( BOM_FIELD ){ |
|||
.name = "Value", .label = "Value", .show = true, .groupBy = true }, |
|||
( BOM_FIELD ){ |
|||
.name = "Datasheet", .label = "Datasheet", .show = true, .groupBy = false }, |
|||
( BOM_FIELD ){ |
|||
.name = "Footprint", .label = "Footprint", .show = true, .groupBy = false }, |
|||
( BOM_FIELD ){ |
|||
.name = "Quantity", .label = "Qty", .show = true, .groupBy = false }, |
|||
} ); |
|||
|
|||
return p; |
|||
} |
|||
|
|||
|
|||
BOM_PRESET BOM_PRESET::GroupedByValueFootprint() |
|||
{ |
|||
BOM_PRESET p = { .name = _HKI( "Grouped By Value and Footprint" ), |
|||
.readOnly = true, |
|||
.sortField = _( "Reference" ), |
|||
.sortAsc = true, |
|||
.groupSymbols = true }; |
|||
|
|||
p.fieldsOrdered = std::vector<BOM_FIELD>( { |
|||
( BOM_FIELD ){ |
|||
.name = "Reference", .label = "Reference", .show = true, .groupBy = false }, |
|||
( BOM_FIELD ){ |
|||
.name = "Value", .label = "Value", .show = true, .groupBy = true }, |
|||
( BOM_FIELD ){ |
|||
.name = "Datasheet", .label = "Datasheet", .show = true, .groupBy = false }, |
|||
( BOM_FIELD ){ |
|||
.name = "Footprint", .label = "Footprint", .show = true, .groupBy = true }, |
|||
( BOM_FIELD ){ |
|||
.name = "Quantity", .label = "Qty", .show = true, .groupBy = false }, |
|||
} ); |
|||
|
|||
return p; |
|||
} |
|||
|
|||
|
|||
//Implementations for BOM_FMT_PRESET
|
|||
bool BOM_FMT_PRESET::operator==( const BOM_FMT_PRESET& rhs ) const |
|||
{ |
|||
return this->name == rhs.name && this->readOnly == rhs.readOnly |
|||
&& this->fieldDelimiter == rhs.fieldDelimiter |
|||
&& this->stringDelimiter == rhs.stringDelimiter && this->refDelimiter == rhs.refDelimiter |
|||
&& this->refRangeDelimiter == rhs.refRangeDelimiter && this->keepTabs == rhs.keepTabs |
|||
&& this->keepLineBreaks == rhs.keepLineBreaks; |
|||
} |
|||
|
|||
|
|||
const bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs ) |
|||
{ |
|||
return !( lhs == rhs ); |
|||
} |
|||
|
|||
|
|||
const bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs ) |
|||
{ |
|||
return lhs.name < rhs.name; |
|||
} |
|||
|
|||
|
|||
void to_json( nlohmann::json& j, const BOM_FMT_PRESET& p ) |
|||
{ |
|||
j = nlohmann::json{ { "name", p.name }, |
|||
{ "field_delimiter", p.fieldDelimiter }, |
|||
{ "string_delimiter", p.stringDelimiter }, |
|||
{ "ref_delimiter", p.refDelimiter }, |
|||
{ "ref_range_delimiter", p.refRangeDelimiter }, |
|||
{ "keep_tabs", p.keepTabs }, |
|||
{ "keep_line_breaks", p.keepLineBreaks } }; |
|||
} |
|||
|
|||
|
|||
void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f ) |
|||
{ |
|||
j.at( "name" ).get_to( f.name ); |
|||
j.at( "field_delimiter" ).get_to( f.fieldDelimiter ); |
|||
j.at( "string_delimiter" ).get_to( f.stringDelimiter ); |
|||
j.at( "ref_delimiter" ).get_to( f.refDelimiter ); |
|||
j.at( "ref_range_delimiter" ).get_to( f.refRangeDelimiter ); |
|||
j.at( "keep_tabs" ).get_to( f.keepTabs ); |
|||
j.at( "keep_line_breaks" ).get_to( f.keepLineBreaks ); |
|||
} |
|||
|
|||
|
|||
BOM_FMT_PRESET BOM_FMT_PRESET::CSV() |
|||
{ |
|||
return ( BOM_FMT_PRESET ){ .name = _HKI( "CSV" ), |
|||
.readOnly = true, |
|||
.fieldDelimiter = wxS( "," ), |
|||
.stringDelimiter = wxT( "\"" ), |
|||
.refDelimiter = wxT( "," ), |
|||
.refRangeDelimiter = wxT( "" ), |
|||
.keepTabs = false, |
|||
.keepLineBreaks = false }; |
|||
} |
|||
|
|||
BOM_FMT_PRESET BOM_FMT_PRESET::TSV() |
|||
{ |
|||
return ( BOM_FMT_PRESET ){ .name = _HKI( "TSV" ), |
|||
.readOnly = true, |
|||
.fieldDelimiter = wxS( "\t" ), |
|||
.stringDelimiter = wxT( "" ), |
|||
.refDelimiter = wxT( "," ), |
|||
.refRangeDelimiter = wxT( "" ), |
|||
.keepTabs = false, |
|||
.keepLineBreaks = false }; |
|||
} |
|||
|
|||
BOM_FMT_PRESET BOM_FMT_PRESET::Semicolons() |
|||
{ |
|||
return ( BOM_FMT_PRESET ){ .name = _HKI( "Semicolons" ), |
|||
.readOnly = true, |
|||
.fieldDelimiter = wxS( ";" ), |
|||
.stringDelimiter = wxT( "'" ), |
|||
.refDelimiter = wxT( "," ), |
|||
.refRangeDelimiter = wxT( "" ), |
|||
.keepTabs = false, |
|||
.keepLineBreaks = false }; |
|||
} |
@ -0,0 +1,98 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Mike Williams <mike@mikebwilliams.com> |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or (at your |
|||
* option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
* General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef _BOM_SETTINGS_H |
|||
#define _BOM_SETTINGS_H |
|||
|
|||
|
|||
#include <settings/json_settings.h> |
|||
#include <settings/parameters.h> |
|||
#include <i18n_utility.h> |
|||
|
|||
// A single field within a BOM, e.g. Reference, Value, Footprint |
|||
struct BOM_FIELD |
|||
{ |
|||
wxString name; |
|||
wxString label; |
|||
bool show = false; |
|||
bool groupBy = false; |
|||
|
|||
bool operator==( const BOM_FIELD& rhs ) const; |
|||
}; |
|||
|
|||
const bool operator!=( const BOM_FIELD& lhs, const BOM_FIELD& rhs ); |
|||
const bool operator<( const BOM_FIELD& lhs, const BOM_FIELD& rhs ); |
|||
|
|||
void to_json( nlohmann::json& j, const BOM_FIELD& f ); |
|||
void from_json( const nlohmann::json& j, BOM_FIELD& f ); |
|||
|
|||
|
|||
// A complete preset defining a BOM "View" with a list of all the fields to show, |
|||
// group by, order, filtering settings, etc. |
|||
struct BOM_PRESET |
|||
{ |
|||
wxString name; |
|||
bool readOnly = false; |
|||
std::vector<BOM_FIELD> fieldsOrdered; |
|||
wxString sortField; |
|||
bool sortAsc = true; |
|||
wxString filterString; |
|||
bool groupSymbols = false; |
|||
|
|||
bool operator==( const BOM_PRESET& rhs ) const; |
|||
|
|||
static BOM_PRESET GroupedByValue(); |
|||
static BOM_PRESET GroupedByValueFootprint(); |
|||
}; |
|||
|
|||
const bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs ); |
|||
const bool operator<( const BOM_PRESET& lhs, const BOM_PRESET& rhs ); |
|||
|
|||
void to_json( nlohmann::json& j, const BOM_PRESET& f ); |
|||
void from_json( const nlohmann::json& j, BOM_PRESET& f ); |
|||
|
|||
|
|||
// A formatting preset, like CSV (Comma Separated Values) |
|||
struct BOM_FMT_PRESET |
|||
{ |
|||
wxString name; |
|||
bool readOnly = false; |
|||
wxString fieldDelimiter; |
|||
wxString stringDelimiter; |
|||
wxString refDelimiter; |
|||
wxString refRangeDelimiter; |
|||
bool keepTabs = false; |
|||
bool keepLineBreaks = false; |
|||
|
|||
bool operator==( const BOM_FMT_PRESET& rhs ) const; |
|||
|
|||
static BOM_FMT_PRESET CSV(); |
|||
static BOM_FMT_PRESET TSV(); |
|||
static BOM_FMT_PRESET Semicolons(); |
|||
}; |
|||
|
|||
const bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs ); |
|||
const bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs ); |
|||
|
|||
void to_json( nlohmann::json& j, const BOM_FMT_PRESET& f ); |
|||
void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f ); |
|||
|
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue