2015-01-11 17:22:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-09-21 23:17:54 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-01-11 17:22:45 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
2023-09-21 23:17:54 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
|
|
|
#include <bitmaps.h>
|
2015-01-11 17:22:45 +00:00
|
|
|
#include <project.h> // For PROJECT_VAR_NAME definition
|
2023-01-22 18:38:02 +00:00
|
|
|
#include <fp_lib_table.h> // For KICAD7_FOOTPRINT_DIR definition
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
#include <dialog_config_equfiles.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project/project_file.h>
|
2020-05-26 02:27:27 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2015-01-11 17:22:45 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
DIALOG_CONFIG_EQUFILES::DIALOG_CONFIG_EQUFILES( wxWindow* aParent ) :
|
2015-01-11 17:22:45 +00:00
|
|
|
DIALOG_CONFIG_EQUFILES_BASE( aParent )
|
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
SetTitle( wxString::Format( _( "Project file: '%s'" ), Prj().GetProjectFullName() ) );
|
2018-06-04 14:06:33 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
m_bpAdd->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
|
|
|
m_bpEdit->SetBitmap( KiBitmap( BITMAPS::small_edit ) );
|
|
|
|
m_bpMoveUp->SetBitmap( KiBitmap( BITMAPS::small_up ) );
|
|
|
|
m_bpMoveDown->SetBitmap( KiBitmap( BITMAPS::small_down ) );
|
|
|
|
m_bpDelete->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
|
2018-06-04 14:06:33 +00:00
|
|
|
|
2020-05-26 02:27:27 +00:00
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
|
|
|
|
|
|
|
if( !project.m_EquivalenceFiles.empty() )
|
|
|
|
{
|
|
|
|
wxArrayString arr;
|
|
|
|
|
|
|
|
for( const auto& entry : project.m_EquivalenceFiles )
|
|
|
|
arr.Add( entry );
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->InsertItems( arr, 0 );
|
2020-05-26 02:27:27 +00:00
|
|
|
}
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
m_gridEnvVars->ClearRows();
|
|
|
|
m_gridEnvVars->AppendRows( 2 );
|
|
|
|
m_gridEnvVars->SetCellValue( 0, 0, PROJECT_VAR_NAME );
|
|
|
|
m_gridEnvVars->SetCellValue( 1, 0, FP_LIB_TABLE::GlobalPathEnvVariableName() );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
for( int row = 0; row < m_gridEnvVars->GetTable()->GetRowsCount(); row++ )
|
2015-01-11 17:22:45 +00:00
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
wxString evValue;
|
|
|
|
|
2015-01-11 17:22:45 +00:00
|
|
|
if( wxGetEnv( m_gridEnvVars->GetCellValue( row, 0 ), &evValue ) )
|
|
|
|
m_gridEnvVars->SetCellValue( row, 1, evValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_gridEnvVars->AutoSizeColumns();
|
2023-09-21 23:17:54 +00:00
|
|
|
|
|
|
|
SetupStandardButtons();
|
|
|
|
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Center();
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 14:06:33 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
void DIALOG_CONFIG_EQUFILES::OnEditEquFile( wxCommandEvent& event )
|
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
wxString editorname = Pgm().GetTextEditor();
|
2015-01-15 20:01:53 +00:00
|
|
|
|
|
|
|
if( editorname.IsEmpty() )
|
|
|
|
{
|
2021-09-19 13:45:27 +00:00
|
|
|
wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
|
2015-01-15 20:01:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayInt selections;
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->GetSelections( selections );
|
2015-01-15 20:01:53 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < selections.GetCount(); ii++ )
|
2023-09-21 23:17:54 +00:00
|
|
|
ExecuteFile( editorname, wxExpandEnvVars( m_filesListBox->GetString( selections[ii] ) ) );
|
2015-01-15 20:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
void DIALOG_CONFIG_EQUFILES::OnOkClick( wxCommandEvent& event )
|
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
2020-05-26 02:27:27 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
// Recreate equ list
|
|
|
|
project.m_EquivalenceFiles.clear();
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
for( unsigned ii = 0; ii < m_filesListBox->GetCount(); ii++ )
|
|
|
|
project.m_EquivalenceFiles.emplace_back( m_filesListBox->GetString( ii ) );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
Pgm().GetSettingsManager().SaveProject();
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIG_EQUFILES::OnCloseWindow( wxCloseEvent& event )
|
|
|
|
{
|
|
|
|
EndModal( wxID_CANCEL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIG_EQUFILES::OnButtonMoveUp( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxArrayInt selections;
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->GetSelections( selections );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
if ( selections.GetCount() <= 0 ) // No selection.
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( selections[0] == 0 ) // The first lib is selected. cannot move up it
|
|
|
|
return;
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
wxArrayString libnames = m_filesListBox->GetStrings();
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
for( size_t ii = 0; ii < selections.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
int jj = selections[ii];
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( libnames[jj], libnames[jj-1] );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->Set( libnames );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
// Reselect previously selected names
|
|
|
|
for( size_t ii = 0; ii < selections.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
int jj = selections[ii];
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->SetSelection( jj-1 );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIG_EQUFILES::OnButtonMoveDown( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxArrayInt selections;
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->GetSelections( selections );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
if ( selections.GetCount() <= 0 ) // No selection.
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The last lib is selected. cannot move down it
|
2023-09-21 23:17:54 +00:00
|
|
|
if( selections.Last() == int( m_filesListBox->GetCount()-1 ) )
|
2015-01-11 17:22:45 +00:00
|
|
|
return;
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
wxArrayString libnames = m_filesListBox->GetStrings();
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
for( int ii = selections.GetCount()-1; ii >= 0; ii-- )
|
|
|
|
{
|
|
|
|
int jj = selections[ii];
|
2018-06-04 14:06:33 +00:00
|
|
|
std::swap( libnames[jj], libnames[jj+1] );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->Set( libnames );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
// Reselect previously selected names
|
|
|
|
for( size_t ii = 0; ii < selections.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
int jj = selections[ii];
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->SetSelection( jj+1 );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Remove a library to the library list.
|
|
|
|
* The real list (g_LibName_List) is not changed, so the change can be canceled
|
|
|
|
*/
|
|
|
|
void DIALOG_CONFIG_EQUFILES::OnRemoveFiles( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxArrayInt selections;
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->GetSelections( selections );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
std::sort( selections.begin(), selections.end() );
|
|
|
|
|
|
|
|
for( int ii = selections.GetCount()-1; ii >= 0; ii-- )
|
2023-09-21 23:17:54 +00:00
|
|
|
m_filesListBox->Delete( selections[ii] );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CONFIG_EQUFILES::OnAddFiles( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// Get a default path to open the file dialog:
|
|
|
|
wxArrayInt selectedRows = m_gridEnvVars->GetSelectedRows();
|
2023-09-21 23:17:54 +00:00
|
|
|
int row = selectedRows.GetCount() ? selectedRows[0] : m_gridEnvVars->GetGridCursorRow();
|
|
|
|
wxString libpath = m_gridEnvVars->GetCellValue( wxGridCellCoords( row, 1 ) );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
wxFileDialog dlg( this, _( "Footprint Association File" ), libpath, wxEmptyString,
|
|
|
|
EquFileWildcard(), wxFD_DEFAULT_STYLE | wxFD_MULTIPLE );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2015-01-11 17:22:45 +00:00
|
|
|
return;
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
wxArrayString filenames;
|
|
|
|
dlg.GetPaths( filenames );
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
for( unsigned jj = 0; jj < filenames.GetCount(); jj++ )
|
2015-01-11 17:22:45 +00:00
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
wxFileName fn = filenames[jj];
|
|
|
|
wxString filepath;
|
2015-01-11 17:22:45 +00:00
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
for( row = 0; row < m_gridEnvVars->GetTable()->GetRowsCount(); row++ )
|
2015-01-11 17:22:45 +00:00
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
libpath = m_gridEnvVars->GetCellValue( wxGridCellCoords( row, 1 ) );
|
|
|
|
|
|
|
|
if( fn.MakeRelativeTo( libpath ) )
|
2015-01-11 17:22:45 +00:00
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
filepath.Printf( wxT( "${%s}%c%s" ),
|
|
|
|
m_gridEnvVars->GetCellValue( wxGridCellCoords( row, 0 ) ),
|
|
|
|
wxFileName::GetPathSeparator(),
|
|
|
|
fn.GetFullPath() );
|
|
|
|
break;
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 23:17:54 +00:00
|
|
|
if( filepath.IsEmpty() )
|
|
|
|
filepath = filenames[jj];
|
2015-01-11 17:22:45 +00:00
|
|
|
|
|
|
|
// Add or insert new library name, if not already in list
|
2023-09-21 23:17:54 +00:00
|
|
|
if( m_filesListBox->FindString( filepath, wxFileName::IsCaseSensitive() ) == wxNOT_FOUND )
|
2015-01-11 17:22:45 +00:00
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
filepath.Replace( wxT( "\\" ), wxT( "/" ) ); // Use unix separators only.
|
|
|
|
m_filesListBox->Append( filepath );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-21 23:17:54 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "File '%s' already exists in list." ),
|
|
|
|
filepath.GetData() ) );
|
2015-01-11 17:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|