Overplot schematic symbol fields and pins

In the absence of z-ordering, we need to ensure that pin text and symbol
fields are always visible in plots as they are in the schematic window.
We do this by overplotting the fields/pins when symbols overlap each
other.

This can be removed if/when we implement https://gitlab.com/kicad/code/kicad/-/issues/2211

Fixes https://gitlab.com/kicad/code/kicad/issues/11969

(cherry picked from commit ff54b8c718)
This commit is contained in:
Seth Hillbrand 2022-07-05 16:37:36 -07:00
parent b2855e6288
commit 6a1dfd6e32
4 changed files with 73 additions and 3 deletions

View File

@ -225,6 +225,11 @@ public:
{ {
return type_tree->end( m_rect ); return type_tree->end( m_rect );
} }
bool empty()
{
return type_tree->Count() == 0;
}
}; };
EE_TYPE OfType( KICAD_T aType ) const EE_TYPE OfType( KICAD_T aType ) const

View File

@ -840,6 +840,7 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter ) const
// Ensure links are up to date, even if a library was reloaded for some reason: // Ensure links are up to date, even if a library was reloaded for some reason:
std::vector<SCH_ITEM*> junctions; std::vector<SCH_ITEM*> junctions;
std::vector<SCH_ITEM*> bitmaps; std::vector<SCH_ITEM*> bitmaps;
std::vector<SCH_SYMBOL*> symbols;
std::vector<SCH_ITEM*> other; std::vector<SCH_ITEM*> other;
for( SCH_ITEM* item : Items() ) for( SCH_ITEM* item : Items() )
@ -853,6 +854,21 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter ) const
bitmaps.push_back( item ); bitmaps.push_back( item );
else else
other.push_back( item ); other.push_back( item );
// Where the symbols overlap each other, we need to plot the text items a second
// time to get them on top of the overlapping element. This collection is in addition
// to the symbols already collected in `other`
if( item->Type() == SCH_SYMBOL_T )
{
for( SCH_ITEM* sym : m_rtree.Overlapping( SCH_SYMBOL_T, item->GetBoundingBox() ) )
{
if( sym != item )
{
symbols.push_back( static_cast<SCH_SYMBOL*>( item ) );
break;
}
}
}
} }
/// Sort to ensure plot-order consistency with screen drawing /// Sort to ensure plot-order consistency with screen drawing
@ -882,6 +898,18 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter ) const
item->Plot( aPlotter ); item->Plot( aPlotter );
} }
// After plotting the symbols as a group above (in `other`), we need to overplot the pins
// and symbols to ensure that they are always visible
for( const SCH_SYMBOL* sym :symbols )
{
aPlotter->SetCurrentLineWidth( std::max( sym->GetPenWidth(), defaultPenWidth ) );
for( SCH_FIELD field : sym->GetFields() )
field.Plot( aPlotter );
sym->PlotPins( aPlotter );
}
for( const SCH_ITEM* item : junctions ) for( const SCH_ITEM* item : junctions )
{ {
aPlotter->SetCurrentLineWidth( std::max( item->GetPenWidth(), defaultPenWidth ) ); aPlotter->SetCurrentLineWidth( std::max( item->GetPenWidth(), defaultPenWidth ) );

View File

@ -1912,6 +1912,35 @@ void SCH_SYMBOL::Plot( PLOTTER* aPlotter ) const
} }
void SCH_SYMBOL::PlotPins( PLOTTER* aPlotter ) const
{
if( m_part )
{
LIB_PINS libPins;
m_part->GetPins( libPins, GetUnit(), GetConvert() );
// Copy the source to stay const
LIB_SYMBOL tempSymbol( *m_part );
LIB_PINS tempPins;
tempSymbol.GetPins( tempPins, GetUnit(), GetConvert() );
TRANSFORM transform = GetTransform();
// Copy the pin info from the symbol to the temp pins
for( unsigned i = 0; i < tempPins.size(); ++ i )
{
SCH_PIN* symbolPin = GetPin( libPins[ i ] );
LIB_PIN* tempPin = tempPins[ i ];
tempPin->SetName( symbolPin->GetShownName() );
tempPin->SetType( symbolPin->GetType() );
tempPin->SetShape( symbolPin->GetShape() );
tempPin->Plot( aPlotter, m_pos, false, transform);
}
}
}
bool SCH_SYMBOL::HasBrightenedPins() bool SCH_SYMBOL::HasBrightenedPins()
{ {
for( const auto& pin : m_pins ) for( const auto& pin : m_pins )

View File

@ -650,6 +650,14 @@ public:
void Plot( PLOTTER* aPlotter ) const override; void Plot( PLOTTER* aPlotter ) const override;
/**
* Plot just the symbol pins. This is separated to match the GAL display order. The pins are
* ALSO plotted with the symbol group. This replotting allows us to ensure that they are shown above
* other elements in the schematic
* @param aPlotter
*/
void PlotPins( PLOTTER* aPlotter ) const;
EDA_ITEM* Clone() const override; EDA_ITEM* Clone() const override;
#if defined(DEBUG) #if defined(DEBUG)