2016-02-19 15:59:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-02-08 12:16:07 +00:00
|
|
|
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-02-19 15:59:31 +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
|
|
|
|
*/
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2016-02-19 15:59:31 +00:00
|
|
|
#include "dialog_lib_edit_pin_table.h"
|
2015-03-27 10:26:07 +00:00
|
|
|
#include "lib_pin.h"
|
2016-01-13 19:09:07 +00:00
|
|
|
#include "pin_number.h"
|
2018-02-08 12:16:07 +00:00
|
|
|
#include "grid_tricks.h"
|
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
2018-05-30 10:52:19 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2015-03-27 10:26:07 +00:00
|
|
|
#include <queue>
|
2018-02-08 12:16:07 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <wx/bmpcbox.h>
|
|
|
|
#include <kiface_i.h>
|
2018-09-19 21:22:31 +00:00
|
|
|
#include <kicad_string.h>
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
#define PinTableShownColumnsKey wxT( "PinTableShownColumns" )
|
2015-03-27 10:26:07 +00:00
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
static std::vector<BITMAP_DEF> g_typeIcons;
|
|
|
|
static wxArrayString g_typeNames;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
static std::vector<BITMAP_DEF> g_shapeIcons;
|
|
|
|
static wxArrayString g_shapeNames;
|
2016-01-15 02:21:26 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
static std::vector<BITMAP_DEF> g_orientationIcons;
|
|
|
|
static wxArrayString g_orientationNames;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
class PIN_TABLE_DATA_MODEL : public wxGridTableBase
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Because the rows of the grid can either be a single pin or a group of pins, the
|
|
|
|
// data model is a 2D vector. If we're in the single pin case, each row's LIB_PINS
|
|
|
|
// contains only a single pin.
|
|
|
|
std::vector<LIB_PINS> m_rows;
|
|
|
|
|
|
|
|
EDA_UNITS_T m_userUnits;
|
|
|
|
|
2015-03-27 10:26:07 +00:00
|
|
|
public:
|
2018-02-08 12:16:07 +00:00
|
|
|
PIN_TABLE_DATA_MODEL( EDA_UNITS_T aUserUnits ) :
|
|
|
|
m_userUnits( aUserUnits )
|
|
|
|
{}
|
|
|
|
|
|
|
|
int GetNumberRows() override { return (int) m_rows.size(); }
|
|
|
|
int GetNumberCols() override { return COL_COUNT; }
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
wxString GetColLabelValue( int aCol ) override
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER: return _( "Number" );
|
|
|
|
case COL_NAME: return _( "Name" );
|
|
|
|
case COL_TYPE: return _( "Electrical Type" );
|
|
|
|
case COL_SHAPE: return _( "Graphic Style" );
|
|
|
|
case COL_ORIENTATION: return _( "Orientation" );
|
|
|
|
case COL_NUMBER_SIZE: return _( "Number Text Size" );
|
|
|
|
case COL_NAME_SIZE: return _( "Name Text Size" );
|
|
|
|
case COL_LENGTH: return _( "Length" );
|
|
|
|
case COL_POSX: return _( "X Position" );
|
|
|
|
case COL_POSY: return _( "Y Position" );
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
bool IsEmptyCell( int row, int col ) override
|
|
|
|
{
|
|
|
|
return false; // don't allow adjacent cell overflow, even if we are actually empty
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
wxString GetValue( int aRow, int aCol ) override
|
|
|
|
{
|
|
|
|
return GetValue( m_rows[ aRow ], aCol, m_userUnits );
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
static wxString GetValue( const LIB_PINS& pins, int aCol, EDA_UNITS_T aUserUnits )
|
|
|
|
{
|
|
|
|
wxString fieldValue;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( pins.empty())
|
|
|
|
return fieldValue;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
for( LIB_PIN* pin : pins )
|
|
|
|
{
|
|
|
|
wxString val;
|
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
val = pin->GetNumber();
|
|
|
|
break;
|
|
|
|
case COL_NAME:
|
|
|
|
val = pin->GetName();
|
|
|
|
break;
|
|
|
|
case COL_TYPE:
|
|
|
|
val = g_typeNames[ pin->GetType() ];
|
|
|
|
break;
|
|
|
|
case COL_SHAPE:
|
|
|
|
val = g_shapeNames[ pin->GetShape() ];
|
|
|
|
break;
|
|
|
|
case COL_ORIENTATION:
|
|
|
|
val = g_orientationNames[ LIB_PIN::GetOrientationIndex( pin->GetOrientation() ) ];
|
|
|
|
break;
|
|
|
|
case COL_NUMBER_SIZE:
|
|
|
|
val = StringFromValue( aUserUnits, pin->GetNumberTextSize(), true, true );
|
|
|
|
break;
|
|
|
|
case COL_NAME_SIZE:
|
|
|
|
val = StringFromValue( aUserUnits, pin->GetNameTextSize(), true, true );
|
|
|
|
break;
|
|
|
|
case COL_LENGTH:
|
|
|
|
val = StringFromValue( aUserUnits, pin->GetLength(), true );
|
|
|
|
break;
|
|
|
|
case COL_POSX:
|
|
|
|
val = StringFromValue( aUserUnits, pin->GetPosition().x, true );
|
|
|
|
break;
|
|
|
|
case COL_POSY:
|
|
|
|
val = StringFromValue( aUserUnits, pin->GetPosition().y, true );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aCol == COL_NUMBER )
|
|
|
|
{
|
|
|
|
if( fieldValue.length() )
|
|
|
|
fieldValue += wxT( ", " );
|
|
|
|
fieldValue += val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !fieldValue.Length() )
|
|
|
|
fieldValue = val;
|
|
|
|
else if( val != fieldValue )
|
2018-03-07 12:48:08 +00:00
|
|
|
fieldValue = INDETERMINATE;
|
2018-02-08 12:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
return fieldValue;
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void SetValue( int aRow, int aCol, const wxString &aValue ) override
|
2018-01-20 23:41:25 +00:00
|
|
|
{
|
2018-03-07 12:48:08 +00:00
|
|
|
if( aValue == INDETERMINATE )
|
2018-02-08 12:16:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
LIB_PINS pins = m_rows[ aRow ];
|
|
|
|
|
|
|
|
for( LIB_PIN* pin : pins )
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
pin->SetNumber( aValue );
|
|
|
|
break;
|
|
|
|
case COL_NAME:
|
|
|
|
pin->SetName( aValue );
|
|
|
|
break;
|
|
|
|
case COL_TYPE:
|
|
|
|
pin->SetType( (ELECTRICAL_PINTYPE) g_typeNames.Index( aValue ), false );
|
|
|
|
break;
|
|
|
|
case COL_SHAPE:
|
|
|
|
pin->SetShape( (GRAPHIC_PINSHAPE) g_shapeNames.Index( aValue ) );
|
|
|
|
break;
|
|
|
|
case COL_ORIENTATION:
|
|
|
|
pin->SetOrientation( LIB_PIN::GetOrientationCode(
|
|
|
|
g_orientationNames.Index( aValue ) ), false );
|
|
|
|
break;
|
|
|
|
case COL_NUMBER_SIZE:
|
|
|
|
pin->SetNumberTextSize( ValueFromString( m_userUnits, aValue, true ) );
|
|
|
|
break;
|
|
|
|
case COL_NAME_SIZE:
|
|
|
|
pin->SetNameTextSize( ValueFromString( m_userUnits, aValue, true ) );
|
|
|
|
break;
|
|
|
|
case COL_LENGTH:
|
|
|
|
pin->SetLength( ValueFromString( m_userUnits, aValue ) );
|
|
|
|
break;
|
|
|
|
case COL_POSX:
|
|
|
|
pin->SetPinPosition( wxPoint( ValueFromString( m_userUnits, aValue ),
|
|
|
|
pin->GetPosition().y ) );
|
|
|
|
break;
|
|
|
|
case COL_POSY:
|
|
|
|
pin->SetPinPosition( wxPoint( pin->GetPosition().x,
|
|
|
|
ValueFromString( m_userUnits, aValue ) ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-20 23:41:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
static int findRow( const std::vector<LIB_PINS>& aRowSet, const wxString& aName )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < aRowSet.size(); ++i )
|
|
|
|
{
|
|
|
|
if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
|
|
|
|
return i;
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-01-13 19:17:54 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
static bool compare( const LIB_PINS& lhs, const LIB_PINS& rhs,
|
|
|
|
int sortCol, bool ascending, EDA_UNITS_T units )
|
|
|
|
{
|
|
|
|
wxString lhStr = GetValue( lhs, sortCol, units );
|
|
|
|
wxString rhStr = GetValue( rhs, sortCol, units );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( lhStr == rhStr )
|
|
|
|
{
|
|
|
|
// Secondary sort key is always COL_NUMBER
|
2018-10-09 13:53:55 +00:00
|
|
|
sortCol = COL_NUMBER;
|
|
|
|
lhStr = GetValue( lhs, sortCol, units );
|
|
|
|
rhStr = GetValue( rhs, sortCol, units );
|
2018-02-08 12:16:07 +00:00
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-10-09 13:53:55 +00:00
|
|
|
bool cmp;
|
|
|
|
|
|
|
|
switch( sortCol )
|
|
|
|
{
|
|
|
|
case COL_NUMBER:
|
|
|
|
case COL_NAME:
|
|
|
|
cmp = PinNumbers::Compare( lhStr, rhStr ) < 0;
|
|
|
|
break;
|
|
|
|
case COL_NUMBER_SIZE:
|
|
|
|
case COL_NAME_SIZE:
|
|
|
|
cmp = ValueFromString( units, lhStr, true ) < ValueFromString( units, rhStr, true );
|
|
|
|
break;
|
|
|
|
case COL_LENGTH:
|
|
|
|
case COL_POSX:
|
|
|
|
case COL_POSY:
|
|
|
|
cmp = ValueFromString( units, lhStr ) < ValueFromString( units, rhStr );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cmp = StrNumCmp( lhStr, rhStr ) < 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ascending == cmp;
|
2018-02-08 12:16:07 +00:00
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void RebuildRows( LIB_PINS& aPins, bool groupByName )
|
|
|
|
{
|
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
// Commit any pending in-place edits before the row gets moved out from under
|
|
|
|
// the editor.
|
2018-08-19 16:10:14 +00:00
|
|
|
dynamic_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
2016-01-13 19:17:54 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_rows.clear();
|
2016-01-13 19:17:54 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
for( LIB_PIN* pin : aPins )
|
|
|
|
{
|
|
|
|
int rowIndex = -1;
|
2016-01-13 19:17:54 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( groupByName )
|
|
|
|
rowIndex = findRow( m_rows, pin->GetName() );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( rowIndex < 0 )
|
|
|
|
{
|
|
|
|
m_rows.emplace_back( LIB_PINS() );
|
|
|
|
rowIndex = m_rows.size() - 1;
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_rows[ rowIndex ].push_back( pin );
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
int sortCol = 0;
|
|
|
|
bool ascending = true;
|
2018-01-20 23:41:25 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
sortCol = GetView()->GetSortingColumn();
|
|
|
|
ascending = GetView()->IsSortOrderAscending();
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
SortRows( sortCol, ascending );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void SortRows( int aSortCol, bool ascending )
|
|
|
|
{
|
|
|
|
std::sort( m_rows.begin(), m_rows.end(),
|
|
|
|
[ aSortCol, ascending, this ]( LIB_PINS lhs, LIB_PINS rhs ) -> bool
|
|
|
|
{ return compare( lhs, rhs, aSortCol, ascending, m_userUnits ); } );
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void AppendRow( LIB_PIN* aPin )
|
2016-02-28 17:33:29 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
LIB_PINS row;
|
|
|
|
row.push_back( aPin );
|
|
|
|
m_rows.push_back( row );
|
|
|
|
|
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
}
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
LIB_PINS RemoveRow( int aRow )
|
|
|
|
{
|
|
|
|
LIB_PINS removedRow = m_rows[ aRow ];
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_rows.erase( m_rows.begin() + aRow );
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
return removedRow;
|
|
|
|
}
|
|
|
|
};
|
2015-03-27 10:26:07 +00:00
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( wxWindow* parent, LIB_PART* aPart ) :
|
|
|
|
DIALOG_LIB_EDIT_PIN_TABLE_BASE( parent ),
|
|
|
|
m_part( aPart )
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
m_config = Kiface().KifaceSettings();
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( g_typeNames.empty())
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < PINTYPE_COUNT; ++i )
|
|
|
|
g_typeIcons.push_back( GetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
|
|
|
|
for( unsigned i = 0; i < PINTYPE_COUNT; ++i )
|
|
|
|
g_typeNames.push_back( GetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
|
2018-03-07 12:48:08 +00:00
|
|
|
g_typeNames.push_back( INDETERMINATE );
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < PINSHAPE_COUNT; ++i )
|
|
|
|
g_shapeIcons.push_back( GetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
|
|
|
|
for( unsigned i = 0; i < PINSHAPE_COUNT; ++i )
|
|
|
|
g_shapeNames.push_back( GetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
|
2018-03-07 12:48:08 +00:00
|
|
|
g_shapeNames.push_back( INDETERMINATE );
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < LIB_PIN::GetOrientationNames().size(); ++i )
|
|
|
|
g_orientationIcons.push_back( LIB_PIN::GetOrientationSymbols()[ i ] );
|
|
|
|
g_orientationNames = LIB_PIN::GetOrientationNames();
|
2018-03-07 12:48:08 +00:00
|
|
|
g_orientationNames.push_back( INDETERMINATE );
|
2018-02-08 12:16:07 +00:00
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_dataModel = new PIN_TABLE_DATA_MODEL( GetUserUnits() );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
// Save original columns widths so we can do proportional sizing.
|
|
|
|
for( int i = 0; i < COL_COUNT; ++i )
|
|
|
|
m_originalColWidths[ i ] = m_grid->GetColSize( i );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
m_grid->SetTable( m_dataModel );
|
2018-02-08 12:16:07 +00:00
|
|
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
// Show/hide columns according to the user's preference
|
|
|
|
m_config->Read( PinTableShownColumnsKey, &m_columnsShown, wxT( "0 1 2 3 4 8 9" ) );
|
2018-05-30 10:52:19 +00:00
|
|
|
m_grid->ShowHideColumns( m_columnsShown );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
// Set special attributes
|
|
|
|
wxGridCellAttr* attr;
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( g_typeIcons, g_typeNames ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( g_typeIcons, g_typeNames ) );
|
|
|
|
m_grid->SetColAttr( COL_TYPE, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( g_shapeIcons, g_shapeNames ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( g_shapeIcons, g_shapeNames ) );
|
|
|
|
m_grid->SetColAttr( COL_SHAPE, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( g_orientationIcons, g_orientationNames ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( g_orientationIcons, g_orientationNames ) );
|
|
|
|
m_grid->SetColAttr( COL_ORIENTATION, attr );
|
|
|
|
|
|
|
|
/* Right-aligned position values look much better, but only MSW and GTK2+
|
|
|
|
* currently support righ-aligned textEditCtrls, so the text jumps on all
|
|
|
|
* the other platforms when you edit it.
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetAlignment( wxALIGN_RIGHT, wxALIGN_TOP );
|
|
|
|
m_grid->SetColAttr( COL_POSX, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetAlignment( wxALIGN_RIGHT, wxALIGN_TOP );
|
|
|
|
m_grid->SetColAttr( COL_POSY, attr );
|
|
|
|
*/
|
|
|
|
|
|
|
|
m_addButton->SetBitmap( KiBitmap( small_plus_xpm ) );
|
|
|
|
m_deleteButton->SetBitmap( KiBitmap( trash_xpm ) );
|
|
|
|
m_refreshButton->SetBitmap( KiBitmap( refresh_xpm ) );
|
|
|
|
|
|
|
|
GetSizer()->SetSizeHints(this);
|
|
|
|
Centre();
|
|
|
|
|
|
|
|
m_ButtonsOK->SetDefault();
|
|
|
|
m_initialized = true;
|
|
|
|
|
|
|
|
// Connect Events
|
|
|
|
m_grid->Connect( wxEVT_GRID_COL_SORT, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE::OnColSort ), nullptr, this );
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE()
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-05-30 10:52:19 +00:00
|
|
|
m_config->Write( PinTableShownColumnsKey, m_grid->GetShownColumns() );
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
// Disconnect Events
|
|
|
|
m_grid->Disconnect( wxEVT_GRID_COL_SORT, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE::OnColSort ), nullptr, this );
|
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
2018-05-30 10:52:19 +00:00
|
|
|
m_grid->DestroyTable( m_dataModel );
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
|
|
|
|
|
|
|
// This is our copy of the pins. If they were transfered to the part on an OK, then
|
|
|
|
// m_pins will already be empty.
|
|
|
|
for( auto pin : m_pins )
|
|
|
|
delete pin;
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataToWindow()
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
// Make a copy of the pins for editing
|
|
|
|
for( LIB_PIN* pin = m_part->GetNextPin( nullptr ); pin; pin = m_part->GetNextPin( pin ) )
|
|
|
|
m_pins.push_back( new LIB_PIN( *pin ) );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue() );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
updateSummary();
|
|
|
|
|
|
|
|
return true;
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataFromWindow()
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
// Delete the part's pins
|
|
|
|
while( LIB_PIN* pin = m_part->GetNextPin( nullptr ) )
|
|
|
|
m_part->RemoveDrawItem( pin );
|
|
|
|
|
|
|
|
// Transfer our pins to the part
|
|
|
|
for( LIB_PIN* pin : m_pins )
|
|
|
|
{
|
|
|
|
pin->SetParent( m_part );
|
|
|
|
m_part->AddDrawItem( pin );
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_pins.clear();
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
return true;
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnColSort( wxGridEvent& aEvent )
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
int sortCol = aEvent.GetCol();
|
|
|
|
bool ascending;
|
|
|
|
|
|
|
|
// This is bonkers, but wxWidgets doesn't tell us ascending/descending in the
|
|
|
|
// event, and if we ask it will give us pre-event info.
|
|
|
|
if( m_grid->IsSortingBy( sortCol ) )
|
|
|
|
// same column; invert ascending
|
|
|
|
ascending = !m_grid->IsSortOrderAscending();
|
2016-01-15 02:26:42 +00:00
|
|
|
else
|
2018-02-08 12:16:07 +00:00
|
|
|
// different column; start with ascending
|
|
|
|
ascending = true;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_dataModel->SortRows( sortCol, ascending );
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow( wxCommandEvent& event )
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_pins.push_back( new LIB_PIN( nullptr ) );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_dataModel->AppendRow( m_pins[ m_pins.size() - 1 ] );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_grid->MakeCellVisible( m_grid->GetNumberRows() - 1, 0 );
|
|
|
|
m_grid->SetGridCursor( m_grid->GetNumberRows() - 1, 0 );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_grid->EnableCellEditControl( true );
|
|
|
|
m_grid->ShowCellEditControl();
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
updateSummary();
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow( wxCommandEvent& event )
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
int curRow = m_grid->GetGridCursorRow();
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( curRow < 0 )
|
|
|
|
return;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
LIB_PINS removedRow = m_dataModel->RemoveRow( curRow );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
for( auto pin : removedRow )
|
|
|
|
m_pins.erase( std::find( m_pins.begin(), m_pins.end(), pin ) );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
curRow = std::max( 0, curRow - 1 );
|
|
|
|
m_grid->MakeCellVisible( curRow, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->SetGridCursor( curRow, m_grid->GetGridCursorCol() );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
updateSummary();
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnCellEdited( wxGridEvent& event )
|
2016-01-13 19:17:54 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
updateSummary();
|
2016-01-13 19:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnRebuildRows( wxCommandEvent& )
|
2016-01-15 02:21:26 +00:00
|
|
|
{
|
2018-08-19 16:10:14 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue() );
|
2016-01-15 02:21:26 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
adjustGridColumns( m_grid->GetRect().GetWidth() );
|
2016-01-15 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::adjustGridColumns( int aWidth )
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
// Account for scroll bars
|
|
|
|
aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope;
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
// The Number and Name columns must be at least wide enough to hold their contents, but
|
|
|
|
// no less wide than their original widths.
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_grid->AutoSizeColumn( COL_NUMBER );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( m_grid->GetColSize( COL_NUMBER ) < m_originalColWidths[ COL_NUMBER ] )
|
|
|
|
m_grid->SetColSize( COL_NUMBER, m_originalColWidths[ COL_NUMBER ] );
|
2016-01-15 02:21:26 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_grid->AutoSizeColumn( COL_NAME );
|
2016-01-15 02:21:26 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( m_grid->GetColSize( COL_NAME ) < m_originalColWidths[ COL_NAME ] )
|
|
|
|
m_grid->SetColSize( COL_NAME, m_originalColWidths[ COL_NAME ] );
|
2016-01-15 02:21:26 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
// If the grid is still wider than the columns, then stretch the Number and Name columns
|
|
|
|
// to fit.
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
for( int i = 0; i < COL_COUNT; ++i )
|
|
|
|
aWidth -= m_grid->GetColSize( i );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( aWidth > 0 )
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
m_grid->SetColSize( COL_NUMBER, m_grid->GetColSize( COL_NUMBER ) + aWidth / 2 );
|
|
|
|
m_grid->SetColSize( COL_NAME, m_grid->GetColSize( COL_NAME ) + aWidth / 2 );
|
|
|
|
}
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnSize( wxSizeEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized )
|
|
|
|
adjustGridColumns( event.GetSize().GetX() );
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
event.Skip();
|
2015-03-27 10:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
|
2016-01-15 02:21:26 +00:00
|
|
|
{
|
2018-05-30 10:52:19 +00:00
|
|
|
wxString columnsShown = m_grid->GetShownColumns();
|
2018-02-08 12:16:07 +00:00
|
|
|
|
|
|
|
if( columnsShown != m_columnsShown )
|
2016-02-28 17:33:29 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
m_columnsShown = columnsShown;
|
2016-02-28 17:33:29 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
if( !m_grid->IsCellEditControlShown() )
|
|
|
|
adjustGridColumns( m_grid->GetRect().GetWidth() );
|
2016-02-28 17:33:29 +00:00
|
|
|
}
|
2016-01-15 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
void DIALOG_LIB_EDIT_PIN_TABLE::updateSummary()
|
2015-03-27 10:26:07 +00:00
|
|
|
{
|
2018-02-08 12:16:07 +00:00
|
|
|
PinNumbers pinNumbers;
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
for( LIB_PIN* pin : m_pins )
|
|
|
|
{
|
|
|
|
if( pin->GetNumber().Length() )
|
|
|
|
pinNumbers.insert( pin->GetNumber() );
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2018-02-08 12:16:07 +00:00
|
|
|
m_summary->SetLabel( pinNumbers.GetSummary() );
|
|
|
|
}
|
2015-03-27 10:26:07 +00:00
|
|
|
|
|
|
|
|
2015-03-28 16:25:34 +00:00
|
|
|
|
2016-01-15 02:21:26 +00:00
|
|
|
|