Add browse button to footprint 3d settings

Add normalization to 3d settings and footprint library table editor
This commit is contained in:
Mark Roszko 2020-09-01 02:00:38 +00:00 committed by Jon Evans
parent 2feef44fca
commit a9532c2fa1
12 changed files with 145 additions and 77 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -27,6 +27,7 @@
#include <kiway.h>
#include <kiway_player.h>
#include <dialog_shim.h>
#include <env_paths.h>
#include <widgets/grid_text_button_helpers.h>
#include <eda_doc.h>
@ -314,11 +315,14 @@ class TEXT_BUTTON_FILE_BROWSER : public wxComboCtrl
{
public:
TEXT_BUTTON_FILE_BROWSER( wxWindow* aParent, DIALOG_SHIM* aParentDlg,
wxString* aCurrentDir, wxString* aExt = nullptr ) :
wxString* aCurrentDir, wxString* aExt = nullptr,
bool aNormalize = false, wxString aNormalizeBasePath = wxEmptyString ) :
wxComboCtrl( aParent ),
m_dlg( aParentDlg ),
m_currentDir( aCurrentDir ),
m_ext( aExt )
m_ext( aExt ),
m_normalize( aNormalize ),
m_normalizeBasePath( aNormalizeBasePath )
{
SetButtonBitmaps( KiBitmap( folder_xpm ) );
}
@ -340,13 +344,29 @@ protected:
if( m_ext )
{
wxFileDialog dlg( nullptr, _( "Select a File" ), path, wxEmptyString, *m_ext,
wxFileName fn( path );
wxFileDialog dlg( nullptr, _( "Select a File" ), fn.GetPath(), fn.GetFullName(), *m_ext,
wxFD_FILE_MUST_EXIST | wxFD_OPEN );
if( dlg.ShowModal() == wxID_OK )
{
SetValue( dlg.GetPath() );
*m_currentDir = dlg.GetPath();
wxString filePath = dlg.GetPath();
wxString lastPath = dlg.GetDirectory();
wxString relPath = wxEmptyString;
if( m_normalize )
{
relPath = NormalizePath( filePath, &Pgm().GetLocalEnvVariables(),
m_normalizeBasePath );
lastPath = NormalizePath( dlg.GetDirectory(), &Pgm().GetLocalEnvVariables(),
m_normalizeBasePath );
}
if( relPath.IsEmpty() )
relPath = filePath;
SetValue( relPath );
*m_currentDir = lastPath;
}
}
else
@ -356,8 +376,20 @@ protected:
if( dlg.ShowModal() == wxID_OK )
{
SetValue( dlg.GetPath() );
*m_currentDir = dlg.GetPath();
wxString filePath = dlg.GetPath();
wxString relPath = wxEmptyString;
if ( m_normalize )
{
relPath = NormalizePath( filePath, &Pgm().GetLocalEnvVariables(),
m_normalizeBasePath );
}
if( relPath.IsEmpty() )
relPath = filePath;
SetValue( relPath );
*m_currentDir = relPath;
}
}
}
@ -365,6 +397,8 @@ protected:
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
wxString* m_ext;
bool m_normalize;
wxString m_normalizeBasePath;
};
@ -372,9 +406,11 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
if( m_ext.IsEmpty() )
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir );
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, nullptr,
m_normalize, m_normalizeBasePath );
else
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, &m_ext );
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, &m_ext,
m_normalize, m_normalizeBasePath );
#if wxUSE_VALIDATORS
// validate text in textctrl, if validator is set
@ -385,23 +421,4 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
#endif
wxGridCellEditor::Create( aParent, aId, aEventHandler );
}
void GRID_CELL_SYMLIB_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, &m_ext );
#if wxUSE_VALIDATORS
// validate text in textctrl, if validator is set
if ( m_validator )
{
Combo()->SetValidator( *m_validator );
}
#endif
wxGridCellEditor::Create( aParent, aId, aEventHandler );
}
}

View File

@ -39,7 +39,9 @@
#include <lib_view_frame.h>
#include <sch_edit_frame.h>
#include <kiway.h>
#include <pgm_base.h>
#include <sch_screen.h>
#include <settings/settings_manager.h>
#include <widgets/grid_readonly_text_helpers.h>
#include <widgets/grid_text_button_helpers.h>
@ -214,8 +216,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
m_globalTable( aGlobal ),
m_projectTable( aProject ),
m_projectBasePath( aProjectBasePath ),
m_parent( aParent ),
m_lastBrowseDir( aProjectBasePath )
m_parent( aParent )
{
// wxGrid only supports user owned tables if they exist past end of ~wxGrid(),
// so make it a grid owned table.
@ -229,6 +230,13 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_KICAD ) );
pluginChoices.Add( SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
if( cfg->m_lastSymbolLibDir.IsEmpty() )
{
cfg->m_lastSymbolLibDir = m_projectBasePath;
}
auto setupGrid =
[&]( WX_GRID* aGrid )
{
@ -245,8 +253,13 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_SYMLIB_EDITOR( m_parent, &m_lastBrowseDir,
KiCadSymbolLibFileWildcard() ) );
wxString wildcards = AllSymbolLibFilesWildcard()
+ "|" + KiCadSymbolLibFileWildcard()
+ "|" + LegacySymbolLibFileWildcard();
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &cfg->m_lastSymbolLibDir,
wildcards,
true, m_projectBasePath ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;
@ -467,7 +480,8 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
+ "|" + KiCadSymbolLibFileWildcard()
+ "|" + LegacySymbolLibFileWildcard();
wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir, wxEmptyString, wildcards,
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
wxFileDialog dlg( this, _( "Select Library" ), cfg->m_lastSymbolLibDir, wxEmptyString, wildcards,
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
auto result = dlg.ShowModal();
@ -475,7 +489,7 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
if( result == wxID_CANCEL )
return;
m_lastBrowseDir = dlg.GetDirectory();
cfg->m_lastSymbolLibDir = dlg.GetDirectory();
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
bool addDuplicates = false;

View File

@ -79,7 +79,6 @@ private:
WX_GRID* m_cur_grid; ///< changed based on tab choice
static size_t m_pageNdx; ///< Remember the last notebook page selected during a session
wxString m_lastBrowseDir; ///< last browsed directory
};

View File

@ -335,6 +335,9 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() :
m_params.emplace_back( new PARAM<bool>( "lib_view.show_pin_electrical_type",
&m_LibViewPanel.show_pin_electrical_type, true ) );
m_params.emplace_back( new PARAM<wxString>( "system.last_symbol_lib_dir",
&m_lastSymbolLibDir, "" ) );
}

View File

@ -209,6 +209,8 @@ public:
bool m_RescueNeverShow;
wxString m_lastSymbolLibDir;
protected:
virtual std::string getLegacyFrameName() const override { return "SchematicFrame"; }

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -128,13 +128,27 @@ protected:
};
/**
* Editor for wxGrid cells that adds a file/folder browser to the grid input field
*/
class GRID_CELL_PATH_EDITOR : public GRID_CELL_TEXT_BUTTON
{
public:
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParent, wxString* aCurrentDir, const wxString& aExt ) :
/**
* Constructor
*
* @param aCurrentDir is current directory the path editor will open at
* @param aExt is the file extension(s) to filter by. If empty, the path editor will switch to folder mode instead of file.
* @param aNormalize indicates whether to normalize the selected path (replace part of path with variables or relative path)
* @param aNormalizeBasePath is the path to use when trying to base variables (generally current project path)
*/
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParent, wxString* aCurrentDir, const wxString& aExt,
bool aNormalize = false, wxString aNormalizeBasePath = wxEmptyString ) :
m_dlg( aParent ),
m_currentDir( aCurrentDir ),
m_ext( aExt )
m_ext( aExt ),
m_normalize( aNormalize ),
m_normalizeBasePath( aNormalizeBasePath )
{ }
wxGridCellEditor* Clone() const override
@ -148,29 +162,8 @@ protected:
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
wxString m_ext;
};
class GRID_CELL_SYMLIB_EDITOR : public GRID_CELL_TEXT_BUTTON
{
public:
GRID_CELL_SYMLIB_EDITOR( DIALOG_SHIM* aParent, wxString* aCurrentDir, const wxString& aExt ) :
m_dlg( aParent ),
m_currentDir( aCurrentDir ),
m_ext( aExt )
{ }
wxGridCellEditor* Clone() const override
{
return new GRID_CELL_SYMLIB_EDITOR( m_dlg, m_currentDir, m_ext );
}
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
protected:
DIALOG_SHIM* m_dlg;
wxString* m_currentDir;
wxString m_ext;
bool m_normalize;
wxString m_normalizeBasePath;
};

View File

@ -37,8 +37,10 @@
#include <pcbnew_settings.h>
#include <pgm_base.h>
#include <validators.h>
#include <widgets/grid_text_button_helpers.h>
#include <widgets/text_ctrl_eval.h>
#include <widgets/wx_grid.h>
#include <settings/settings_manager.h>
#include "3d_cache/dialogs/3d_cache_dialogs.h"
#include "3d_cache/dialogs/panel_prev_3d.h"
@ -48,6 +50,7 @@
int DIALOG_FOOTPRINT_BOARD_EDITOR::m_page = 0; // remember the last open page during session
DIALOG_FOOTPRINT_BOARD_EDITOR::DIALOG_FOOTPRINT_BOARD_EDITOR( PCB_EDIT_FRAME* aParent,
MODULE* aModule ) :
DIALOG_FOOTPRINT_BOARD_EDITOR_BASE( aParent ),
@ -94,7 +97,20 @@ DIALOG_FOOTPRINT_BOARD_EDITOR::DIALOG_FOOTPRINT_BOARD_EDITOR( PCB_EDIT_FRAME* aP
m_itemsGrid->ShowHideColumns( m_frame->GetPcbNewSettings()->m_FootprintTextShownColumns );
// Set up the 3D models grid
// Path selector
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
if( cfg->m_lastFootprint3dDir.IsEmpty() )
{
wxGetEnv( KISYS3DMOD, &cfg->m_lastFootprint3dDir );
}
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
true, Prj().GetProjectPath() ) );
m_modelsGrid->SetColAttr( 0, attr );
// Show checkbox
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );

View File

@ -35,6 +35,7 @@
#include <board_design_settings.h>
#include <board_commit.h>
#include <bitmaps.h>
#include <widgets/grid_text_button_helpers.h>
#include <widgets/wx_grid.h>
#include <widgets/text_ctrl_eval.h>
#include <class_module.h>
@ -45,6 +46,7 @@
#include <pgm_base.h>
#include "3d_cache/dialogs/panel_prev_3d.h"
#include "3d_cache/dialogs/3d_cache_dialogs.h"
#include <settings/settings_manager.h>
#include <fp_lib_table.h>
@ -88,8 +90,19 @@ DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR( FOOTPRINT_EDIT_FRAME* aP
// Show/hide columns according to the user's preference
m_itemsGrid->ShowHideColumns( m_frame->GetSettings()->m_FootprintTextShownColumns );
// Set up the 3D models grid
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
if( cfg->m_lastFootprint3dDir.IsEmpty() )
{
wxGetEnv( KISYS3DMOD, &cfg->m_lastFootprint3dDir );
}
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, &cfg->m_lastFootprint3dDir, "*.*",
true, Prj().GetProjectPath() ) );
m_modelsGrid->SetColAttr( 0, attr );
// Show checkbox
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_BOTTOM );

View File

@ -59,6 +59,7 @@
#include <widgets/grid_readonly_text_helpers.h>
#include <widgets/grid_text_button_helpers.h>
#include <pcbnew_id.h> // For ID_PCBNEW_END_LIST
#include <settings/settings_manager.h>
// clang-format off
@ -387,6 +388,10 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
/* PCAD_PLUGIN does not support Footprint*() functions
choices.Add( IO_MGR::ShowType( IO_MGR::PCAD ) );
*/
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
if( cfg->m_lastFootprintLibDir.IsEmpty() )
cfg->m_lastFootprintLibDir = m_projectBasePath;
auto setupGrid =
[&]( WX_GRID* aGrid )
@ -403,8 +408,8 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
wxGridCellAttr* attr;
attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &m_lastBrowseDir,
wxEmptyString ) );
attr->SetEditor( new GRID_CELL_PATH_EDITOR( m_parent, &cfg->m_lastFootprintLibDir,
wxEmptyString, true, m_projectBasePath ) );
aGrid->SetColAttr( COL_URI, attr );
attr = new wxGridCellAttr;
@ -770,8 +775,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
supportedFileType fileType = fileTypeIt->second;
if( m_lastBrowseDir.IsEmpty() )
m_lastBrowseDir = m_projectBasePath;
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
wxArrayString files;
@ -781,7 +785,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
if( fileType.m_IsFile )
{
wxFileDialog dlg( this, title, m_lastBrowseDir, wxEmptyString,
wxFileDialog dlg( this, title, cfg->m_lastFootprintLibDir, wxEmptyString,
fileType.m_FileFilter, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
int result = dlg.ShowModal();
@ -791,11 +795,11 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
dlg.GetPaths( files );
m_lastBrowseDir = dlg.GetDirectory();
cfg->m_lastFootprintLibDir = dlg.GetDirectory();
}
else
{
wxDirDialog dlg( nullptr, title, m_lastBrowseDir,
wxDirDialog dlg( nullptr, title, cfg->m_lastFootprintLibDir,
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
int result = dlg.ShowModal();
@ -831,12 +835,12 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
files.Add( dlg.GetPath() );
}
m_lastBrowseDir = dlg.GetPath();
cfg->m_lastFootprintLibDir = dlg.GetPath();
}
// Drop the last directory if the path is a .pretty folder
if( m_lastBrowseDir.EndsWith( KiCadFootprintLibPathExtension ) )
m_lastBrowseDir = m_lastBrowseDir.BeforeLast( wxFileName::GetPathSeparator() );
if( cfg->m_lastFootprintLibDir.EndsWith( KiCadFootprintLibPathExtension ) )
cfg->m_lastFootprintLibDir = cfg->m_lastFootprintLibDir.BeforeLast( wxFileName::GetPathSeparator() );
const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
bool addDuplicates = false;
@ -1017,8 +1021,6 @@ void PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable()
size_t PANEL_FP_LIB_TABLE::m_pageNdx = 0;
wxString PANEL_FP_LIB_TABLE::m_lastBrowseDir;
void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller )
{

View File

@ -89,7 +89,6 @@ private:
WX_GRID* m_cur_grid; // changed based on tab choice
static size_t m_pageNdx; // Remember last notebook page selected during a session
static wxString m_lastBrowseDir; // Remember last directory browsed during a session
};
#endif // PANEL_FP_LIB_TABLE_H

View File

@ -471,6 +471,12 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS()
&m_FootprintViewerZoom, 1.0 ) );
addParamsForWindow( &m_FootprintWizard, "footprint_wizard" );
m_params.emplace_back( new PARAM<wxString>( "system.last_footprint_lib_dir",
&m_lastFootprintLibDir, "" ) );
m_params.emplace_back( new PARAM<wxString>( "system.last_footprint3d_dir",
&m_lastFootprint3dDir, "" ) );
}

View File

@ -296,6 +296,10 @@ public:
double m_FootprintViewerZoom; ///< The last zoom level in the footprint viewer
wxString m_lastFootprintLibDir;
wxString m_lastFootprint3dDir;
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
ACTION_PLUGIN_SETTINGS_LIST m_VisibleActionPlugins;
#endif