2018-04-28 15:22:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-03-16 14:28:01 +00:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <base_units.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
2019-03-04 11:02:12 +00:00
|
|
|
#include <grid_tricks.h>
|
2018-04-28 15:22:25 +00:00
|
|
|
#include <panel_setup_text_and_graphics.h>
|
|
|
|
|
2021-06-03 15:41:26 +00:00
|
|
|
#include <wx/treebook.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,
|
|
|
|
COL_TEXT_UPRIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ROW_SILK = 0,
|
|
|
|
ROW_COPPER,
|
|
|
|
ROW_EDGES,
|
2018-08-24 20:08:30 +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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS( PAGED_DIALOG* aParent,
|
|
|
|
PCB_EDIT_FRAME* aFrame ) :
|
2020-09-12 00:36:43 +00:00
|
|
|
PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParent->GetTreebook() ),
|
2020-09-12 15:46:33 +00:00
|
|
|
m_arrowLength( aFrame, m_lblArrowLength, m_dimensionArrowLength, m_arrowLengthUnits ),
|
|
|
|
m_extensionOffset( aFrame, m_lblExtensionOffset, m_dimensionExtensionOffset,
|
|
|
|
m_dimensionExtensionOffsetUnits )
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
|
|
|
m_Parent = aParent;
|
|
|
|
m_Frame = aFrame;
|
|
|
|
m_BrdSettings = &m_Frame->GetBoard()->GetDesignSettings();
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2021-05-16 07:11:13 +00:00
|
|
|
// Gives a suitable size to m_grid columns
|
|
|
|
// The default wxWidget col size is not very good
|
|
|
|
// Calculate a min best size to handle longest usual numeric values:
|
|
|
|
int min_best_width = m_grid->GetTextExtent( "555,555555 mils" ).x;
|
|
|
|
|
|
|
|
for( int i = 0; i < m_grid->GetNumberCols(); ++i )
|
|
|
|
{
|
|
|
|
// 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?)
|
|
|
|
int min_width = m_grid->GetVisibleWidth( i, true, true, false );
|
|
|
|
|
|
|
|
m_grid->SetColMinimalWidth( i, min_width );
|
|
|
|
|
|
|
|
// We use a "best size" >= min_best_width
|
|
|
|
m_grid->SetColSize( i, std::max( min_width, min_best_width ) );
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_SETUP_TEXT_AND_GRAPHICS::~PANEL_SETUP_TEXT_AND_GRAPHICS()
|
|
|
|
{
|
|
|
|
// destroy GRID_TRICKS before m_grid.
|
|
|
|
m_grid->PopEventHandler( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
wxColour disabledColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
|
|
|
|
|
|
|
|
#define SET_MILS_CELL( row, col, val ) \
|
2020-10-02 20:51:24 +00:00
|
|
|
m_grid->SetCellValue( row, col, StringFromValue( m_Frame->GetUserUnits(), val, true ) )
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
#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-08-24 20:08:30 +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 );
|
|
|
|
DISABLE_CELL( i, COL_TEXT_UPRIGHT );
|
|
|
|
}
|
|
|
|
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" : "" );
|
|
|
|
m_grid->SetCellValue( i, COL_TEXT_UPRIGHT, m_BrdSettings->m_TextUpright[ i ] ? "1" : "" );
|
|
|
|
|
|
|
|
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 );
|
2018-04-28 15:22:25 +00:00
|
|
|
m_grid->SetAttr( i, COL_TEXT_ITALIC, attr );
|
|
|
|
|
|
|
|
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 );
|
2018-04-28 15:22:25 +00:00
|
|
|
m_grid->SetAttr( i, COL_TEXT_UPRIGHT, attr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 23:31:31 +00:00
|
|
|
// Work around an issue where wxWidgets doesn't calculate the row width on its own
|
|
|
|
for( int col = 0; col < m_grid->GetNumberCols(); col++ )
|
|
|
|
m_grid->SetColMinimalWidth( col, m_grid->GetVisibleWidth( col, true, true, false ) );
|
|
|
|
|
|
|
|
m_grid->SetRowLabelSize( m_grid->GetVisibleWidth( -1, true, true, true ) );
|
|
|
|
|
|
|
|
Layout();
|
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
wxASSERT_MSG( m_BrdSettings->m_DimensionPrecision <= 4, "Unhandled dimension precision!" );
|
|
|
|
|
2020-09-12 00:36:43 +00:00
|
|
|
int mode = static_cast<int>( m_BrdSettings->m_DimensionUnitsMode );
|
|
|
|
m_dimensionUnits->SetSelection( mode );
|
|
|
|
|
|
|
|
int format = static_cast<int>( m_BrdSettings->m_DimensionUnitsFormat );
|
|
|
|
m_dimensionUnitsFormat->SetSelection( format );
|
|
|
|
|
2019-10-31 23:25:50 +00:00
|
|
|
m_dimensionPrecision->SetSelection( m_BrdSettings->m_DimensionPrecision );
|
2020-09-12 15:46:33 +00:00
|
|
|
m_dimensionSuppressZeroes->SetValue( m_BrdSettings->m_DimensionSuppressZeroes );
|
2019-10-31 23:25:50 +00:00
|
|
|
|
2020-09-12 00:36:43 +00:00
|
|
|
int position = static_cast<int>( m_BrdSettings->m_DimensionTextPosition );
|
|
|
|
m_dimensionTextPositionMode->SetSelection( position );
|
|
|
|
|
|
|
|
m_dimensionTextKeepAligned->SetValue( m_BrdSettings->m_DimensionKeepTextAligned );
|
|
|
|
m_arrowLength.SetValue( m_BrdSettings->m_DimensionArrowLength );
|
2020-09-12 15:46:33 +00:00
|
|
|
m_extensionOffset.SetValue( m_BrdSettings->m_DimensionExtensionOffset );
|
2020-09-12 00:36:43 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PANEL_SETUP_TEXT_AND_GRAPHICS::getGridValue( int aRow, int aCol )
|
|
|
|
{
|
2020-10-02 20:51:24 +00:00
|
|
|
return ValueFromString( m_Frame->GetUserUnits(), m_grid->GetCellValue( aRow, aCol ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-16 14:28:01 +00:00
|
|
|
bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow()
|
2018-04-28 15:22:25 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-04-28 15:22:25 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < ROW_COUNT; ++i )
|
|
|
|
{
|
|
|
|
m_BrdSettings->m_LineThickness[ i ] = getGridValue( i, COL_LINE_THICKNESS );
|
|
|
|
|
2018-08-24 20:08:30 +00:00
|
|
|
if( i == ROW_EDGES || i == ROW_COURTYARD )
|
2018-04-28 15:22:25 +00:00
|
|
|
continue;
|
|
|
|
|
2021-03-16 14:28:01 +00:00
|
|
|
m_BrdSettings->m_TextSize[ i ] = wxSize( getGridValue( i, COL_TEXT_WIDTH ),
|
|
|
|
getGridValue( i, COL_TEXT_HEIGHT ) );
|
2018-04-28 15:22:25 +00:00
|
|
|
m_BrdSettings->m_TextThickness[ i ] = getGridValue( i, COL_TEXT_THICKNESS );
|
|
|
|
m_BrdSettings->m_TextItalic[ i ] =
|
|
|
|
wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
|
|
|
|
m_BrdSettings->m_TextUpright[ i ] =
|
|
|
|
wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_UPRIGHT ) );
|
|
|
|
}
|
|
|
|
|
2020-10-13 22:05:15 +00:00
|
|
|
// These are all stored in project file, not board, so no need for OnModify()
|
|
|
|
|
|
|
|
int mode = m_dimensionUnits->GetSelection();
|
2020-09-12 00:36:43 +00:00
|
|
|
m_BrdSettings->m_DimensionUnitsMode = static_cast<DIM_UNITS_MODE>( mode );
|
|
|
|
int format = m_dimensionUnitsFormat->GetSelection();
|
|
|
|
m_BrdSettings->m_DimensionUnitsFormat = static_cast<DIM_UNITS_FORMAT>( format );
|
|
|
|
m_BrdSettings->m_DimensionPrecision = m_dimensionPrecision->GetSelection();
|
2020-09-12 15:46:33 +00:00
|
|
|
m_BrdSettings->m_DimensionSuppressZeroes = m_dimensionSuppressZeroes->GetValue();
|
2020-09-12 00:36:43 +00:00
|
|
|
int position = m_dimensionTextPositionMode->GetSelection();
|
|
|
|
m_BrdSettings->m_DimensionTextPosition = static_cast<DIM_TEXT_POSITION>( position );
|
|
|
|
m_BrdSettings->m_DimensionKeepTextAligned = m_dimensionTextKeepAligned->GetValue();
|
|
|
|
m_BrdSettings->m_DimensionArrowLength = m_arrowLength.GetValue();
|
2020-09-12 15:46:33 +00:00
|
|
|
m_BrdSettings->m_DimensionExtensionOffset = m_extensionOffset.GetValue();
|
2019-10-31 23:25:50 +00:00
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_TEXT_AND_GRAPHICS::ImportSettingsFrom( BOARD* aBoard )
|
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-04-28 15:22:25 +00:00
|
|
|
BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
|
|
|
|
|
|
|
|
m_BrdSettings = &aBoard->GetDesignSettings();
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
|
|
|
m_BrdSettings = savedSettings;
|
|
|
|
}
|