7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Implement private flag for SCH_FIELD.

I don't think this was the original intent, but the
GUI for setting the flag leaked out via the
properties inspector so it kind of needs to work.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18760
This commit is contained in:
Jeff Young 2024-12-09 20:30:01 +00:00
parent 10cd4582f2
commit 1d4945dad5
8 changed files with 49 additions and 18 deletions

View File

@ -667,6 +667,8 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit,
if( libField )
{
field.SetPrivate( libField->IsPrivate() );
bool resetText = libField->GetText().IsEmpty() ? m_resetEmptyFields->GetValue()
: m_resetFieldText->GetValue();
@ -753,6 +755,7 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit,
schField->SetAttributes( libField );
schField->SetText( libField.GetText() );
schField->SetTextPos( symbol->GetPosition() + libField.GetTextPos() );
schField->SetPrivate( libField.IsPrivate() );
}
if( resetPositions && frame->eeconfig()->m_AutoplaceFields.enable )

View File

@ -90,6 +90,7 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
SCH_ITEM( aField ),
EDA_TEXT( aField )
{
m_private = aField.m_private;
m_id = aField.m_id;
m_name = aField.m_name;
m_showName = aField.m_showName;
@ -119,6 +120,7 @@ SCH_FIELD& SCH_FIELD::operator=( const SCH_FIELD& aField )
{
EDA_TEXT::operator=( aField );
m_private = aField.m_private;
m_id = aField.m_id;
m_name = aField.m_name;
m_showName = aField.m_showName;
@ -528,6 +530,7 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
std::swap( m_showName, item->m_showName );
std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
std::swap( m_isNamedVariable, item->m_isNamedVariable );
std::swap( m_private, item->m_private );
SwapText( *item );
SwapAttributes( *item );

View File

@ -39,19 +39,20 @@
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20200827 // Remove host tag.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20200908 // Add include in BOM and on board support.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20201005 // Separate ki_fp_filters by spaces.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20210619 // Change pin overbar syntax from `~...~` to `~{...}`.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20211014 // Arc formatting.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220101 // Class flags.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220102 // Fonts.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220126 // Text boxes.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220328 // Text box start/end -> at/size.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220331 // Text colors.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220914 // Symbol unit display names.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220914 // Don't save property ID
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20230620 // ki_description -> Description Field
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20231120 // generator_version; V8 cleanups
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20240529 // Embedded Files
#define SEXPR_SYMBOL_LIB_FILE_VERSION 20240819 // Embedded Files - Update hash algorithm to Murmur3
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20210619 // Change pin overbar syntax from `~...~` to `~{...}`.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20211014 // Arc formatting.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220101 // Class flags.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220102 // Fonts.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220126 // Text boxes.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220328 // Text box start/end -> at/size.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220331 // Text colors.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220914 // Symbol unit display names.
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20220914 // Don't save property ID
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20230620 // ki_description -> Description Field
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20231120 // generator_version; V8 cleanups
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20240529 // Embedded Files
//#define SEXPR_SYMBOL_LIB_FILE_VERSION 20240819 // Embedded Files - Update hash algorithm to Murmur3
#define SEXPR_SYMBOL_LIB_FILE_VERSION 20241209 // Private flags for SCH_FIELDs
/**
* Schematic file version.
*/
@ -111,4 +112,5 @@
//#define SEXPR_SCHEMATIC_FILE_VERSION 20240716 // Multiple netclass assignments
//#define SEXPR_SCHEMATIC_FILE_VERSION 20240812 // Netclass color highlighting
//#define SEXPR_SCHEMATIC_FILE_VERSION 20240819 // Embedded Files - Update hash algorithm to Murmur3
#define SEXPR_SCHEMATIC_FILE_VERSION 20241004 // Use booleans for 'hide' in symbols
//#define SEXPR_SCHEMATIC_FILE_VERSION 20241004 // Use booleans for 'hide' in symbols
#define SEXPR_SCHEMATIC_FILE_VERSION 20241209 // Private flags for SCH_FIELDs

View File

@ -881,7 +881,8 @@ void SCH_IO_KICAD_SEXPR::saveField( SCH_FIELD* aField )
m_nextFreeFieldId = aField->GetId() + 1;
}
m_out->Print( "(property %s %s (at %s %s %s)",
m_out->Print( "(property %s %s %s (at %s %s %s)",
aField->IsPrivate() ? "private" : "",
m_out->Quotew( fieldName ).c_str(),
m_out->Quotew( aField->GetText() ).c_str(),
EDA_UNIT_UTILS::FormatInternalUnits( schIUScale,

View File

@ -411,7 +411,8 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveField( SCH_FIELD* aField, OUTPUTFORMATTER
if( aField->IsMandatory() )
fieldName = GetCanonicalFieldName( aField->GetId() );
aFormatter.Print( "(property %s %s (at %s %s %g)",
aFormatter.Print( "(property %s %s %s (at %s %s %g)",
aField->IsPrivate() ? "private" : "",
aFormatter.Quotew( fieldName ).c_str(),
aFormatter.Quotew( aField->GetText() ).c_str(),
EDA_UNIT_UTILS::FormatInternalUnits( schIUScale,

View File

@ -956,6 +956,12 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
T token = NextTok();
if( token == T_private )
{
field->SetPrivate( true );
token = NextTok();
}
if( !IsSymbol( token ) )
{
THROW_PARSE_ERROR( _( "Invalid property name" ), CurSource(), CurLine(), CurLineNumber(),
@ -2164,8 +2170,16 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent )
wxCHECK_MSG( CurTok() == T_property, nullptr,
"Cannot parse " + GetTokenString( CurTok() ) + " as a property token." );
bool is_private = false;
T token = NextTok();
if( token == T_private )
{
is_private = true;
token = NextTok();
}
if( !IsSymbol( token ) )
{
THROW_PARSE_ERROR( _( "Invalid property name" ), CurSource(), CurLine(), CurLineNumber(),
@ -2198,10 +2212,12 @@ SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent )
else if( aParent->Type() == SCH_SHEET_T )
mandatoryFieldCount = SHEET_MANDATORY_FIELDS;
std::unique_ptr<SCH_FIELD> field =
std::make_unique<SCH_FIELD>( VECTOR2I( -1, -1 ), mandatoryFieldCount, aParent, name );
std::unique_ptr<SCH_FIELD> field = std::make_unique<SCH_FIELD>( VECTOR2I( -1, -1 ),
mandatoryFieldCount,
aParent, name );
field->SetText( value );
field->SetVisible( true );
field->SetPrivate( is_private );
// Correctly set the ID based on canonical (untranslated) field name
// If ID is stored in the file (old versions), it will overwrite this

View File

@ -2303,6 +2303,9 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
if( !isUnitAndConversionShown( aField ) )
return;
if( aField->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
return;
// Must check layer as fields are sometimes drawn by their parent rather than directly
// from the view.
std::vector<int> layers = aField->ViewGetLayers();

View File

@ -1071,6 +1071,8 @@ void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, b
}
}
schField->SetPrivate( libField->IsPrivate() );
if( aUpdateStyle )
{
schField->ImportValues( *libField );