Use netclass colours for label graphics, text and fields.

Fixes https://gitlab.com/kicad/code/kicad/issues/4984
This commit is contained in:
Jeff Young 2022-09-24 23:50:52 +01:00
parent 659a6e5b04
commit 5fc02a63a3
6 changed files with 79 additions and 13 deletions

View File

@ -64,7 +64,8 @@ SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
m_name( aName ), m_name( aName ),
m_showName( false ), m_showName( false ),
m_allowAutoPlace( true ), m_allowAutoPlace( true ),
m_renderCacheValid( false ) m_renderCacheValid( false ),
m_lastResolvedColor( COLOR4D::UNSPECIFIED )
{ {
SetTextPos( aPos ); SetTextPos( aPos );
SetId( aFieldId ); // will also set the layer SetId( aFieldId ); // will also set the layer
@ -91,6 +92,8 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
m_renderCacheValid = aField.m_renderCacheValid; m_renderCacheValid = aField.m_renderCacheValid;
m_renderCachePos = aField.m_renderCachePos; m_renderCachePos = aField.m_renderCachePos;
m_lastResolvedColor = aField.m_lastResolvedColor;
} }
@ -114,6 +117,8 @@ SCH_FIELD& SCH_FIELD::operator=( const SCH_FIELD& aField )
m_renderCacheValid = aField.m_renderCacheValid; m_renderCacheValid = aField.m_renderCacheValid;
m_renderCachePos = aField.m_renderCachePos; m_renderCachePos = aField.m_renderCachePos;
m_lastResolvedColor = aField.m_lastResolvedColor;
return *this; return *this;
} }
@ -387,6 +392,26 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
std::swap( m_allowAutoPlace, item->m_allowAutoPlace ); std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
SwapText( *item ); SwapText( *item );
SwapAttributes( *item ); SwapAttributes( *item );
std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
}
COLOR4D SCH_FIELD::GetFieldColor() const
{
if( GetTextColor() != COLOR4D::UNSPECIFIED )
{
m_lastResolvedColor = GetTextColor();
}
else
{
SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
if( parentLabel && !parentLabel->IsConnectivityDirty() )
m_lastResolvedColor = parentLabel->GetEffectiveNetClass()->GetSchematicColor();
}
return m_lastResolvedColor;
} }

View File

@ -119,10 +119,20 @@ public:
wxString GetShownText( int aDepth = 0 ) const override; wxString GetShownText( int aDepth = 0 ) const override;
COLOR4D GetFieldColor() const;
void SetLastResolvedState( const SCH_ITEM* aItem ) override
{
const SCH_FIELD* aField = dynamic_cast<const SCH_FIELD*>( aItem );
if( aField )
m_lastResolvedColor = aField->m_lastResolvedColor;
}
/** /**
* Adjusters to allow EDA_TEXT to draw/print/etc. text in absolute coords. * Adjusters to allow EDA_TEXT to draw/print/etc. text in absolute coords.
*/ */
EDA_ANGLE GetDrawRotation() const override; EDA_ANGLE GetDrawRotation() const override;
const BOX2I GetBoundingBox() const override; const BOX2I GetBoundingBox() const override;
@ -242,6 +252,8 @@ private:
mutable bool m_renderCacheValid; mutable bool m_renderCacheValid;
mutable VECTOR2I m_renderCachePos; mutable VECTOR2I m_renderCachePos;
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache; mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;
mutable COLOR4D m_lastResolvedColor;
}; };

View File

@ -156,7 +156,8 @@ SCH_LABEL_BASE::SCH_LABEL_BASE( const VECTOR2I& aPos, const wxString& aText, KIC
SCH_TEXT( aPos, aText, aType ), SCH_TEXT( aPos, aText, aType ),
m_shape( L_UNSPECIFIED ), m_shape( L_UNSPECIFIED ),
m_connectionType( CONNECTION_TYPE::NONE ), m_connectionType( CONNECTION_TYPE::NONE ),
m_isDangling( true ) m_isDangling( true ),
m_lastResolvedColor( COLOR4D::UNSPECIFIED )
{ {
SetMultilineAllowed( false ); SetMultilineAllowed( false );
ClearFieldsAutoplaced(); // fiels are not yet autoplaced. ClearFieldsAutoplaced(); // fiels are not yet autoplaced.
@ -167,7 +168,8 @@ SCH_LABEL_BASE::SCH_LABEL_BASE( const SCH_LABEL_BASE& aLabel ) :
SCH_TEXT( aLabel ), SCH_TEXT( aLabel ),
m_shape( aLabel.m_shape ), m_shape( aLabel.m_shape ),
m_connectionType( aLabel.m_connectionType ), m_connectionType( aLabel.m_connectionType ),
m_isDangling( aLabel.m_isDangling ) m_isDangling( aLabel.m_isDangling ),
m_lastResolvedColor( aLabel.m_lastResolvedColor )
{ {
SetMultilineAllowed( false ); SetMultilineAllowed( false );
@ -254,6 +256,18 @@ void SCH_LABEL_BASE::SwapData( SCH_ITEM* aItem )
std::swap( m_shape, label->m_shape ); std::swap( m_shape, label->m_shape );
std::swap( m_connectionType, label->m_connectionType ); std::swap( m_connectionType, label->m_connectionType );
std::swap( m_isDangling, label->m_isDangling ); std::swap( m_isDangling, label->m_isDangling );
std::swap( m_lastResolvedColor, label->m_lastResolvedColor );
}
COLOR4D SCH_LABEL_BASE::GetLabelColor() const
{
if( GetTextColor() != COLOR4D::UNSPECIFIED )
m_lastResolvedColor = GetTextColor();
else if( !IsConnectivityDirty() )
m_lastResolvedColor = GetEffectiveNetClass()->GetSchematicColor();
return m_lastResolvedColor;
} }

View File

@ -31,9 +31,6 @@
#include <sch_connection.h> // for CONNECTION_TYPE #include <sch_connection.h> // for CONNECTION_TYPE
extern const char* SheetLabelType[]; /* names of types of labels */
class SCH_LABEL_BASE : public SCH_TEXT class SCH_LABEL_BASE : public SCH_TEXT
{ {
public: public:
@ -76,6 +73,16 @@ public:
LABEL_FLAG_SHAPE GetShape() const override { return m_shape; } LABEL_FLAG_SHAPE GetShape() const override { return m_shape; }
void SetShape( LABEL_FLAG_SHAPE aShape ) override { m_shape = aShape; } void SetShape( LABEL_FLAG_SHAPE aShape ) override { m_shape = aShape; }
COLOR4D GetLabelColor() const;
void SetLastResolvedState( const SCH_ITEM* aItem ) override
{
const SCH_LABEL_BASE* aLabel = dynamic_cast<const SCH_LABEL_BASE*>( aItem );
if( aLabel )
m_lastResolvedColor = aLabel->m_lastResolvedColor;
}
static const wxString GetDefaultFieldName( const wxString& aName, bool aUseDefaultName ); static const wxString GetDefaultFieldName( const wxString& aName, bool aUseDefaultName );
virtual int GetMandatoryFieldCount() { return 0; } virtual int GetMandatoryFieldCount() { return 0; }
@ -203,6 +210,8 @@ protected:
CONNECTION_TYPE m_connectionType; CONNECTION_TYPE m_connectionType;
bool m_isDangling; bool m_isDangling;
bool m_autoRotateOnPlacement = false; bool m_autoRotateOnPlacement = false;
mutable COLOR4D m_lastResolvedColor;
}; };

View File

@ -355,7 +355,7 @@ float SCH_PAINTER::getShadowWidth( bool aForHighlight ) const
COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDrawingShadows, COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDrawingShadows,
bool aDimmed ) const bool aDimmed ) const
{ {
COLOR4D color = m_schSettings.GetLayerColor( aLayer ); COLOR4D color = m_schSettings.GetLayerColor( aLayer );
@ -405,6 +405,14 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDr
else else
color = shape->GetStroke().GetColor(); color = shape->GetStroke().GetColor();
} }
else if( aItem->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
{
color = static_cast<const SCH_LABEL_BASE*>( aItem )->GetLabelColor();
}
else if( aItem->Type() == SCH_FIELD_T )
{
color = static_cast<const SCH_FIELD*>( aItem )->GetFieldColor();
}
else if( aItem->Type() == SCH_TEXTBOX_T ) else if( aItem->Type() == SCH_TEXTBOX_T )
{ {
const SCH_TEXTBOX* textBox = static_cast<const SCH_TEXTBOX*>( aItem ); const SCH_TEXTBOX* textBox = static_cast<const SCH_TEXTBOX*>( aItem );
@ -1898,8 +1906,9 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer )
{ {
if( aText->IsDangling() ) if( aText->IsDangling() )
{ {
drawDanglingSymbol( aText->GetTextPos(), color, schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), drawDanglingSymbol( aText->GetTextPos(), color,
drawingShadows, aText->IsBrightened() ); schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), drawingShadows,
aText->IsBrightened() );
} }
return; return;

View File

@ -108,9 +108,6 @@ enum LABEL_FLAG_SHAPE
}; };
extern const char* SheetLabelType[]; /* names of types of labels */
class SCH_TEXT : public SCH_ITEM, public EDA_TEXT class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
{ {
public: public: