2018-05-14 17:34:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-02-10 08:49:42 +00:00
|
|
|
* Copyright (C) 1992-2019 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <widgets/paged_dialog.h>
|
|
|
|
#include <footprint_edit_frame.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2019-03-04 11:02:12 +00:00
|
|
|
#include <grid_tricks.h>
|
2018-05-14 17:34:18 +00:00
|
|
|
|
|
|
|
#include <panel_modedit_defaults.h>
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
// Columns of layer classes grid
|
|
|
|
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,
|
2018-04-28 15:22:25 +00:00
|
|
|
ROW_OTHERS,
|
|
|
|
|
|
|
|
ROW_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
PANEL_MODEDIT_DEFAULTS::PANEL_MODEDIT_DEFAULTS( FOOTPRINT_EDIT_FRAME* aFrame, PAGED_DIALOG* aParent) :
|
2018-07-15 23:15:48 +00:00
|
|
|
PANEL_MODEDIT_DEFAULTS_BASE( aParent->GetTreebook() ),
|
2018-05-14 17:34:18 +00:00
|
|
|
m_brdSettings( aFrame->GetDesignSettings() ),
|
|
|
|
m_frame( aFrame ),
|
2018-04-28 15:22:25 +00:00
|
|
|
m_Parent( aParent )
|
|
|
|
{
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
|
|
|
|
|
|
|
// Work around a bug in wxWidgets where it fails to recalculate the grid height
|
|
|
|
// after changing the default row size
|
|
|
|
m_grid->AppendRows( 1 );
|
|
|
|
m_grid->DeleteRows( m_grid->GetNumberRows() - 1, 1 );
|
|
|
|
|
|
|
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
|
|
|
|
2018-07-19 12:07:50 +00:00
|
|
|
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
|
|
|
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
|
|
|
|
m_staticTextInfo->SetFont( infoFont );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_MODEDIT_DEFAULTS::~PANEL_MODEDIT_DEFAULTS()
|
|
|
|
{
|
|
|
|
// destroy GRID_TRICKS before m_grid.
|
|
|
|
m_grid->PopEventHandler( true );
|
|
|
|
}
|
2018-05-14 17:34:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_MODEDIT_DEFAULTS::TransferDataToWindow()
|
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
|
|
|
|
|
|
|
|
#define SET_MILS_CELL( row, col, val ) \
|
|
|
|
m_grid->SetCellValue( row, col, StringFromValue( m_frame->GetUserUnits(), val, true, true ) )
|
|
|
|
|
|
|
|
#define DISABLE_CELL( row, col ) \
|
|
|
|
m_grid->SetReadOnly( row, col ); m_grid->SetCellBackgroundColour( row, col, disabledColour );
|
|
|
|
|
|
|
|
for( int i = 0; i < ROW_COUNT; ++i )
|
|
|
|
{
|
|
|
|
SET_MILS_CELL( i, COL_LINE_THICKNESS, m_brdSettings.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
|
|
|
{
|
|
|
|
DISABLE_CELL( i, COL_TEXT_WIDTH );
|
|
|
|
DISABLE_CELL( i, COL_TEXT_HEIGHT );
|
|
|
|
DISABLE_CELL( i, COL_TEXT_THICKNESS );
|
|
|
|
DISABLE_CELL( i, COL_TEXT_ITALIC );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SET_MILS_CELL( i, COL_TEXT_WIDTH, m_brdSettings.m_TextSize[ i ].x );
|
|
|
|
SET_MILS_CELL( i, COL_TEXT_HEIGHT, m_brdSettings.m_TextSize[ i ].y );
|
|
|
|
SET_MILS_CELL( i, COL_TEXT_THICKNESS, m_brdSettings.m_TextThickness[ i ] );
|
|
|
|
m_grid->SetCellValue( i, COL_TEXT_ITALIC, m_brdSettings.m_TextItalic[ i ] ? "1" : "" );
|
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 07:42:18 +00:00
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
2018-04-28 15:22:25 +00:00
|
|
|
m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Footprint defaults
|
2018-05-14 17:34:18 +00:00
|
|
|
m_textCtrlRefText->SetValue( m_brdSettings.m_RefDefaultText );
|
|
|
|
m_choiceLayerReference->SetSelection( m_brdSettings.m_RefDefaultlayer == F_SilkS ? 0 : 1 );
|
|
|
|
m_choiceVisibleReference->SetSelection( m_brdSettings.m_RefDefaultVisibility ? 0 : 1 );
|
|
|
|
|
|
|
|
m_textCtrlValueText->SetValue( m_brdSettings.m_ValueDefaultText );
|
|
|
|
m_choiceLayerValue->SetSelection( m_brdSettings.m_ValueDefaultlayer == F_SilkS ? 0 : 1 );
|
|
|
|
m_choiceVisibleValue->SetSelection( m_brdSettings.m_ValueDefaultVisibility ? 0 : 1 );
|
|
|
|
|
2019-02-10 06:59:27 +00:00
|
|
|
for( int col = 0; col < m_grid->GetNumberCols(); col++ )
|
2019-02-10 08:49:42 +00:00
|
|
|
{
|
|
|
|
// Set the minimal width to the column label size.
|
|
|
|
m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, false, 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
|
2019-02-17 14:09:35 +00:00
|
|
|
if( m_grid->IsColShown( col ) )
|
|
|
|
m_grid->SetColSize( col, m_grid->GetVisibleWidth( col, true, true, true ) );
|
2019-02-10 08:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
|
2019-02-09 23:31:31 +00:00
|
|
|
|
2019-02-10 08:49:42 +00:00
|
|
|
Layout();
|
2019-02-09 23:31:31 +00:00
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
int PANEL_MODEDIT_DEFAULTS::getGridValue( int aRow, int aCol )
|
|
|
|
{
|
|
|
|
return ValueFromString( m_frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_MODEDIT_DEFAULTS::validateData()
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
// Test text parameters.
|
|
|
|
for( int row : { ROW_SILK, ROW_COPPER, ROW_OTHERS } )
|
|
|
|
{
|
|
|
|
int textSize = std::min( getGridValue( row, COL_TEXT_WIDTH ),
|
|
|
|
getGridValue( row, COL_TEXT_HEIGHT ) );
|
|
|
|
|
|
|
|
if( getGridValue( row, COL_TEXT_THICKNESS ) > textSize / 4 )
|
|
|
|
{
|
|
|
|
wxString msg = _( "Text will not be readable with a thickness greater than\n"
|
|
|
|
"1/4 its width or height." );
|
|
|
|
m_Parent->SetError( msg, this, m_grid, row, COL_TEXT_THICKNESS );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
bool PANEL_MODEDIT_DEFAULTS::TransferDataFromWindow()
|
|
|
|
{
|
2018-04-28 15:22:25 +00:00
|
|
|
if( !validateData() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( int i = 0; i < ROW_COUNT; ++i )
|
|
|
|
{
|
|
|
|
m_brdSettings.m_LineThickness[ i ] = getGridValue( i, COL_LINE_THICKNESS );
|
|
|
|
|
2018-09-20 22:29:31 +00:00
|
|
|
if( i == ROW_EDGES || i == ROW_COURTYARD )
|
2018-04-28 15:22:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
m_brdSettings.m_TextSize[ i ] =
|
|
|
|
wxSize( getGridValue( i, COL_TEXT_WIDTH ), getGridValue( i, COL_TEXT_HEIGHT ) );
|
|
|
|
m_brdSettings.m_TextThickness[ i ] = getGridValue( i, COL_TEXT_THICKNESS );
|
|
|
|
m_brdSettings.m_TextItalic[ i ] =
|
|
|
|
wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
|
|
|
|
}
|
2018-05-14 17:34:18 +00:00
|
|
|
|
2020-02-11 14:47:04 +00:00
|
|
|
// Footprint defaults
|
|
|
|
m_brdSettings.m_RefDefaultText = m_textCtrlRefText->GetValue();
|
|
|
|
m_brdSettings.m_RefDefaultlayer = (m_choiceLayerReference->GetSelection() == 0) ? F_SilkS : F_Fab;
|
|
|
|
m_brdSettings.m_RefDefaultVisibility = m_choiceVisibleReference->GetSelection() == 0;
|
|
|
|
|
|
|
|
|
|
|
|
m_brdSettings.m_ValueDefaultText = m_textCtrlValueText->GetValue();
|
|
|
|
m_brdSettings.m_ValueDefaultlayer = (m_choiceLayerValue->GetSelection() == 0) ? F_SilkS : F_Fab;
|
|
|
|
m_brdSettings.m_ValueDefaultVisibility = m_choiceVisibleValue->GetSelection() == 0;
|
|
|
|
|
2018-05-14 17:34:18 +00:00
|
|
|
m_frame->SetDesignSettings( m_brdSettings );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|