Add unit and eval support to WX_GRIDs.

Fixes https://gitlab.com/kicad/code/kicad/issues/1871

Fixes https://gitlab.com/kicad/code/kicad/issues/4285
This commit is contained in:
Jeff Young 2022-10-11 18:01:47 +01:00
parent ad5df7f4cc
commit e02c05d38f
19 changed files with 414 additions and 191 deletions

View File

@ -102,6 +102,8 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, EDA_DRAW_
m_netclassesDirty = true;
m_netclassGrid->SetUnitsProvider( m_frame );
// Prevent Size events from firing before we are ready
Freeze();
m_netclassGrid->BeginBatch();
@ -109,23 +111,34 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, EDA_DRAW_
if( m_isEEschema )
{
constexpr int ECO = EESCHEMA_COL_OFFSET;
m_netclassGrid->DeleteCols( GRID_FIRST_PCBNEW, GRID_FIRST_EESCHEMA - GRID_FIRST_PCBNEW );
m_netclassGrid->SetAutoEvalCols( { GRID_WIREWIDTH - ECO, GRID_BUSWIDTH - ECO } );
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 );
m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR - ECO, 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_netclassGrid->SetColAttr( GRID_LINESTYLE - ECO, attr );
m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
}
else
{
m_netclassGrid->DeleteCols( GRID_FIRST_EESCHEMA, GRID_END - GRID_FIRST_EESCHEMA );
m_netclassGrid->SetAutoEvalCols( { GRID_CLEARANCE,
GRID_TRACKSIZE,
GRID_VIASIZE,
GRID_VIADRILL,
GRID_uVIASIZE,
GRID_uVIADRILL,
GRID_DIFF_PAIR_WIDTH,
GRID_DIFF_PAIR_GAP } );
m_colorDefaultHelpText->Hide();
}
@ -232,12 +245,6 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
{
int row = 0;
auto setCell =
[&]( int aRow, int aCol, int aValue )
{
m_netclassGrid->SetCellValue( aRow, aCol, m_frame->StringFromValue( aValue, true ) );
};
auto netclassToGridRow =
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
{
@ -245,12 +252,13 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
if( m_isEEschema )
{
setCell( aRow, GRID_WIREWIDTH - EESCHEMA_COL_OFFSET, nc->GetWireWidth() );
setCell( aRow, GRID_BUSWIDTH - EESCHEMA_COL_OFFSET, nc->GetBusWidth() );
constexpr int ECO = EESCHEMA_COL_OFFSET;
m_netclassGrid->SetUnitValue( aRow, GRID_WIREWIDTH - ECO, nc->GetWireWidth() );
m_netclassGrid->SetUnitValue( aRow, GRID_BUSWIDTH - ECO, nc->GetBusWidth() );
wxString colorAsString = nc->GetSchematicColor().ToCSSString();
m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET,
colorAsString );
m_netclassGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR - ECO, colorAsString );
int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
@ -262,14 +270,14 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
}
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() );
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() );
}
};
@ -335,18 +343,6 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
int row = 0;
auto getCell =
[this]( int aRow, int aCol ) -> int
{
return m_frame->ValueFromString( m_netclassGrid->GetCellValue( aRow, aCol ) );
};
auto getCellStr =
[this]( int aRow, int aCol ) -> wxString
{
return m_netclassGrid->GetCellValue( aRow, aCol );
};
auto gridRowToNetclass =
[&]( int aRow, const std::shared_ptr<NETCLASS>& nc )
{
@ -354,26 +350,28 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
if( m_isEEschema )
{
nc->SetWireWidth( getCell( aRow, GRID_WIREWIDTH - EESCHEMA_COL_OFFSET ) );
nc->SetBusWidth( getCell( aRow, GRID_BUSWIDTH - EESCHEMA_COL_OFFSET ) );
constexpr int ECO = EESCHEMA_COL_OFFSET;
wxString color = getCellStr( aRow, GRID_SCHEMATIC_COLOR - EESCHEMA_COL_OFFSET );
nc->SetWireWidth( m_netclassGrid->GetUnitValue( aRow, GRID_WIREWIDTH - ECO ) );
nc->SetBusWidth( m_netclassGrid->GetUnitValue( aRow, GRID_BUSWIDTH - ECO ) );
wxString color = m_netclassGrid->GetCellValue( aRow, GRID_SCHEMATIC_COLOR - ECO );
nc->SetSchematicColor( wxColour( color ) );
wxString lineStyle = getCellStr( aRow, GRID_LINESTYLE - EESCHEMA_COL_OFFSET );
wxString lineStyle = m_netclassGrid->GetCellValue( aRow, GRID_LINESTYLE - ECO );
nc->SetLineStyle( g_lineStyleNames.Index( lineStyle ) );
wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
}
else
{
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 ) );
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 ) );
}
};

View File

@ -2,7 +2,7 @@
* This file is part of libeval, a simple math expression evaluator
*
* Copyright (C) 2017 Michael Geselbracht, mgeselbracht3@gmail.com
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
@ -54,13 +54,7 @@ NUMERIC_EVALUATOR::NUMERIC_EVALUATOR( EDA_UNITS aUnits )
m_parser = numEval::ParseAlloc( malloc );
switch( aUnits )
{
case EDA_UNITS::MILLIMETRES: m_defaultUnits = Unit::MM; break;
case EDA_UNITS::MILS: m_defaultUnits = Unit::Mil; break;
case EDA_UNITS::INCHES: m_defaultUnits = Unit::Inch; break;
default: m_defaultUnits = Unit::MM; break;
}
SetDefaultUnits( aUnits );
}
@ -85,6 +79,18 @@ void NUMERIC_EVALUATOR::Clear()
}
void NUMERIC_EVALUATOR::SetDefaultUnits( EDA_UNITS aUnits )
{
switch( aUnits )
{
case EDA_UNITS::MILLIMETRES: m_defaultUnits = Unit::MM; break;
case EDA_UNITS::MILS: m_defaultUnits = Unit::Mil; break;
case EDA_UNITS::INCHES: m_defaultUnits = Unit::Inch; break;
default: m_defaultUnits = Unit::MM; break;
}
}
void NUMERIC_EVALUATOR::parseError( const char* s )
{
m_parseError = true;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014-2015 CERN
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -104,6 +104,8 @@ void UNIT_BINDER::SetUnits( EDA_UNITS aUnits )
{
m_units = aUnits;
m_eval.SetDefaultUnits( m_units );
if( m_unitLabel )
m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) );
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -26,7 +26,7 @@
#include <widgets/wx_grid.h>
#include <widgets/ui_common.h>
#include <algorithm>
#include <core/kicad_algo.h>
#define MIN_GRIDCELL_MARGIN 3
@ -34,7 +34,8 @@
WX_GRID::WX_GRID( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name ) :
wxGrid( parent, id, pos, size, style, name ),
m_weOwnTable( false )
m_weOwnTable( false ),
m_unitsProvider( nullptr )
{
SetDefaultCellOverflow( false );
@ -45,6 +46,8 @@ WX_GRID::WX_GRID( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxS
Connect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this );
#endif
Connect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( WX_GRID::onCellEditorShown ), nullptr, this );
Connect( wxEVT_GRID_EDITOR_HIDDEN, wxGridEventHandler( WX_GRID::onCellEditorHidden ), nullptr, this );
}
@ -126,16 +129,63 @@ void WX_GRID::SetTable( wxGridTableBase* aTable, bool aTakeOwnership )
void WX_GRID::onGridCellSelect( wxGridEvent& aEvent )
{
// Highlight the selected cell.
// Calling SelectBlock() allows a visual effect when cells are selected
// by tab or arrow keys.
// Otherwise, one cannot really know what actual cell is selected
// Calling SelectBlock() allows a visual effect when cells are selected by tab or arrow keys.
// Otherwise, one cannot really know what actual cell is selected.
int row = aEvent.GetRow();
int col = aEvent.GetCol();
if( row >= 0 && col >= 0 )
SelectBlock(row,col,row,col,false);
SelectBlock( row, col, row, col, false );
}
void WX_GRID::onCellEditorShown( wxGridEvent& aEvent )
{
if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
{
int row = aEvent.GetRow();
int col = aEvent.GetCol();
const std::pair<wxString, wxString>& beforeAfter = m_evalBeforeAfter[ { row, col } ];
if( GetCellValue( row, col ) == beforeAfter.second )
SetCellValue( row, col, beforeAfter.first );
}
}
void WX_GRID::onCellEditorHidden( wxGridEvent& aEvent )
{
if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
{
m_eval->SetDefaultUnits( m_unitsProvider->GetUserUnits() );
int row = aEvent.GetRow();
int col = aEvent.GetCol();
CallAfter(
[this, row, col]()
{
wxString stringValue = GetCellValue( row, col );
if( m_eval->Process( stringValue ) )
{
int val = m_unitsProvider->ValueFromString( m_eval->Result() );
wxString evalValue = m_unitsProvider->StringFromValue( val, true );
if( stringValue != evalValue )
{
SetCellValue( row, col, evalValue );
m_evalBeforeAfter[ { row, col } ] = { stringValue, evalValue };
}
}
} );
}
aEvent.Skip();
}
void WX_GRID::DestroyTable( wxGridTableBase* aTable )
{
// wxGrid's destructor will crash trying to look up the cell attr if the edit control
@ -272,6 +322,35 @@ bool WX_GRID::CommitPendingChanges( bool aQuietMode )
}
void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider )
{
m_unitsProvider = aProvider;
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_unitsProvider->GetUserUnits() );
}
int WX_GRID::GetUnitValue( int aRow, int aCol )
{
wxString stringValue = GetCellValue( aRow, aCol );
if( alg::contains( m_autoEvalCols, aCol ) )
{
m_eval->SetDefaultUnits( m_unitsProvider->GetUserUnits() );
if( m_eval->Process( stringValue ) )
stringValue = m_eval->Result();
}
return m_unitsProvider->ValueFromString( stringValue );
}
void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
{
SetCellValue( aRow, aCol, m_unitsProvider->StringFromValue( aValue, true ) );
}
void WX_GRID::onGridColMove( wxGridEvent& aEvent )
{
// wxWidgets won't move an open editor, so better just to close it

View File

@ -86,6 +86,8 @@ public:
m_edited( false ),
m_pinTable( aPinTable )
{
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
m_frame->Bind( UNITS_CHANGED, &PIN_TABLE_DATA_MODEL::onUnitsChanged, this );
}
@ -136,6 +138,17 @@ public:
wxString GetValue( int aRow, int aCol ) override
{
wxGrid* grid = GetView();
if( grid->GetGridCursorRow() == aRow && grid->GetGridCursorCol() == aCol
&& grid->IsCellEditControlShown() )
{
auto it = m_evalOriginal.find( { m_rows[ aRow ], aCol } );
if( it != m_evalOriginal.end() )
return it->second;
}
return GetValue( m_rows[ aRow ], aCol, m_frame );
}
@ -252,13 +265,36 @@ public:
if( aValue == INDETERMINATE_STATE )
return;
wxString value = aValue;
switch( aCol )
{
case COL_NUMBER_SIZE:
case COL_NAME_SIZE:
case COL_LENGTH:
case COL_POSX:
case COL_POSY:
m_eval->SetDefaultUnits( m_frame->GetUserUnits() );
if( m_eval->Process( value ) )
{
m_evalOriginal[ { m_rows[ aRow ], aCol } ] = value;
value = m_eval->Result();
}
break;
default:
break;
}
LIB_PINS pins = m_rows[ aRow ];
// If the NUMBER column is edited and the pins are grouped, renumber, and add or
// remove pins based on the comma separated list of pins.
if( aCol == COL_NUMBER && m_pinTable->IsDisplayGrouped() )
{
wxStringTokenizer tokenizer( aValue, "," );
wxStringTokenizer tokenizer( value, "," );
size_t i = 0;
while( tokenizer.HasMoreTokens() )
@ -323,59 +359,59 @@ public:
{
case COL_NUMBER:
if( !m_pinTable->IsDisplayGrouped() )
pin->SetNumber( aValue );
pin->SetNumber( value );
break;
case COL_NAME:
pin->SetName( aValue );
pin->SetName( value );
break;
case COL_TYPE:
if( PinTypeNames().Index( aValue ) != wxNOT_FOUND )
pin->SetType( (ELECTRICAL_PINTYPE) PinTypeNames().Index( aValue ) );
if( PinTypeNames().Index( value ) != wxNOT_FOUND )
pin->SetType( (ELECTRICAL_PINTYPE) PinTypeNames().Index( value ) );
break;
case COL_SHAPE:
if( PinShapeNames().Index( aValue ) != wxNOT_FOUND )
pin->SetShape( (GRAPHIC_PINSHAPE) PinShapeNames().Index( aValue ) );
if( PinShapeNames().Index( value ) != wxNOT_FOUND )
pin->SetShape( (GRAPHIC_PINSHAPE) PinShapeNames().Index( value ) );
break;
case COL_ORIENTATION:
if( PinOrientationNames().Index( aValue ) != wxNOT_FOUND )
pin->SetOrientation( PinOrientationCode( PinOrientationNames().Index( aValue ) ) );
if( PinOrientationNames().Index( value ) != wxNOT_FOUND )
pin->SetOrientation( PinOrientationCode( PinOrientationNames().Index( value ) ) );
break;
case COL_NUMBER_SIZE:
pin->SetNumberTextSize( m_frame->ValueFromString( aValue ) );
pin->SetNumberTextSize( m_frame->ValueFromString( value ) );
break;
case COL_NAME_SIZE:
pin->SetNameTextSize( m_frame->ValueFromString( aValue ) );
pin->SetNameTextSize( m_frame->ValueFromString( value ) );
break;
case COL_LENGTH:
pin->ChangeLength( m_frame->ValueFromString( aValue ) );
pin->ChangeLength( m_frame->ValueFromString( value ) );
break;
case COL_POSX:
pin->SetPosition( wxPoint( m_frame->ValueFromString( aValue ),
pin->SetPosition( wxPoint( m_frame->ValueFromString( value ),
pin->GetPosition().y ) );
break;
case COL_POSY:
pin->SetPosition( wxPoint( pin->GetPosition().x,
-m_frame->ValueFromString( aValue ) ) );
-m_frame->ValueFromString( value ) ) );
break;
case COL_VISIBLE:
pin->SetVisible(BoolFromString( aValue ));
pin->SetVisible(BoolFromString( value ));
break;
case COL_UNIT:
if( aValue == UNITS_ALL )
if( value == UNITS_ALL )
{
pin->SetUnit( 0 );
}
@ -383,7 +419,7 @@ public:
{
for( int i = 1; i <= pin->GetParent()->GetUnitCount(); i++ )
{
if( aValue == LIB_SYMBOL::SubReference( i, false ) )
if( value == LIB_SYMBOL::SubReference( i, false ) )
{
pin->SetUnit( i );
break;
@ -393,9 +429,9 @@ public:
break;
case COL_DEMORGAN:
if( aValue == DEMORGAN_STD )
if( value == DEMORGAN_STD )
pin->SetConvert( 1 );
else if( aValue == DEMORGAN_ALT )
else if( value == DEMORGAN_ALT )
pin->SetConvert( 2 );
else
pin->SetConvert( 0 );
@ -656,6 +692,9 @@ private:
bool m_edited;
DIALOG_LIB_EDIT_PIN_TABLE* m_pinTable;
std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
std::map< std::pair<LIB_PINS, int>, wxString > m_evalOriginal;
};

View File

@ -291,6 +291,8 @@ void FIELDS_GRID_TABLE<T>::initGrid( WX_GRID* aGrid )
m_colorAttr->SetRenderer( new GRID_CELL_COLOR_RENDERER( m_dialog ) );
m_colorAttr->SetEditor( new GRID_CELL_COLOR_SELECTOR( m_dialog, aGrid ) );
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
m_frame->Bind( UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
}
@ -519,8 +521,19 @@ template <class T>
wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
{
wxCHECK( aRow < GetNumberRows(), wxEmptyString );
wxGrid* grid = GetView();
const T& field = this->at( (size_t) aRow );
if( grid->GetGridCursorRow() == aRow && grid->GetGridCursorCol() == aCol
&& grid->IsCellEditControlShown() )
{
auto it = m_evalOriginal.find( { aRow, aCol } );
if( it != m_evalOriginal.end() )
return it->second;
}
switch( aCol )
{
case FDC_NAME:
@ -640,17 +653,35 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
wxCHECK( aRow < GetNumberRows(), /*void*/ );
T& field = this->at( (size_t) aRow );
VECTOR2I pos;
wxString value = aValue;
switch( aCol )
{
case FDC_TEXT_SIZE:
case FDC_POSX:
case FDC_POSY:
m_eval->SetDefaultUnits( m_frame->GetUserUnits() );
if( m_eval->Process( value ) )
{
m_evalOriginal[ { aRow, aCol } ] = value;
value = m_eval->Result();
}
break;
default:
break;
}
switch( aCol )
{
case FDC_NAME:
field.SetName( aValue );
field.SetName( value );
break;
case FDC_VALUE:
{
wxString value( aValue );
if( m_parentType == SCH_SHEET_T && aRow == SHEETFILENAME )
{
wxFileName fn( value );
@ -673,53 +704,53 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
}
case FDC_SHOWN:
field.SetVisible( BoolFromString( aValue ) );
field.SetVisible( BoolFromString( value ) );
break;
case FDC_H_ALIGN:
if( aValue == _( "Left" ) )
if( value == _( "Left" ) )
field.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
else if( aValue == _( "Center" ) )
else if( value == _( "Center" ) )
field.SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
else if( aValue == _( "Right" ) )
else if( value == _( "Right" ) )
field.SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
else
wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + aValue );
wxFAIL_MSG( wxT( "unknown horizontal alignment: " ) + value );
break;
case FDC_V_ALIGN:
if( aValue == _( "Top" ) )
if( value == _( "Top" ) )
field.SetVertJustify( GR_TEXT_V_ALIGN_TOP );
else if( aValue == _( "Center" ) )
else if( value == _( "Center" ) )
field.SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
else if( aValue == _( "Bottom" ) )
else if( value == _( "Bottom" ) )
field.SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
else
wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + aValue);
wxFAIL_MSG( wxT( "unknown vertical alignment: " ) + value);
break;
case FDC_ITALIC:
field.SetItalic( BoolFromString( aValue ) );
field.SetItalic( BoolFromString( value ) );
break;
case FDC_BOLD:
field.SetBold( BoolFromString( aValue ) );
field.SetBold( BoolFromString( value ) );
break;
case FDC_TEXT_SIZE:
field.SetTextSize( wxSize( m_frame->ValueFromString( aValue ),
m_frame->ValueFromString( aValue ) ) );
field.SetTextSize( wxSize( m_frame->ValueFromString( value ),
m_frame->ValueFromString( value ) ) );
break;
case FDC_ORIENTATION:
if( aValue == _( "Horizontal" ) )
if( value == _( "Horizontal" ) )
field.SetTextAngle( ANGLE_HORIZONTAL );
else if( aValue == _( "Vertical" ) )
else if( value == _( "Vertical" ) )
field.SetTextAngle( ANGLE_VERTICAL );
else
wxFAIL_MSG( wxT( "unknown orientation: " ) + aValue );
wxFAIL_MSG( wxT( "unknown orientation: " ) + value );
break;
@ -728,17 +759,17 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
pos = field.GetTextPos();
if( aCol == FDC_POSX )
pos.x = m_frame->ValueFromString( aValue );
pos.x = m_frame->ValueFromString( value );
else
pos.y = m_frame->ValueFromString( aValue );
pos.y = m_frame->ValueFromString( value );
field.SetTextPos( pos );
break;
case FDC_FONT:
if( aValue == DEFAULT_FONT_NAME )
if( value == DEFAULT_FONT_NAME )
field.SetFont( nullptr );
else if( aValue == KICAD_FONT_NAME )
else if( value == KICAD_FONT_NAME )
field.SetFont( KIFONT::FONT::GetFont( wxEmptyString, field.IsBold(), field.IsItalic() ) );
else
field.SetFont( KIFONT::FONT::GetFont( aValue, field.IsBold(), field.IsItalic() ) );
@ -746,7 +777,7 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
break;
case FDC_COLOR:
field.SetTextColor( wxColor( aValue ) );
field.SetTextColor( wxColor( value ) );
break;
default:

View File

@ -145,6 +145,9 @@ private:
wxGridCellAttr* m_netclassAttr;
wxGridCellAttr* m_fontAttr;
wxGridCellAttr* m_colorAttr;
std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
std::map< std::pair<int, int>, wxString > m_evalOriginal;
};

View File

@ -104,6 +104,8 @@ public:
*/
void Clear();
void SetDefaultUnits( EDA_UNITS aUnits );
/* Used by the lemon parser */
void parseError(const char* s);
void parseOk();

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -27,6 +27,8 @@
#include <wx/event.h>
#include <wx/grid.h>
#include <wx/version.h>
#include <units_provider.h>
#include <libeval/numeric_evaluator.h>
class WX_GRID : public wxGrid
@ -76,6 +78,25 @@ public:
*/
bool CommitPendingChanges( bool aQuietMode = false );
/**
* Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
* @param aProvider
*/
void SetUnitsProvider( UNITS_PROVIDER* aProvider );
void SetAutoEvalCols( const std::vector<int>& aCols ) { m_autoEvalCols = aCols; }
/**
* Apply standard KiCad unit and eval services to a numeric cell.
* @return the value held by the cell in internal units
*/
int GetUnitValue( int aRow, int aCol );
/**
* Set a unitized cell's value.
*/
void SetUnitValue( int aRow, int aCol, int aValue );
/**
* Calculates the specified column based on the actual size of the text
* on screen. Will return the maximum value of all calculated widths.
@ -121,12 +142,22 @@ protected:
void onGridColMove( wxGridEvent& aEvent );
void onGridCellSelect( wxGridEvent& aEvent );
void onCellEditorShown( wxGridEvent& aEvent );
void onCellEditorHidden( wxGridEvent& aEvent );
#if wxCHECK_VERSION( 3, 1, 3 )
void onDPIChanged(wxDPIChangedEvent& event);
#endif
bool m_weOwnTable;
protected:
bool m_weOwnTable;
UNITS_PROVIDER* m_unitsProvider;
std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
std::vector<int> m_autoEvalCols;
std::map< std::pair<int, int>, std::pair<wxString, wxString> > m_evalBeforeAfter;
};
#endif //KICAD_WX_GRID_H

View File

@ -265,6 +265,11 @@ DIALOG_PAD_PRIMITIVE_POLY_PROPS::DIALOG_PAD_PRIMITIVE_POLY_PROPS( wxWindow* aPar
m_deleteButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
m_warningIcon->SetBitmap( KiBitmap( BITMAPS::dialog_warning ) );
m_gridCornersList->SetUnitsProvider( aFrame );
m_gridCornersList->SetAutoEvalCols( { 0, 1 } );
m_gridCornersList->SetDefaultRowSize( m_gridCornersList->GetDefaultRowSize() + 4 );
// Test for acceptable polygon (more than 2 corners, and not self-intersecting) and
// remove any redundant corners. A warning message is displayed if not OK.
doValidate( true );
@ -312,19 +317,13 @@ bool DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow()
}
// enter others corner coordinates
wxString msg;
for( unsigned row = 0; row < m_currPoints.size(); ++row )
{
// Row label is "Corner x"
msg.Printf( _( "Corner %d" ), row+1 );
m_gridCornersList->SetRowLabelValue( row, msg );
m_gridCornersList->SetRowLabelValue( row, wxString::Format( _( "Corner %d" ), row+1 ) );
msg = m_frame->StringFromValue( m_currPoints[row].x, true );
m_gridCornersList->SetCellValue( row, 0, msg );
msg = m_frame->StringFromValue( m_currPoints[row].y, true );
m_gridCornersList->SetCellValue( row, 1, msg );
m_gridCornersList->SetUnitValue( row, 0, m_currPoints[row].x );
m_gridCornersList->SetUnitValue( row, 1, m_currPoints[row].y );
}
return true;
@ -556,21 +555,21 @@ void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onGridSelect( wxGridRangeSelectEvent& even
void DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging( wxGridEvent& event )
{
int row = event.GetRow();
int col = event.GetCol();
wxString msg = event.GetString();
int row = event.GetRow();
int col = event.GetCol();
if( msg.IsEmpty() )
return;
CallAfter(
[this, row, col]()
{
if( col == 0 ) // Set the X value
m_currPoints[row].x = m_gridCornersList->GetUnitValue( row, col );
else // Set the Y value
m_currPoints[row].y = m_gridCornersList->GetUnitValue( row, col );
if( col == 0 ) // Set the X value
m_currPoints[row].x = m_frame->ValueFromString( msg );
else // Set the Y value
m_currPoints[row].y = m_frame->ValueFromString( msg );
Validate();
Validate();
m_panelPoly->Refresh();
m_panelPoly->Refresh();
} );
}

View File

@ -35,7 +35,6 @@
#include <convert_basic_shapes_to_polygon.h> // for enum RECT_CHAMFER_POSITIONS definition
#include <geometry/shape_segment.h>
#include <dialog_pad_properties.h>
#include <gal/graphics_abstraction_layer.h>
#include <dialogs/html_message_box.h>
#include <macros.h>
#include <pad.h>

View File

@ -1489,7 +1489,7 @@ DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE::DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE( wxWi
bSizerRightButts->Add( m_deleteButton, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
bLeftSizer->Add( bSizerRightButts, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxRIGHT|wxLEFT, 5 );
bLeftSizer->Add( bSizerRightButts, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 );
wxFlexGridSizer* fgSizerThickness;
fgSizerThickness = new wxFlexGridSizer( 0, 4, 0, 0 );
@ -1515,7 +1515,7 @@ DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE::DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE( wxWi
bLeftSizer->Add( fgSizerThickness, 0, wxALL|wxEXPAND, 10 );
bSizerUpper->Add( bLeftSizer, 1, wxEXPAND, 5 );
bSizerUpper->Add( bLeftSizer, 1, wxEXPAND|wxRIGHT, 5 );
wxBoxSizer* bRightSizer;
bRightSizer = new wxBoxSizer( wxVERTICAL );
@ -1545,10 +1545,10 @@ DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE::DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE( wxWi
bRightSizer->Add( m_warningSizer, 0, wxEXPAND|wxRIGHT, 10 );
bSizerUpper->Add( bRightSizer, 1, wxEXPAND, 5 );
bSizerUpper->Add( bRightSizer, 1, wxEXPAND|wxLEFT, 5 );
bSizerMain->Add( bSizerUpper, 1, wxEXPAND, 5 );
bSizerMain->Add( bSizerUpper, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
m_staticline3 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline3, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 );

View File

@ -14579,7 +14579,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
@ -14588,7 +14588,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="flag">wxEXPAND|wxRIGHT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
@ -14685,11 +14685,11 @@
<event name="OnGridSelectCell">onCellSelect</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxEXPAND|wxRIGHT|wxLEFT</property>
<property name="flag">wxEXPAND|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="0">
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerRightButts</property>
<property name="orient">wxHORIZONTAL</property>
@ -15126,7 +15126,7 @@
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="flag">wxEXPAND|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>

View File

@ -179,7 +179,6 @@ PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS( wxWindow* aParent,
m_parent = static_cast<PAGED_DIALOG*>( aParent->GetParent() );
m_textItemsGrid->SetDefaultRowSize( m_textItemsGrid->GetDefaultRowSize() + 4 );
m_graphicsGrid->SetDefaultRowSize( m_graphicsGrid->GetDefaultRowSize() + 4 );
m_textItemsGrid->SetTable( new TEXT_ITEMS_GRID_TABLE(), true );
m_textItemsGrid->PushEventHandler( new GRID_TRICKS( m_textItemsGrid ) );
@ -196,6 +195,14 @@ PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS( wxWindow* aParent,
attr->SetEditor( new GRID_CELL_LAYER_SELECTOR( nullptr, {} ) );
m_textItemsGrid->SetColAttr( 2, attr );
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 );
// Work around a bug in wxWidgets where it fails to recalculate the grid height
// after changing the default row size
m_graphicsGrid->AppendRows( 1 );

View File

@ -21,7 +21,6 @@
* 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>
@ -62,10 +61,14 @@ PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS( PAGED_DIALOG* aPar
m_extensionOffset( aFrame, m_lblExtensionOffset, m_dimensionExtensionOffset,
m_dimensionExtensionOffsetUnits )
{
m_Parent = aParent;
m_Frame = aFrame;
m_BrdSettings = &m_Frame->GetBoard()->GetDesignSettings();
m_grid->SetUnitsProvider( m_Frame );
m_grid->SetAutoEvalCols( { COL_LINE_THICKNESS,
COL_TEXT_WIDTH,
COL_TEXT_HEIGHT,
COL_TEXT_THICKNESS } );
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
// Work around a bug in wxWidgets where it fails to recalculate the grid height
@ -196,12 +199,6 @@ bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataToWindow()
}
int PANEL_SETUP_TEXT_AND_GRAPHICS::getGridValue( int aRow, int aCol )
{
return m_Frame->ValueFromString( m_grid->GetCellValue( aRow, aCol ) );
}
bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow()
{
if( !m_grid->CommitPendingChanges() )
@ -209,14 +206,14 @@ bool PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow()
for( int i = 0; i < ROW_COUNT; ++i )
{
m_BrdSettings->m_LineThickness[ i ] = getGridValue( i, COL_LINE_THICKNESS );
m_BrdSettings->m_LineThickness[ i ] = m_grid->GetUnitValue( i, COL_LINE_THICKNESS );
if( i == ROW_EDGES || i == ROW_COURTYARD )
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_TextSize[ i ] = wxSize( m_grid->GetUnitValue( i, COL_TEXT_WIDTH ),
m_grid->GetUnitValue( i, COL_TEXT_HEIGHT ) );
m_BrdSettings->m_TextThickness[ i ] = m_grid->GetUnitValue( i, COL_TEXT_THICKNESS );
m_BrdSettings->m_TextItalic[ i ] =
wxGridCellBoolEditor::IsTrueValue( m_grid->GetCellValue( i, COL_TEXT_ITALIC ) );
m_BrdSettings->m_TextUpright[ i ] =

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -47,12 +47,9 @@ public:
void ImportSettingsFrom( BOARD* aBoard );
private:
int getGridValue( int aRow, int aCol );
void onUnitsChanged( wxCommandEvent& aEvent );
private:
PAGED_DIALOG* m_Parent;
PCB_EDIT_FRAME* m_Frame;
BOARD_DESIGN_SETTINGS* m_BrdSettings;
UNIT_BINDER m_arrowLength;

View File

@ -22,7 +22,6 @@
*/
#include <base_units.h>
#include <pcb_edit_frame.h>
#include <board_design_settings.h>
#include <bitmaps.h>
@ -97,6 +96,14 @@ PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS( PAGED_DIALOG* aParent,
m_viaSizesGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
m_diffPairsGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
m_trackWidthsGrid->SetUnitsProvider( m_Frame );
m_viaSizesGrid->SetUnitsProvider( m_Frame );
m_diffPairsGrid->SetUnitsProvider( m_Frame );
m_trackWidthsGrid->SetAutoEvalCols( { 0 } );
m_viaSizesGrid->SetAutoEvalCols( { 0, 1 } );
m_diffPairsGrid->SetAutoEvalCols( { 0, 1, 2 } );
// Ensure width of columns is enough to enter any reasonable value
WX_GRID* grid_list[] = { m_trackWidthsGrid, m_viaSizesGrid, m_diffPairsGrid, nullptr };
int min_linesize = m_trackWidthsGrid->GetTextExtent( wxT( "000.000000 mm " ) ).x;
@ -286,25 +293,19 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow()
for( int row = 0; row < m_trackWidthsGrid->GetNumberRows(); ++row )
{
msg = m_trackWidthsGrid->GetCellValue( row, TR_WIDTH_COL );
if( !msg.IsEmpty() )
trackWidths.push_back( m_Frame->ValueFromString( msg ) );
if( !m_trackWidthsGrid->GetCellValue( row, TR_WIDTH_COL ).IsEmpty() )
trackWidths.push_back( m_trackWidthsGrid->GetUnitValue( row, TR_WIDTH_COL ) );
}
for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
{
msg = m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL );
if( !msg.IsEmpty() )
if( !m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL ).IsEmpty() )
{
VIA_DIMENSION via_dim;
via_dim.m_Diameter = m_Frame->ValueFromString( msg );
via_dim.m_Diameter = m_viaSizesGrid->GetUnitValue( row, VIA_SIZE_COL );
msg = m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL );
if( !msg.IsEmpty() )
via_dim.m_Drill = m_Frame->ValueFromString( msg );
if( !m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL ).IsEmpty() )
via_dim.m_Drill = m_viaSizesGrid->GetUnitValue( row, VIA_DRILL_COL );
vias.push_back( via_dim );
}
@ -312,20 +313,16 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow()
for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
{
msg = m_diffPairsGrid->GetCellValue( row, DP_WIDTH_COL );
if( !msg.IsEmpty() )
if( !m_diffPairsGrid->GetCellValue( row, DP_WIDTH_COL ).IsEmpty() )
{
DIFF_PAIR_DIMENSION diffPair_dim;
diffPair_dim.m_Width = m_Frame->ValueFromString( msg );
diffPair_dim.m_Width = m_diffPairsGrid->GetUnitValue( row, DP_WIDTH_COL );
msg = m_diffPairsGrid->GetCellValue( row, DP_GAP_COL );
diffPair_dim.m_Gap = m_Frame->ValueFromString( msg );
if( !m_diffPairsGrid->GetCellValue( row, DP_GAP_COL ).IsEmpty() )
diffPair_dim.m_Gap = m_diffPairsGrid->GetUnitValue( row, DP_GAP_COL );
msg = m_diffPairsGrid->GetCellValue( row, DP_VIA_GAP_COL );
if( !msg.IsEmpty() )
diffPair_dim.m_ViaGap = m_Frame->ValueFromString( msg );
if( !m_diffPairsGrid->GetCellValue( row, DP_VIA_GAP_COL ).IsEmpty() )
diffPair_dim.m_ViaGap = m_diffPairsGrid->GetUnitValue( row, DP_VIA_GAP_COL );
diffPairs.push_back( diffPair_dim );
}
@ -374,7 +371,6 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::Validate()
m_Parent->SetError( msg, this, m_viaSizesGrid, row, VIA_DRILL_COL );
return false;
}
}
// Test diff pairs
@ -401,7 +397,7 @@ void PANEL_SETUP_TRACKS_AND_VIAS::AppendTrackWidth( const int aWidth )
m_trackWidthsGrid->AppendRows( 1 );
m_trackWidthsGrid->SetCellValue( i, TR_WIDTH_COL, m_Frame->StringFromValue( aWidth, true ) );
m_trackWidthsGrid->SetUnitValue( i, TR_WIDTH_COL, aWidth );
}
@ -411,10 +407,10 @@ void PANEL_SETUP_TRACKS_AND_VIAS::AppendViaSize( int aSize, int aDrill )
m_viaSizesGrid->AppendRows( 1 );
m_viaSizesGrid->SetCellValue( i, VIA_SIZE_COL, m_Frame->StringFromValue( aSize, true ) );
m_viaSizesGrid->SetUnitValue( i, VIA_SIZE_COL, aSize );
if( aDrill > 0 )
m_viaSizesGrid->SetCellValue( i, VIA_DRILL_COL, m_Frame->StringFromValue( aDrill, true ) );
m_viaSizesGrid->SetUnitValue( i, VIA_DRILL_COL, aDrill );
}
@ -424,13 +420,13 @@ void PANEL_SETUP_TRACKS_AND_VIAS::AppendDiffPairs( int aWidth, int aGap, int aVi
m_diffPairsGrid->AppendRows( 1 );
m_diffPairsGrid->SetCellValue( i, DP_WIDTH_COL, m_Frame->StringFromValue( aWidth, true ) );
m_diffPairsGrid->SetUnitValue( i, DP_WIDTH_COL, aWidth );
if( aGap > 0 )
m_diffPairsGrid->SetCellValue( i, DP_GAP_COL, m_Frame->StringFromValue( aGap, true ) );
m_diffPairsGrid->SetUnitValue( i, DP_GAP_COL, aGap );
if( aViaGap > 0 )
m_diffPairsGrid->SetCellValue( i, DP_VIA_GAP_COL, m_Frame->StringFromValue( aViaGap, true ) );
m_diffPairsGrid->SetUnitValue( i, DP_VIA_GAP_COL, aViaGap );
}

View File

@ -67,6 +67,8 @@ FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) :
m_layerColAttr->SetRenderer( new GRID_CELL_LAYER_RENDERER( m_frame ) );
m_layerColAttr->SetEditor( new GRID_CELL_LAYER_SELECTOR( m_frame, {} ) );
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
m_frame->Bind( UNITS_CHANGED, &FP_TEXT_GRID_TABLE::onUnitsChanged, this );
}
@ -191,8 +193,18 @@ wxGridCellAttr* FP_TEXT_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr:
wxString FP_TEXT_GRID_TABLE::GetValue( int aRow, int aCol )
{
wxGrid* grid = GetView();
const FP_TEXT& text = this->at( (size_t) aRow );
if( grid->GetGridCursorRow() == aRow && grid->GetGridCursorCol() == aCol
&& grid->IsCellEditControlShown() )
{
auto it = m_evalOriginal.find( { aRow, aCol } );
if( it != m_evalOriginal.end() )
return it->second;
}
switch( aCol )
{
case FPT_TEXT:
@ -263,27 +275,49 @@ void FP_TEXT_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue )
{
FP_TEXT& text = this->at( (size_t) aRow );
VECTOR2I pos;
wxString value = aValue;
switch( aCol )
{
case FPT_WIDTH:
case FPT_HEIGHT:
case FPT_THICKNESS:
case FPT_XOFFSET:
case FPT_YOFFSET:
m_eval->SetDefaultUnits( m_frame->GetUserUnits() );
if( m_eval->Process( value ) )
{
m_evalOriginal[ { aRow, aCol } ] = value;
value = m_eval->Result();
}
break;
default:
break;
}
switch( aCol )
{
case FPT_TEXT:
text.SetText( aValue );
text.SetText( value );
break;
case FPT_WIDTH:
text.SetTextWidth( m_frame->ValueFromString( aValue ) );
text.SetTextWidth( m_frame->ValueFromString( value ) );
break;
case FPT_HEIGHT:
text.SetTextHeight( m_frame->ValueFromString( aValue ) );
text.SetTextHeight( m_frame->ValueFromString( value ) );
break;
case FPT_THICKNESS:
text.SetTextThickness( m_frame->ValueFromString( aValue ) );
text.SetTextThickness( m_frame->ValueFromString( value ) );
break;
case FPT_ORIENTATION:
text.SetTextAngle( m_frame->AngleValueFromString( aValue ) );
text.SetTextAngle( m_frame->AngleValueFromString( value ) );
text.SetDrawCoord();
break;
@ -292,9 +326,9 @@ void FP_TEXT_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue )
pos = text.GetPos0();
if( aCol == FPT_XOFFSET )
pos.x = m_frame->ValueFromString( aValue );
pos.x = m_frame->ValueFromString( value );
else
pos.y = m_frame->ValueFromString( aValue );
pos.y = m_frame->ValueFromString( value );
text.SetPos0( pos );
text.SetDrawCoord();

View File

@ -89,6 +89,9 @@ private:
wxGridCellAttr* m_boolColAttr;
wxGridCellAttr* m_orientationColAttr;
wxGridCellAttr* m_layerColAttr;
std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
std::map< std::pair<int, int>, wxString > m_evalOriginal;
};