2014-10-21 15:48:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2020-07-29 15:03:40 +00:00
|
|
|
* Copyright (C) 2016 - 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-21 15:48:00 +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
|
|
|
|
*/
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-10-18 12:25:46 +00:00
|
|
|
#include <sch_painter.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2012-09-22 11:19:37 +00:00
|
|
|
#include <lib_pin.h>
|
2020-08-03 21:12:29 +00:00
|
|
|
#include <dialog_pin_properties.h>
|
2018-05-23 17:41:37 +00:00
|
|
|
#include <confirm.h>
|
2019-08-22 09:53:50 +00:00
|
|
|
#include <widgets/tab_traversal.h>
|
2020-08-21 15:54:24 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
|
|
|
#include <grid_tricks.h>
|
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
|
|
|
|
|
|
|
class ALT_PIN_DATA_MODEL : public wxGridTableBase, public std::vector<LIB_PIN::ALT>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ALT_PIN_DATA_MODEL( EDA_UNITS aUserUnits )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetNumberRows() override { return (int) size(); }
|
|
|
|
int GetNumberCols() override { return COL_COUNT; }
|
|
|
|
|
|
|
|
wxString GetColLabelValue( int aCol ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NAME: return _( "Alternate Pin Name" );
|
|
|
|
case COL_TYPE: return _( "Electrical Type" );
|
|
|
|
case COL_SHAPE: return _( "Graphic Style" );
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmptyCell( int row, int col ) override
|
|
|
|
{
|
|
|
|
return false; // don't allow adjacent cell overflow, even if we are actually empty
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetValue( int aRow, int aCol ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NAME: return at( aRow ).m_Name;
|
|
|
|
case COL_TYPE: return PinTypeNames()[static_cast<int>( at( aRow ).m_Type )];
|
|
|
|
case COL_SHAPE: return PinShapeNames()[static_cast<int>( at( aRow ).m_Shape )];
|
|
|
|
default: wxFAIL; return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetValue( int aRow, int aCol, const wxString &aValue ) override
|
|
|
|
{
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case COL_NAME:
|
|
|
|
at( aRow ).m_Name = aValue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_TYPE:
|
|
|
|
if( PinTypeNames().Index( aValue ) != wxNOT_FOUND )
|
|
|
|
at( aRow ).m_Type = (ELECTRICAL_PINTYPE) PinTypeNames().Index( aValue );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COL_SHAPE:
|
|
|
|
if( PinShapeNames().Index( aValue ) != wxNOT_FOUND )
|
|
|
|
at( aRow ).m_Shape = (GRAPHIC_PINSHAPE) PinShapeNames().Index( aValue );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendRow( const LIB_PIN::ALT& aAlt )
|
|
|
|
{
|
|
|
|
push_back( aAlt );
|
|
|
|
|
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveRow( int aRow )
|
|
|
|
{
|
|
|
|
erase( begin() + aRow );
|
|
|
|
|
|
|
|
if ( GetView() )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
|
|
|
|
GetView()->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, LIB_PIN* aPin ) :
|
2020-08-03 21:12:29 +00:00
|
|
|
DIALOG_PIN_PROPERTIES_BASE( parent ),
|
2018-05-23 17:41:37 +00:00
|
|
|
m_frame( parent ),
|
|
|
|
m_pin( aPin ),
|
2021-03-12 15:12:49 +00:00
|
|
|
m_posX( parent, m_posXLabel, m_posXCtrl, m_posXUnits ),
|
|
|
|
m_posY( parent, m_posYLabel, m_posYCtrl, m_posYUnits ),
|
|
|
|
m_pinLength( parent, m_pinLengthLabel, m_pinLengthCtrl, m_pinLengthUnits ),
|
|
|
|
m_nameSize( parent, m_nameSizeLabel, m_nameSizeCtrl, m_nameSizeUnits ),
|
|
|
|
m_numberSize( parent, m_numberSizeLabel, m_numberSizeCtrl, m_numberSizeUnits ),
|
2020-08-21 15:54:24 +00:00
|
|
|
m_delayedFocusRow( -1 ),
|
|
|
|
m_delayedFocusColumn( -1 ),
|
|
|
|
m_initialized( false )
|
2012-09-22 11:19:37 +00:00
|
|
|
{
|
|
|
|
// Creates a dummy pin to show on a panel, inside this dialog:
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin = new LIB_PIN( *m_pin );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2021-08-14 08:15:18 +00:00
|
|
|
m_bSizerInfo->Show( m_frame->m_SyncPinEdit );
|
|
|
|
|
|
|
|
if( m_frame->m_SyncPinEdit )
|
|
|
|
{
|
|
|
|
if( aPin->IsNew() )
|
|
|
|
{
|
|
|
|
m_textInfoUpper->SetLabel( _( "Synchronized pins edit mode, and this pin is new" ) );
|
|
|
|
m_textInfoLower->SetLabel( _( "Similar pins will be automatically added to other units, "
|
|
|
|
"if this pin is not common to all units" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_textInfoUpper->SetLabel( _( "Synchronized pins edit mode" ) );
|
|
|
|
m_textInfoLower->SetLabel( _( "Similar pins at the same location will be edited. "
|
|
|
|
"Pin number of other pins will be not modified" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:25:46 +00:00
|
|
|
COLOR4D bgColor = parent->GetRenderSettings()->GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
|
|
|
|
m_panelShowPin->SetBackgroundColour( bgColor.ToColour() );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
const wxArrayString& orientationNames = PinOrientationNames();
|
2021-03-08 02:59:07 +00:00
|
|
|
const std::vector<BITMAPS>& orientationIcons = PinOrientationIcons();
|
2018-05-23 17:41:37 +00:00
|
|
|
|
|
|
|
for ( unsigned ii = 0; ii < orientationNames.GetCount(); ii++ )
|
2020-08-21 15:54:24 +00:00
|
|
|
m_choiceOrientation->Insert( orientationNames[ii], KiBitmap( orientationIcons[ii] ), ii );
|
2018-05-23 17:41:37 +00:00
|
|
|
|
2019-08-24 16:12:59 +00:00
|
|
|
// We can't set the tab order through wxWidgets due to shortcomings in their mnemonics
|
|
|
|
// implementation on MSW
|
2019-08-26 17:36:35 +00:00
|
|
|
m_tabOrder = {
|
2019-08-22 09:53:50 +00:00
|
|
|
m_textPinName,
|
|
|
|
m_textPinNumber,
|
|
|
|
m_choiceElectricalType,
|
|
|
|
m_choiceStyle,
|
|
|
|
m_posXCtrl,
|
|
|
|
m_posYCtrl,
|
|
|
|
m_choiceOrientation,
|
|
|
|
m_pinLengthCtrl,
|
|
|
|
m_nameSizeCtrl,
|
2019-08-23 21:14:12 +00:00
|
|
|
m_numberSizeCtrl,
|
|
|
|
m_checkApplyToAllParts,
|
|
|
|
m_checkApplyToAllConversions,
|
2019-08-24 16:12:59 +00:00
|
|
|
m_checkShow,
|
2019-08-26 17:36:35 +00:00
|
|
|
m_sdbSizerButtonsOK,
|
|
|
|
m_sdbSizerButtonsCancel
|
2019-08-22 20:16:40 +00:00
|
|
|
};
|
2019-08-22 09:53:50 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
// Default alternates turndow to whether or not alternates exist
|
|
|
|
m_alternatesTurndown->Collapse( m_pin->GetAlternates().size() == 0 );
|
|
|
|
|
|
|
|
m_alternatesDataModel = new ALT_PIN_DATA_MODEL( GetUserUnits() );
|
|
|
|
|
|
|
|
// Save original columns widths so we can do proportional sizing.
|
|
|
|
for( int i = 0; i < COL_COUNT; ++i )
|
|
|
|
m_originalColWidths[ i ] = m_alternatesGrid->GetColSize( i );
|
|
|
|
|
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_alternatesGrid->SetDefaultRowSize( m_alternatesGrid->GetDefaultRowSize() + 4 );
|
|
|
|
|
|
|
|
m_alternatesGrid->SetTable( m_alternatesDataModel );
|
|
|
|
m_alternatesGrid->PushEventHandler( new GRID_TRICKS( m_alternatesGrid ) );
|
|
|
|
|
2021-01-04 23:56:50 +00:00
|
|
|
if( aPin->GetParent()->HasConversion() )
|
|
|
|
{
|
|
|
|
m_alternatesTurndown->Collapse();
|
|
|
|
m_alternatesTurndown->Disable();
|
|
|
|
m_alternatesTurndown->SetToolTip(
|
2021-06-14 18:00:08 +00:00
|
|
|
_( "Alternate pin assignments are not available for DeMorgan symbols." ) );
|
2021-01-04 23:56:50 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
// Set special attributes
|
|
|
|
wxGridCellAttr* attr;
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( PinTypeIcons(), PinTypeNames() ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( PinTypeIcons(), PinTypeNames() ) );
|
|
|
|
m_alternatesGrid->SetColAttr( COL_TYPE, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_ICON_TEXT_RENDERER( PinShapeIcons(), PinShapeNames() ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( PinShapeIcons(), PinShapeNames() ) );
|
|
|
|
m_alternatesGrid->SetColAttr( COL_SHAPE, attr );
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
m_addAlternate->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
|
|
|
|
m_deleteAlternate->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
2020-08-21 15:54:24 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
m_sdbSizerButtonsOK->SetDefault();
|
2018-05-23 17:41:37 +00:00
|
|
|
SetInitialFocus( m_textPinName );
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2015-03-14 11:50:39 +00:00
|
|
|
|
2019-08-24 16:12:59 +00:00
|
|
|
// On some window managers (Unity, XFCE) the dialog is not always raised, depending on
|
2021-06-09 19:32:58 +00:00
|
|
|
// how it is run.
|
2015-03-14 16:47:25 +00:00
|
|
|
Raise();
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
m_initialized = true;
|
|
|
|
m_width = 0;
|
2012-09-22 11:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
DIALOG_PIN_PROPERTIES::~DIALOG_PIN_PROPERTIES()
|
2012-09-22 11:19:37 +00:00
|
|
|
{
|
|
|
|
delete m_dummyPin;
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
|
|
|
m_alternatesGrid->DestroyTable( m_alternatesDataModel );
|
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_alternatesGrid->PopEventHandler( true );
|
2012-09-22 11:19:37 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
bool DIALOG_PIN_PROPERTIES::TransferDataToWindow()
|
2015-09-13 22:43:38 +00:00
|
|
|
{
|
2018-05-23 17:41:37 +00:00
|
|
|
if( !DIALOG_SHIM::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
2020-07-03 01:11:21 +00:00
|
|
|
m_origPos = m_pin->GetPosition();
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
m_choiceOrientation->SetSelection( PinOrientationIndex( m_pin->GetOrientation() ) );
|
2018-05-23 17:41:37 +00:00
|
|
|
m_choiceStyle->SetSelection( m_pin->GetShape() );
|
|
|
|
m_choiceElectricalType->SetSelection( m_pin->GetType() );
|
|
|
|
m_textPinName->SetValue( m_pin->GetName() );
|
|
|
|
m_nameSize.SetValue( m_pin->GetNameTextSize() );
|
2020-07-03 01:11:21 +00:00
|
|
|
m_posX.SetValue( m_origPos.x );
|
|
|
|
m_posY.SetValue( -m_origPos.y );
|
2018-05-23 17:41:37 +00:00
|
|
|
m_textPinNumber->SetValue( m_pin->GetNumber() );
|
|
|
|
m_numberSize.SetValue( m_pin->GetNumberTextSize() );
|
|
|
|
m_pinLength.SetValue( m_pin->GetLength() );
|
|
|
|
m_checkApplyToAllParts->SetValue( m_pin->GetUnit() == 0 );
|
|
|
|
m_checkApplyToAllConversions->SetValue( m_pin->GetConvert() == 0 );
|
|
|
|
m_checkShow->SetValue( m_pin->IsVisible() );
|
|
|
|
|
2019-02-15 23:59:37 +00:00
|
|
|
m_dummyPin->SetVisible( m_pin->IsVisible() );
|
|
|
|
|
2021-08-13 01:19:27 +00:00
|
|
|
bool hasMultiUnit = m_pin->GetParent()->GetUnitCount() > 1;
|
|
|
|
|
2021-08-14 08:15:18 +00:00
|
|
|
m_checkApplyToAllParts->Enable( hasMultiUnit );
|
2021-08-13 01:19:27 +00:00
|
|
|
|
|
|
|
wxString toolTip;
|
|
|
|
|
|
|
|
if( !hasMultiUnit )
|
|
|
|
toolTip = _( "This symbol only has one unit. This control has no effect." );
|
|
|
|
else if( m_frame->m_SyncPinEdit )
|
2021-08-14 08:15:18 +00:00
|
|
|
toolTip = _( "Synchronized pin edit mode is enabled.\n"
|
|
|
|
"Similar pins will be edited, regardless this option." );
|
|
|
|
else
|
|
|
|
toolTip = _( "If checked, this pin will exist in all units." );
|
2021-08-13 01:19:27 +00:00
|
|
|
|
|
|
|
m_checkApplyToAllParts->SetToolTip( toolTip );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
for( const std::pair<const wxString, LIB_PIN::ALT>& alt : m_pin->GetAlternates() )
|
|
|
|
m_alternatesDataModel->AppendRow( alt.second );
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-07-16 10:54:55 +00:00
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
bool DIALOG_PIN_PROPERTIES::TransferDataFromWindow()
|
2018-05-23 17:41:37 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
if( !m_alternatesGrid->CommitPendingChanges() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check for missing alternate names.
|
|
|
|
for( size_t i = 0; i < m_alternatesDataModel->size(); ++i )
|
|
|
|
{
|
|
|
|
if( m_alternatesDataModel->at( i ).m_Name.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "Alternate pin definitions must have a name." ) );
|
|
|
|
|
|
|
|
m_delayedFocusColumn = COL_NAME;
|
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
if( !DIALOG_SHIM::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2020-07-03 01:11:21 +00:00
|
|
|
wxPoint newPos( m_posX.GetValue(), -m_posY.GetValue() );
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
const int acceptable_mingrid = 50;
|
|
|
|
|
2020-07-03 01:11:21 +00:00
|
|
|
// Only show the warning if the position has been changed
|
|
|
|
if( ( m_origPos != newPos )
|
|
|
|
&& ( ( m_posX.GetValue() % acceptable_mingrid ) || ( m_posY.GetValue() % acceptable_mingrid ) ) )
|
2018-05-23 17:41:37 +00:00
|
|
|
{
|
|
|
|
auto msg = wxString::Format( _( "This pin is not on a %d mils grid which will make it\n"
|
|
|
|
"difficult to connect to in the schematic.\n"
|
|
|
|
"Do you want to continue?" ),
|
|
|
|
acceptable_mingrid );
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pin->SetName( m_textPinName->GetValue() );
|
|
|
|
m_pin->SetNumber( m_textPinNumber->GetValue() );
|
|
|
|
m_pin->SetNameTextSize( m_nameSize.GetValue() );
|
|
|
|
m_pin->SetNumberTextSize( m_numberSize.GetValue() );
|
2020-08-21 15:54:24 +00:00
|
|
|
m_pin->SetOrientation( PinOrientationCode( m_choiceOrientation->GetSelection() ) );
|
2018-05-23 17:41:37 +00:00
|
|
|
m_pin->SetLength( m_pinLength.GetValue() );
|
2020-08-03 21:12:29 +00:00
|
|
|
m_pin->SetPosition( newPos );
|
2018-05-23 17:41:37 +00:00
|
|
|
m_pin->SetType( m_choiceElectricalType->GetPinTypeSelection() );
|
|
|
|
m_pin->SetShape( m_choiceStyle->GetPinShapeSelection() );
|
2020-08-03 21:12:29 +00:00
|
|
|
m_pin->SetConvert( m_checkApplyToAllConversions->GetValue() ? 0 : m_frame->GetConvert() );
|
|
|
|
m_pin->SetUnit( m_checkApplyToAllParts->GetValue() ? 0 : m_frame->GetUnit() );
|
2018-05-23 17:41:37 +00:00
|
|
|
m_pin->SetVisible( m_checkShow->GetValue() );
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
std::map<wxString, LIB_PIN::ALT>& alternates = m_pin->GetAlternates();
|
|
|
|
alternates.clear();
|
|
|
|
|
|
|
|
for( const LIB_PIN::ALT& alt : *m_alternatesDataModel )
|
|
|
|
alternates[ alt.m_Name ] = alt;
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
return true;
|
2015-09-13 22:43:38 +00:00
|
|
|
}
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
/*
|
2019-08-20 17:22:30 +00:00
|
|
|
* Draw (on m_panelShowPin) the pin according to current settings in dialog
|
2012-09-22 11:19:37 +00:00
|
|
|
*/
|
2020-08-03 21:12:29 +00:00
|
|
|
void DIALOG_PIN_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event )
|
2012-09-22 11:19:37 +00:00
|
|
|
{
|
2019-07-16 00:29:25 +00:00
|
|
|
wxPaintDC dc( m_panelShowPin );
|
|
|
|
wxSize dc_size = dc.GetSize();
|
2012-09-22 11:19:37 +00:00
|
|
|
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
|
|
|
|
|
|
// Give a parent to m_dummyPin only from draw purpose.
|
|
|
|
// In fact m_dummyPin should not have a parent, but draw functions need a parent
|
|
|
|
// to know some options, about pin texts
|
2020-10-31 01:27:16 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbolEditor = (SYMBOL_EDIT_FRAME*) GetParent();
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
// Calculate a suitable scale to fit the available draw area
|
2019-02-15 23:59:37 +00:00
|
|
|
EDA_RECT bBox = m_dummyPin->GetBoundingBox( true );
|
2019-07-16 00:29:25 +00:00
|
|
|
double xscale = (double) dc_size.x / bBox.GetWidth();
|
|
|
|
double yscale = (double) dc_size.y / bBox.GetHeight();
|
|
|
|
double scale = std::min( xscale, yscale );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
2019-07-16 00:29:25 +00:00
|
|
|
// Give a 10% margin and limit to no more than 100% zoom
|
|
|
|
scale = std::min( scale * 0.9, 1.0 );
|
2012-09-22 11:19:37 +00:00
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
GRResetPenAndBrush( &dc );
|
2016-05-19 16:38:36 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL_OPTIONS opts;
|
2019-07-16 00:29:25 +00:00
|
|
|
opts.draw_hidden_fields = true;
|
2021-05-27 18:44:06 +00:00
|
|
|
opts.show_connect_point = true;
|
2019-07-16 00:29:25 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
RENDER_SETTINGS* renderSettings = symbolEditor->GetRenderSettings();
|
2020-04-14 12:25:00 +00:00
|
|
|
renderSettings->SetPrintDC( &dc );
|
|
|
|
|
|
|
|
m_dummyPin->Print( renderSettings, -bBox.Centre(), (void*) &opts, DefaultTransform );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
void DIALOG_PIN_PROPERTIES::OnPropertiesChange( wxCommandEvent& event )
|
2012-09-22 11:19:37 +00:00
|
|
|
{
|
2018-05-23 17:41:37 +00:00
|
|
|
if( !IsShown() ) // do nothing at init time
|
2012-09-22 11:19:37 +00:00
|
|
|
return;
|
|
|
|
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin->SetName( m_textPinName->GetValue() );
|
|
|
|
m_dummyPin->SetNumber( m_textPinNumber->GetValue() );
|
|
|
|
m_dummyPin->SetNameTextSize( m_nameSize.GetValue() );
|
|
|
|
m_dummyPin->SetNumberTextSize( m_numberSize.GetValue() );
|
2020-08-21 15:54:24 +00:00
|
|
|
m_dummyPin->SetOrientation( PinOrientationCode( m_choiceOrientation->GetSelection() ) );
|
2018-05-23 17:41:37 +00:00
|
|
|
m_dummyPin->SetLength( m_pinLength.GetValue() );
|
|
|
|
m_dummyPin->SetType( m_choiceElectricalType->GetPinTypeSelection() );
|
|
|
|
m_dummyPin->SetShape( m_choiceStyle->GetPinShapeSelection() );
|
|
|
|
m_dummyPin->SetVisible( m_checkShow->GetValue() );
|
2012-09-22 11:19:37 +00:00
|
|
|
|
|
|
|
m_panelShowPin->Refresh();
|
|
|
|
}
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PIN_PROPERTIES::OnAddAlternate( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( !m_alternatesGrid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIB_PIN::ALT newAlt;
|
|
|
|
newAlt.m_Name = wxEmptyString;
|
|
|
|
newAlt.m_Type = m_pin->GetType();
|
|
|
|
newAlt.m_Shape = m_pin->GetShape();
|
|
|
|
|
|
|
|
m_alternatesDataModel->AppendRow( newAlt );
|
|
|
|
|
|
|
|
m_alternatesGrid->MakeCellVisible( m_alternatesGrid->GetNumberRows() - 1, 0 );
|
|
|
|
m_alternatesGrid->SetGridCursor( m_alternatesGrid->GetNumberRows() - 1, 0 );
|
|
|
|
|
|
|
|
m_alternatesGrid->EnableCellEditControl( true );
|
|
|
|
m_alternatesGrid->ShowCellEditControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PIN_PROPERTIES::OnDeleteAlternate( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( !m_alternatesGrid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_alternatesDataModel->size() == 0 ) // empty table
|
|
|
|
return;
|
|
|
|
|
|
|
|
int curRow = m_alternatesGrid->GetGridCursorRow();
|
|
|
|
|
|
|
|
if( curRow < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_alternatesDataModel->RemoveRow( curRow );
|
|
|
|
|
|
|
|
curRow = std::max( 0, curRow - 1 );
|
|
|
|
m_alternatesGrid->MakeCellVisible( curRow, m_alternatesGrid->GetGridCursorCol() );
|
|
|
|
m_alternatesGrid->SetGridCursor( curRow, m_alternatesGrid->GetGridCursorCol() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PIN_PROPERTIES::adjustGridColumns( int aWidth )
|
|
|
|
{
|
|
|
|
m_width = aWidth;
|
|
|
|
|
|
|
|
// Account for margins
|
|
|
|
aWidth -= 30;
|
|
|
|
|
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope;
|
|
|
|
|
|
|
|
m_alternatesGrid->SetColSize( COL_TYPE, m_originalColWidths[ COL_TYPE ] );
|
|
|
|
m_alternatesGrid->SetColSize( COL_SHAPE, m_originalColWidths[ COL_SHAPE ] );
|
|
|
|
|
|
|
|
m_alternatesGrid->SetColSize( COL_NAME, aWidth - m_originalColWidths[ COL_TYPE ]
|
|
|
|
- m_originalColWidths[ COL_SHAPE ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PIN_PROPERTIES::OnSize( wxSizeEvent& event )
|
|
|
|
{
|
|
|
|
auto new_size = event.GetSize().GetX();
|
|
|
|
|
|
|
|
if( m_initialized && m_width != new_size )
|
|
|
|
adjustGridColumns( new_size );
|
|
|
|
|
|
|
|
// Always propagate for a grid repaint (needed if the height changes, as well as width)
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_PIN_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
// Handle a delayed focus
|
|
|
|
if( m_delayedFocusRow >= 0 )
|
|
|
|
{
|
|
|
|
m_alternatesTurndown->Collapse( false );
|
|
|
|
|
|
|
|
m_alternatesGrid->SetFocus();
|
|
|
|
m_alternatesGrid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
m_alternatesGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
|
|
|
|
m_alternatesGrid->EnableCellEditControl( true );
|
|
|
|
m_alternatesGrid->ShowCellEditControl();
|
|
|
|
|
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-14 08:15:18 +00:00
|
|
|
void DIALOG_PIN_PROPERTIES::onUpdateUIInfo( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
// Disable Info texts for pins common to all units
|
|
|
|
event.Enable( m_checkApplyToAllParts->GetValue() == 0 );
|
|
|
|
}
|