2013-03-30 00:06:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-16 16:43:50 +00:00
|
|
|
* Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-03-30 00:06:08 +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
|
|
|
|
*/
|
|
|
|
|
2019-02-20 23:20:06 +00:00
|
|
|
#include <dialogs/dialog_edit_component_in_schematic.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
#include <wx/tooltip.h>
|
2019-02-20 23:20:06 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2019-02-20 23:20:06 +00:00
|
|
|
#include <kiface_i.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <menus_helpers.h>
|
2019-02-20 23:20:06 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2019-02-20 23:20:06 +00:00
|
|
|
|
2020-03-30 13:14:44 +00:00
|
|
|
#include <ee_collectors.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <eeschema_settings.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <fields_grid_table.h>
|
2017-10-02 12:53:48 +00:00
|
|
|
#include <invoke_sch_dialog.h>
|
2019-02-20 23:20:06 +00:00
|
|
|
#include <sch_draw_panel.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_reference_list.h>
|
|
|
|
#include <symbol_lib_table.h>
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2016-08-11 12:42:13 +00:00
|
|
|
#ifdef KICAD_SPICE
|
2016-08-11 12:41:40 +00:00
|
|
|
#include <dialog_spice_model.h>
|
2016-08-11 12:42:13 +00:00
|
|
|
#endif /* KICAD_SPICE */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( SCH_EDIT_FRAME* aParent,
|
|
|
|
SCH_COMPONENT* aComponent ) :
|
2018-03-18 21:37:27 +00:00
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_BASE( aParent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_cmp = aComponent;
|
2019-12-31 13:05:52 +00:00
|
|
|
m_part = m_cmp->GetPartRef().get();
|
2018-08-08 20:57:53 +00:00
|
|
|
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_part );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-02-27 07:07:32 +00:00
|
|
|
m_width = 0;
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusRow = REFERENCE;
|
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
|
|
|
|
2016-08-11 12:42:13 +00:00
|
|
|
#ifndef KICAD_SPICE
|
2018-02-28 16:54:35 +00:00
|
|
|
m_spiceFieldsButton->Hide();
|
2016-08-11 12:42:13 +00:00
|
|
|
#endif /* not KICAD_SPICE */
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// disable some options inside the edit dialog which can cause problems while dragging
|
|
|
|
if( m_cmp->IsDragging() )
|
|
|
|
{
|
|
|
|
m_rbOrientation->Disable();
|
|
|
|
m_rbMirror->Disable();
|
|
|
|
m_libraryNameTextCtrl->Disable();
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
m_grid->SetTable( m_fields );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Show/hide columns according to user's preference
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-03-29 16:42:24 +00:00
|
|
|
|
|
|
|
if( cfg )
|
2020-05-04 12:01:35 +00:00
|
|
|
{
|
2020-03-29 16:42:24 +00:00
|
|
|
m_shownColumns = cfg->m_Appearance.edit_component_visible_columns;
|
2020-05-04 12:01:35 +00:00
|
|
|
m_grid->ShowHideColumns( m_shownColumns );
|
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
wxToolTip::Enable( true );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_stdDialogButtonSizerOK->SetDefault();
|
2009-07-26 17:16:42 +00:00
|
|
|
|
2017-09-12 07:43:51 +00:00
|
|
|
// Configure button logos
|
2018-07-20 15:03:43 +00:00
|
|
|
m_buttonBrowseLibrary->SetBitmap( KiBitmap( small_library_xpm ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmap( small_plus_xpm ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmap( trash_xpm ) );
|
|
|
|
m_bpMoveUp->SetBitmap( KiBitmap( small_up_xpm ) );
|
|
|
|
m_bpMoveDown->SetBitmap( KiBitmap( small_down_xpm ) );
|
2017-09-12 07:43:51 +00:00
|
|
|
|
2020-03-13 17:28:17 +00:00
|
|
|
// Set font sizes
|
|
|
|
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
|
|
|
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
|
|
|
|
m_timeStampLabel->SetFont( infoFont );
|
|
|
|
m_textCtrlTimeStamp->SetFont( infoFont );
|
|
|
|
m_textCtrlTimeStamp->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// wxFormBuilder doesn't include this event...
|
2019-05-10 12:21:08 +00:00
|
|
|
m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnGridCellChanging ),
|
|
|
|
NULL, this );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
FinishDialogSettings();
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::~DIALOG_EDIT_COMPONENT_IN_SCHEMATIC()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-03-29 16:42:24 +00:00
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
cfg->m_Appearance.edit_component_visible_columns = m_grid->GetShownColumns();
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Prevents crash bug in wxGrid's d'tor
|
2018-05-30 10:52:19 +00:00
|
|
|
m_grid->DestroyTable( m_fields );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
|
|
|
|
wxGridEventHandler( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnGridCellChanging ),
|
|
|
|
NULL, this );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-02-20 23:20:06 +00:00
|
|
|
SCH_EDIT_FRAME* DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::GetParent()
|
|
|
|
{
|
|
|
|
return dynamic_cast<SCH_EDIT_FRAME*>( wxDialog::GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataToWindow()
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
2014-09-17 16:04:04 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
std::set<wxString> defined;
|
|
|
|
|
2020-04-01 14:00:40 +00:00
|
|
|
// Push a copy of each field into m_updateFields
|
2018-02-28 16:54:35 +00:00
|
|
|
for( int i = 0; i < m_cmp->GetFieldCount(); ++i )
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
SCH_FIELD field( *m_cmp->GetField( i ) );
|
|
|
|
|
|
|
|
// change offset to be symbol-relative
|
|
|
|
field.Offset( -m_cmp->GetPosition() );
|
|
|
|
|
|
|
|
defined.insert( field.GetName() );
|
|
|
|
m_fields->push_back( field );
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Add in any template fieldnames not yet defined:
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const TEMPLATE_FIELDNAME& templateFieldname : GetParent()->GetTemplateFieldNames() )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
if( defined.count( templateFieldname.m_Name ) <= 0 )
|
|
|
|
{
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_FIELD field( wxPoint( 0, 0 ), -1, m_cmp, templateFieldname.m_Name );
|
2018-02-28 16:54:35 +00:00
|
|
|
field.SetVisible( templateFieldname.m_Visible );
|
|
|
|
m_fields->push_back( field );
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 16:04:04 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
AdjustGridColumns( m_grid->GetRect().GetWidth() );
|
|
|
|
|
|
|
|
// If a multi-unit component, set up the unit selector and interchangeable checkbox.
|
|
|
|
if( m_cmp->GetUnitCount() > 1 )
|
2017-10-06 18:07:43 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
for( int ii = 1; ii <= m_cmp->GetUnitCount(); ii++ )
|
|
|
|
m_unitChoice->Append( LIB_PART::SubReference( ii, false ) );
|
|
|
|
|
|
|
|
if( m_cmp->GetUnit() <= ( int )m_unitChoice->GetCount() )
|
|
|
|
m_unitChoice->SetSelection( m_cmp->GetUnit() - 1 );
|
2017-10-06 18:07:43 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_unitLabel->Enable( false );
|
|
|
|
m_unitChoice->Enable( false );
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( m_part != nullptr && m_part->HasConversion() )
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2019-04-15 13:59:36 +00:00
|
|
|
if( m_cmp->GetConvert() > LIB_ITEM::LIB_CONVERT::BASE )
|
2018-02-28 16:54:35 +00:00
|
|
|
m_cbAlternateSymbol->SetValue( true );
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
|
|
|
m_cbAlternateSymbol->Enable( false );
|
|
|
|
|
|
|
|
// Set the symbol orientation and mirroring.
|
|
|
|
int orientation = m_cmp->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
|
2014-09-18 10:29:52 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( orientation == CMP_ORIENT_90 )
|
|
|
|
m_rbOrientation->SetSelection( 1 );
|
|
|
|
else if( orientation == CMP_ORIENT_180 )
|
|
|
|
m_rbOrientation->SetSelection( 2 );
|
|
|
|
else if( orientation == CMP_ORIENT_270 )
|
|
|
|
m_rbOrientation->SetSelection( 3 );
|
|
|
|
else
|
|
|
|
m_rbOrientation->SetSelection( 0 );
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
int mirror = m_cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
|
|
|
|
|
|
|
|
if( mirror == CMP_MIRROR_X )
|
|
|
|
m_rbMirror->SetSelection( 1 );
|
|
|
|
else if( mirror == CMP_MIRROR_Y )
|
|
|
|
m_rbMirror->SetSelection( 2 );
|
|
|
|
else
|
|
|
|
m_rbMirror->SetSelection( 0 );
|
|
|
|
|
|
|
|
// Set the component's unique ID time stamp.
|
2020-02-20 12:11:04 +00:00
|
|
|
m_textCtrlTimeStamp->SetValue( m_cmp->m_Uuid.AsString() );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
// Set the component's library name.
|
|
|
|
m_libraryNameTextCtrl->SetValue( m_cmp->GetLibId().Format() );
|
|
|
|
|
|
|
|
Layout();
|
|
|
|
|
|
|
|
return true;
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnBrowseLibrary( wxCommandEvent& event )
|
2014-09-17 16:04:04 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
SCH_BASE_FRAME::HISTORY_LIST dummy;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_ID id;
|
2018-07-26 14:38:30 +00:00
|
|
|
id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2019-05-01 09:24:43 +00:00
|
|
|
auto sel = GetParent()->SelectCompFromLibTree( nullptr, dummy, true, 0, 0, false, &id );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2017-11-06 01:59:51 +00:00
|
|
|
if( !sel.LibId.IsValid() )
|
2014-09-17 16:04:04 +00:00
|
|
|
return;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_libraryNameTextCtrl->SetValue( sel.LibId.Format() );
|
2018-04-24 23:35:37 +00:00
|
|
|
|
|
|
|
LIB_PART* entry = GetParent()->GetLibPart( sel.LibId );
|
|
|
|
|
2019-04-09 15:58:23 +00:00
|
|
|
if( entry )
|
|
|
|
{
|
|
|
|
// Update the value field for Power symbols
|
|
|
|
if( entry->IsPower() )
|
|
|
|
m_grid->SetCellValue( VALUE, FDC_VALUE, sel.LibId.GetLibItemName() );
|
|
|
|
|
|
|
|
// Update the units control
|
|
|
|
int unit = m_unitChoice->GetSelection();
|
|
|
|
m_unitChoice->Clear();
|
|
|
|
|
|
|
|
if( entry->GetUnitCount() > 1 )
|
|
|
|
{
|
|
|
|
for( int ii = 1; ii <= entry->GetUnitCount(); ii++ )
|
|
|
|
m_unitChoice->Append( LIB_PART::SubReference( ii, false ) );
|
|
|
|
|
2019-04-15 13:59:36 +00:00
|
|
|
if( unit < 0 || static_cast<unsigned>( unit ) >= m_unitChoice->GetCount() )
|
2019-04-09 15:58:23 +00:00
|
|
|
unit = 0;
|
|
|
|
|
|
|
|
m_unitChoice->SetSelection( unit );
|
|
|
|
m_unitLabel->Enable( true );
|
|
|
|
m_unitChoice->Enable( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_unitChoice->SetSelection( -1 );
|
|
|
|
m_unitLabel->Enable( false );
|
|
|
|
m_unitChoice->Enable( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the deMorgan conversion controls
|
|
|
|
bool conversion = m_cbAlternateSymbol->GetValue();
|
|
|
|
|
|
|
|
m_cbAlternateSymbol->SetValue( conversion && entry->HasConversion() );
|
|
|
|
m_cbAlternateSymbol->Enable( entry->HasConversion() );
|
|
|
|
}
|
2014-09-17 16:04:04 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnEditSpiceModel( wxCommandEvent& event )
|
2016-08-11 12:41:10 +00:00
|
|
|
{
|
2016-08-11 12:42:13 +00:00
|
|
|
#ifdef KICAD_SPICE
|
2018-02-28 16:54:35 +00:00
|
|
|
int diff = m_fields->size();
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2019-01-10 05:42:14 +00:00
|
|
|
DIALOG_SPICE_MODEL dialog( this, *m_cmp, m_fields );
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( dialog.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2020-03-25 18:06:18 +00:00
|
|
|
diff = (int) m_fields->size() - diff;
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( diff > 0 )
|
|
|
|
{
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
else if( diff < 0 )
|
|
|
|
{
|
2020-02-14 07:36:25 +00:00
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, -diff );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->ProcessTableMessage( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_grid->ForceRefresh();
|
|
|
|
#endif /* KICAD_SPICE */
|
2008-11-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2019-01-31 19:05:11 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::Validate()
|
2014-09-15 12:06:00 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxString msg;
|
|
|
|
LIB_ID id;
|
2014-09-15 11:59:40 +00:00
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() || !m_grid->Validate() )
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2014-09-15 11:59:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( !SCH_COMPONENT::IsReferenceStringValid( m_fields->at( REFERENCE ).GetText() ) )
|
|
|
|
{
|
2018-07-21 20:23:13 +00:00
|
|
|
DisplayErrorMessage( this, _( "References must start with a letter." ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
|
|
|
m_delayedFocusRow = REFERENCE;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-31 01:31:19 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !id.IsValid() )
|
2013-03-30 00:06:08 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
DisplayErrorMessage( this, _( "Library reference is not valid." ) );
|
|
|
|
|
|
|
|
m_libraryNameTextCtrl->SetFocus();
|
|
|
|
|
|
|
|
return false;
|
2013-03-30 00:06:08 +00:00
|
|
|
}
|
2017-01-31 01:31:19 +00:00
|
|
|
else if( id != m_cmp->GetLibId() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* alias = nullptr;
|
2017-10-06 18:07:43 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !alias )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
msg.Printf( _( "Symbol \"%s\" not found in library \"%s\"." ),
|
|
|
|
id.GetLibItemName().wx_str(),
|
|
|
|
id.GetLibNickname().wx_str() );
|
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
|
|
|
|
m_libraryNameTextCtrl->SetFocus();
|
|
|
|
|
|
|
|
return false;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
}
|
2020-05-05 14:55:54 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_libraryNameTextCtrl->SetValue( id.Format() );
|
|
|
|
|
|
|
|
// Check for missing field names.
|
2018-08-15 11:19:41 +00:00
|
|
|
for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD& field = m_fields->at( i );
|
|
|
|
wxString fieldName = field.GetName( false );
|
|
|
|
|
|
|
|
if( fieldName.IsEmpty() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
DisplayErrorMessage( this, _( "Fields must have a name." ) );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
m_delayedFocusColumn = FDC_NAME;
|
|
|
|
m_delayedFocusRow = i;
|
|
|
|
|
|
|
|
return false;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow()
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2019-05-10 12:21:08 +00:00
|
|
|
if( !wxDialog::TransferDataFromWindow() ) // Calls our Validate() method.
|
2018-08-13 17:00:08 +00:00
|
|
|
return false;
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2020-05-05 14:55:54 +00:00
|
|
|
SCH_SCREEN* currentScreen = GetParent()->GetScreen();
|
|
|
|
|
|
|
|
wxCHECK( currentScreen, false );
|
|
|
|
|
|
|
|
// This needs to be done before the LIB_ID is changed to prevent stale library symbols in
|
|
|
|
// the schematic file.
|
|
|
|
currentScreen->Remove( m_cmp );
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// save old cmp in undo list if not already in edit, or moving ...
|
2019-04-28 16:36:31 +00:00
|
|
|
if( m_cmp->GetEditFlags() == 0 )
|
2018-02-28 16:54:35 +00:00
|
|
|
GetParent()->SaveCopyInUndoList( m_cmp, UR_CHANGED );
|
|
|
|
|
|
|
|
// Save current flags which could be modified by next change settings
|
|
|
|
STATUS_FLAGS flags = m_cmp->GetFlags();
|
|
|
|
|
|
|
|
// Library symbol identifier
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID id;
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
if( id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true ) >= 0 )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "'%s' is not a valid library indentifier." ),
|
|
|
|
m_libraryNameTextCtrl->GetValue() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_PART* libSymbol = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
|
|
|
|
|
|
|
if( !libSymbol )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Symbol '%s' not found in symbol library '%s'." ),
|
|
|
|
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-05 14:55:54 +00:00
|
|
|
m_cmp->SetLibSymbol( libSymbol->Flatten().release() );
|
2020-04-16 16:43:50 +00:00
|
|
|
m_cmp->SetLibId( id );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
// For symbols with multiple shapes (De Morgan representation) Set the selected shape:
|
2019-04-15 13:59:36 +00:00
|
|
|
if( m_cbAlternateSymbol->IsEnabled() && m_cbAlternateSymbol->GetValue() )
|
|
|
|
m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::DEMORGAN );
|
|
|
|
else
|
|
|
|
m_cmp->SetConvert( LIB_ITEM::LIB_CONVERT::BASE );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
//Set the part selection in multiple part per package
|
2019-04-09 15:58:23 +00:00
|
|
|
int unit_selection = m_unitChoice->IsEnabled()
|
|
|
|
? m_unitChoice->GetSelection() + 1
|
2019-04-15 13:59:36 +00:00
|
|
|
: 1;
|
2019-04-09 15:58:23 +00:00
|
|
|
m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection );
|
|
|
|
m_cmp->SetUnit( unit_selection );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
switch( m_rbOrientation->GetSelection() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
case 0: m_cmp->SetOrientation( CMP_ORIENT_0 ); break;
|
|
|
|
case 1: m_cmp->SetOrientation( CMP_ORIENT_90 ); break;
|
|
|
|
case 2: m_cmp->SetOrientation( CMP_ORIENT_180 ); break;
|
|
|
|
case 3: m_cmp->SetOrientation( CMP_ORIENT_270 ); break;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
switch( m_rbMirror->GetSelection() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
case 0: break;
|
|
|
|
case 1: m_cmp->SetOrientation( CMP_MIRROR_X ); break;
|
|
|
|
case 2: m_cmp->SetOrientation( CMP_MIRROR_Y ); break;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2014-12-16 18:58:26 +00:00
|
|
|
|
|
|
|
// Restore m_Flag modified by SetUnit() and other change settings
|
2015-02-17 18:47:21 +00:00
|
|
|
m_cmp->ClearFlags();
|
|
|
|
m_cmp->SetFlags( flags );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// change all field positions from relative to absolute
|
|
|
|
for( unsigned i = 0; i < m_fields->size(); ++i )
|
|
|
|
m_fields->at( i ).Offset( m_cmp->GetPosition() );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_PART* entry = GetParent()->GetLibPart( m_cmp->GetLibId() );
|
2011-05-31 16:29:14 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( entry && entry->IsPower() )
|
|
|
|
m_fields->at( VALUE ).SetText( m_cmp->GetLibId().GetLibItemName() );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Remove any TEMPLATE_FIELDNAMES which were not set (given values).
|
|
|
|
TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames();
|
2011-01-18 10:42:49 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
SCH_FIELD& field = m_fields->at( i );
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& fieldname : templateFieldnames )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() )
|
2011-08-30 19:24:28 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->erase( m_fields->begin() + i );
|
2018-11-13 13:01:51 +00:00
|
|
|
|
|
|
|
// grid needs to be notified about the size change,
|
|
|
|
// as it still accesses the data on close (size event)
|
2020-04-16 16:43:50 +00:00
|
|
|
wxGridTableMessage gridMsg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, i, 1 );
|
|
|
|
m_grid->ProcessTableMessage( gridMsg );
|
2018-02-28 16:54:35 +00:00
|
|
|
i--;
|
|
|
|
break;
|
2011-08-30 19:24:28 +00:00
|
|
|
}
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_cmp->SetFields( *m_fields );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// Reference has a specific initialization, depending on the current active sheet
|
|
|
|
// because for a given component, in a complex hierarchy, there are more than one
|
2010-01-13 13:43:36 +00:00
|
|
|
// reference.
|
2018-02-28 16:54:35 +00:00
|
|
|
m_cmp->SetRef( &GetParent()->GetCurrentSheet(), m_fields->at( REFERENCE ).GetText() );
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2018-01-06 12:36:08 +00:00
|
|
|
// The value, footprint and datasheet fields should be kept in sync in multi-unit
|
|
|
|
// parts.
|
|
|
|
if( m_cmp->GetUnitCount() > 1 )
|
|
|
|
{
|
2020-03-30 13:14:44 +00:00
|
|
|
std::vector<SCH_COMPONENT*> otherUnits;
|
2018-01-06 12:36:08 +00:00
|
|
|
|
2020-03-30 13:14:44 +00:00
|
|
|
CollectOtherUnits( GetParent()->GetCurrentSheet(), m_cmp, &otherUnits );
|
2019-05-10 12:21:08 +00:00
|
|
|
|
2020-03-30 13:14:44 +00:00
|
|
|
for( SCH_COMPONENT* otherUnit : otherUnits )
|
2018-01-06 12:36:08 +00:00
|
|
|
{
|
2020-03-30 13:14:44 +00:00
|
|
|
GetParent()->SaveCopyInUndoList( otherUnit, UR_CHANGED, true /* append */);
|
|
|
|
otherUnit->GetField( VALUE )->SetText( m_fields->at( VALUE ).GetText() );
|
|
|
|
otherUnit->GetField( FOOTPRINT )->SetText( m_fields->at( FOOTPRINT ).GetText() );
|
|
|
|
otherUnit->GetField( DATASHEET )->SetText( m_fields->at( DATASHEET ).GetText() );
|
|
|
|
GetParent()->RefreshItem( otherUnit );
|
2018-01-06 12:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 14:55:54 +00:00
|
|
|
currentScreen->Append( m_cmp );
|
2018-10-16 13:11:33 +00:00
|
|
|
GetParent()->TestDanglingEnds();
|
2018-10-18 09:50:43 +00:00
|
|
|
GetParent()->RefreshItem( m_cmp );
|
|
|
|
GetParent()->OnModify();
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
return true;
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnGridCellChanging( wxGridEvent& event )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2018-07-21 20:23:13 +00:00
|
|
|
wxGridCellEditor* editor = m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
|
|
|
|
wxControl* control = editor->GetControl();
|
|
|
|
|
|
|
|
if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
event.Veto();
|
|
|
|
m_delayedFocusRow = event.GetRow();
|
|
|
|
m_delayedFocusColumn = event.GetCol();
|
|
|
|
}
|
2018-07-21 20:23:13 +00:00
|
|
|
|
|
|
|
editor->DecRef();
|
2008-11-26 06:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnAddField( wxCommandEvent& event )
|
2013-08-08 16:12:41 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
int fieldID = m_fields->size();
|
2020-04-14 12:25:00 +00:00
|
|
|
SCH_FIELD newField( wxPoint( 0, 0 ), fieldID, m_cmp,
|
2020-04-18 20:04:41 +00:00
|
|
|
TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID ) );
|
2014-05-05 17:28:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
newField.SetTextAngle( m_fields->at( REFERENCE ).GetTextAngle() );
|
2014-05-04 00:44:57 +00:00
|
|
|
|
2020-04-04 20:32:14 +00:00
|
|
|
newField.SetTextSize( wxSize( GetParent()->GetDefaultTextSize(),
|
|
|
|
GetParent()->GetDefaultTextSize() ) );
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->push_back( newField );
|
2014-05-04 00:44:57 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2016-05-17 18:02:49 +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 );
|
2014-05-04 00:44:57 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->EnableCellEditControl();
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->ShowCellEditControl();
|
2013-08-08 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnDeleteField( wxCommandEvent& event )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
int curRow = m_grid->GetGridCursorRow();
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( curRow < 0 )
|
2020-05-05 14:55:54 +00:00
|
|
|
{
|
2008-11-26 06:25:20 +00:00
|
|
|
return;
|
2020-05-05 14:55:54 +00:00
|
|
|
}
|
2018-08-13 17:00:08 +00:00
|
|
|
else if( curRow < MANDATORY_FIELDS )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "The first %d fields are mandatory." ),
|
|
|
|
MANDATORY_FIELDS ) );
|
2008-11-26 06:25:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->CommitPendingChanges( true /* quiet mode */ );
|
|
|
|
|
|
|
|
m_fields->erase( m_fields->begin() + curRow );
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, curRow, 1 );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( m_grid->GetNumberRows() > 0 )
|
2017-09-12 07:43:51 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
m_grid->MakeCellVisible( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->SetGridCursor( std::max( 0, curRow-1 ), m_grid->GetGridCursorCol() );
|
2017-09-12 07:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnMoveUp( wxCommandEvent& event )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
int i = m_grid->GetGridCursorRow();
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
if( i > MANDATORY_FIELDS )
|
2018-02-28 16:54:35 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
SCH_FIELD tmp = m_fields->at( (unsigned) i );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i - 1, tmp );
|
|
|
|
m_grid->ForceRefresh();
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
|
|
|
|
}
|
|
|
|
else
|
2020-05-05 14:55:54 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxBell();
|
2020-05-05 14:55:54 +00:00
|
|
|
}
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnMoveDown( wxCommandEvent& event )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
int i = m_grid->GetGridCursorRow();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-11-13 13:14:08 +00:00
|
|
|
if( i >= MANDATORY_FIELDS && i < m_grid->GetNumberRows() - 1 )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
SCH_FIELD tmp = m_fields->at( (unsigned) i );
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
|
|
|
|
m_fields->insert( m_fields->begin() + i + 1, tmp );
|
|
|
|
m_grid->ForceRefresh();
|
2011-08-30 19:24:28 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() );
|
|
|
|
}
|
|
|
|
else
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxBell();
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2008-12-31 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::UpdateFieldsFromLibrary( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-08-13 17:00:08 +00:00
|
|
|
if( !m_grid->CommitPendingChanges() )
|
|
|
|
return;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
LIB_ID id;
|
|
|
|
wxString msg;
|
2018-02-28 16:54:35 +00:00
|
|
|
SCH_COMPONENT copy( *m_cmp );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
copy.SetFields( *m_fields );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2019-07-08 21:55:42 +00:00
|
|
|
id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
if( id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH, true ) >= 0 )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "'%s' is not a valid library indentifier." ),
|
|
|
|
m_libraryNameTextCtrl->GetValue() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_PART* libSymbol = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
|
|
|
|
|
|
|
if( !libSymbol )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Symbol '%s' not found in symbol library '%s'." ),
|
|
|
|
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-06 14:42:50 +00:00
|
|
|
copy.SetLibSymbol( libSymbol->Flatten().release() );
|
2019-07-08 21:55:42 +00:00
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// Update the requested fields in the component copy
|
2018-02-28 16:54:35 +00:00
|
|
|
std::list<SCH_COMPONENT*> components;
|
|
|
|
components.push_back( © );
|
|
|
|
InvokeDialogUpdateFields( GetParent(), components, false );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2019-04-04 11:26:07 +00:00
|
|
|
wxGridTableMessage clear( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_fields->size() );
|
|
|
|
m_grid->ProcessTableMessage( clear );
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
// Copy fields from the component copy to the dialog buffer
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->clear();
|
|
|
|
std::set<wxString> defined;
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
for( int i = 0; i < copy.GetFieldCount(); ++i )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
copy.GetField( i )->SetParent( m_cmp );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
defined.insert( copy.GetField( i )->GetName() );
|
|
|
|
m_fields->push_back( *copy.GetField( i ) );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Add in any template fieldnames not yet defined:
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const TEMPLATE_FIELDNAME& templateFieldname : GetParent()->GetTemplateFieldNames() )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
if( defined.count( templateFieldname.m_Name ) <= 0 )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_FIELD field( wxPoint( 0, 0 ), -1, m_cmp, templateFieldname.m_Name );
|
2018-02-28 16:54:35 +00:00
|
|
|
field.SetVisible( templateFieldname.m_Visible );
|
|
|
|
m_fields->push_back( field );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:26:07 +00:00
|
|
|
wxGridTableMessage refresh( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->size() );
|
|
|
|
m_grid->ProcessTableMessage( refresh );
|
2008-11-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::AdjustGridColumns( int aWidth )
|
2008-11-24 21:06:50 +00:00
|
|
|
{
|
2019-02-27 07:07:32 +00:00
|
|
|
m_width = aWidth;
|
2018-02-28 16:54:35 +00:00
|
|
|
// Account for scroll bars
|
|
|
|
aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->AutoSizeColumn( 0 );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
int fixedColsWidth = m_grid->GetColSize( 0 );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
for( int i = 2; i < m_grid->GetNumberCols(); i++ )
|
|
|
|
fixedColsWidth += m_grid->GetColSize( i );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->SetColSize( 1, aWidth - fixedColsWidth );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnUpdateUI( wxUpdateUIEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-05-30 10:52:19 +00:00
|
|
|
wxString shownColumns = m_grid->GetShownColumns();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( shownColumns != m_shownColumns )
|
2016-04-17 15:15:26 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_shownColumns = shownColumns;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( !m_grid->IsCellEditControlShown() )
|
|
|
|
AdjustGridColumns( m_grid->GetRect().GetWidth() );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Handle a delayed focus
|
|
|
|
if( m_delayedFocusRow >= 0 )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->SetFocus();
|
|
|
|
m_grid->MakeCellVisible( m_delayedFocusRow, m_delayedFocusColumn );
|
|
|
|
m_grid->SetGridCursor( m_delayedFocusRow, m_delayedFocusColumn );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-07-11 17:26:03 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->EnableCellEditControl( true );
|
|
|
|
m_grid->ShowCellEditControl();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2017-08-25 11:37:21 +00:00
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSizeGrid( wxSizeEvent& event )
|
2017-08-25 11:37:21 +00:00
|
|
|
{
|
2019-02-27 07:07:32 +00:00
|
|
|
auto new_size = event.GetSize().GetX();
|
2017-08-25 11:37:21 +00:00
|
|
|
|
2019-02-27 07:07:32 +00:00
|
|
|
if( m_width != new_size )
|
|
|
|
{
|
|
|
|
AdjustGridColumns( new_size );
|
|
|
|
}
|
2019-04-27 12:50:21 +00:00
|
|
|
|
|
|
|
// Always propagate for a grid repaint (needed if the height changes, as well as width)
|
|
|
|
event.Skip();
|
2018-03-05 00:06:12 +00:00
|
|
|
}
|
2019-02-20 23:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnInitDlg( wxInitDialogEvent& event )
|
|
|
|
{
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
2019-02-27 07:07:32 +00:00
|
|
|
}
|