Fix rendering of net colors on items

This commit is contained in:
Jon Evans 2020-08-15 18:49:56 -04:00
parent beab35472b
commit 0db00046d1
4 changed files with 61 additions and 12 deletions

View File

@ -943,6 +943,27 @@ inline bool IsDCodeLayer( int aLayer )
} }
/**
* Checks if the given layer is "net copper", meaning it is eligible for net coloring
* @param aLayer is the layer to test
* @return true if the layer is one that participates in net coloring
*/
inline bool IsNetCopperLayer( LAYER_NUM aLayer )
{
static std::set<LAYER_NUM> netCopperLayers =
{
LAYER_PAD_FR,
LAYER_PAD_BK,
LAYER_PADS_TH,
LAYER_VIA_THROUGH,
LAYER_VIA_BBLIND,
LAYER_VIA_MICROVIA
};
return IsCopperLayer( aLayer ) || netCopperLayers.count( aLayer );
}
PCB_LAYER_ID ToLAYER_ID( int aLayer ); PCB_LAYER_ID ToLAYER_ID( int aLayer );
#endif // LAYERS_ID_AND_VISIBILITY_H_ #endif // LAYERS_ID_AND_VISIBILITY_H_

View File

@ -267,22 +267,34 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) cons
netCode = conItem->GetNetCode(); netCode = conItem->GetNetCode();
// Apply net color overrides // Apply net color overrides
if( conItem && m_netColorMode == NET_COLOR_MODE::ALL ) if( conItem && m_netColorMode == NET_COLOR_MODE::ALL && IsNetCopperLayer( aLayer ) )
{ {
if( m_netColors.count( conItem->GetNetCode() ) ) if( m_netColors.count( netCode ) )
color = m_netColors.at( conItem->GetNetCode() ); color = m_netColors.at( netCode );
else if( m_netclassColors.count( conItem->GetNetClassName() ) ) else if( m_netclassColors.count( conItem->GetNetClassName() ) )
color = m_netclassColors.at( conItem->GetNetClassName() ); color = m_netclassColors.at( conItem->GetNetClassName() );
if( item->IsSelected() )
color.Brighten( m_selectFactor );
else if( m_highlightEnabled && m_highlightNetcodes.count( netCode ) )
color.Brighten( m_highlightFactor );
else if( m_highlightEnabled )
color.Darken( 1.0 - m_highlightFactor );
else if( m_contrastModeDisplay == HIGH_CONTRAST_MODE::DIMMED
&& m_activeLayers.count( aLayer ) == 0 )
color.Mix( m_layerColors[LAYER_PCB_BACKGROUND], m_hiContrastFactor );
} }
else
{
// Single net highlight mode
if( m_highlightEnabled )
color = m_highlightNetcodes.count( netCode ) ? m_layerColorsHi[aLayer]
: m_layerColorsDark[aLayer];
// Single net highlight mode // Return grayish color for non-highlighted layers in the dimmed high contrast mode
if( m_highlightEnabled ) if( m_contrastModeDisplay == HIGH_CONTRAST_MODE::DIMMED && m_activeLayers.count( aLayer ) == 0 )
color = m_highlightNetcodes.count( netCode ) ? m_layerColorsHi[aLayer] color = m_hiContrastColor[aLayer];
: m_layerColorsDark[aLayer]; }
// Return grayish color for non-highlighted layers in the dimmed high contrast mode
if( m_contrastModeDisplay == HIGH_CONTRAST_MODE::DIMMED && m_activeLayers.count( aLayer ) == 0 )
color = m_hiContrastColor[aLayer];
// For vias, some layers depend on other layers in high contrast mode // For vias, some layers depend on other layers in high contrast mode
if( m_hiContrastEnabled && item->Type() == PCB_VIA_T && if( m_hiContrastEnabled && item->Type() == PCB_VIA_T &&

View File

@ -121,6 +121,9 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
for( const auto& pair : netSettings.m_PcbNetColors ) for( const auto& pair : netSettings.m_PcbNetColors )
{ {
if( pair.second == COLOR4D::UNSPECIFIED )
continue;
if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) ) if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
netColors[net->GetNet()] = pair.second; netColors[net->GetNet()] = pair.second;
} }
@ -216,6 +219,9 @@ void PCB_EDIT_FRAME::SaveProjectSettings()
for( const auto& pair : rs->GetNetColorMap() ) for( const auto& pair : rs->GetNetColorMap() )
{ {
if( pair.second == COLOR4D::UNSPECIFIED )
continue;
if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) ) if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
netSettings.m_PcbNetColors[net->GetNetname()] = pair.second; netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
} }
@ -225,7 +231,8 @@ void PCB_EDIT_FRAME::SaveProjectSettings()
// NOTE: this assumes netclasses will have already been updated, which I think is the case // NOTE: this assumes netclasses will have already been updated, which I think is the case
for( const auto& pair : netSettings.m_NetClasses ) for( const auto& pair : netSettings.m_NetClasses )
{ {
if( netclassColors.count( pair.first ) ) if( netclassColors.count( pair.first )
&& netclassColors.at( pair.first ) != COLOR4D::UNSPECIFIED )
pair.second->SetPcbColor( netclassColors.at( pair.first ) ); pair.second->SetPcbColor( netclassColors.at( pair.first ) );
} }

View File

@ -1201,6 +1201,8 @@ void APPEARANCE_CONTROLS::rebuildNets()
if( s->GetSwatchColor() == COLOR4D::UNSPECIFIED ) if( s->GetSwatchColor() == COLOR4D::UNSPECIFIED )
s->Hide(); s->Hide();
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
m_frame->GetCanvas()->RedrawRatsnest(); m_frame->GetCanvas()->RedrawRatsnest();
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();
} ); } );
@ -1658,6 +1660,9 @@ void APPEARANCE_CONTROLS::onNetContextMenu( wxCommandEvent& aEvent )
netColors[m_contextMenuNetCode] = color; netColors[m_contextMenuNetCode] = color;
else else
netColors.erase( m_contextMenuNetCode ); netColors.erase( m_contextMenuNetCode );
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
m_frame->GetCanvas()->Refresh();
} }
break; break;
@ -1761,6 +1766,7 @@ void APPEARANCE_CONTROLS::onNetclassColorChanged( wxCommandEvent& aEvent )
if( swatch->GetSwatchColor() == COLOR4D::UNSPECIFIED ) if( swatch->GetSwatchColor() == COLOR4D::UNSPECIFIED )
swatch->Hide(); swatch->Hide();
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
m_frame->GetCanvas()->RedrawRatsnest(); m_frame->GetCanvas()->RedrawRatsnest();
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();
} }
@ -1788,6 +1794,7 @@ void APPEARANCE_CONTROLS::onNetColorModeChanged( wxCommandEvent& aEvent )
options.m_NetColorMode = NET_COLOR_MODE::OFF; options.m_NetColorMode = NET_COLOR_MODE::OFF;
m_frame->SetDisplayOptions( options ); m_frame->SetDisplayOptions( options );
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
} }
@ -1823,6 +1830,8 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent )
netclassColors[m_contextMenuNetclass] = color; netclassColors[m_contextMenuNetclass] = color;
else else
netclassColors.erase( m_contextMenuNetclass ); netclassColors.erase( m_contextMenuNetclass );
view->UpdateAllLayersColor();
} }
break; break;