diff --git a/common/database/database_lib_settings.cpp b/common/database/database_lib_settings.cpp index 66a77e613b..39ec926062 100644 --- a/common/database/database_lib_settings.cpp +++ b/common/database/database_lib_settings.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include @@ -36,8 +37,11 @@ DATABASE_FIELD_MAPPING::DATABASE_FIELD_MAPPING( std::string aColumn, std::string bool aVisibleOnAdd, bool aVisibleInChooser, bool aShowName, bool aInheritProperties ) : column( aColumn ), - name( aName ), name_wx( aName.c_str(), wxConvUTF8 ), visible_on_add( aVisibleOnAdd ), - visible_in_chooser( aVisibleInChooser ), show_name( aShowName ), + name( aName ), + name_wx( aName.c_str(), wxConvUTF8 ), + visible_on_add( aVisibleOnAdd ), + visible_in_chooser( aVisibleInChooser ), + show_name( aShowName ), inherit_properties( aInheritProperties ) { } @@ -53,89 +57,86 @@ DATABASE_LIB_SETTINGS::DATABASE_LIB_SETTINGS( const std::string& aFilename ) : m_params.emplace_back( new PARAM( "source.password", &m_Source.password, "" ) ); - m_params.emplace_back( - new PARAM( "source.connection_string", &m_Source.connection_string, "" ) ); + m_params.emplace_back( new PARAM( "source.connection_string", + &m_Source.connection_string, "" ) ); m_params.emplace_back( new PARAM( "source.timeout_seconds", &m_Source.timeout, 2 ) ); m_params.emplace_back( new PARAM_LAMBDA( - "libraries", - [&]() -> nlohmann::json - { - // TODO: implement this; libraries are read-only from KiCad at the moment - return {}; - }, - [&]( const nlohmann::json aObj ) - { - m_Tables.clear(); - - if( !aObj.is_array() ) - return; - - for( const nlohmann::json& entry : aObj ) + "libraries", + [&]() -> nlohmann::json { - if( entry.empty() || !entry.is_object() ) - continue; + // TODO: implement this; libraries are read-only from KiCad at the moment + return {}; + }, + [&]( const nlohmann::json aObj ) + { + m_Tables.clear(); - DATABASE_LIB_TABLE table; + if( !aObj.is_array() ) + return; - table.name = entry["name"].get(); - table.table = entry["table"].get(); - table.key_col = entry["key"].get(); - table.symbols_col = entry["symbols"].get(); - table.footprints_col = entry["footprints"].get(); - - // Sanitize library display names; currently only `/` is removed because we use it - // as a separator and allow it in symbol names. - table.name.erase( std::remove( table.name.begin(), table.name.end(), '/' ), - table.name.end() ); - - if( entry.contains( "properties" ) && entry["properties"].is_object() ) + for( const nlohmann::json& entry : aObj ) { - const nlohmann::json& pj = entry["properties"]; + if( entry.empty() || !entry.is_object() ) + continue; - table.properties.description = fetchOrDefault( pj, "description" ); + DATABASE_LIB_TABLE table; - table.properties.footprint_filters = - fetchOrDefault( pj, "footprint_filters" ); + table.name = entry["name"].get(); + table.table = entry["table"].get(); + table.key_col = entry["key"].get(); + table.symbols_col = entry["symbols"].get(); + table.footprints_col = entry["footprints"].get(); - table.properties.keywords = fetchOrDefault( pj, "keywords" ); + // Sanitize library display names; currently only `/` is removed because we + // use it as a separator and allow it in symbol names. + alg::delete_matching( table.name, '/' ); - table.properties.exclude_from_bom = - fetchOrDefault( pj, "exclude_from_bom" ); - - table.properties.exclude_from_board = - fetchOrDefault( pj, "exclude_from_board" ); - - table.properties.exclude_from_sim = - fetchOrDefault( pj, "exclude_from_sim" ); - } - - if( entry.contains( "fields" ) && entry["fields"].is_array() ) - { - for( const nlohmann::json& fieldJson : entry["fields"] ) + if( entry.contains( "properties" ) && entry["properties"].is_object() ) { - if( fieldJson.empty() || !fieldJson.is_object() ) - continue; + const nlohmann::json& propJson = entry["properties"]; - std::string column = fetchOrDefault( fieldJson, "column" ); - std::string name = fetchOrDefault( fieldJson, "name" ); - bool visible_on_add = fetchOrDefault( fieldJson, "visible_on_add" ); - bool visible_in_chooser = - fetchOrDefault( fieldJson, "visible_in_chooser" ); - bool show_name = fetchOrDefault( fieldJson, "show_name" ); - bool inherit = fetchOrDefault( fieldJson, "inherit_properties" ); + table.properties.description = + fetchOrDefault( propJson, "description" ); - table.fields.emplace_back( - DATABASE_FIELD_MAPPING( column, name, visible_on_add, - visible_in_chooser, show_name, inherit ) ); + table.properties.footprint_filters = + fetchOrDefault( propJson, "footprint_filters" ); + + table.properties.keywords = + fetchOrDefault( propJson, "keywords" ); + + table.properties.exclude_from_bom = + fetchOrDefault( propJson, "exclude_from_bom" ); + + table.properties.exclude_from_board = + fetchOrDefault( propJson, "exclude_from_board" ); + + table.properties.exclude_from_sim = + fetchOrDefault( propJson, "exclude_from_sim" ); } - } - m_Tables.emplace_back( std::move( table ) ); - } - }, - {} ) ); + if( entry.contains( "fields" ) && entry["fields"].is_array() ) + { + for( const nlohmann::json& fieldJson : entry["fields"] ) + { + if( fieldJson.empty() || !fieldJson.is_object() ) + continue; + + table.fields.emplace_back( DATABASE_FIELD_MAPPING( + fetchOrDefault( fieldJson, "column" ), + fetchOrDefault( fieldJson, "name" ), + fetchOrDefault( fieldJson, "visible_on_add" ), + fetchOrDefault( fieldJson, "visible_in_chooser" ), + fetchOrDefault( fieldJson, "show_name" ), + fetchOrDefault( fieldJson, "inherit_properties" ) ) ); + } + } + + m_Tables.emplace_back( std::move( table ) ); + } + }, + {} ) ); m_params.emplace_back( new PARAM( "cache.max_size", &m_Cache.max_size, 256 ) ); diff --git a/eeschema/symbol.h b/eeschema/symbol.h index a8a4fa4bf8..6ef2e45883 100644 --- a/eeschema/symbol.h +++ b/eeschema/symbol.h @@ -148,7 +148,7 @@ public: bool GetExcludedFromBoard() const { return m_excludedFromBoard; } /** - * Set or clear the 'Do Not Populate' flaga + * Set or clear the 'Do Not Populate' flag. */ bool GetDNP() const { return m_DNP; } void SetDNP( bool aDNP ) { m_DNP = aDNP; } diff --git a/eeschema/widgets/panel_symbol_chooser.h b/eeschema/widgets/panel_symbol_chooser.h index d5cb9c911d..10f39fa0ac 100644 --- a/eeschema/widgets/panel_symbol_chooser.h +++ b/eeschema/widgets/panel_symbol_chooser.h @@ -44,18 +44,18 @@ struct PICKED_SYMBOL; class PANEL_SYMBOL_CHOOSER : public wxPanel { public: -/** - * Create dialog to choose symbol. - * - * @param aFrame the parent frame (usually a SCH_EDIT_FRAME or SYMBOL_CHOOSER_FRAME) - * @param aParent the parent window (usually a DIALOG_SHIM or SYMBOL_CHOOSER_FRAME) - * @param aAllowFieldEdits if false, all functions that allow the user to edit fields - * (currently just footprint selection) will not be available. - * @param aShowFootprints if false, all footprint preview and selection features are - * disabled. This forces aAllowFieldEdits false too. - * @param aAcceptHandler a handler to be called on double-click of a footprint - * @param aEscapeHandler a handler to be called on - */ + /** + * Create dialog to choose symbol. + * + * @param aFrame the parent frame (usually a SCH_EDIT_FRAME or SYMBOL_CHOOSER_FRAME) + * @param aParent the parent window (usually a DIALOG_SHIM or SYMBOL_CHOOSER_FRAME) + * @param aAllowFieldEdits if false, all functions that allow the user to edit fields + * (currently just footprint selection) will not be available. + * @param aShowFootprints if false, all footprint preview and selection features are + * disabled. This forces aAllowFieldEdits false too. + * @param aAcceptHandler a handler to be called on double-click of a footprint + * @param aEscapeHandler a handler to be called on + */ PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent, const SYMBOL_LIBRARY_FILTER* aFilter, std::vector& aHistoryList,