@ -30,10 +30,13 @@
# include <bitmaps.h>
# include <netclass.h>
# include <confirm.h>
# include <gal/painter.h>
# include <grid_tricks.h>
# include <dialogs/panel_setup_netclasses.h>
# include <tool/tool_manager.h>
# include <pcb_painter.h>
# include <string_utils.h>
# include <view/view.h>
# include <widgets/grid_color_swatch_helpers.h>
# include <widgets/grid_icon_text_helpers.h>
# include <widgets/wx_html_report_box.h>
@ -43,7 +46,8 @@
// columns of netclasses grid
enum {
enum
{
GRID_NAME = 0 ,
GRID_FIRST_PCBNEW ,
@ -55,6 +59,7 @@ enum {
GRID_uVIADRILL ,
GRID_DIFF_PAIR_WIDTH ,
GRID_DIFF_PAIR_GAP ,
GRID_PCB_COLOR ,
GRID_FIRST_EESCHEMA ,
GRID_WIREWIDTH = GRID_FIRST_EESCHEMA ,
@ -163,15 +168,29 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
m_netclassGrid ) ) ;
m_netclassGrid - > SetColAttr ( GRID_SCHEMATIC_COLOR , attr ) ;
attr = new wxGridCellAttr ;
attr - > SetRenderer ( new GRID_CELL_COLOR_RENDERER ( PAGED_DIALOG : : GetDialog ( this ) ) ) ;
attr - > SetEditor (
new GRID_CELL_COLOR_SELECTOR ( PAGED_DIALOG : : GetDialog ( this ) , m_netclassGrid ) ) ;
m_netclassGrid - > SetColAttr ( GRID_PCB_COLOR , attr ) ;
attr = new wxGridCellAttr ;
attr - > SetRenderer ( new GRID_CELL_ICON_TEXT_RENDERER ( g_lineStyleIcons , g_lineStyleNames ) ) ;
attr - > SetEditor ( new GRID_CELL_ICON_TEXT_POPUP ( g_lineStyleIcons , g_lineStyleNames ) ) ;
m_netclassGrid - > SetColAttr ( GRID_LINESTYLE , attr ) ;
if ( m_isEEschema )
m_colorDefaultHelpText - > SetFont ( KIUI : : GetInfoFont ( this ) . Italic ( ) ) ;
{
m_importColorsButton - > Hide ( ) ;
}
else
m_colorDefaultHelpText - > Hide ( ) ;
{
m_colorDefaultHelpText - > SetLabel (
_ ( " Set color to transparent to use layer default color. " ) ) ;
m_colorDefaultHelpText - > GetParent ( ) - > Layout ( ) ;
}
m_colorDefaultHelpText - > SetFont ( KIUI : : GetInfoFont ( this ) . Italic ( ) ) ;
m_netclassGrid - > SetAutoEvalCols ( { GRID_WIREWIDTH ,
GRID_BUSWIDTH ,
@ -262,41 +281,70 @@ PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES()
void PANEL_SETUP_NETCLASSES : : loadNetclasses ( )
{
KIGFX : : PCB_RENDER_SETTINGS * rs = nullptr ;
if ( ! m_isEEschema )
{
rs = static_cast < KIGFX : : PCB_RENDER_SETTINGS * > (
m_frame - > GetCanvas ( ) - > GetView ( ) - > GetPainter ( ) - > GetSettings ( ) ) ;
}
int row = 0 ;
auto netclassToGridRow =
[ & ] ( int aRow , const std : : shared_ptr < NETCLASS > & nc )
{
m_netclassGrid - > SetCellValue ( aRow , GRID_NAME , nc - > GetName ( ) ) ;
auto netclassToGridRow = [ & ] ( int aRow , const std : : shared_ptr < NETCLASS > & nc , bool isDefault )
{
m_netclassGrid - > SetCellValue ( aRow , GRID_NAME , nc - > GetName ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_WIREWIDTH , nc - > GetWireWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_BUSWIDTH , nc - > GetBusWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_WIREWIDTH , nc - > GetWireWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_BUSWIDTH , nc - > GetBusWidth ( ) ) ;
wxString colorAsString = nc - > GetSchematicColor ( ) . ToCSSString ( ) ;
m_netclassGrid - > SetCellValue ( aRow , GRID_SCHEMATIC_COLOR , colorAsString ) ;
wxString colorAsString = nc - > GetSchematicColor ( ) . ToCSSString ( ) ;
m_netclassGrid - > SetCellValue ( aRow , GRID_SCHEMATIC_COLOR , colorAsString ) ;
int lineStyleIdx = std : : max ( 0 , nc - > GetLineStyle ( ) ) ;
int lineStyleIdx = std : : max ( 0 , nc - > GetLineStyle ( ) ) ;
if ( lineStyleIdx > = ( int ) g_lineStyleNames . size ( ) )
lineStyleIdx = 0 ;
if ( lineStyleIdx > = ( int ) g_lineStyleNames . size ( ) )
lineStyleIdx = 0 ;
m_netclassGrid - > SetCellValue ( aRow , GRID_LINESTYLE ,
g_lineStyleNames [ lineStyleIdx ] ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_CLEARANCE , nc - > GetClearance ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_TRACKSIZE , nc - > GetTrackWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_VIASIZE , nc - > GetViaDiameter ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_VIADRILL , nc - > GetViaDrill ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_uVIASIZE , nc - > GetuViaDiameter ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_uVIADRILL , nc - > GetuViaDrill ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_DIFF_PAIR_WIDTH , nc - > GetDiffPairWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_DIFF_PAIR_GAP , nc - > GetDiffPairGap ( ) ) ;
} ;
m_netclassGrid - > SetCellValue ( aRow , GRID_LINESTYLE , g_lineStyleNames [ lineStyleIdx ] ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_CLEARANCE , nc - > GetClearance ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_TRACKSIZE , nc - > GetTrackWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_VIASIZE , nc - > GetViaDiameter ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_VIADRILL , nc - > GetViaDrill ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_uVIASIZE , nc - > GetuViaDiameter ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_uVIADRILL , nc - > GetuViaDrill ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_DIFF_PAIR_WIDTH , nc - > GetDiffPairWidth ( ) ) ;
m_netclassGrid - > SetUnitValue ( aRow , GRID_DIFF_PAIR_GAP , nc - > GetDiffPairGap ( ) ) ;
colorAsString = KIGFX : : COLOR4D ( 0.0 , 0.0 , 0.0 , 0.0 ) . ToCSSString ( ) ;
if ( m_isEEschema )
{
colorAsString = nc - > GetPcbColor ( ) . ToCSSString ( ) ;
}
if ( rs )
{
std : : map < wxString , KIGFX : : COLOR4D > & netclassColors = rs - > GetNetclassColorMap ( ) ;
if ( netclassColors . find ( nc - > GetName ( ) ) ! = netclassColors . end ( ) )
{
colorAsString = netclassColors [ nc - > GetName ( ) ] . ToCSSString ( ) ;
}
}
if ( isDefault )
{
colorAsString = KIGFX : : COLOR4D ( 0.0 , 0.0 , 0.0 , 0.0 ) . ToCSSString ( ) ;
m_netclassGrid - > SetReadOnly ( aRow , GRID_PCB_COLOR ) ;
}
m_netclassGrid - > SetCellValue ( aRow , GRID_PCB_COLOR , colorAsString ) ;
} ;
m_netclassGrid - > ClearRows ( ) ;
// enter the Default NETCLASS.
m_netclassGrid - > AppendRows ( 1 ) ;
netclassToGridRow ( row + + , m_netSettings - > m_DefaultNetClass ) ;
netclassToGridRow ( row + + , m_netSettings - > m_DefaultNetClass , true ) ;
// make the Default NETCLASS name read-only
wxGridCellAttr * cellAttr = m_netclassGrid - > GetOrCreateCellAttr ( 0 , GRID_NAME ) ;
@ -307,7 +355,7 @@ void PANEL_SETUP_NETCLASSES::loadNetclasses()
m_netclassGrid - > AppendRows ( ( int ) m_netSettings - > m_NetClasses . size ( ) ) ;
for ( const auto & [ name , netclass ] : m_netSettings - > m_NetClasses )
netclassToGridRow ( row + + , netclass ) ;
netclassToGridRow ( row + + , netclass , false ) ;
m_assignmentGrid - > ClearRows ( ) ;
m_assignmentGrid - > AppendRows ( m_netSettings - > m_NetClassPatternAssignments . size ( ) ) ;
@ -396,41 +444,67 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
int row = 0 ;
auto gridRowToNetclass =
[ & ] ( int aRow , const std : : shared_ptr < NETCLASS > & nc )
{
nc - > SetName ( m_netclassGrid - > GetCellValue ( aRow , GRID_NAME ) ) ;
auto gridRowToNetclass = [ & ] ( int aRow , const std : : shared_ptr < NETCLASS > & nc , bool isDefault )
{
nc - > SetName ( m_netclassGrid - > GetCellValue ( aRow , GRID_NAME ) ) ;
nc - > SetWireWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_WIREWIDTH ) ) ;
nc - > SetBusWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_BUSWIDTH ) ) ;
nc - > SetWireWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_WIREWIDTH ) ) ;
nc - > SetBusWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_BUSWIDTH ) ) ;
wxString color = m_netclassGrid - > GetCell Value ( aRow , GRID_SCHEMATIC_COLOR ) ;
nc - > SetSchematicColor ( wxColour ( color ) ) ;
wxString color = m_netclassGrid - > GetCellValue ( aRow , GRID_SCHEMATIC_COLOR ) ;
nc - > SetSchematicColor ( wxColour ( color ) ) ;
wxString lineStyle = m_netclassGrid - > GetCellValue ( aRow , GRID_LINESTYLE ) ;
nc - > SetLineStyle ( g_lineStyleNames . Index ( lineStyle ) ) ;
wxASSERT_MSG ( nc - > GetLineStyle ( ) > = 0 , " Line style name not found. " ) ;
wxString lineStyle = m_netclassGrid - > GetCellValue ( aRow , GRID_LINESTYLE ) ;
nc - > SetLineStyle ( g_lineStyleNames . Index ( lineStyle ) ) ;
wxASSERT_MSG ( nc - > GetLineStyle ( ) > = 0 , " Line style name not found. " ) ;
nc - > SetClearance ( m_netclassGrid - > GetUnitValue ( aRow , GRID_CLEARANCE ) ) ;
nc - > SetTrackWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_TRACKSIZE ) ) ;
nc - > SetViaDiameter ( m_netclassGrid - > GetUnitValue ( aRow , GRID_VIASIZE ) ) ;
nc - > SetViaDrill ( m_netclassGrid - > GetUnitValue ( aRow , GRID_VIADRILL ) ) ;
nc - > SetuViaDiameter ( m_netclassGrid - > GetUnitValue ( aRow , GRID_uVIASIZE ) ) ;
nc - > SetuViaDrill ( m_netclassGrid - > GetUnitValue ( aRow , GRID_uVIADRILL ) ) ;
nc - > SetDiffPairWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_DIFF_PAIR_WIDTH ) ) ;
nc - > SetDiffPairGap ( m_netclassGrid - > GetUnitValue ( aRow , GRID_DIFF_PAIR_GAP ) ) ;
if ( ! isDefault )
{
color = m_netclassGrid - > GetCellValue ( aRow , GRID_PCB_COLOR ) ;
KIGFX : : COLOR4D newPcbColor ( color ) ;
if ( newPcbColor ! = KIGFX : : COLOR4D : : UNSPECIFIED )
{
nc - > SetPcbColor ( newPcbColor ) ;
}
nc - > SetClearance ( m_netclassGrid - > GetUnitValue ( aRow , GRID_CLEARANCE ) ) ;
nc - > SetTrackWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_TRACKSIZE ) ) ;
nc - > SetViaDiameter ( m_netclassGrid - > GetUnitValue ( aRow , GRID_VIASIZE ) ) ;
nc - > SetViaDrill ( m_netclassGrid - > GetUnitValue ( aRow , GRID_VIADRILL ) ) ;
nc - > SetuViaDiameter ( m_netclassGrid - > GetUnitValue ( aRow , GRID_uVIASIZE ) ) ;
nc - > SetuViaDrill ( m_netclassGrid - > GetUnitValue ( aRow , GRID_uVIADRILL ) ) ;
nc - > SetDiffPairWidth ( m_netclassGrid - > GetUnitValue ( aRow , GRID_DIFF_PAIR_WIDTH ) ) ;
nc - > SetDiffPairGap ( m_netclassGrid - > GetUnitValue ( aRow , GRID_DIFF_PAIR_GAP ) ) ;
} ;
if ( ! m_isEEschema )
{
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 ( ) ;
if ( newPcbColor ! = COLOR4D : : UNSPECIFIED )
{
netclassColors [ nc - > GetName ( ) ] = newPcbColor ;
}
else
{
netclassColors . erase ( nc - > GetName ( ) ) ;
}
}
}
} ;
m_netSettings - > m_NetClasses . clear ( ) ;
// Copy the default NetClass:
gridRowToNetclass ( row + + , m_netSettings - > m_DefaultNetClass ) ;
gridRowToNetclass ( row + + , m_netSettings - > m_DefaultNetClass , true ) ;
// Copy other NetClasses:
for ( row = 1 ; row < m_netclassGrid - > GetNumberRows ( ) ; + + row )
{
auto nc = std : : make_shared < NETCLASS > ( m_netclassGrid - > GetCellValue ( row , GRID_NAME ) ) ;
gridRowToNetclass ( row , nc ) ;
gridRowToNetclass ( row , nc , false ) ;
m_netSettings - > m_NetClasses [ nc - > GetName ( ) ] = nc ;
}
@ -547,6 +621,7 @@ void PANEL_SETUP_NETCLASSES::OnNetclassGridMouseEvent( wxMouseEvent& aEvent )
case GRID_BUSWIDTH : tip = _ ( " Bus wire thickness " ) ; break ;
case GRID_SCHEMATIC_COLOR : tip = _ ( " Schematic wire color " ) ; break ;
case GRID_LINESTYLE : tip = _ ( " Schematic wire line style " ) ; break ;
case GRID_PCB_COLOR : tip = _ ( " PCB netclass color " ) ; break ;
}
m_netclassGrid - > GetGridColLabelWindow ( ) - > UnsetToolTip ( ) ;
@ -687,6 +762,23 @@ void PANEL_SETUP_NETCLASSES::OnRemoveAssignmentClick( wxCommandEvent& event )
}
void PANEL_SETUP_NETCLASSES : : OnImportColorsClick ( wxCommandEvent & event )
{
std : : map < wxString , std : : shared_ptr < NETCLASS > > & netclasses = m_netSettings - > m_NetClasses ;
for ( int row = 1 ; row < m_netclassGrid - > GetNumberRows ( ) ; + + row )
{
wxString netclassName = m_netclassGrid - > GetCellValue ( row , GRID_NAME ) ;
if ( netclasses . find ( netclassName ) ! = netclasses . end ( ) )
{
const KIGFX : : COLOR4D ncColor = netclasses [ netclassName ] - > GetSchematicColor ( ) ;
m_netclassGrid - > SetCellValue ( row , GRID_PCB_COLOR , ncColor . ToCSSString ( ) ) ;
}
}
}
void PANEL_SETUP_NETCLASSES : : AdjustAssignmentGridColumns ( int aWidth )
{
// Account for scroll bars