2013-05-24 21:30:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2018-02-28 16:54:35 +00:00
|
|
|
* Copyright (C) 2007-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-24 21:30:27 +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
|
|
|
|
*/
|
|
|
|
|
2008-12-30 19:18:56 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2014-05-05 17:28:40 +00:00
|
|
|
#include <kiway.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <class_drawpanel.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <kiface_i.h>
|
2018-05-30 10:52:19 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <dialog_helpers.h>
|
2017-09-03 14:03:56 +00:00
|
|
|
#include <bitmaps.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
#include <fields_grid_table.h>
|
2017-09-03 14:03:56 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_edit_libentry_fields_in_lib_base.h>
|
2018-02-28 16:54:35 +00:00
|
|
|
|
2016-10-15 18:05:03 +00:00
|
|
|
#ifdef KICAD_SPICE
|
|
|
|
#include <dialog_spice_model.h>
|
|
|
|
#include <netlist_exporter_pspice.h>
|
|
|
|
#endif /* KICAD_SPICE */
|
2008-12-30 19:18:56 +00:00
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
#define LibEditFieldsShownColumnsKey wxT( "LibEditFieldsShownColumns" )
|
|
|
|
|
|
|
|
|
2008-12-30 19:18:56 +00:00
|
|
|
|
|
|
|
class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE
|
|
|
|
{
|
|
|
|
public:
|
2015-02-21 09:46:44 +00:00
|
|
|
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( LIB_EDIT_FRAME* aParent, LIB_PART* aLibEntry );
|
2018-02-28 16:54:35 +00:00
|
|
|
~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB() override;
|
2008-12-30 19:18:56 +00:00
|
|
|
|
|
|
|
private:
|
2018-02-28 16:54:35 +00:00
|
|
|
wxConfigBase* m_config;
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_EDIT_FRAME* m_parent;
|
|
|
|
LIB_PART* m_libEntry;
|
|
|
|
|
|
|
|
FIELDS_GRID_TABLE<LIB_FIELD>* m_fields;
|
|
|
|
|
|
|
|
int m_delayedFocusRow;
|
|
|
|
int m_delayedFocusColumn;
|
|
|
|
wxString m_shownColumns;
|
|
|
|
|
|
|
|
bool TransferDataToWindow() override;
|
2013-05-24 21:30:27 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
bool Validate() override;
|
2013-05-24 21:30:27 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// event handlers:
|
|
|
|
void OnOKButtonClick( wxCommandEvent& event ) override;
|
|
|
|
void OnAddField( wxCommandEvent& event ) override;
|
|
|
|
void OnDeleteField( wxCommandEvent& event ) override;
|
|
|
|
void OnMoveUp( wxCommandEvent& event ) override;
|
|
|
|
void OnMoveDown( wxCommandEvent& event ) override;
|
|
|
|
void OnEditSpiceModel( wxCommandEvent& event ) override;
|
|
|
|
void OnSizeGrid( wxSizeEvent& event ) override;
|
|
|
|
void OnGridCellChanging( wxGridEvent& event );
|
|
|
|
void OnUpdateUI( wxUpdateUIEvent& event ) override;
|
|
|
|
|
|
|
|
void AdjustGridColumns( int aWidth );
|
2008-12-30 19:18:56 +00:00
|
|
|
};
|
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
|
2010-11-19 16:28:46 +00:00
|
|
|
void LIB_EDIT_FRAME::InstallFieldsEditorDialog( wxCommandEvent& event )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2014-10-26 11:42:25 +00:00
|
|
|
if( !GetCurPart() )
|
2008-12-30 19:18:56 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
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
|
|
|
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB dlg( this, GetCurPart() );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-03-31 11:31:49 +00:00
|
|
|
if( GetDrawItem() && GetDrawItem()->Type() == LIB_FIELD_T )
|
|
|
|
SetDrawItem( nullptr ); // selected LIB_FIELD might be deleted
|
|
|
|
|
2014-08-17 23:00:49 +00:00
|
|
|
// This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
|
|
|
|
// frame. Therefore this dialog as a modal frame parent, MUST be run under
|
|
|
|
// quasimodal mode for the quasimodal frame support to work. So don't use
|
|
|
|
// the QUASIMODAL macros here.
|
2014-09-15 11:59:40 +00:00
|
|
|
if( dlg.ShowQuasiModal() != wxID_OK )
|
2009-09-22 12:27:57 +00:00
|
|
|
return;
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
UpdateAliasSelectList();
|
|
|
|
UpdatePartSelectList();
|
2008-12-31 15:01:29 +00:00
|
|
|
DisplayLibInfos();
|
2009-09-22 12:27:57 +00:00
|
|
|
Refresh();
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( LIB_EDIT_FRAME* aParent,
|
|
|
|
LIB_PART* aLibEntry ) :
|
2008-12-30 19:18:56 +00:00
|
|
|
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( aParent )
|
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_config = Kiface().KifaceSettings();
|
|
|
|
|
2013-04-01 10:50:01 +00:00
|
|
|
m_parent = aParent;
|
|
|
|
m_libEntry = aLibEntry;
|
2018-07-20 15:03:43 +00:00
|
|
|
m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, true, m_libEntry );
|
2018-02-28 16:54:35 +00:00
|
|
|
|
|
|
|
m_delayedFocusRow = REFERENCE;
|
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
2016-10-15 18:05:03 +00:00
|
|
|
|
|
|
|
#ifndef KICAD_SPICE
|
2018-02-28 16:54:35 +00:00
|
|
|
m_spiceFieldsButton->Hide();
|
2016-10-15 18:05:03 +00:00
|
|
|
#endif
|
2017-09-03 14:03:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Give a bit more room for combobox editors
|
|
|
|
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 2 );
|
2008-12-30 19:18:56 +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-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
stdDialogButtonSizerOK->SetDefault();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Configure button logos
|
|
|
|
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 ) );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// wxFormBuilder doesn't include this event...
|
|
|
|
m_grid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnGridCellChanging ), NULL, this );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
FinishDialogSettings();
|
|
|
|
}
|
2008-12-30 19:18:56 +00:00
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB()
|
|
|
|
{
|
2018-05-30 10:52:19 +00:00
|
|
|
m_config->Write( LibEditFieldsShownColumnsKey, m_grid->GetShownColumns() );
|
2016-07-16 10:54:55 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnGridCellChanging ), NULL, this );
|
|
|
|
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_grid->PopEventHandler( true );
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::TransferDataToWindow()
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
if( !wxDialog::TransferDataToWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Push a copy of each field into m_fields
|
|
|
|
m_libEntry->GetFields( *m_fields );
|
|
|
|
|
|
|
|
// 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 )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxPoint pos = m_fields->at( i ).GetPosition();
|
|
|
|
pos.y = -pos.y;
|
|
|
|
m_fields->at( i ).SetPosition( pos );
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// notify the grid
|
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_fields->GetNumberRows() );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Show/hide columns according to the user's preference
|
|
|
|
m_config->Read( LibEditFieldsShownColumnsKey, &m_shownColumns, wxT( "0 1 2 3 4 5 6 7" ) );
|
2018-05-30 10:52:19 +00:00
|
|
|
m_grid->ShowHideColumns( m_shownColumns );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
Layout();
|
|
|
|
|
|
|
|
return true;
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::Validate()
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
// Commit any pending in-place edits and close the editor
|
|
|
|
m_grid->DisableCellEditControl();
|
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() ) )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( nullptr, _( "References must start with a letter." ) );
|
2014-09-15 11:59:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusColumn = FDC_VALUE;
|
|
|
|
m_delayedFocusRow = REFERENCE;
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Check for missing field names.
|
|
|
|
for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i )
|
|
|
|
{
|
|
|
|
LIB_FIELD& field = m_fields->at( i );
|
|
|
|
wxString fieldName = field.GetName( false );
|
2018-05-03 10:20:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( fieldName.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( nullptr, _( "Fields must have a name." ) );
|
2018-05-03 10:20:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusColumn = FDC_NAME;
|
|
|
|
m_delayedFocusRow = i;
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-31 16:29:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( !Validate() )
|
2010-10-04 18:54:14 +00:00
|
|
|
return;
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2013-05-24 21:30:27 +00:00
|
|
|
// save old cmp in undo list
|
2015-01-27 11:01:58 +00:00
|
|
|
m_parent->SaveCopyInUndoList( m_libEntry );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +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
|
|
|
|
for( size_t i = 0; i < m_fields->size(); ++i )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxPoint pos = m_fields->at( i ).GetPosition();
|
|
|
|
pos.y = -pos.y;
|
|
|
|
m_fields->at( i ).SetPosition( pos );
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_libEntry->SetFields( *m_fields );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2010-08-22 17:42:55 +00:00
|
|
|
// We need to keep the name and the value the same at the moment!
|
2013-04-01 10:50:01 +00:00
|
|
|
SetName( m_libEntry->GetValueField().GetText() );
|
2010-08-22 17:42:55 +00:00
|
|
|
|
2013-04-01 10:50:01 +00:00
|
|
|
m_parent->OnModify();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2014-09-15 11:59:40 +00:00
|
|
|
EndQuasiModal( wxID_OK );
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnEditSpiceModel( wxCommandEvent& event )
|
2016-10-15 18:05:03 +00:00
|
|
|
{
|
|
|
|
#ifdef KICAD_SPICE
|
|
|
|
// DIALOG_SPICE_MODEL expects a SCH_COMPONENT,
|
|
|
|
// and a list of SCH_FIELDS to create/edit/delete Spice fields.
|
|
|
|
SCH_COMPONENT component; // This dummy component
|
|
|
|
|
|
|
|
// Build fields list from the m_FieldsBuf fields buffer dialog
|
|
|
|
// to be sure to use the current fields.
|
2018-02-28 16:54:35 +00:00
|
|
|
SCH_FIELDS schFields;
|
2016-10-15 18:05:03 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
for( unsigned ii = 0; ii < m_fields->size(); ++ii )
|
2016-10-15 18:05:03 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_FIELD& libField = m_fields->at( ii );
|
|
|
|
SCH_FIELD schField( libField.GetTextPos(), libField.GetId(),
|
|
|
|
&component, libField.GetName() );
|
|
|
|
schField.ImportValues( m_fields->at( ii ) );
|
|
|
|
schField.SetText( m_fields->at( ii ).GetText() );
|
2016-10-15 18:05:03 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
schFields.push_back( schField );
|
2016-10-15 18:05:03 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
component.SetFields( schFields );
|
|
|
|
int diff = schFields.size();
|
2016-10-15 18:05:03 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
DIALOG_SPICE_MODEL dialog( this, component, schFields );
|
2016-10-15 18:05:03 +00:00
|
|
|
|
|
|
|
if( dialog.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
2018-04-26 18:12:14 +00:00
|
|
|
// Transfer sch fields to the m_FieldsBuf fields buffer dialog:
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->clear();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
for( auto& schField : schFields )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_FIELD libField;
|
|
|
|
schField.ExportValues( libField );
|
|
|
|
m_fields->push_back( libField );
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
diff = m_fields->size() - diff;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( diff > 0 )
|
2009-01-02 13:19:34 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, diff );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2009-01-02 13:19:34 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else if( diff < 0 )
|
2009-01-02 13:19:34 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, diff );
|
|
|
|
m_grid->ProcessTableMessage( msg );
|
2009-01-02 13:19:34 +00:00
|
|
|
}
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->ForceRefresh();
|
|
|
|
#endif /* KICAD_SPICE */
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnGridCellChanging( wxGridEvent& event )
|
2017-09-03 14:03:56 +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 ) )
|
2017-09-03 14:03:56 +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();
|
2017-09-03 14:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnAddField( wxCommandEvent& event )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
int fieldID = m_fields->size();
|
|
|
|
LIB_FIELD& refField = m_fields->at( REFERENCE );
|
|
|
|
LIB_FIELD newField( fieldID );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
newField.SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldID ) );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Give new fields a slight offset so they don't all end up on top of each other
|
|
|
|
newField.SetPosition( refField.GetTextPos()
|
|
|
|
+ wxPoint( (fieldID - MANDATORY_FIELDS + 1) * 100,
|
|
|
|
(fieldID - MANDATORY_FIELDS + 1) * 100 ) );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
newField.SetTextAngle( refField.GetTextAngle() );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_fields->push_back( newField );
|
2008-12-30 19:18:56 +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 );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->MakeCellVisible( m_fields->size() - 1, 0 );
|
|
|
|
m_grid->SetGridCursor( m_fields->size() - 1, 0 );
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->EnableCellEditControl( true );
|
|
|
|
m_grid->ShowCellEditControl();
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnDeleteField( wxCommandEvent& event )
|
2013-08-08 16:12:41 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
int rowCount = m_grid->GetNumberRows();
|
|
|
|
int curRow = m_grid->GetGridCursorRow();
|
|
|
|
|
|
|
|
if( curRow < 0 || curRow >= (int) m_fields->size() )
|
|
|
|
return;
|
2014-05-05 17:28:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( curRow < MANDATORY_FIELDS )
|
2014-05-05 17:28:40 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
DisplayError( nullptr, wxString::Format( _( "The first %d fields are mandatory." ),
|
|
|
|
MANDATORY_FIELDS ) );
|
|
|
|
return;
|
2014-05-05 17:28:40 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
auto start = m_fields->begin() + curRow;
|
|
|
|
m_fields->erase( start, start + 1 );
|
2014-05-05 17:28:40 +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 );
|
2014-05-05 17:28:40 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( curRow == rowCount - 1 )
|
|
|
|
{
|
|
|
|
m_grid->MakeCellVisible( curRow-1, m_grid->GetGridCursorCol() );
|
|
|
|
m_grid->SetGridCursor( curRow-1, m_grid->GetGridCursorCol() );
|
2014-05-05 17:28:40 +00:00
|
|
|
}
|
2013-08-08 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnMoveUp( wxCommandEvent& event )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
int i = m_grid->GetGridCursorRow();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->DisableCellEditControl();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( i > MANDATORY_FIELDS && i < (int) m_fields->size() )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_FIELD tmp = m_fields->at( 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();
|
2010-06-17 16:30:10 +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() );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
|
|
|
wxBell();
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnMoveDown( wxCommandEvent& event )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
int i = m_grid->GetGridCursorRow();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->DisableCellEditControl();
|
2014-06-03 15:31:58 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( i >= MANDATORY_FIELDS && i < (int) m_fields->size() - 1 )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
LIB_FIELD tmp = m_fields->at( 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();
|
2010-06-17 16:30:10 +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() );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
2018-02-28 16:54:35 +00:00
|
|
|
else
|
|
|
|
wxBell();
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::AdjustGridColumns( int aWidth )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
// Account for scroll bars
|
|
|
|
aWidth -= ( m_grid->GetSize().x - m_grid->GetClientSize().x );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->AutoSizeColumn( 0 );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
int fixedColsWidth = m_grid->GetColSize( 0 );
|
2008-12-30 19:18:56 +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-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->SetColSize( 1, aWidth - fixedColsWidth );
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnUpdateUI( wxUpdateUIEvent& event )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-05-30 10:52:19 +00:00
|
|
|
wxString shownColumns = m_grid->GetShownColumns();
|
2009-05-12 12:12:34 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( shownColumns != m_shownColumns )
|
2010-12-04 12:56:19 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
m_shownColumns = shownColumns;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
if( !m_grid->IsCellEditControlShown() )
|
|
|
|
AdjustGridColumns( m_grid->GetRect().GetWidth() );
|
2016-04-17 15:15:26 +00:00
|
|
|
}
|
2013-08-08 16:12:41 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
// Handle a delayed focus
|
|
|
|
if( m_delayedFocusRow >= 0 )
|
2008-12-30 19:18:56 +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-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_grid->EnableCellEditControl( true );
|
|
|
|
m_grid->ShowCellEditControl();
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
m_delayedFocusRow = -1;
|
|
|
|
m_delayedFocusColumn = -1;
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnSizeGrid( wxSizeEvent& event )
|
2008-12-30 19:18:56 +00:00
|
|
|
{
|
2018-02-28 16:54:35 +00:00
|
|
|
AdjustGridColumns( event.GetSize().GetX() );
|
2008-12-30 19:18:56 +00:00
|
|
|
|
2018-02-28 16:54:35 +00:00
|
|
|
event.Skip();
|
2008-12-30 19:18:56 +00:00
|
|
|
}
|