2018-04-28 15:22:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2009 Dick Hollenbeck, dick@softplc.com
|
2022-06-13 20:26:06 +00:00
|
|
|
* Copyright (C) 2009-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-04-28 15:22:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-02-23 14:34:18 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <pgm_base.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <base_units.h>
|
2021-12-22 21:43:41 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <bitmaps.h>
|
2020-07-03 22:30:23 +00:00
|
|
|
#include <netclass.h>
|
2019-07-06 13:35:46 +00:00
|
|
|
#include <confirm.h>
|
2019-03-04 11:02:12 +00:00
|
|
|
#include <grid_tricks.h>
|
2020-12-17 16:43:46 +00:00
|
|
|
#include <dialogs/panel_setup_netclasses.h>
|
2022-09-03 18:29:02 +00:00
|
|
|
#include "widgets/wx_html_report_box.h"
|
2019-07-06 13:35:46 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-07-08 18:29:16 +00:00
|
|
|
#include <widgets/grid_color_swatch_helpers.h>
|
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
2021-06-03 15:41:26 +00:00
|
|
|
#include <wx/treebook.h>
|
2022-08-14 11:03:18 +00:00
|
|
|
#include <project/net_settings.h>
|
2021-06-03 15:41:26 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2020-07-08 18:29:16 +00:00
|
|
|
// PCBNEW columns of netclasses grid
|
2018-04-28 15:22:25 +00:00
|
|
|
enum {
|
|
|
|
GRID_NAME = 0,
|
2020-07-08 18:29:16 +00:00
|
|
|
|
|
|
|
GRID_FIRST_PCBNEW,
|
|
|
|
GRID_CLEARANCE = GRID_FIRST_PCBNEW,
|
2018-04-28 15:22:25 +00:00
|
|
|
GRID_TRACKSIZE,
|
|
|
|
GRID_VIASIZE,
|
|
|
|
GRID_VIADRILL,
|
|
|
|
GRID_uVIASIZE,
|
|
|
|
GRID_uVIADRILL,
|
|
|
|
GRID_DIFF_PAIR_WIDTH,
|
|
|
|
GRID_DIFF_PAIR_GAP,
|
2020-07-08 18:29:16 +00:00
|
|
|
|
|
|
|
GRID_FIRST_EESCHEMA,
|
|
|
|
GRID_WIREWIDTH = GRID_FIRST_EESCHEMA,
|
|
|
|
GRID_BUSWIDTH,
|
|
|
|
GRID_SCHEMATIC_COLOR,
|
|
|
|
GRID_LINESTYLE,
|
|
|
|
|
|
|
|
GRID_END
|
2018-04-28 15:22:25 +00:00
|
|
|
};
|
|
|
|
|
2022-06-13 20:26:06 +00:00
|
|
|
constexpr int EESCHEMA_COL_OFFSET = GRID_FIRST_EESCHEMA - GRID_FIRST_PCBNEW;
|
|
|
|
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
std::vector<BITMAPS> g_lineStyleIcons;
|
|
|
|
wxArrayString g_lineStyleNames;
|
2020-07-08 18:29:16 +00:00
|
|
|
|
|
|
|
|
2021-12-22 21:43:41 +00:00
|
|
|
PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, EDA_DRAW_FRAME* aFrame,
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS> aNetSettings,
|
2022-09-03 18:29:02 +00:00
|
|
|
const std::set<wxString>& aNetNames,
|
2020-07-08 18:29:16 +00:00
|
|
|
bool aIsEEschema ) :
|
2020-07-03 22:30:23 +00:00
|
|
|
PANEL_SETUP_NETCLASSES_BASE( aParent->GetTreebook() ),
|
2021-12-22 21:43:41 +00:00
|
|
|
m_frame( aFrame ),
|
|
|
|
m_parent( aParent ),
|
2022-06-13 20:26:06 +00:00
|
|
|
m_isEEschema( aIsEEschema ),
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings( aNetSettings ),
|
2021-02-12 01:49:51 +00:00
|
|
|
m_netNames( aNetNames ),
|
2022-08-21 11:26:47 +00:00
|
|
|
m_hoveredCol( -1 ),
|
|
|
|
m_lastNetclassGridWidth( -1 )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2021-11-07 13:49:48 +00:00
|
|
|
// Clear and re-load each time. Language (or darkmode) might have changed.
|
|
|
|
g_lineStyleIcons.clear();
|
|
|
|
g_lineStyleNames.clear();
|
|
|
|
|
|
|
|
g_lineStyleIcons.push_back( BITMAPS::stroke_solid );
|
|
|
|
g_lineStyleNames.push_back( _( "Solid" ) );
|
|
|
|
g_lineStyleIcons.push_back( BITMAPS::stroke_dash );
|
|
|
|
g_lineStyleNames.push_back( _( "Dashed" ) );
|
|
|
|
g_lineStyleIcons.push_back( BITMAPS::stroke_dot );
|
|
|
|
g_lineStyleNames.push_back( _( "Dotted" ) );
|
|
|
|
g_lineStyleIcons.push_back( BITMAPS::stroke_dashdot );
|
|
|
|
g_lineStyleNames.push_back( _( "Dash-Dot" ) );
|
2021-07-22 23:05:01 +00:00
|
|
|
g_lineStyleIcons.push_back( BITMAPS::stroke_dashdotdot );
|
|
|
|
g_lineStyleNames.push_back( _( "Dash-Dot-Dot" ) );
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
m_netclassesDirty = true;
|
|
|
|
|
2019-04-07 14:07:02 +00:00
|
|
|
// Prevent Size events from firing before we are ready
|
|
|
|
Freeze();
|
2019-08-20 11:35:24 +00:00
|
|
|
m_netclassGrid->BeginBatch();
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->BeginBatch();
|
2019-08-20 11:35:24 +00:00
|
|
|
|
2022-06-13 20:26:06 +00:00
|
|
|
if( m_isEEschema )
|
|
|
|
{
|
|
|
|
m_netclassGrid->DeleteCols( GRID_FIRST_PCBNEW, GRID_FIRST_EESCHEMA - GRID_FIRST_PCBNEW );
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( aParent ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( aParent, m_netclassGrid ) );
|
|
|
|
m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET, 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 - EESCHEMA_COL_OFFSET, attr );
|
|
|
|
|
|
|
|
m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_netclassGrid->DeleteCols( GRID_FIRST_EESCHEMA, GRID_END - GRID_FIRST_EESCHEMA );
|
|
|
|
|
|
|
|
m_colorDefaultHelpText->Hide();
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
|
2019-02-18 09:09:22 +00:00
|
|
|
// Calculate a min best size to handle longest usual numeric values:
|
2020-05-04 14:01:25 +00:00
|
|
|
int min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
|
2019-02-02 04:03:45 +00:00
|
|
|
{
|
2019-02-18 09:09:22 +00:00
|
|
|
// We calculate the column min size only from texts sizes, not using the initial col width
|
|
|
|
// as this initial width is sometimes strange depending on the language (wxGrid bug?)
|
2022-08-18 16:56:36 +00:00
|
|
|
int min_width = m_netclassGrid->GetVisibleWidth( i, true, true );
|
2020-07-08 18:29:16 +00:00
|
|
|
|
|
|
|
if( i == GRID_LINESTYLE )
|
|
|
|
min_best_width *= 1.5;
|
|
|
|
|
2019-02-18 09:09:22 +00:00
|
|
|
m_netclassGrid->SetColMinimalWidth( i, min_width );
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2019-02-18 09:09:22 +00:00
|
|
|
// We use a "best size" >= min_best_width
|
|
|
|
m_originalColWidths[ i ] = std::max( min_width, min_best_width );
|
2019-02-02 04:03:45 +00:00
|
|
|
m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
|
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2019-02-18 19:34:44 +00:00
|
|
|
// Be sure the column labels are readable
|
|
|
|
m_netclassGrid->EnsureColLabelsVisible();
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
// Membership combobox editors require a bit more room, so increase the row size of
|
|
|
|
// all our grids for consistency
|
2019-02-02 04:03:45 +00:00
|
|
|
m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->SetDefaultRowSize( m_assignmentGrid->GetDefaultRowSize() + 4 );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2018-08-25 14:29:00 +00:00
|
|
|
m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->PushEventHandler( new GRID_TRICKS( m_assignmentGrid ) );
|
2018-08-25 14:29:00 +00:00
|
|
|
|
2018-08-25 16:49:51 +00:00
|
|
|
m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2021-02-23 14:34:18 +00:00
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
|
|
|
m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_addButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_removeButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_addAssignmentButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_removeAssignmentButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
// wxFormBuilder doesn't include this event...
|
2020-11-24 16:03:48 +00:00
|
|
|
m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ),
|
2021-07-15 19:26:35 +00:00
|
|
|
nullptr, this );
|
2019-04-07 14:07:02 +00:00
|
|
|
|
2021-02-12 01:49:51 +00:00
|
|
|
// Handle tooltips for grid
|
|
|
|
m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
|
|
|
|
&PANEL_SETUP_NETCLASSES::OnNetclassGridMouseEvent,
|
|
|
|
this );
|
|
|
|
|
2021-12-22 21:43:41 +00:00
|
|
|
m_frame->Bind( UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
|
|
|
|
|
2019-08-20 11:35:24 +00:00
|
|
|
m_netclassGrid->EndBatch();
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->EndBatch();
|
2019-04-07 14:07:02 +00:00
|
|
|
Thaw();
|
2022-08-14 11:03:18 +00:00
|
|
|
|
|
|
|
m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES()
|
|
|
|
{
|
2021-02-23 14:34:18 +00:00
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
|
|
|
cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
delete [] m_originalColWidths;
|
|
|
|
|
2018-08-25 14:29:00 +00:00
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_netclassGrid->PopEventHandler( true );
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->PopEventHandler( true );
|
2018-08-25 14:29:00 +00:00
|
|
|
|
2020-11-24 16:03:48 +00:00
|
|
|
m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ),
|
2021-07-15 19:26:35 +00:00
|
|
|
nullptr, this );
|
2021-12-22 21:43:41 +00:00
|
|
|
|
|
|
|
m_frame->Unbind( UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
|
|
|
|
std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
|
2021-12-22 21:43:41 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings = tempNetSettings;
|
2021-12-22 21:43:41 +00:00
|
|
|
|
|
|
|
TransferDataFromWindow();
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings = saveNetSettings;
|
2021-12-22 21:43:41 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
EDA_UNITS units = m_frame->GetUserUnits();
|
|
|
|
int row = 0;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-06-13 20:26:06 +00:00
|
|
|
auto setCell =
|
2022-08-14 11:03:18 +00:00
|
|
|
[&]( int aRow, int aCol, int aValue )
|
2022-06-13 20:26:06 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netclassGrid->SetCellValue( aRow, aCol, StringFromValue( units, aValue, true ) );
|
2022-06-13 20:26:06 +00:00
|
|
|
};
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto netclassToGridRow =
|
|
|
|
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
|
|
|
|
{
|
|
|
|
m_netclassGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
|
2021-11-07 13:49:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_isEEschema )
|
|
|
|
{
|
|
|
|
setCell( aRow, GRID_WIREWIDTH - EESCHEMA_COL_OFFSET, nc->GetWireWidth() );
|
|
|
|
setCell( aRow, GRID_BUSWIDTH - EESCHEMA_COL_OFFSET, nc->GetBusWidth() );
|
2021-11-07 13:49:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
wxString colorAsString = nc->GetSchematicColor().ToWxString( wxC2S_CSS_SYNTAX );
|
|
|
|
m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET,
|
|
|
|
colorAsString );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( lineStyleIdx >= (int) g_lineStyleNames.size() )
|
|
|
|
lineStyleIdx = 0;
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netclassGrid->SetCellValue( aRow, GRID_LINESTYLE - EESCHEMA_COL_OFFSET,
|
|
|
|
g_lineStyleNames[ lineStyleIdx ] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setCell( aRow, GRID_CLEARANCE, nc->GetClearance() );
|
|
|
|
setCell( aRow, GRID_TRACKSIZE, nc->GetTrackWidth() );
|
|
|
|
setCell( aRow, GRID_VIASIZE, nc->GetViaDiameter() );
|
|
|
|
setCell( aRow, GRID_VIADRILL, nc->GetViaDrill() );
|
|
|
|
setCell( aRow, GRID_uVIASIZE, nc->GetuViaDiameter() );
|
|
|
|
setCell( aRow, GRID_uVIADRILL, nc->GetuViaDrill() );
|
|
|
|
setCell( aRow, GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() );
|
|
|
|
setCell( aRow, GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() );
|
|
|
|
}
|
|
|
|
};
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2021-08-10 11:59:53 +00:00
|
|
|
m_netclassGrid->ClearRows();
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
// enter the Default NETCLASS.
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netclassGrid->AppendRows( 1 );
|
|
|
|
netclassToGridRow( row++, m_netSettings->m_DefaultNetClass );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
// make the Default NETCLASS name read-only
|
|
|
|
wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
|
|
|
|
cellAttr->SetReadOnly();
|
|
|
|
cellAttr->DecRef();
|
|
|
|
|
|
|
|
// enter other netclasses
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netclassGrid->AppendRows( (int) m_netSettings->m_NetClasses.size() );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ name, netclass ] : m_netSettings->m_NetClasses )
|
|
|
|
netclassToGridRow( row++, netclass );
|
2020-07-03 22:30:23 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->ClearRows();
|
|
|
|
m_assignmentGrid->AppendRows( m_netSettings->m_NetClassPatternAssignments.size() );
|
|
|
|
row = 0;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( const auto& [ matcher, netclassName ] : m_netSettings->m_NetClassPatternAssignments )
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->SetCellValue( row, 0, matcher->GetPattern() );
|
|
|
|
m_assignmentGrid->SetCellValue( row, 1, netclassName );
|
|
|
|
row++;
|
2020-07-06 10:51:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
return true;
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
/*
|
|
|
|
* Populates drop-downs with the list of net classes
|
2018-04-28 15:22:25 +00:00
|
|
|
*/
|
|
|
|
void PANEL_SETUP_NETCLASSES::rebuildNetclassDropdowns()
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->CommitPendingChanges( true );
|
2018-12-24 01:53:48 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
wxArrayString netclassNames;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
|
|
|
|
{
|
|
|
|
wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
|
2020-07-18 09:58:10 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
if( !netclassName.IsEmpty() )
|
|
|
|
netclassNames.push_back( netclassName );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
2020-09-04 21:22:10 +00:00
|
|
|
attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->SetColAttr( 1, attr );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( !Validate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
EDA_UNITS units = m_frame->GetUserUnits();
|
|
|
|
int row = 0;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-06-13 20:26:06 +00:00
|
|
|
auto getCell =
|
2022-08-15 15:03:30 +00:00
|
|
|
[this, units]( int aRow, int aCol ) -> long long int
|
2022-06-13 20:26:06 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
return ValueFromString( units, m_netclassGrid->GetCellValue( aRow, aCol ) );
|
2022-06-13 20:26:06 +00:00
|
|
|
};
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto getCellStr =
|
2022-08-15 15:03:30 +00:00
|
|
|
[this]( int aRow, int aCol ) -> wxString
|
2022-08-14 11:03:18 +00:00
|
|
|
{
|
|
|
|
return m_netclassGrid->GetCellValue( aRow, aCol );
|
|
|
|
};
|
2020-07-08 18:29:16 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
auto gridRowToNetclass =
|
2022-08-15 15:03:30 +00:00
|
|
|
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
|
2022-08-14 11:03:18 +00:00
|
|
|
{
|
2022-08-15 15:03:30 +00:00
|
|
|
nc->SetName( m_netclassGrid->GetCellValue( aRow, GRID_NAME ) );
|
2021-11-07 13:49:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_isEEschema )
|
|
|
|
{
|
2022-08-15 15:03:30 +00:00
|
|
|
nc->SetWireWidth( getCell( aRow, GRID_WIREWIDTH - EESCHEMA_COL_OFFSET ) );
|
|
|
|
nc->SetBusWidth( getCell( aRow, GRID_BUSWIDTH - EESCHEMA_COL_OFFSET ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-15 15:03:30 +00:00
|
|
|
wxString color = getCellStr( aRow, GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET );
|
2022-08-14 11:03:18 +00:00
|
|
|
nc->SetSchematicColor( wxColour( color ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-15 15:03:30 +00:00
|
|
|
wxString lineStyle = getCellStr( aRow, GRID_LINESTYLE - EESCHEMA_COL_OFFSET );
|
2022-08-14 11:03:18 +00:00
|
|
|
nc->SetLineStyle( g_lineStyleNames.Index( lineStyle ) );
|
|
|
|
wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-15 15:03:30 +00:00
|
|
|
nc->SetClearance( getCell( aRow, GRID_CLEARANCE ) );
|
|
|
|
nc->SetTrackWidth( getCell( aRow, GRID_TRACKSIZE ) );
|
|
|
|
nc->SetViaDiameter( getCell( aRow, GRID_VIASIZE ) );
|
|
|
|
nc->SetViaDrill( getCell( aRow, GRID_VIADRILL ) );
|
|
|
|
nc->SetuViaDiameter( getCell( aRow, GRID_uVIASIZE ) );
|
|
|
|
nc->SetuViaDrill( getCell( aRow, GRID_uVIADRILL ) );
|
|
|
|
nc->SetDiffPairWidth( getCell( aRow, GRID_DIFF_PAIR_WIDTH ) );
|
|
|
|
nc->SetDiffPairGap( getCell( aRow, GRID_DIFF_PAIR_GAP ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
}
|
|
|
|
};
|
2018-07-17 06:52:33 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings->m_NetClasses.clear();
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
// Copy the default NetClass:
|
2022-08-14 11:03:18 +00:00
|
|
|
gridRowToNetclass( row++, m_netSettings->m_DefaultNetClass );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2020-07-08 18:29:16 +00:00
|
|
|
// Copy other NetClasses:
|
2022-08-14 11:03:18 +00:00
|
|
|
for( row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-06-13 20:26:06 +00:00
|
|
|
auto nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
|
2022-08-14 11:03:18 +00:00
|
|
|
gridRowToNetclass( row, nc );
|
|
|
|
m_netSettings->m_NetClasses[ nc->GetName() ] = nc;
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings->m_NetClassPatternAssignments.clear();
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
wxString pattern = m_assignmentGrid->GetCellValue( row, 0 );
|
|
|
|
wxString netclass = m_assignmentGrid->GetCellValue( row, 1 );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings->m_NetClassPatternAssignments.push_back(
|
|
|
|
{
|
|
|
|
std::make_unique<EDA_COMBINED_MATCHER>( pattern, CTX_NETCLASS ),
|
|
|
|
netclass
|
|
|
|
} );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
|
|
|
|
bool focusFirst )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString tmp = aName;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
tmp.Trim( true );
|
|
|
|
tmp.Trim( false );
|
|
|
|
|
|
|
|
if( tmp.IsEmpty() )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
|
|
|
wxString msg = _( "Netclass must have a name." );
|
2021-12-22 21:43:41 +00:00
|
|
|
m_parent->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
|
2018-04-28 15:22:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
|
|
|
|
{
|
2021-07-27 12:22:27 +00:00
|
|
|
if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
|
|
|
wxString msg = _( "Netclass name already in use." );
|
2021-12-22 21:43:41 +00:00
|
|
|
m_parent->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, GRID_NAME );
|
2018-04-28 15:22:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetCol() == GRID_NAME )
|
|
|
|
{
|
|
|
|
if( validateNetclassName( event.GetRow(), event.GetString() ) )
|
2020-06-01 19:35:43 +00:00
|
|
|
{
|
|
|
|
wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
|
|
|
|
wxString newName = event.GetString();
|
|
|
|
|
2020-07-18 09:58:10 +00:00
|
|
|
if( !oldName.IsEmpty() )
|
2020-06-01 19:35:43 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
|
2020-07-18 09:58:10 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_assignmentGrid->GetCellValue( row, 1 ) == oldName )
|
|
|
|
m_assignmentGrid->SetCellValue( row, 1, newName );
|
2020-07-18 09:58:10 +00:00
|
|
|
}
|
2020-06-01 19:35:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
m_netclassesDirty = true;
|
2020-06-01 19:35:43 +00:00
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
else
|
2020-07-18 09:58:10 +00:00
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
event.Veto();
|
2020-07-18 09:58:10 +00:00
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-12 01:49:51 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::OnNetclassGridMouseEvent( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
|
|
|
|
|
|
|
|
if( aEvent.Moving() || aEvent.Entering() )
|
|
|
|
{
|
|
|
|
aEvent.Skip();
|
|
|
|
|
|
|
|
if( col == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( col == m_hoveredCol )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_hoveredCol = col;
|
|
|
|
|
|
|
|
wxString tip;
|
|
|
|
|
2022-06-13 20:26:06 +00:00
|
|
|
if( m_isEEschema && col > GRID_NAME )
|
|
|
|
col += EESCHEMA_COL_OFFSET;
|
|
|
|
|
2021-02-12 01:49:51 +00:00
|
|
|
switch( col )
|
|
|
|
{
|
|
|
|
case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
|
|
|
|
case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
|
|
|
|
case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
|
|
|
|
case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
|
|
|
|
case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
|
|
|
|
case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
|
|
|
|
case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
|
|
|
|
case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
|
|
|
|
case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
|
|
|
|
m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
|
|
|
|
}
|
|
|
|
else if( aEvent.Leaving() )
|
|
|
|
{
|
|
|
|
m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::OnAddNetclassClick( wxCommandEvent& event )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_netclassGrid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
int row = m_netclassGrid->GetNumberRows();
|
|
|
|
m_netclassGrid->AppendRows();
|
|
|
|
|
|
|
|
// Copy values of the default class:
|
2022-06-13 20:26:06 +00:00
|
|
|
if( m_isEEschema )
|
|
|
|
{
|
|
|
|
for( int col = GRID_FIRST_EESCHEMA; col < GRID_END; col++ )
|
|
|
|
{
|
2022-08-14 22:05:30 +00:00
|
|
|
wxString defaultValue = m_netclassGrid->GetCellValue( 0, col - EESCHEMA_COL_OFFSET );
|
|
|
|
m_netclassGrid->SetCellValue( row, col - EESCHEMA_COL_OFFSET, defaultValue );
|
2022-06-13 20:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
for( int col = GRID_FIRST_PCBNEW; col < GRID_FIRST_EESCHEMA; col++ )
|
2022-08-14 22:05:30 +00:00
|
|
|
{
|
|
|
|
wxString defaultValue = m_netclassGrid->GetCellValue( 0, col );
|
|
|
|
m_netclassGrid->SetCellValue( row, col, defaultValue );
|
|
|
|
}
|
2022-06-13 20:26:06 +00:00
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
m_netclassGrid->MakeCellVisible( row, 0 );
|
|
|
|
m_netclassGrid->SetGridCursor( row, 0 );
|
|
|
|
|
|
|
|
m_netclassGrid->EnableCellEditControl( true );
|
|
|
|
m_netclassGrid->ShowCellEditControl();
|
|
|
|
|
|
|
|
m_netclassesDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_NETCLASSES::OnRemoveNetclassClick( wxCommandEvent& event )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_netclassGrid->CommitPendingChanges() )
|
|
|
|
return;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
int curRow = m_netclassGrid->GetGridCursorRow();
|
|
|
|
|
2018-08-25 14:29:00 +00:00
|
|
|
if( curRow < 0 )
|
2021-01-23 21:59:31 +00:00
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
return;
|
2021-01-23 21:59:31 +00:00
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
else if( curRow == 0 )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "The default net class is required." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset the net class to default for members of the removed class
|
|
|
|
wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( m_assignmentGrid->GetCellValue( row, 1 ) == classname )
|
|
|
|
m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_netclassGrid->DeleteRows( curRow, 1 );
|
|
|
|
|
2018-08-19 16:10:14 +00:00
|
|
|
m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
|
|
|
|
m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
m_netclassesDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_NETCLASSES::AdjustNetclassGridColumns( int aWidth )
|
|
|
|
{
|
2022-08-21 11:26:47 +00:00
|
|
|
if( aWidth != m_lastNetclassGridWidth )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-21 11:26:47 +00:00
|
|
|
m_lastNetclassGridWidth = aWidth;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-21 11:26:47 +00:00
|
|
|
// Account for scroll bars
|
|
|
|
aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
|
|
|
|
|
|
|
|
for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
|
|
|
|
{
|
|
|
|
m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
|
|
|
|
aWidth -= m_originalColWidths[ i ];
|
|
|
|
}
|
|
|
|
|
|
|
|
m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
|
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_NETCLASSES::OnSizeNetclassGrid( wxSizeEvent& event )
|
|
|
|
{
|
|
|
|
AdjustNetclassGridColumns( event.GetSize().GetX() );
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::OnAddAssignmentClick( wxCommandEvent& event )
|
2020-11-24 16:03:48 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( !m_assignmentGrid->CommitPendingChanges() )
|
|
|
|
return;
|
2020-11-24 16:03:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
int row = m_assignmentGrid->GetNumberRows();
|
|
|
|
m_assignmentGrid->AppendRows();
|
2020-11-24 16:03:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->SetCellValue( row, 1, m_netSettings->m_DefaultNetClass->GetName() );
|
2020-11-24 16:03:48 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->MakeCellVisible( row, 0 );
|
|
|
|
m_assignmentGrid->SetGridCursor( row, 0 );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->EnableCellEditControl( true );
|
|
|
|
m_assignmentGrid->ShowCellEditControl();
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::OnRemoveAssignmentClick( wxCommandEvent& event )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( !m_assignmentGrid->CommitPendingChanges() )
|
2018-08-19 16:10:14 +00:00
|
|
|
return;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
int curRow = m_assignmentGrid->GetGridCursorRow();
|
2018-07-17 06:52:33 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
if( curRow < 0 )
|
|
|
|
return;
|
2018-07-17 06:52:33 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->DeleteRows( curRow, 1 );
|
2018-07-17 06:52:33 +00:00
|
|
|
|
2022-08-21 11:26:47 +00:00
|
|
|
if( m_assignmentGrid->GetNumberRows() > 0 )
|
|
|
|
{
|
|
|
|
m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 );
|
|
|
|
m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 );
|
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::AdjustAssignmentGridColumns( int aWidth )
|
2018-07-17 06:52:33 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
// Account for scroll bars
|
|
|
|
aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x );
|
2018-07-17 06:52:33 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
// Set className column width to original className width from netclasses grid
|
|
|
|
int classNameWidth = m_originalColWidths[ 0 ];
|
|
|
|
m_assignmentGrid->SetColSize( 1, m_originalColWidths[ 0 ] );
|
|
|
|
m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
|
|
|
|
}
|
2018-07-17 06:52:33 +00:00
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::OnSizeAssignmentGrid( wxSizeEvent& event )
|
|
|
|
{
|
|
|
|
AdjustAssignmentGridColumns( event.GetSize().GetX());
|
2018-07-17 06:52:33 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
event.Skip();
|
2018-07-17 06:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
if( m_netclassesDirty )
|
|
|
|
{
|
|
|
|
rebuildNetclassDropdowns();
|
|
|
|
m_netclassesDirty = false;
|
|
|
|
}
|
2022-08-14 11:03:18 +00:00
|
|
|
|
2022-08-28 12:53:25 +00:00
|
|
|
if( m_assignmentGrid->GetNumberRows() == 0 )
|
2022-08-28 12:27:59 +00:00
|
|
|
return;
|
|
|
|
|
2022-08-26 15:41:05 +00:00
|
|
|
wxString pattern;
|
2022-08-14 11:03:18 +00:00
|
|
|
int row = m_assignmentGrid->GetGridCursorRow();
|
2022-08-26 15:41:05 +00:00
|
|
|
int col = m_assignmentGrid->GetGridCursorCol();
|
2022-08-14 11:03:18 +00:00
|
|
|
|
2022-08-28 12:27:59 +00:00
|
|
|
if( row >= 0 )
|
2022-08-26 15:41:05 +00:00
|
|
|
pattern = m_assignmentGrid->GetCellValue( row, 0 );
|
|
|
|
|
|
|
|
if( col == 0 && m_assignmentGrid->IsCellEditControlShown() )
|
2022-08-14 11:03:18 +00:00
|
|
|
{
|
|
|
|
wxGridCellEditor* cellEditor = m_assignmentGrid->GetCellEditor( row, 0 );
|
|
|
|
|
|
|
|
if( wxTextEntry* txt = dynamic_cast<wxTextEntry*>( cellEditor->GetControl() ) )
|
|
|
|
pattern = txt->GetValue();
|
|
|
|
|
|
|
|
cellEditor->DecRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pattern != m_lastPattern )
|
|
|
|
{
|
|
|
|
m_matchingNets->Clear();
|
|
|
|
|
|
|
|
if( !pattern.IsEmpty() )
|
|
|
|
{
|
|
|
|
EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
|
|
|
|
|
|
|
|
m_matchingNets->Report( wxString::Format( _( "<b>Nets matching '%s':</b>" ),
|
|
|
|
pattern ) );
|
|
|
|
|
|
|
|
for( const wxString& net : m_netNames )
|
|
|
|
{
|
|
|
|
int matches;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
if( matcher.Find( net, matches, offset ) && offset == 0 )
|
|
|
|
m_matchingNets->Report( net );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_matchingNets->Flush();
|
|
|
|
m_lastPattern = pattern;
|
|
|
|
}
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-12 03:19:46 +00:00
|
|
|
bool PANEL_SETUP_NETCLASSES::Validate()
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
if( !m_netclassGrid->CommitPendingChanges() || !m_assignmentGrid->CommitPendingChanges() )
|
2018-08-19 16:10:14 +00:00
|
|
|
return false;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
// Test net class parameters.
|
|
|
|
for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
|
|
|
|
{
|
|
|
|
wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
|
|
|
|
netclassName.Trim( true );
|
|
|
|
netclassName.Trim( false );
|
|
|
|
|
|
|
|
if( !validateNetclassName( row, netclassName, false ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptr<NET_SETTINGS>& aNetSettings )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00:00
|
|
|
std::shared_ptr<NET_SETTINGS> savedSettings = m_netSettings;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings = aNetSettings;
|
2018-04-28 15:22:25 +00:00
|
|
|
TransferDataToWindow();
|
|
|
|
|
2020-04-05 23:05:19 +00:00
|
|
|
rebuildNetclassDropdowns();
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
m_netclassGrid->ForceRefresh();
|
2022-08-14 11:03:18 +00:00
|
|
|
m_assignmentGrid->ForceRefresh();
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-08-14 11:03:18 +00:00
|
|
|
m_netSettings = savedSettings;
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|