Add unit & body style property access.

(It had gotten lost in SCH_ITEM/LIB_ITEM collapse, but
then again the old version didn't work right
anyway.)

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18049
This commit is contained in:
Jeff Young 2024-05-20 23:37:29 +01:00
parent 59a2de7408
commit cb76ad3206
2 changed files with 52 additions and 2 deletions

View File

@ -422,9 +422,10 @@ void SCH_SYMBOL::UpdatePins()
void SCH_SYMBOL::SetBodyStyle( int aBodyStyle )
{
if( m_bodyStyle != aBodyStyle )
if( HasAlternateBodyStyle() && m_bodyStyle != aBodyStyle )
{
m_bodyStyle = aBodyStyle;
m_bodyStyle = ( m_bodyStyle == BODY_STYLE::BASE ) ? BODY_STYLE::DEMORGAN
: BODY_STYLE::BASE;
// The body style may have a different pin layout so the update the pin map.
UpdatePins();
@ -2800,6 +2801,32 @@ static struct SCH_SYMBOL_DESC
NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetKeyWords ),
groupFields );
auto multiUnit =
[=]( INSPECTABLE* aItem ) -> bool
{
if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
return symbol->IsMulti();
return false;
};
auto multiBodyStyle =
[=]( INSPECTABLE* aItem ) -> bool
{
if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
return symbol->HasAlternateBodyStyle();
return false;
};
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Unit" ),
&SCH_SYMBOL::SetUnitProp, &SCH_SYMBOL::GetUnitProp ) )
.SetAvailableFunc( multiUnit );
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Body Style" ),
&SCH_SYMBOL::SetBodyStyleProp, &SCH_SYMBOL::GetBodyStyleProp ) )
.SetAvailableFunc( multiBodyStyle );
const wxString groupAttributes = _HKI( "Attributes" );
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Board" ),

View File

@ -548,6 +548,29 @@ public:
{
SetValueFieldText( aRef );
}
int GetUnitProp() const
{
return GetUnitSelection( &Schematic()->CurrentSheet() );
}
void SetUnitProp( int aUnit )
{
if( aUnit < 1 )
return;
if( aUnit > GetUnitCount() )
aUnit = GetUnitCount();
SetUnitSelection( &Schematic()->CurrentSheet(), aUnit );
SetUnit( aUnit );
}
int GetBodyStyleProp() const
{
return GetBodyStyle();
}
void SetBodyStyleProp( int aBodyStyle )
{
SetBodyStyle( aBodyStyle );
}
/**
* Restore fields to the original library values.