diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 19e67846d0..51a50b2808 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -64,7 +64,8 @@ SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent, m_name( aName ), m_showName( false ), m_allowAutoPlace( true ), - m_renderCacheValid( false ) + m_renderCacheValid( false ), + m_lastResolvedColor( COLOR4D::UNSPECIFIED ) { SetTextPos( aPos ); 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_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_renderCachePos = aField.m_renderCachePos; + m_lastResolvedColor = aField.m_lastResolvedColor; + return *this; } @@ -387,6 +392,26 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem ) std::swap( m_allowAutoPlace, item->m_allowAutoPlace ); SwapText( *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( GetParent() ); + + if( parentLabel && !parentLabel->IsConnectivityDirty() ) + m_lastResolvedColor = parentLabel->GetEffectiveNetClass()->GetSchematicColor(); + } + + return m_lastResolvedColor; } diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 34cf7ff288..51f194c24d 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -119,10 +119,20 @@ public: wxString GetShownText( int aDepth = 0 ) const override; + COLOR4D GetFieldColor() const; + + void SetLastResolvedState( const SCH_ITEM* aItem ) override + { + const SCH_FIELD* aField = dynamic_cast( aItem ); + + if( aField ) + m_lastResolvedColor = aField->m_lastResolvedColor; + } + /** * 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; @@ -242,6 +252,8 @@ private: mutable bool m_renderCacheValid; mutable VECTOR2I m_renderCachePos; mutable std::vector> m_renderCache; + + mutable COLOR4D m_lastResolvedColor; }; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 9fdf5c2114..1d44bc8d30 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -156,7 +156,8 @@ SCH_LABEL_BASE::SCH_LABEL_BASE( const VECTOR2I& aPos, const wxString& aText, KIC SCH_TEXT( aPos, aText, aType ), m_shape( L_UNSPECIFIED ), m_connectionType( CONNECTION_TYPE::NONE ), - m_isDangling( true ) + m_isDangling( true ), + m_lastResolvedColor( COLOR4D::UNSPECIFIED ) { SetMultilineAllowed( false ); ClearFieldsAutoplaced(); // fiels are not yet autoplaced. @@ -167,7 +168,8 @@ SCH_LABEL_BASE::SCH_LABEL_BASE( const SCH_LABEL_BASE& aLabel ) : SCH_TEXT( aLabel ), m_shape( aLabel.m_shape ), m_connectionType( aLabel.m_connectionType ), - m_isDangling( aLabel.m_isDangling ) + m_isDangling( aLabel.m_isDangling ), + m_lastResolvedColor( aLabel.m_lastResolvedColor ) { SetMultilineAllowed( false ); @@ -254,6 +256,18 @@ void SCH_LABEL_BASE::SwapData( SCH_ITEM* aItem ) std::swap( m_shape, label->m_shape ); std::swap( m_connectionType, label->m_connectionType ); 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; } diff --git a/eeschema/sch_label.h b/eeschema/sch_label.h index ee90027128..917920dbe2 100644 --- a/eeschema/sch_label.h +++ b/eeschema/sch_label.h @@ -31,9 +31,6 @@ #include // for CONNECTION_TYPE -extern const char* SheetLabelType[]; /* names of types of labels */ - - class SCH_LABEL_BASE : public SCH_TEXT { public: @@ -76,6 +73,16 @@ public: LABEL_FLAG_SHAPE GetShape() const override { return m_shape; } 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( aItem ); + + if( aLabel ) + m_lastResolvedColor = aLabel->m_lastResolvedColor; + } + static const wxString GetDefaultFieldName( const wxString& aName, bool aUseDefaultName ); virtual int GetMandatoryFieldCount() { return 0; } @@ -203,6 +210,8 @@ protected: CONNECTION_TYPE m_connectionType; bool m_isDangling; bool m_autoRotateOnPlacement = false; + + mutable COLOR4D m_lastResolvedColor; }; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 02879afab6..dfc09c47af 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -355,7 +355,7 @@ float SCH_PAINTER::getShadowWidth( bool aForHighlight ) const COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDrawingShadows, - bool aDimmed ) const + bool aDimmed ) const { COLOR4D color = m_schSettings.GetLayerColor( aLayer ); @@ -405,6 +405,14 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDr else color = shape->GetStroke().GetColor(); } + else if( aItem->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) + { + color = static_cast( aItem )->GetLabelColor(); + } + else if( aItem->Type() == SCH_FIELD_T ) + { + color = static_cast( aItem )->GetFieldColor(); + } else if( aItem->Type() == SCH_TEXTBOX_T ) { const SCH_TEXTBOX* textBox = static_cast( aItem ); @@ -1898,8 +1906,9 @@ void SCH_PAINTER::draw( const SCH_TEXT *aText, int aLayer ) { if( aText->IsDangling() ) { - drawDanglingSymbol( aText->GetTextPos(), color, schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), - drawingShadows, aText->IsBrightened() ); + drawDanglingSymbol( aText->GetTextPos(), color, + schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), drawingShadows, + aText->IsBrightened() ); } return; diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index d363cb0440..f066679d88 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -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 { public: