2013-06-07 09:49:36 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-06-09 21:41:33 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-06-07 09:49:36 +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
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <bitmaps.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <kiway.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2022-09-16 03:06:23 +00:00
|
|
|
#include <lib_symbol_library_manager.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2021-12-16 14:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <widgets/grid_text_button_helpers.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <dialog_sim_model.h>
|
2019-01-10 05:42:14 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
#include <dialog_lib_symbol_properties.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_editor_settings.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
int DIALOG_LIB_SYMBOL_PROPERTIES::m_lastOpenedPage = 0;
|
2023-11-14 01:13:29 +00:00
|
|
|
DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT DIALOG_LIB_SYMBOL_PROPERTIES::m_lastLayout =
|
|
|
|
DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT::NONE;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* aParent,
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* aLibEntry ) :
|
2020-10-22 09:40:54 +00:00
|
|
|
DIALOG_LIB_SYMBOL_PROPERTIES_BASE( aParent ),
|
2018-08-13 17:00:08 +00:00
|
|
|
m_Parent( aParent ),
|
|
|
|
m_libEntry( aLibEntry ),
|
|
|
|
m_pinNameOffset( aParent, m_nameOffsetLabel, m_nameOffsetCtrl, m_nameOffsetUnits, true ),
|
|
|
|
m_delayedFocusCtrl( nullptr ),
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusGrid( nullptr ),
|
2019-01-12 14:58:40 +00:00
|
|
|
m_delayedFocusRow( -1 ),
|
|
|
|
m_delayedFocusColumn( -1 ),
|
2021-12-17 04:00:24 +00:00
|
|
|
m_delayedFocusPage( -1 )
|
2010-11-18 21:10:52 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
2021-02-17 14:06:19 +00:00
|
|
|
m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, aParent, m_grid, m_libEntry );
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->SetTable( m_fields );
|
2023-03-02 17:50:39 +00:00
|
|
|
m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this,
|
|
|
|
[&]( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
OnAddField( aEvent );
|
|
|
|
} ) );
|
2021-12-12 17:27:40 +00:00
|
|
|
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
// Show/hide columns according to the user's preference
|
2021-06-06 22:36:31 +00:00
|
|
|
SYMBOL_EDITOR_SETTINGS* cfg = m_Parent->GetSettings();
|
2021-06-14 18:00:08 +00:00
|
|
|
m_grid->ShowHideColumns( cfg->m_EditSymbolVisibleColumns );
|
2019-03-18 15:44:44 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
2023-09-28 03:04:53 +00:00
|
|
|
attr->SetEditor( new GRID_CELL_URL_EDITOR( this, PROJECT_SCH::SchSearchS( &Prj() ) ) );
|
2020-11-12 21:31:41 +00:00
|
|
|
m_grid->SetAttr( DATASHEET_FIELD, FDC_VALUE, attr );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2023-06-13 15:06:30 +00:00
|
|
|
m_SymbolNameCtrl->SetValidator( FIELD_VALIDATOR( VALUE_FIELD ) );
|
2018-09-13 15:39:14 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// Configure button logos
|
2023-10-21 18:56:19 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_bpMoveUp->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
|
|
|
|
m_bpMoveDown->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
|
|
|
|
m_addFilterButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_deleteFilterButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_editFilterButton->SetBitmap( KiBitmapBundle( BITMAPS::small_edit ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
|
|
|
|
2021-07-16 19:03:17 +00:00
|
|
|
if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
|
2020-12-22 02:29:27 +00:00
|
|
|
{
|
|
|
|
m_stdSizerButtonCancel->SetDefault();
|
|
|
|
m_stdSizerButtonOK->SetLabel( _( "Read Only" ) );
|
|
|
|
m_stdSizerButtonOK->Enable( false );
|
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
// wxFormBuilder doesn't include this event...
|
2019-03-18 15:44:44 +00:00
|
|
|
m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
|
2020-10-22 09:40:54 +00:00
|
|
|
wxGridEventHandler( DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging ),
|
2021-07-16 20:13:26 +00:00
|
|
|
nullptr, this );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-11-14 01:13:29 +00:00
|
|
|
if( m_lastLayout != DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT::NONE )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2023-11-14 01:13:29 +00:00
|
|
|
if( ( m_lastLayout == DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT::ALIAS
|
|
|
|
&& aLibEntry->IsRoot() )
|
|
|
|
|| ( m_lastLayout == DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT::PARENT
|
|
|
|
&& aLibEntry->IsAlias() ) )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2020-11-16 11:16:44 +00:00
|
|
|
resetSize();
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-14 01:13:29 +00:00
|
|
|
m_lastLayout = ( aLibEntry->IsAlias() ) ? DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT::ALIAS
|
|
|
|
: DIALOG_LIB_SYMBOL_PROPERTIES::LAST_LAYOUT::PARENT;
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
m_grid->GetParent()->Layout();
|
2019-11-06 19:15:42 +00:00
|
|
|
syncControlStates( m_libEntry->IsAlias() );
|
2018-08-13 17:00:08 +00:00
|
|
|
Layout();
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2010-11-18 21:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
DIALOG_LIB_SYMBOL_PROPERTIES::~DIALOG_LIB_SYMBOL_PROPERTIES()
|
2010-11-18 21:10:52 +00:00
|
|
|
{
|
2013-06-07 09:49:36 +00:00
|
|
|
m_lastOpenedPage = m_NoteBook->GetSelection( );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2023-04-13 12:45:22 +00:00
|
|
|
if( SYMBOL_EDITOR_SETTINGS* cfg = m_Parent->GetSettings() )
|
|
|
|
cfg->m_EditSymbolVisibleColumns = m_grid->GetShownColumnsAsString();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
|
|
|
m_grid->DestroyTable( m_fields );
|
|
|
|
|
2019-03-18 15:44:44 +00:00
|
|
|
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
2020-10-22 09:40:54 +00:00
|
|
|
wxGridEventHandler( DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging ),
|
2021-07-16 20:13:26 +00:00
|
|
|
nullptr, this );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
2010-11-18 21:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow()
|
2010-11-18 21:10:52 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2020-04-01 14:00:40 +00:00
|
|
|
// Push a copy of each field into m_updateFields
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->GetFields( *m_fields );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// The Y axis for components in lib is from bottom to top while the screen axis is top
|
|
|
|
// to bottom: we must change the y coord sign for editing
|
|
|
|
for( size_t i = 0; i < m_fields->size(); ++i )
|
2010-11-18 21:10:52 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = m_fields->at( i ).GetPosition();
|
2018-08-13 17:00:08 +00:00
|
|
|
pos.y = -pos.y;
|
|
|
|
m_fields->at( i ).SetPosition( pos );
|
2010-11-18 21:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2021-12-16 14:39:58 +00:00
|
|
|
adjustGridColumns();
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
m_SymbolNameCtrl->ChangeValue( UnescapeString( m_libEntry->GetName() ) );
|
2018-01-22 17:59:44 +00:00
|
|
|
|
2021-04-09 16:10:40 +00:00
|
|
|
m_KeywordCtrl->ChangeValue( m_libEntry->GetKeyWords() );
|
2018-08-13 17:00:08 +00:00
|
|
|
m_SelNumberOfUnits->SetValue( m_libEntry->GetUnitCount() );
|
2021-07-16 20:13:26 +00:00
|
|
|
m_OptionPartsInterchangeable->SetValue( !m_libEntry->UnitsLocked() ||
|
|
|
|
m_libEntry->GetUnitCount() == 1 );
|
2022-03-24 18:30:53 +00:00
|
|
|
|
|
|
|
// If a symbol contains no conversion-specific pins or graphic items, symbol->HasConversion()
|
|
|
|
// will return false. But when editing a symbol with DeMorgan option set, we don't want to
|
|
|
|
// keep turning it off just because there aren't any conversion-specific items yet, so we force
|
|
|
|
// it to on if the parent frame has it enabled.
|
|
|
|
m_AsConvertButt->SetValue( m_Parent->GetShowDeMorgan() );
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_OptionPower->SetValue( m_libEntry->IsPower() );
|
2022-12-28 13:43:14 +00:00
|
|
|
|
2023-04-14 18:40:41 +00:00
|
|
|
if( m_libEntry->IsPower() )
|
|
|
|
m_spiceFieldsButton->Hide();
|
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludeFromSimCheckBox->SetValue( m_libEntry->GetExcludedFromSim() );
|
2023-07-30 06:42:33 +00:00
|
|
|
m_excludeFromBomCheckBox->SetValue( m_libEntry->GetExcludedFromBOM() );
|
|
|
|
m_excludeFromBoardCheckBox->SetValue( m_libEntry->GetExcludedFromBoard() );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_ShowPinNumButt->SetValue( m_libEntry->ShowPinNumbers() );
|
|
|
|
m_ShowPinNameButt->SetValue( m_libEntry->ShowPinNames() );
|
|
|
|
m_PinsNameInsideButt->SetValue( m_libEntry->GetPinNameOffset() != 0 );
|
2021-04-09 16:10:40 +00:00
|
|
|
m_pinNameOffset.ChangeValue( m_libEntry->GetPinNameOffset() );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2020-12-14 13:47:32 +00:00
|
|
|
wxArrayString tmp = m_libEntry->GetFPFilters();
|
2019-11-06 19:15:42 +00:00
|
|
|
m_FootprintFilterListBox->Append( tmp );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// Populate the list of root parts for inherited objects.
|
|
|
|
if( m_libEntry->IsAlias() )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
2023-08-20 16:05:31 +00:00
|
|
|
wxArrayString symbolNames;
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString libName = m_Parent->GetCurLib();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
// Someone forgot to set the current library in the editor frame window.
|
|
|
|
wxCHECK( !libName.empty(), false );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2023-08-20 16:05:31 +00:00
|
|
|
m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
|
|
|
|
|
|
|
|
// Do allow an inherited symbol to be derived from itself.
|
|
|
|
symbolNames.Remove( m_libEntry->GetName() );
|
|
|
|
m_inheritanceSelectCombo->Append( symbolNames );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL_SPTR rootSymbol = m_libEntry->GetParent().lock();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
wxCHECK( rootSymbol, false );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2021-06-30 10:53:04 +00:00
|
|
|
wxString parentName = UnescapeString( rootSymbol->GetName() );
|
2019-11-06 19:15:42 +00:00
|
|
|
int selection = m_inheritanceSelectCombo->FindString( parentName );
|
2013-06-07 09:49:36 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK( selection != wxNOT_FOUND, false );
|
|
|
|
m_inheritanceSelectCombo->SetSelection( selection );
|
|
|
|
|
|
|
|
m_lastOpenedPage = 0;
|
|
|
|
}
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_NoteBook->SetSelection( (unsigned) m_lastOpenedPage );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return true;
|
2010-11-18 21:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
bool DIALOG_LIB_SYMBOL_PROPERTIES::Validate()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-06-01 17:45:46 +00:00
|
|
|
// Alias symbol reference can be empty because it inherits from the parent symbol.
|
|
|
|
if( m_libEntry->IsRoot() &&
|
2021-06-10 14:10:55 +00:00
|
|
|
!SCH_SYMBOL::IsReferenceStringValid( m_fields->at( REFERENCE_FIELD ).GetText() ) )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
|
|
|
if( m_NoteBook->GetSelection() != 0 )
|
|
|
|
m_NoteBook->SetSelection( 0 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_delayedErrorMessage = _( "References must start with a letter." );
|
|
|
|
m_delayedFocusGrid = m_grid;
|
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
2020-11-12 21:31:41 +00:00
|
|
|
m_delayedFocusRow = REFERENCE_FIELD;
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusPage = 0;
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2010-11-18 21:10:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// Check for missing field names.
|
2022-12-28 13:43:14 +00:00
|
|
|
for( int ii = MANDATORY_FIELDS; ii < (int) m_fields->size(); ++ii )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
2022-12-28 13:43:14 +00:00
|
|
|
LIB_FIELD& field = m_fields->at( ii );
|
2018-08-13 17:00:08 +00:00
|
|
|
wxString fieldName = field.GetName( false );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2023-03-19 19:15:02 +00:00
|
|
|
if( fieldName.IsEmpty() && !field.GetText().IsEmpty() )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
|
|
|
if( m_NoteBook->GetSelection() != 0 )
|
|
|
|
m_NoteBook->SetSelection( 0 );
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_delayedErrorMessage = _( "Fields must have a name." );
|
|
|
|
m_delayedFocusGrid = m_grid;
|
|
|
|
m_delayedFocusColumn = FDC_NAME;
|
2022-12-28 13:43:14 +00:00
|
|
|
m_delayedFocusRow = ii;
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusPage = 0;
|
2015-04-07 11:52:29 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 11:52:29 +00:00
|
|
|
|
2020-07-20 03:17:08 +00:00
|
|
|
// Verify that the parent name is set if the symbol is inherited
|
|
|
|
if( m_libEntry->IsAlias() )
|
|
|
|
{
|
|
|
|
wxString parentName = m_inheritanceSelectCombo->GetValue();
|
|
|
|
|
|
|
|
if( parentName.IsEmpty() )
|
|
|
|
{
|
2022-11-16 17:09:59 +00:00
|
|
|
m_delayedErrorMessage = _( "Derived symbol must have a parent selected" );
|
2020-07-20 03:17:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-29 19:27:24 +00:00
|
|
|
/*
|
|
|
|
* Confirm destructive actions.
|
|
|
|
*/
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( m_SelNumberOfUnits->GetValue() < m_libEntry->GetUnitCount() )
|
|
|
|
{
|
|
|
|
if( !IsOK( this, _( "Delete extra units from symbol?" ) ) )
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-07 11:52:29 +00:00
|
|
|
|
2021-10-29 19:27:24 +00:00
|
|
|
if( !m_AsConvertButt->GetValue() && m_libEntry->HasConversion() )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
2021-10-29 19:27:24 +00:00
|
|
|
if( !IsOK( this, _( "Delete alternate body style (De Morgan) from symbol?" ) ) )
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2010-10-25 15:43:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2019-03-18 15:44:44 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2021-03-26 23:25:28 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return false;
|
|
|
|
|
2022-08-20 21:43:20 +00:00
|
|
|
wxString newName = EscapeString( m_SymbolNameCtrl->GetValue(), CTX_LIBID );
|
2019-12-16 15:11:06 +00:00
|
|
|
wxString oldName = m_libEntry->GetName();
|
|
|
|
|
2023-11-01 02:11:46 +00:00
|
|
|
if( newName.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "Symbol must have a name." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:11:06 +00:00
|
|
|
if( oldName != newName )
|
|
|
|
{
|
|
|
|
wxString libName = m_Parent->GetCurLib();
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( m_Parent->GetLibManager().SymbolExists( newName, libName ) )
|
2019-12-16 15:11:06 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2022-04-21 10:57:15 +00:00
|
|
|
msg.Printf( _( "Symbol name '%s' already in use in library '%s'." ),
|
2021-06-30 10:53:04 +00:00
|
|
|
UnescapeString( newName ),
|
|
|
|
libName );
|
2019-12-16 15:11:06 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-22 21:30:36 +00:00
|
|
|
|
2023-06-09 21:41:33 +00:00
|
|
|
m_Parent->SaveCopyInUndoList( _( "Edit Symbol Properties" ), m_libEntry,
|
|
|
|
UNDO_REDO::LIB_RENAME );
|
2019-12-16 15:11:06 +00:00
|
|
|
}
|
2019-05-11 14:38:05 +00:00
|
|
|
else
|
2019-12-16 15:11:06 +00:00
|
|
|
{
|
2023-06-09 21:41:33 +00:00
|
|
|
m_Parent->SaveCopyInUndoList( _( "Edit Symbol Properties" ), m_libEntry );
|
2019-12-16 15:11:06 +00:00
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
// The Y axis for components in lib is from bottom to top while the screen axis is top
|
|
|
|
// to bottom: we must change the y coord sign when writing back to the library
|
2022-12-28 13:43:14 +00:00
|
|
|
for( int ii = 0; ii < (int) m_fields->size(); ++ii )
|
2009-10-10 17:27:53 +00:00
|
|
|
{
|
2022-12-28 13:43:14 +00:00
|
|
|
VECTOR2I pos = m_fields->at( ii ).GetPosition();
|
2018-08-13 17:00:08 +00:00
|
|
|
pos.y = -pos.y;
|
2022-12-28 13:43:14 +00:00
|
|
|
m_fields->at( ii ).SetPosition( pos );
|
|
|
|
m_fields->at( ii ).SetId( ii );
|
2009-10-10 17:27:53 +00:00
|
|
|
}
|
|
|
|
|
2023-03-19 19:15:02 +00:00
|
|
|
for( int ii = m_fields->GetNumberRows() - 1; ii >= MANDATORY_FIELDS; ii-- )
|
|
|
|
{
|
|
|
|
LIB_FIELD& field = m_fields->at( ii );
|
|
|
|
const wxString& fieldName = field.GetCanonicalName();
|
|
|
|
|
|
|
|
if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
|
|
|
|
m_fields->erase( m_fields->begin() + ii );
|
|
|
|
else if( fieldName.IsEmpty() )
|
|
|
|
field.SetName( _( "untitled" ) );
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetFields( *m_fields );
|
|
|
|
|
2020-07-20 03:17:08 +00:00
|
|
|
// Update the parent for inherited symbols
|
|
|
|
if( m_libEntry->IsAlias() )
|
|
|
|
{
|
2021-06-30 10:53:04 +00:00
|
|
|
wxString parentName = EscapeString( m_inheritanceSelectCombo->GetValue(), CTX_LIBID );
|
2020-07-20 03:17:08 +00:00
|
|
|
|
|
|
|
// The parentName was verified to be non-empty in the Validator
|
|
|
|
wxString libName = m_Parent->GetCurLib();
|
|
|
|
|
|
|
|
// Get the parent from the libManager based on the name set in the inheritance combo box.
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* newParent = m_Parent->GetLibManager().GetAlias( parentName, libName );
|
2020-07-20 03:17:08 +00:00
|
|
|
|
|
|
|
// Verify that the requested parent exists
|
|
|
|
wxCHECK( newParent, false );
|
|
|
|
|
|
|
|
m_libEntry->SetParent( newParent );
|
|
|
|
}
|
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
m_libEntry->SetName( newName );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() );
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetUnitCount( m_SelNumberOfUnits->GetValue() );
|
2021-06-10 18:51:46 +00:00
|
|
|
m_libEntry->LockUnits( m_libEntry->GetUnitCount() > 1 &&
|
|
|
|
!m_OptionPartsInterchangeable->GetValue() );
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetConversion( m_AsConvertButt->GetValue() );
|
2022-03-24 18:30:53 +00:00
|
|
|
m_Parent->SetShowDeMorgan( m_AsConvertButt->GetValue() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( m_OptionPower->GetValue() )
|
2022-08-20 21:43:20 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetPower();
|
2022-08-20 21:43:20 +00:00
|
|
|
// Power symbols must have value matching name for now
|
|
|
|
m_libEntry->GetValueField().SetText( newName );
|
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
else
|
2022-08-20 21:43:20 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetNormal();
|
2022-08-20 21:43:20 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
m_libEntry->SetExcludedFromSim( m_excludeFromSimCheckBox->GetValue() );
|
2023-06-25 02:03:06 +00:00
|
|
|
m_libEntry->SetExcludedFromBOM( m_excludeFromBomCheckBox->GetValue() );
|
|
|
|
m_libEntry->SetExcludedFromBoard( m_excludeFromBoardCheckBox->GetValue() );
|
2020-09-09 13:03:37 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetShowPinNumbers( m_ShowPinNumButt->GetValue() );
|
|
|
|
m_libEntry->SetShowPinNames( m_ShowPinNameButt->GetValue() );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( m_PinsNameInsideButt->GetValue() )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-01-23 20:45:51 +00:00
|
|
|
int offset = KiROUND( (double) m_pinNameOffset.GetValue() );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
// We interpret an offset of 0 as "outside", so make sure it's non-zero
|
|
|
|
m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
m_libEntry->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 13:47:32 +00:00
|
|
|
m_libEntry->SetFPFilters( m_FootprintFilterListBox->GetStrings());
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2020-07-16 00:08:31 +00:00
|
|
|
m_Parent->UpdateAfterSymbolProperties( &oldName );
|
2019-12-16 15:11:06 +00:00
|
|
|
|
2020-05-07 19:54:49 +00:00
|
|
|
// It's possible that the symbol being edited has no pins, in which case there may be no
|
2021-06-10 18:51:46 +00:00
|
|
|
// alternate body style objects causing #LIB_SYMBOL::HasCoversion() to always return false.
|
2020-05-07 19:54:49 +00:00
|
|
|
// This allows the user to edit the alternate body style just in case this condition occurs.
|
|
|
|
m_Parent->SetShowDeMorgan( m_AsConvertButt->GetValue() );
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging( wxGridEvent& event )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
|
|
|
wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
|
|
|
|
wxControl* control = editor->GetControl();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
|
|
|
|
{
|
|
|
|
event.Veto();
|
|
|
|
|
|
|
|
m_delayedFocusGrid = m_grid;
|
|
|
|
m_delayedFocusRow = event.GetRow();
|
|
|
|
m_delayedFocusColumn = event.GetCol();
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusPage = 0;
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
2020-06-02 20:42:17 +00:00
|
|
|
else if( event.GetCol() == FDC_NAME )
|
|
|
|
{
|
|
|
|
wxString newName = event.GetString();
|
|
|
|
|
|
|
|
for( int i = 0; i < m_grid->GetNumberRows(); ++i )
|
|
|
|
{
|
|
|
|
if( i == event.GetRow() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( newName.CmpNoCase( m_grid->GetCellValue( i, FDC_NAME ) ) == 0 )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "The name '%s' is already in use." ),
|
|
|
|
newName ) );
|
|
|
|
event.Veto();
|
|
|
|
m_delayedFocusRow = event.GetRow();
|
|
|
|
m_delayedFocusColumn = event.GetCol();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
editor->DecRef();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSymbolNameText( wxCommandEvent& event )
|
2018-09-13 15:39:14 +00:00
|
|
|
{
|
2022-08-20 21:43:20 +00:00
|
|
|
if( m_OptionPower->IsChecked() )
|
2021-04-09 16:10:40 +00:00
|
|
|
m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
|
2018-09-13 15:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSymbolNameKillFocus( wxFocusEvent& event )
|
2018-09-13 15:39:14 +00:00
|
|
|
{
|
2022-03-07 10:25:28 +00:00
|
|
|
if( !m_delayedFocusCtrl )
|
2018-09-13 15:39:14 +00:00
|
|
|
{
|
2022-03-07 10:25:28 +00:00
|
|
|
// If the validation fails and we throw up a dialog then GTK will give us another
|
|
|
|
// KillFocus event and we end up in infinite recursion. So we use m_delayedFocusCtrl
|
|
|
|
// as a re-entrancy block and then clear it again if validation passes.
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusCtrl = m_SymbolNameCtrl;
|
|
|
|
m_delayedFocusPage = 0;
|
2022-03-07 10:25:28 +00:00
|
|
|
|
|
|
|
if( m_SymbolNameCtrl->GetValidator()->Validate( m_SymbolNameCtrl ) )
|
2022-04-20 13:50:25 +00:00
|
|
|
{
|
2022-03-07 10:25:28 +00:00
|
|
|
m_delayedFocusCtrl = nullptr;
|
2022-04-20 13:50:25 +00:00
|
|
|
m_delayedFocusPage = -1;
|
|
|
|
}
|
2018-09-13 15:39:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
2010-10-25 15:43:42 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-06 22:36:31 +00:00
|
|
|
SYMBOL_EDITOR_SETTINGS* settings = m_Parent->GetSettings();
|
2022-12-28 13:43:14 +00:00
|
|
|
int fieldID = (int) m_fields->size();
|
2020-10-31 01:27:16 +00:00
|
|
|
LIB_FIELD newField( m_libEntry, fieldID );
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
newField.SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
|
|
|
|
schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
|
2020-04-04 20:32:14 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_fields->push_back( newField );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2010-10-25 15:43:42 +00:00
|
|
|
|
2020-03-25 18:06:18 +00:00
|
|
|
m_grid->MakeCellVisible( (int) m_fields->size() - 1, 0 );
|
|
|
|
m_grid->SetGridCursor( (int) m_fields->size() - 1, 0 );
|
2010-10-25 15:43:42 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->EnableCellEditControl();
|
|
|
|
m_grid->ShowCellEditControl();
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
wxArrayInt selectedRows = m_grid->GetSelectedRows();
|
2018-01-22 17:59:44 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
if( selectedRows.empty() && m_grid->GetGridCursorRow() >= 0 )
|
|
|
|
selectedRows.push_back( m_grid->GetGridCursorRow() );
|
|
|
|
|
|
|
|
if( selectedRows.empty() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return;
|
2021-12-12 17:27:40 +00:00
|
|
|
|
|
|
|
for( int row : selectedRows )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
if( row < MANDATORY_FIELDS )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
|
|
|
|
MANDATORY_FIELDS ) );
|
|
|
|
return;
|
|
|
|
}
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->CommitPendingChanges( true /* quiet mode */ );
|
2023-08-31 22:28:02 +00:00
|
|
|
m_grid->ClearSelection();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
// Reverse sort so deleting a row doesn't change the indexes of the other rows.
|
|
|
|
selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2021-12-12 17:27:40 +00:00
|
|
|
for( int row : selectedRows )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
2021-12-12 17:27:40 +00:00
|
|
|
m_fields->erase( m_fields->begin() + row );
|
|
|
|
|
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
|
|
|
|
if( m_grid->GetNumberRows() > 0 )
|
|
|
|
{
|
|
|
|
m_grid->MakeCellVisible( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->SetGridCursor( std::max( 0, row-1 ), m_grid->GetGridCursorCol() );
|
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
2018-01-23 14:17:51 +00:00
|
|
|
return;
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
int i = m_grid->GetGridCursorRow();
|
2018-01-23 14:17:51 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( i > MANDATORY_FIELDS )
|
2018-01-23 14:17:51 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
LIB_FIELD tmp = m_fields->at( (unsigned) i );
|
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i - 1, tmp );
|
|
|
|
m_grid->ForceRefresh();
|
|
|
|
|
|
|
|
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
|
|
|
else
|
2021-06-10 18:51:46 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
wxBell();
|
2021-06-10 18:51:46 +00:00
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
|
|
|
if( !m_grid->CommitPendingChanges() )
|
2007-09-20 21:06:49 +00:00
|
|
|
return;
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
int i = m_grid->GetGridCursorRow();
|
|
|
|
|
2019-03-18 03:19:21 +00:00
|
|
|
if( i >= MANDATORY_FIELDS && i + 1 < m_fields->GetNumberRows() )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
|
|
|
LIB_FIELD tmp = m_fields->at( (unsigned) i );
|
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i + 1, tmp );
|
|
|
|
m_grid->ForceRefresh();
|
|
|
|
|
|
|
|
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2018-01-23 14:17:51 +00:00
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
else
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
wxBell();
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
|
2019-01-10 05:42:14 +00:00
|
|
|
{
|
2022-12-11 22:59:27 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<LIB_FIELD> fields;
|
|
|
|
|
|
|
|
for( const LIB_FIELD& field : *m_fields )
|
|
|
|
fields.emplace_back( field );
|
2019-01-10 05:42:14 +00:00
|
|
|
|
2022-12-11 22:59:27 +00:00
|
|
|
DIALOG_SIM_MODEL dialog( this, *m_libEntry, fields );
|
2019-01-10 05:42:14 +00:00
|
|
|
|
|
|
|
if( dialog.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
2022-12-11 22:59:27 +00:00
|
|
|
// Add in any new fields
|
|
|
|
for( const LIB_FIELD& editedField : fields )
|
2019-01-10 05:42:14 +00:00
|
|
|
{
|
2022-12-11 22:59:27 +00:00
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( LIB_FIELD& existingField : *m_fields )
|
|
|
|
{
|
|
|
|
if( existingField.GetName() == editedField.GetName() )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
existingField.SetText( editedField.GetText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
m_fields->emplace_back( editedField );
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
}
|
2019-01-10 05:42:14 +00:00
|
|
|
}
|
2022-12-11 22:59:27 +00:00
|
|
|
|
|
|
|
// Remove any deleted fields
|
|
|
|
for( int ii = (int) m_fields->size() - 1; ii >= 0; /* advance in loop */ )
|
2019-01-10 05:42:14 +00:00
|
|
|
{
|
2022-12-11 22:59:27 +00:00
|
|
|
LIB_FIELD& existingField = m_fields->at( ii );
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( LIB_FIELD& editedField : fields )
|
|
|
|
{
|
|
|
|
if( editedField.GetName() == existingField.GetName() )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( found )
|
|
|
|
{
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fields->erase( m_fields->begin() + ii );
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
}
|
2019-01-10 05:42:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 11:34:30 +00:00
|
|
|
OnModify();
|
2019-01-10 05:42:14 +00:00
|
|
|
m_grid->ForceRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnFilterDClick( wxMouseEvent& event )
|
2019-02-16 00:51:16 +00:00
|
|
|
{
|
2019-02-20 01:50:17 +00:00
|
|
|
int idx = m_FootprintFilterListBox->HitTest( event.GetPosition() );
|
2019-02-16 00:51:16 +00:00
|
|
|
wxCommandEvent dummy;
|
2019-02-20 01:50:17 +00:00
|
|
|
|
|
|
|
if( idx >= 0 )
|
|
|
|
OnEditFootprintFilter( dummy );
|
|
|
|
else
|
|
|
|
OnAddFootprintFilter( dummy );
|
2019-02-16 00:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnCancelButtonClick( wxCommandEvent& event )
|
2019-02-20 22:57:39 +00:00
|
|
|
{
|
|
|
|
// Running the Footprint Browser gums up the works and causes the automatic cancel
|
|
|
|
// stuff to no longer work. So we do it here ourselves.
|
|
|
|
EndQuasiModal( wxID_CANCEL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddFootprintFilter( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
wxString filterLine;
|
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Add Footprint Filter" ), filterLine );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue().IsEmpty() )
|
2010-07-20 10:30:40 +00:00
|
|
|
return;
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
filterLine = dlg.GetValue();
|
|
|
|
filterLine.Replace( wxT( " " ), wxT( "_" ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// duplicate filters do no harm, so don't be a nanny.
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_FootprintFilterListBox->Append( filterLine );
|
2020-03-25 18:06:18 +00:00
|
|
|
m_FootprintFilterListBox->SetSelection( (int) m_FootprintFilterListBox->GetCount() - 1 );
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteFootprintFilter( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
int ii = m_FootprintFilterListBox->GetSelection();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( ii >= 0 )
|
2018-06-05 21:33:49 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
m_FootprintFilterListBox->Delete( (unsigned) ii );
|
|
|
|
|
|
|
|
if( m_FootprintFilterListBox->GetCount() == 0 )
|
|
|
|
m_FootprintFilterListBox->SetSelection( wxNOT_FOUND );
|
|
|
|
else
|
|
|
|
m_FootprintFilterListBox->SetSelection( std::max( 0, ii - 1 ) );
|
2018-06-05 21:33:49 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
2018-06-05 21:33:49 +00:00
|
|
|
|
2019-03-18 15:44:44 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditFootprintFilter( wxCommandEvent& event )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
|
|
|
int idx = m_FootprintFilterListBox->GetSelection();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( idx >= 0 )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
wxString filter = m_FootprintFilterListBox->GetStringSelection();
|
|
|
|
|
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( this, _( "Filter:" ), _( "Edit Footprint Filter" ), filter );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK && !dlg.GetValue().IsEmpty() )
|
2021-10-25 11:34:30 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
m_FootprintFilterListBox->SetString( (unsigned) idx, dlg.GetValue() );
|
2021-10-25 11:34:30 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2021-12-16 14:39:58 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::adjustGridColumns()
|
2015-02-02 16:43:34 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
// Account for scroll bars
|
2021-12-16 14:39:58 +00:00
|
|
|
int width = KIPLATFORM::UI::GetUnobscuredSize( m_grid ).x;
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->AutoSizeColumn( FDC_NAME );
|
2022-11-16 12:35:21 +00:00
|
|
|
m_grid->SetColSize( FDC_NAME, std::max( 72, m_grid->GetColSize( FDC_NAME ) ) );
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
int fixedColsWidth = m_grid->GetColSize( FDC_NAME );
|
|
|
|
|
|
|
|
for( int i = 2; i < m_grid->GetNumberCols(); i++ )
|
|
|
|
fixedColsWidth += m_grid->GetColSize( i );
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2022-11-16 12:35:21 +00:00
|
|
|
m_grid->SetColSize( FDC_VALUE, std::max( 120, width - fixedColsWidth ) );
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
2021-01-06 01:37:08 +00:00
|
|
|
m_OptionPartsInterchangeable->Enable( m_SelNumberOfUnits->GetValue() > 1 );
|
2018-08-13 17:00:08 +00:00
|
|
|
m_pinNameOffset.Enable( m_PinsNameInsideButt->GetValue() );
|
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
if( m_grid->IsCellEditControlShown() )
|
|
|
|
{
|
|
|
|
int row = m_grid->GetGridCursorRow();
|
|
|
|
int col = m_grid->GetGridCursorCol();
|
|
|
|
|
2022-08-20 21:43:20 +00:00
|
|
|
if( row == VALUE_FIELD && col == FDC_VALUE && m_OptionPower->IsChecked() )
|
2018-09-13 15:39:14 +00:00
|
|
|
{
|
|
|
|
wxGridCellEditor* editor = m_grid->GetCellEditor( row, col );
|
|
|
|
m_SymbolNameCtrl->ChangeValue( editor->GetValue() );
|
|
|
|
editor->DecRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// Handle shown columns changes
|
2023-04-13 12:45:22 +00:00
|
|
|
std::bitset<64> shownColumns = m_grid->GetShownColumns();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
if( shownColumns != m_shownColumns )
|
|
|
|
{
|
|
|
|
m_shownColumns = shownColumns;
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->IsCellEditControlShown() )
|
2021-12-16 14:39:58 +00:00
|
|
|
adjustGridColumns();
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 15:39:14 +00:00
|
|
|
// Handle a delayed focus. The delay allows us to:
|
|
|
|
// a) change focus when the error was triggered from within a killFocus handler
|
|
|
|
// b) show the correct notebook page in the background before the error dialog comes up
|
|
|
|
// when triggered from an OK or a notebook page change
|
|
|
|
|
|
|
|
if( m_delayedFocusPage >= 0 && m_NoteBook->GetSelection() != m_delayedFocusPage )
|
|
|
|
{
|
2021-12-13 20:46:13 +00:00
|
|
|
m_NoteBook->ChangeSelection( (unsigned) m_delayedFocusPage );
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusPage = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_delayedErrorMessage.IsEmpty() )
|
|
|
|
{
|
|
|
|
// We will re-enter this routine when the error dialog is displayed, so make
|
|
|
|
// sure we don't keep putting up more dialogs.
|
|
|
|
wxString msg = m_delayedErrorMessage;
|
|
|
|
m_delayedErrorMessage = wxEmptyString;
|
|
|
|
|
|
|
|
// Do not use DisplayErrorMessage(); it screws up window order on Mac
|
|
|
|
DisplayError( nullptr, msg );
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( m_delayedFocusCtrl )
|
|
|
|
{
|
|
|
|
m_delayedFocusCtrl->SetFocus();
|
|
|
|
|
2020-01-13 01:39:08 +00:00
|
|
|
if( auto textEntry = dynamic_cast<wxTextEntry*>( m_delayedFocusCtrl ) )
|
|
|
|
textEntry->SelectAll();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
|
|
|
m_delayedFocusCtrl = nullptr;
|
|
|
|
}
|
|
|
|
else if( m_delayedFocusGrid )
|
|
|
|
{
|
|
|
|
m_delayedFocusGrid->SetFocus();
|
|
|
|
m_delayedFocusGrid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
m_delayedFocusGrid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_delayedFocusGrid->EnableCellEditControl( true );
|
|
|
|
m_delayedFocusGrid->ShowCellEditControl();
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_delayedFocusGrid = nullptr;
|
2018-09-13 15:39:14 +00:00
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
2018-08-13 17:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-02 16:43:34 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSizeGrid( wxSizeEvent& event )
|
2018-08-13 17:00:08 +00:00
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
auto new_size = event.GetSize();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2021-12-17 04:00:24 +00:00
|
|
|
if( new_size != m_size )
|
2019-03-02 13:47:10 +00:00
|
|
|
{
|
2021-12-17 04:00:24 +00:00
|
|
|
m_size = new_size;
|
2021-12-16 14:39:58 +00:00
|
|
|
|
|
|
|
adjustGridColumns();
|
2019-03-02 13:47:10 +00:00
|
|
|
}
|
2019-05-11 08:07:30 +00:00
|
|
|
|
|
|
|
// Always propagate a wxSizeEvent:
|
|
|
|
event.Skip();
|
2015-02-02 16:43:34 +00:00
|
|
|
}
|
2016-11-09 23:11:47 +00:00
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::syncControlStates( bool aIsAlias )
|
2016-11-09 23:11:47 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
bSizerLowerBasicPanel->Show( !aIsAlias );
|
|
|
|
m_inheritanceSelectCombo->Enable( aIsAlias );
|
|
|
|
m_inheritsStaticText->Enable( aIsAlias );
|
|
|
|
m_grid->ForceRefresh();
|
2016-11-09 23:11:47 +00:00
|
|
|
}
|
2020-09-09 13:03:37 +00:00
|
|
|
|
|
|
|
|
2020-10-22 09:40:54 +00:00
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::onPowerCheckBox( wxCommandEvent& aEvent )
|
2020-09-09 13:03:37 +00:00
|
|
|
{
|
|
|
|
if( m_OptionPower->IsChecked() )
|
|
|
|
{
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludeFromSimCheckBox->SetValue( true );
|
2020-09-09 13:03:37 +00:00
|
|
|
m_excludeFromBomCheckBox->SetValue( true );
|
|
|
|
m_excludeFromBoardCheckBox->SetValue( true );
|
|
|
|
m_excludeFromBomCheckBox->Enable( false );
|
|
|
|
m_excludeFromBoardCheckBox->Enable( false );
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludeFromSimCheckBox->Enable( false );
|
2023-04-14 18:40:41 +00:00
|
|
|
m_spiceFieldsButton->Show( false );
|
2020-09-09 13:03:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_excludeFromBomCheckBox->Enable( true );
|
|
|
|
m_excludeFromBoardCheckBox->Enable( true );
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludeFromSimCheckBox->Enable( true );
|
2023-04-14 18:40:41 +00:00
|
|
|
m_spiceFieldsButton->Show( true );
|
2020-09-09 13:03:37 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnText( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
2020-09-09 13:03:37 +00:00
|
|
|
}
|
2021-10-25 11:34:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnCombobox( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnCheckBox( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSpinCtrl( wxSpinEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSpinCtrlText( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|