Add import netclass color menu items to PCB appearance widget
Fixes https://gitlab.com/kicad/code/kicad/-/issues/16908 ADDED: Context menu item in PCB appearances widget to import netclass color from schematic. ADDED: Context menu item to reset PCB netclass color (replicating same menu item from Nets inspector)
This commit is contained in:
parent
141de7ac11
commit
b8748c4ef8
|
@ -435,6 +435,17 @@ std::shared_ptr<NETCLASS> NET_SETTINGS::GetEffectiveNetClass( const wxString& aN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<NETCLASS> NET_SETTINGS::GetNetClassByName( const wxString& aNetClassName ) const
|
||||||
|
{
|
||||||
|
auto ii = m_NetClasses.find( aNetClassName );
|
||||||
|
|
||||||
|
if( ii == m_NetClasses.end() )
|
||||||
|
return m_DefaultNetClass;
|
||||||
|
else
|
||||||
|
return ii->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool isSuperSubOverbar( wxChar c )
|
static bool isSuperSubOverbar( wxChar c )
|
||||||
{
|
{
|
||||||
return c == '_' || c == '^' || c == '~';
|
return c == '_' || c == '^' || c == '~';
|
||||||
|
|
|
@ -62,6 +62,14 @@ public:
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<NETCLASS> GetEffectiveNetClass( const wxString& aNetName ) const;
|
std::shared_ptr<NETCLASS> GetEffectiveNetClass( const wxString& aNetName ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a NETCLASS object from a given Netclass name string
|
||||||
|
*
|
||||||
|
* @param aNetClassName the Netclass name to resolve
|
||||||
|
* @return shared pointer to the requested NETCLASS object, or the default NETCLASS
|
||||||
|
*/
|
||||||
|
std::shared_ptr<NETCLASS> GetNetClassByName( const wxString& aNetName ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a bus vector (e.g. A[7..0]) into name, begin, and end.
|
* Parse a bus vector (e.g. A[7..0]) into name, begin, and end.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2315,10 +2315,27 @@ void APPEARANCE_CONTROLS::syncObjectSettings()
|
||||||
void APPEARANCE_CONTROLS::buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass,
|
void APPEARANCE_CONTROLS::buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass,
|
||||||
const wxString& aName )
|
const wxString& aName )
|
||||||
{
|
{
|
||||||
|
BOARD* board = m_frame->GetBoard();
|
||||||
|
std::shared_ptr<NET_SETTINGS>& netSettings = board->GetDesignSettings().m_NetSettings;
|
||||||
|
|
||||||
if( !isDefaultClass)
|
if( !isDefaultClass)
|
||||||
{
|
{
|
||||||
aMenu.Append( new wxMenuItem( &aMenu, ID_SET_NET_COLOR, _( "Set Netclass Color" ),
|
aMenu.Append( new wxMenuItem( &aMenu, ID_SET_NET_COLOR, _( "Set Netclass Color" ),
|
||||||
wxEmptyString, wxITEM_NORMAL ) );
|
wxEmptyString, wxITEM_NORMAL ) );
|
||||||
|
|
||||||
|
wxMenuItem* schematicColor =
|
||||||
|
new wxMenuItem( &aMenu, ID_USE_SCHEMATIC_NET_COLOR, _( "Use Color from Schematic" ),
|
||||||
|
wxEmptyString, wxITEM_NORMAL );
|
||||||
|
std::shared_ptr<NETCLASS> nc = netSettings->GetNetClassByName( aName );
|
||||||
|
const KIGFX::COLOR4D ncColor = nc->GetSchematicColor();
|
||||||
|
aMenu.Append( schematicColor );
|
||||||
|
|
||||||
|
if( ncColor == KIGFX::COLOR4D::UNSPECIFIED )
|
||||||
|
schematicColor->Enable( false );
|
||||||
|
|
||||||
|
aMenu.Append( new wxMenuItem( &aMenu, ID_CLEAR_NET_COLOR, _( "Clear Netclass Color" ),
|
||||||
|
wxEmptyString, wxITEM_NORMAL ) );
|
||||||
|
aMenu.AppendSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString name = UnescapeString( aName );
|
wxString name = UnescapeString( aName );
|
||||||
|
@ -3101,14 +3118,16 @@ void APPEARANCE_CONTROLS::showNetclass( const wxString& aClassName, bool aShow )
|
||||||
|
|
||||||
void APPEARANCE_CONTROLS::onNetclassColorChanged( wxCommandEvent& aEvent )
|
void APPEARANCE_CONTROLS::onNetclassColorChanged( wxCommandEvent& aEvent )
|
||||||
{
|
{
|
||||||
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
|
||||||
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
|
||||||
|
|
||||||
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
|
||||||
|
|
||||||
COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
|
COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
|
||||||
wxString netclassName = netclassNameFromEvent( aEvent );
|
wxString netclassName = netclassNameFromEvent( aEvent );
|
||||||
|
|
||||||
|
BOARD* board = m_frame->GetBoard();
|
||||||
|
std::shared_ptr<NET_SETTINGS>& netSettings = board->GetDesignSettings().m_NetSettings;
|
||||||
|
netSettings->m_NetClasses[netclassName]->SetPcbColor( swatch->GetSwatchColor() );
|
||||||
|
|
||||||
|
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
||||||
|
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
||||||
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
||||||
netclassColors[netclassName] = swatch->GetSwatchColor();
|
netclassColors[netclassName] = swatch->GetSwatchColor();
|
||||||
|
|
||||||
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
|
m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
|
||||||
|
@ -3202,6 +3221,7 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent )
|
||||||
switch( aEvent.GetId() )
|
switch( aEvent.GetId() )
|
||||||
{
|
{
|
||||||
case ID_SET_NET_COLOR:
|
case ID_SET_NET_COLOR:
|
||||||
|
{
|
||||||
if( setting )
|
if( setting )
|
||||||
{
|
{
|
||||||
setting->ctl_color->GetNewSwatchColor();
|
setting->ctl_color->GetNewSwatchColor();
|
||||||
|
@ -3219,8 +3239,44 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ID_CLEAR_NET_COLOR:
|
||||||
|
{
|
||||||
|
if( setting )
|
||||||
|
{
|
||||||
|
setting->ctl_color->SetSwatchColor( COLOR4D( 0, 0, 0, 0 ), true );
|
||||||
|
|
||||||
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
||||||
|
netclassColors.erase( m_contextMenuNetclass );
|
||||||
|
|
||||||
|
view->UpdateAllLayersColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ID_USE_SCHEMATIC_NET_COLOR:
|
||||||
|
{
|
||||||
|
if( setting )
|
||||||
|
{
|
||||||
|
std::shared_ptr<NETCLASS> nc =
|
||||||
|
netSettings->GetNetClassByName( m_contextMenuNetclass );
|
||||||
|
const KIGFX::COLOR4D ncColor = nc->GetSchematicColor();
|
||||||
|
|
||||||
|
setting->ctl_color->SetSwatchColor( ncColor, true );
|
||||||
|
|
||||||
|
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
||||||
|
netclassColors[m_contextMenuNetclass] = ncColor;
|
||||||
|
|
||||||
|
view->UpdateAllLayersColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ID_HIGHLIGHT_NET:
|
case ID_HIGHLIGHT_NET:
|
||||||
|
{
|
||||||
if( !m_contextMenuNetclass.IsEmpty() )
|
if( !m_contextMenuNetclass.IsEmpty() )
|
||||||
{
|
{
|
||||||
runOnNetsOfClass( m_contextMenuNetclass,
|
runOnNetsOfClass( m_contextMenuNetclass,
|
||||||
|
@ -3247,9 +3303,11 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ID_SELECT_NET:
|
case ID_SELECT_NET:
|
||||||
case ID_DESELECT_NET:
|
case ID_DESELECT_NET:
|
||||||
|
{
|
||||||
if( !m_contextMenuNetclass.IsEmpty() )
|
if( !m_contextMenuNetclass.IsEmpty() )
|
||||||
{
|
{
|
||||||
TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
|
TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
|
||||||
|
@ -3263,9 +3321,11 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent )
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case ID_SHOW_ALL_NETS:
|
case ID_SHOW_ALL_NETS:
|
||||||
|
{
|
||||||
showNetclass( NETCLASS::Default );
|
showNetclass( NETCLASS::Default );
|
||||||
wxASSERT( m_netclassSettingsMap.count( NETCLASS::Default ) );
|
wxASSERT( m_netclassSettingsMap.count( NETCLASS::Default ) );
|
||||||
m_netclassSettingsMap.at( NETCLASS::Default )->ctl_visibility->SetValue( true );
|
m_netclassSettingsMap.at( NETCLASS::Default )->ctl_visibility->SetValue( true );
|
||||||
|
@ -3279,6 +3339,7 @@ void APPEARANCE_CONTROLS::onNetclassContextMenu( wxCommandEvent& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ID_HIDE_OTHER_NETS:
|
case ID_HIDE_OTHER_NETS:
|
||||||
{
|
{
|
||||||
|
|
|
@ -467,6 +467,7 @@ private:
|
||||||
ID_CHANGE_COLOR = wxID_HIGHEST,
|
ID_CHANGE_COLOR = wxID_HIGHEST,
|
||||||
ID_SET_NET_COLOR,
|
ID_SET_NET_COLOR,
|
||||||
ID_CLEAR_NET_COLOR,
|
ID_CLEAR_NET_COLOR,
|
||||||
|
ID_USE_SCHEMATIC_NET_COLOR,
|
||||||
ID_SHOW_ALL_NETS,
|
ID_SHOW_ALL_NETS,
|
||||||
ID_HIDE_OTHER_NETS,
|
ID_HIDE_OTHER_NETS,
|
||||||
ID_HIGHLIGHT_NET,
|
ID_HIGHLIGHT_NET,
|
||||||
|
|
Loading…
Reference in New Issue