2018-05-14 17:34:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-08-18 16:56:36 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-05-14 17:34:18 +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-08-29 23:33:08 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <footprint_editor_settings.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2023-11-15 10:55:40 +00:00
|
|
|
#include <template_fieldnames.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2019-03-04 11:02:12 +00:00
|
|
|
#include <grid_tricks.h>
|
2021-08-29 23:33:08 +00:00
|
|
|
#include <eda_base_frame.h>
|
2023-12-06 15:39:29 +00:00
|
|
|
#include <eda_text.h>
|
2020-11-16 00:45:43 +00:00
|
|
|
#include <panel_fp_editor_defaults.h>
|
2020-05-08 18:10:47 +00:00
|
|
|
#include <grid_layer_box_helpers.h>
|
2020-05-08 23:45:45 +00:00
|
|
|
#include <bitmaps.h>
|
2021-12-12 17:27:40 +00:00
|
|
|
#include <confirm.h>
|
2021-06-03 15:41:26 +00:00
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
class TEXT_ITEMS_GRID_TABLE : public wxGridTableBase
|
|
|
|
{
|
2023-11-15 10:55:40 +00:00
|
|
|
bool m_forFieldProps;
|
2020-05-08 18:10:47 +00:00
|
|
|
std::vector<TEXT_ITEM_INFO> m_items;
|
|
|
|
|
|
|
|
public:
|
2023-11-15 10:55:40 +00:00
|
|
|
TEXT_ITEMS_GRID_TABLE( bool aForFieldProps ) :
|
|
|
|
m_forFieldProps( aForFieldProps )
|
2020-05-08 18:10:47 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
int GetNumberRows() override { return m_items.size(); }
|
|
|
|
int GetNumberCols() override { return 3; }
|
|
|
|
|
|
|
|
wxString GetColLabelValue( int aCol ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
2023-11-15 10:55:40 +00:00
|
|
|
case 0: return m_forFieldProps ? _( "Value" ) : _( "Text Items" );
|
2020-05-08 18:10:47 +00:00
|
|
|
case 1: return _( "Show" );
|
|
|
|
case 2: return _( "Layer" );
|
|
|
|
default: return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:45:45 +00:00
|
|
|
wxString GetRowLabelValue( int aRow ) override
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
|
|
|
switch( aRow )
|
|
|
|
{
|
|
|
|
case 0: return _( "Reference designator" );
|
|
|
|
case 1: return _( "Value" );
|
|
|
|
default: return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:45:45 +00:00
|
|
|
bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case 0: return aTypeName == wxGRID_VALUE_STRING;
|
|
|
|
case 1: return aTypeName == wxGRID_VALUE_BOOL;
|
|
|
|
case 2: return aTypeName == wxGRID_VALUE_NUMBER;
|
|
|
|
default: wxFAIL; return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:45:45 +00:00
|
|
|
bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
|
|
|
return CanGetValueAs( aRow, aCol, aTypeName );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetValue( int row, int col ) override
|
|
|
|
{
|
|
|
|
return m_items[row].m_Text;
|
|
|
|
}
|
|
|
|
void SetValue( int row, int col, const wxString& value ) override
|
|
|
|
{
|
|
|
|
if( col == 0 )
|
|
|
|
m_items[row].m_Text = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetValueAsBool( int row, int col ) override
|
|
|
|
{
|
|
|
|
return m_items[row].m_Visible;
|
|
|
|
}
|
|
|
|
void SetValueAsBool( int row, int col, bool value ) override
|
|
|
|
{
|
|
|
|
if( col == 1 )
|
|
|
|
m_items[row].m_Visible = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
long GetValueAsLong( int row, int col ) override
|
|
|
|
{
|
|
|
|
return m_items[row].m_Layer;
|
|
|
|
}
|
|
|
|
void SetValueAsLong( int row, int col, long value ) override
|
|
|
|
{
|
|
|
|
if( col == 2 )
|
2020-05-08 23:45:45 +00:00
|
|
|
m_items[row].m_Layer = (int) value;
|
2020-05-08 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AppendRows( size_t aNumRows = 1 ) override
|
|
|
|
{
|
2020-05-09 06:59:00 +00:00
|
|
|
for( size_t i = 0; i < aNumRows; ++i )
|
2020-05-08 18:10:47 +00:00
|
|
|
m_items.emplace_back( wxT( "" ), true, F_SilkS );
|
|
|
|
|
|
|
|
if( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, aNumRows );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeleteRows( size_t aPos, size_t aNumRows ) override
|
|
|
|
{
|
|
|
|
// aPos may be a large positive, e.g. size_t(-1), and the sum of
|
|
|
|
// aPos+aNumRows may wrap here, so both ends of the range are tested.
|
|
|
|
if( aPos < m_items.size() && aPos + aNumRows <= m_items.size() )
|
|
|
|
{
|
|
|
|
m_items.erase( m_items.begin() + aPos, m_items.begin() + aPos + aNumRows );
|
|
|
|
|
|
|
|
if( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPos, aNumRows );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2021-04-10 00:20:31 +00:00
|
|
|
// Columns of graphics grid
|
2018-04-28 15:22:25 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
COL_LINE_THICKNESS = 0,
|
|
|
|
COL_TEXT_WIDTH,
|
|
|
|
COL_TEXT_HEIGHT,
|
|
|
|
COL_TEXT_THICKNESS,
|
|
|
|
COL_TEXT_ITALIC
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROW_SILK = 0,
|
|
|
|
ROW_COPPER,
|
|
|
|
ROW_EDGES,
|
2018-09-20 22:29:31 +00:00
|
|
|
ROW_COURTYARD,
|
2020-05-01 16:24:01 +00:00
|
|
|
ROW_FAB,
|
2018-04-28 15:22:25 +00:00
|
|
|
ROW_OTHERS,
|
|
|
|
|
|
|
|
ROW_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS( wxWindow* aParent,
|
2022-10-12 11:05:15 +00:00
|
|
|
UNITS_PROVIDER* aUnitsProvider ) :
|
2021-08-29 23:33:08 +00:00
|
|
|
PANEL_FP_EDITOR_DEFAULTS_BASE( aParent )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2023-12-06 15:39:29 +00:00
|
|
|
m_unitProvider = aUnitsProvider;
|
2023-11-15 10:55:40 +00:00
|
|
|
m_fieldPropsGrid->SetDefaultRowSize( m_fieldPropsGrid->GetDefaultRowSize() + 4 );
|
|
|
|
|
|
|
|
m_fieldPropsGrid->SetTable( new TEXT_ITEMS_GRID_TABLE( true ), true );
|
|
|
|
m_fieldPropsGrid->PushEventHandler( new GRID_TRICKS( m_fieldPropsGrid ) );
|
|
|
|
m_fieldPropsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_fieldPropsGrid->SetColAttr( 1, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, {} ) );
|
|
|
|
m_fieldPropsGrid->SetColAttr( 2, attr );
|
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 );
|
|
|
|
|
2023-11-15 10:55:40 +00:00
|
|
|
m_textItemsGrid->SetTable( new TEXT_ITEMS_GRID_TABLE( false ), true );
|
2021-09-29 17:43:56 +00:00
|
|
|
m_textItemsGrid->PushEventHandler( new GRID_TRICKS( m_textItemsGrid ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_textItemsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2023-11-15 10:55:40 +00:00
|
|
|
attr = new wxGridCellAttr;
|
2020-05-08 18:10:47 +00:00
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
2021-04-10 00:20:31 +00:00
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2020-05-08 18:10:47 +00:00
|
|
|
m_textItemsGrid->SetColAttr( 1, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
2021-08-29 23:33:08 +00:00
|
|
|
attr->SetRenderer( new GRID_CELL_LAYER_RENDERER( nullptr ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, {} ) );
|
2020-05-08 18:10:47 +00:00
|
|
|
m_textItemsGrid->SetColAttr( 2, attr );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
m_graphicsGrid->SetUnitsProvider( aUnitsProvider );
|
|
|
|
m_graphicsGrid->SetAutoEvalCols( { COL_LINE_THICKNESS,
|
|
|
|
COL_TEXT_WIDTH,
|
|
|
|
COL_TEXT_HEIGHT,
|
|
|
|
COL_TEXT_THICKNESS } );
|
|
|
|
|
|
|
|
m_graphicsGrid->SetDefaultRowSize( m_graphicsGrid->GetDefaultRowSize() + 4 );
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
// Work around a bug in wxWidgets where it fails to recalculate the grid height
|
|
|
|
// after changing the default row size
|
2021-04-09 23:25:05 +00:00
|
|
|
m_graphicsGrid->AppendRows( 1 );
|
|
|
|
m_graphicsGrid->DeleteRows( m_graphicsGrid->GetNumberRows() - 1, 1 );
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2021-04-09 23:25:05 +00:00
|
|
|
m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-16 00:45:43 +00:00
|
|
|
PANEL_FP_EDITOR_DEFAULTS::~PANEL_FP_EDITOR_DEFAULTS()
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2021-09-29 17:43:56 +00:00
|
|
|
// destroy GRID_TRICKS before grids.
|
2023-11-15 10:55:40 +00:00
|
|
|
m_fieldPropsGrid->PopEventHandler( true );
|
2021-09-29 17:43:56 +00:00
|
|
|
m_textItemsGrid->PopEventHandler( true );
|
2021-04-09 23:25:05 +00:00
|
|
|
m_graphicsGrid->PopEventHandler( true );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
2018-05-14 17:34:18 +00:00
|
|
|
|
|
|
|
|
2021-11-01 11:20:13 +00:00
|
|
|
void PANEL_FP_EDITOR_DEFAULTS::loadFPSettings( FOOTPRINT_EDITOR_SETTINGS* aCfg )
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
|
|
|
|
|
2022-10-12 11:05:15 +00:00
|
|
|
auto disableCell =
|
|
|
|
[&]( int row, int col )
|
|
|
|
{
|
|
|
|
m_graphicsGrid->SetReadOnly( row, col );
|
|
|
|
m_graphicsGrid->SetCellBackgroundColour( row, col, disabledColour );
|
|
|
|
};
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < ROW_COUNT; ++i )
|
|
|
|
{
|
2022-10-12 11:05:15 +00:00
|
|
|
m_graphicsGrid->SetUnitValue( i, COL_LINE_THICKNESS, aCfg->m_DesignSettings.m_LineThickness[ i ] );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2018-09-20 22:29:31 +00:00
|
|
|
if( i == ROW_EDGES || i == ROW_COURTYARD )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2022-10-12 11:05:15 +00:00
|
|
|
disableCell( i, COL_TEXT_WIDTH );
|
|
|
|
disableCell( i, COL_TEXT_HEIGHT );
|
|
|
|
disableCell( i, COL_TEXT_THICKNESS );
|
|
|
|
disableCell( i, COL_TEXT_ITALIC );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-12 11:05:15 +00:00
|
|
|
m_graphicsGrid->SetUnitValue( i, COL_TEXT_WIDTH, aCfg->m_DesignSettings.m_TextSize[ i ].x );
|
|
|
|
m_graphicsGrid->SetUnitValue( i, COL_TEXT_HEIGHT, aCfg->m_DesignSettings.m_TextSize[ i ].y );
|
|
|
|
m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS, aCfg->m_DesignSettings.m_TextThickness[ i ] );
|
2022-02-04 22:44:59 +00:00
|
|
|
m_graphicsGrid->SetCellValue( i, COL_TEXT_ITALIC, aCfg->m_DesignSettings.m_TextItalic[ i ] ? wxT( "1" ) : wxT( "" ) );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
auto attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
2020-10-04 08:34:31 +00:00
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2021-04-09 23:25:05 +00:00
|
|
|
m_graphicsGrid->SetAttr( i, COL_TEXT_ITALIC, attr );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Footprint defaults
|
2023-11-15 10:55:40 +00:00
|
|
|
m_fieldPropsGrid->GetTable()->DeleteRows( 0, m_textItemsGrid->GetNumberRows() );
|
|
|
|
m_fieldPropsGrid->GetTable()->AppendRows( 2 );
|
|
|
|
|
|
|
|
for( int i : { REFERENCE_FIELD, VALUE_FIELD } )
|
|
|
|
{
|
|
|
|
TEXT_ITEM_INFO item = aCfg->m_DesignSettings.m_DefaultFPTextItems[i];
|
|
|
|
|
|
|
|
m_fieldPropsGrid->GetTable()->SetValue( i, 0, item.m_Text );
|
|
|
|
m_fieldPropsGrid->GetTable()->SetValueAsBool( i, 1, item.m_Visible );
|
|
|
|
m_fieldPropsGrid->GetTable()->SetValueAsLong( i, 2, item.m_Layer );
|
|
|
|
}
|
|
|
|
|
2021-11-01 11:20:13 +00:00
|
|
|
m_textItemsGrid->GetTable()->DeleteRows( 0, m_textItemsGrid->GetNumberRows() );
|
2023-11-15 10:55:40 +00:00
|
|
|
m_textItemsGrid->GetTable()->AppendRows( aCfg->m_DesignSettings.m_DefaultFPTextItems.size() - 2 );
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2023-11-15 10:55:40 +00:00
|
|
|
for( int i = 2; i < (int) aCfg->m_DesignSettings.m_DefaultFPTextItems.size(); ++i )
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
2021-11-01 11:20:13 +00:00
|
|
|
TEXT_ITEM_INFO item = aCfg->m_DesignSettings.m_DefaultFPTextItems[i];
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2023-11-15 10:55:40 +00:00
|
|
|
m_textItemsGrid->GetTable()->SetValue( i - 2, 0, item.m_Text );
|
|
|
|
m_textItemsGrid->GetTable()->SetValueAsBool( i - 2, 1, item.m_Visible );
|
|
|
|
m_textItemsGrid->GetTable()->SetValueAsLong( i - 2, 2, item.m_Layer );
|
2020-05-08 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 23:25:05 +00:00
|
|
|
for( int col = 0; col < m_graphicsGrid->GetNumberCols(); col++ )
|
2019-02-10 08:49:42 +00:00
|
|
|
{
|
|
|
|
// Set the minimal width to the column label size.
|
2022-08-18 16:56:36 +00:00
|
|
|
m_graphicsGrid->SetColMinimalWidth( col, m_graphicsGrid->GetVisibleWidth( col, true, false ) );
|
2019-02-17 14:09:35 +00:00
|
|
|
|
2019-02-10 08:49:42 +00:00
|
|
|
// Set the width to see the full contents
|
2021-04-09 23:25:05 +00:00
|
|
|
if( m_graphicsGrid->IsColShown( col ) )
|
|
|
|
m_graphicsGrid->SetColSize( col, m_graphicsGrid->GetVisibleWidth( col, true, true, true ) );
|
2019-02-10 08:49:42 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 23:25:05 +00:00
|
|
|
m_graphicsGrid->SetRowLabelSize( m_graphicsGrid->GetVisibleWidth( -1, true, true, true ) );
|
2019-02-09 23:31:31 +00:00
|
|
|
|
2019-02-10 08:49:42 +00:00
|
|
|
Layout();
|
2021-11-01 11:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_FP_EDITOR_DEFAULTS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
FOOTPRINT_EDITOR_SETTINGS* cfg = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
|
|
|
|
|
|
|
|
loadFPSettings( cfg );
|
2019-02-09 23:31:31 +00:00
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-16 00:45:43 +00:00
|
|
|
bool PANEL_FP_EDITOR_DEFAULTS::Show( bool aShow )
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
|
|
|
bool retVal = wxPanel::Show( aShow );
|
|
|
|
|
|
|
|
if( aShow )
|
|
|
|
{
|
|
|
|
// These *should* work in the constructor, and indeed they do if this panel is the
|
|
|
|
// first displayed. However, on OSX 3.0.5 (at least), if another panel is displayed
|
|
|
|
// first then the icons will be blank unless they're set here.
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
2020-05-08 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aShow && m_firstShow )
|
|
|
|
{
|
2021-04-09 23:25:05 +00:00
|
|
|
m_graphicsGrid->SetColSize( 0, m_graphicsGrid->GetColSize( 0 ) + 1 );
|
2020-05-08 18:10:47 +00:00
|
|
|
m_firstShow = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-16 00:45:43 +00:00
|
|
|
bool PANEL_FP_EDITOR_DEFAULTS::TransferDataFromWindow()
|
2018-05-14 17:34:18 +00:00
|
|
|
{
|
2023-05-09 10:10:09 +00:00
|
|
|
if( !m_textItemsGrid->CommitPendingChanges() || !m_graphicsGrid->CommitPendingChanges() )
|
2018-04-28 15:22:25 +00:00
|
|
|
return false;
|
|
|
|
|
2022-10-12 11:05:15 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
BOARD_DESIGN_SETTINGS& cfg = mgr.GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>()->m_DesignSettings;
|
2021-08-29 23:33:08 +00:00
|
|
|
|
2023-12-06 15:39:29 +00:00
|
|
|
// A minimal value for sizes and thickness:
|
|
|
|
const int minWidth = pcbIUScale.mmToIU( MINIMUM_LINE_WIDTH_MM );
|
|
|
|
const int maxWidth = pcbIUScale.mmToIU( MAXIMUM_LINE_WIDTH_MM );
|
|
|
|
const int minSize = pcbIUScale.MilsToIU( TEXT_MIN_SIZE_MILS );
|
|
|
|
const int maxSize = pcbIUScale.MilsToIU( TEXT_MAX_SIZE_MILS );
|
|
|
|
wxString errorsMsg;
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
for( int i = 0; i < ROW_COUNT; ++i )
|
|
|
|
{
|
2023-12-06 15:39:29 +00:00
|
|
|
bool badParam = false;
|
|
|
|
|
|
|
|
int lineWidth = m_graphicsGrid->GetUnitValue( i, COL_LINE_THICKNESS );
|
|
|
|
|
|
|
|
if( lineWidth < minWidth || lineWidth > maxWidth )
|
|
|
|
{
|
|
|
|
if( !errorsMsg.IsEmpty() )
|
|
|
|
errorsMsg += wxT( "\n\n" );
|
|
|
|
|
|
|
|
errorsMsg += wxString::Format( _( "%s: Incorrect line width.\n"
|
|
|
|
"It must be between %s and %s" ),
|
|
|
|
m_graphicsGrid->GetRowLabelValue( i ),
|
|
|
|
m_unitProvider->StringFromValue( minWidth , true),
|
|
|
|
m_unitProvider->StringFromValue( maxWidth , true) );
|
|
|
|
badParam = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !badParam )
|
|
|
|
cfg.m_LineThickness[ i ] = lineWidth;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
2018-09-20 22:29:31 +00:00
|
|
|
if( i == ROW_EDGES || i == ROW_COURTYARD )
|
2018-04-28 15:22:25 +00:00
|
|
|
continue;
|
|
|
|
|
2023-12-06 15:39:29 +00:00
|
|
|
badParam = false;
|
|
|
|
int textWidth = m_graphicsGrid->GetUnitValue( i, COL_TEXT_WIDTH );
|
|
|
|
int textHeight = m_graphicsGrid->GetUnitValue( i, COL_TEXT_HEIGHT );
|
|
|
|
int textThickness = m_graphicsGrid->GetUnitValue( i, COL_TEXT_THICKNESS );
|
|
|
|
|
|
|
|
if( textWidth < minSize || textHeight < minSize
|
|
|
|
|| textWidth > maxSize || textHeight > maxSize )
|
|
|
|
{
|
|
|
|
if( !errorsMsg.IsEmpty() )
|
|
|
|
errorsMsg += wxT( "\n\n" );
|
|
|
|
|
|
|
|
errorsMsg += wxString::Format( _( "%s: Text size is incorrect.\n"
|
|
|
|
"Size must be between %s and %s" ),
|
|
|
|
m_graphicsGrid->GetRowLabelValue( i ),
|
|
|
|
m_unitProvider->StringFromValue( minSize , true),
|
|
|
|
m_unitProvider->StringFromValue( maxSize , true) );
|
|
|
|
badParam = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Text thickness cannot be > text size /4 to be readable
|
|
|
|
int textMinDim = std::min( textWidth, textHeight );
|
|
|
|
int textMaxThickness = std::min( maxWidth, textMinDim /4);
|
|
|
|
|
|
|
|
if( !badParam && ( textThickness < minWidth || textThickness > textMaxThickness ) )
|
|
|
|
{
|
|
|
|
if( !errorsMsg.IsEmpty() )
|
|
|
|
errorsMsg += wxT( "\n\n" );
|
|
|
|
|
|
|
|
if( textThickness > textMaxThickness )
|
|
|
|
errorsMsg += wxString::Format( _( "%s: Text thickness is too large.\n"
|
|
|
|
"It will be truncated to %s" ),
|
|
|
|
m_graphicsGrid->GetRowLabelValue( i ),
|
|
|
|
m_unitProvider->StringFromValue( textMaxThickness , true) );
|
|
|
|
|
|
|
|
else if( textThickness < minWidth )
|
|
|
|
errorsMsg += wxString::Format( _( "%s: Text thickness is too small.\n"
|
|
|
|
"It will be truncated to %s" ),
|
|
|
|
m_graphicsGrid->GetRowLabelValue( i ),
|
|
|
|
m_unitProvider->StringFromValue( minWidth , true ) );
|
|
|
|
|
|
|
|
textThickness = std::min( textThickness, textMaxThickness );
|
|
|
|
textThickness = std::max( textThickness, minWidth );
|
|
|
|
m_graphicsGrid->SetUnitValue( i, COL_TEXT_THICKNESS, textThickness );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !badParam )
|
|
|
|
{
|
|
|
|
cfg.m_TextSize[i] = VECTOR2I( textWidth, textHeight );
|
|
|
|
cfg.m_TextThickness[ i ] = textThickness;
|
|
|
|
}
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2021-04-09 23:25:05 +00:00
|
|
|
wxString msg = m_graphicsGrid->GetCellValue( i, COL_TEXT_ITALIC );
|
2022-10-12 11:05:15 +00:00
|
|
|
cfg.m_TextItalic[ i ] = wxGridCellBoolEditor::IsTrueValue( msg );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2020-02-11 14:47:04 +00:00
|
|
|
// Footprint defaults
|
2022-10-12 11:05:15 +00:00
|
|
|
cfg.m_DefaultFPTextItems.clear();
|
2020-02-11 14:47:04 +00:00
|
|
|
|
2023-11-15 10:55:40 +00:00
|
|
|
wxGridTableBase* table = m_fieldPropsGrid->GetTable();
|
|
|
|
|
|
|
|
for( int i : { REFERENCE_FIELD, VALUE_FIELD } )
|
|
|
|
{
|
|
|
|
wxString text = table->GetValue( i, 0 );
|
|
|
|
bool visible = table->GetValueAsBool( i, 1 );
|
|
|
|
int layer = (int) table->GetValueAsLong( i, 2 );
|
|
|
|
|
|
|
|
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
table = m_textItemsGrid->GetTable();
|
|
|
|
|
2020-05-08 18:10:47 +00:00
|
|
|
for( int i = 0; i < m_textItemsGrid->GetNumberRows(); ++i )
|
|
|
|
{
|
|
|
|
wxString text = table->GetValue( i, 0 );
|
|
|
|
bool visible = table->GetValueAsBool( i, 1 );
|
|
|
|
int layer = (int) table->GetValueAsLong( i, 2 );
|
2020-02-11 14:47:04 +00:00
|
|
|
|
2022-10-12 11:05:15 +00:00
|
|
|
cfg.m_DefaultFPTextItems.emplace_back( text, visible, layer );
|
2020-05-08 18:10:47 +00:00
|
|
|
}
|
2020-02-11 14:47:04 +00:00
|
|
|
|
2023-12-06 15:39:29 +00:00
|
|
|
if( errorsMsg.IsEmpty() )
|
|
|
|
return true;
|
|
|
|
|
2023-12-07 13:41:43 +00:00
|
|
|
KIDIALOG dlg( this, errorsMsg, KIDIALOG::KD_ERROR, _( "Parameter error" ) );
|
|
|
|
dlg.ShowModal();
|
2023-12-06 15:39:29 +00:00
|
|
|
|
|
|
|
return false;
|
2018-05-14 17:34:18 +00:00
|
|
|
}
|
2020-05-08 18:10:47 +00:00
|
|
|
|
|
|
|
|
2020-11-16 00:45:43 +00:00
|
|
|
void PANEL_FP_EDITOR_DEFAULTS::OnAddTextItem( wxCommandEvent& event )
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
2021-04-09 23:25:05 +00:00
|
|
|
if( !m_textItemsGrid->CommitPendingChanges() || !m_graphicsGrid->CommitPendingChanges() )
|
2020-05-08 18:10:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
wxGridTableBase* table = m_textItemsGrid->GetTable();
|
|
|
|
|
|
|
|
int newRow = m_textItemsGrid->GetNumberRows();
|
|
|
|
table->AppendRows( 1 );
|
|
|
|
table->SetValueAsBool( newRow, 1, table->GetValueAsBool( newRow - 1, 1 ) );
|
|
|
|
table->SetValueAsLong( newRow, 2, table->GetValueAsLong( newRow - 1, 2 ) );
|
|
|
|
|
|
|
|
m_textItemsGrid->MakeCellVisible( newRow, 0 );
|
|
|
|
m_textItemsGrid->SetGridCursor( newRow, 0 );
|
|
|
|
|
|
|
|
m_textItemsGrid->EnableCellEditControl( true );
|
|
|
|
m_textItemsGrid->ShowCellEditControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-16 00:45:43 +00:00
|
|
|
void PANEL_FP_EDITOR_DEFAULTS::OnDeleteTextItem( wxCommandEvent& event )
|
2020-05-08 18:10:47 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
wxArrayInt selectedRows = m_textItemsGrid->GetSelectedRows();
|
|
|
|
|
|
|
|
if( selectedRows.empty() && m_textItemsGrid->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.push_back( m_textItemsGrid->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selectedRows.empty() )
|
2020-05-08 18:10:47 +00:00
|
|
|
return;
|
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
for( int row : selectedRows )
|
|
|
|
{
|
|
|
|
if( row < 2 )
|
|
|
|
{
|
|
|
|
DisplayError( nullptr, _( "Reference and value are mandatory." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( !m_textItemsGrid->CommitPendingChanges() || !m_graphicsGrid->CommitPendingChanges() )
|
2020-05-08 18:10:47 +00:00
|
|
|
return;
|
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
|
|
|
|
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
|
|
|
|
|
|
|
|
for( int row : selectedRows )
|
|
|
|
{
|
|
|
|
m_textItemsGrid->GetTable()->DeleteRows( row, 1 );
|
2020-05-08 18:10:47 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( m_textItemsGrid->GetNumberRows() > 0 )
|
|
|
|
{
|
|
|
|
m_textItemsGrid->MakeCellVisible( std::max( 0, row-1 ),
|
|
|
|
m_textItemsGrid->GetGridCursorCol() );
|
|
|
|
m_textItemsGrid->SetGridCursor( std::max( 0, row-1 ),
|
|
|
|
m_textItemsGrid->GetGridCursorCol() );
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-01 11:20:13 +00:00
|
|
|
void PANEL_FP_EDITOR_DEFAULTS::ResetPanel()
|
|
|
|
{
|
|
|
|
FOOTPRINT_EDITOR_SETTINGS cfg;
|
|
|
|
cfg.Load(); // Loading without a file will init to defaults
|
|
|
|
|
|
|
|
loadFPSettings( &cfg );
|
|
|
|
}
|
|
|
|
|
|
|
|
|