Read/write COLOR4D::UNSPECIFIED in netinfo so you can clear colors.

Fixes https://gitlab.com/kicad/code/kicad/issues/5368
This commit is contained in:
Jeff Young 2020-09-03 18:54:14 +01:00
parent 03423f13a1
commit 555b78e7ca
3 changed files with 12 additions and 27 deletions

View File

@ -62,23 +62,19 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
{ "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) },
{ "wire_width", SchIu2Mils( netclass->GetWireWidth() ) },
{ "bus_width", SchIu2Mils( netclass->GetBusWidth() ) },
{ "line_style", netclass->GetLineStyle() }
{ "line_style", netclass->GetLineStyle() },
{ "schematic_color", netclass->GetSchematicColor() },
{ "pcb_color", netclass->GetPcbColor() }
};
if( netclass->GetSchematicColor() != KIGFX::COLOR4D::UNSPECIFIED )
netclassJson["schematic_color"] = netclass->GetSchematicColor();
if( idx > 0 )
if( idx > 0 ) // No need to store members of Default netclass
{
if( netclass->GetPcbColor() != KIGFX::COLOR4D::UNSPECIFIED )
netclassJson["pcb_color"] = netclass->GetPcbColor();
nlohmann::json membersJson = nlohmann::json::array();
for( const auto& ii : *netclass )
for( const wxString& member : *netclass )
{
if( !ii.empty() )
membersJson.push_back( ii );
if( !member.empty() )
membersJson.push_back( member );
}
netclassJson["nets"] = membersJson;

View File

@ -121,10 +121,7 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
netclassColors.clear();
for( const auto& pair : netSettings.m_NetClasses )
{
if( pair.second->GetPcbColor() != COLOR4D::UNSPECIFIED )
netclassColors[pair.first] = pair.second->GetPcbColor();
}
m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
@ -207,11 +204,8 @@ void PCB_EDIT_FRAME::SaveProjectSettings()
netSettings.m_PcbNetColors.clear();
for( const auto& pair : rs->GetNetColorMap() )
for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
{
if( pair.second == COLOR4D::UNSPECIFIED )
continue;
if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
}
@ -219,10 +213,9 @@ void PCB_EDIT_FRAME::SaveProjectSettings()
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
// NOTE: this assumes netclasses will have already been updated, which I think is the case
for( const auto& pair : netSettings.m_NetClasses )
for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
{
if( netclassColors.count( pair.first )
&& netclassColors.at( pair.first ) != COLOR4D::UNSPECIFIED )
if( netclassColors.count( pair.first ) )
pair.second->SetPcbColor( netclassColors.at( pair.first ) );
}

View File

@ -2159,11 +2159,7 @@ void APPEARANCE_CONTROLS::onNetclassColorChanged( wxCommandEvent& aEvent )
COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
wxString className = netclassNameFromEvent( aEvent );
COLOR4D newColor = swatch->GetSwatchColor();
if( newColor == COLOR4D::UNSPECIFIED )
netclassColors.erase( className );
else
netclassColors[className] = swatch->GetSwatchColor();
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();