Fix paths for Copy default global library table.

This commit is contained in:
Alex 2023-01-27 09:24:50 +03:00
parent a0236113da
commit a872ed11bf
7 changed files with 88 additions and 74 deletions

View File

@ -28,12 +28,13 @@
DIALOG_GLOBAL_LIB_TABLE_CONFIG::DIALOG_GLOBAL_LIB_TABLE_CONFIG( wxWindow* aParent,
const wxString& aTableName ) :
const wxString& aTableName,
const KIWAY::FACE_T aFaceType ) :
DIALOG_GLOBAL_LIB_TABLE_CONFIG_BASE( aParent ),
m_defaultFileFound( false )
m_defaultFileFound( false ),
m_faceType( aFaceType ),
m_tableName( aTableName )
{
m_tableName = aTableName;
wxString tmp;
tmp.Printf( _( "Configure Global %s Library Table" ), aTableName.Capitalize() );
@ -106,7 +107,7 @@ bool DIALOG_GLOBAL_LIB_TABLE_CONFIG::TransferDataToWindow()
SEARCH_STACK ss;
SystemDirsAppend( &ss );
GlobalPathsAppend( &ss, m_faceType );
wxString templatePath =
Pgm().GetLocalEnvVariables().at( wxT( "KICAD7_TEMPLATE_DIR" ) ).GetValue();

View File

@ -28,77 +28,12 @@
#include <search_stack.h>
#include <systemdirsappend.h>
/// Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
/// A non-member function so it an be moved easily, plus it's nobody's business.
static void setSearchPaths( SEARCH_STACK* aDst, KIWAY::FACE_T aId )
{
SEARCH_STACK bases;
SystemDirsAppend( &bases );
aDst->Clear();
for( unsigned i = 0; i < bases.GetCount(); ++i )
{
wxFileName fn( bases[i], wxEmptyString );
// Add schematic library file path to search path list.
// we must add <kicad path>/library and <kicad path>/library/doc
if( aId == KIWAY::FACE_SCH )
{
// Add schematic doc file path (library/doc) to search path list.
fn.AppendDir( wxT( "library" ) );
aDst->AddPaths( fn.GetPath() );
fn.AppendDir( wxT( "doc" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
fn.RemoveLastDir(); // "../../" up twice, removing library/doc/
fn.AppendDir( wxT( "symbols" ) );
aDst->AddPaths( fn.GetPath() );
fn.AppendDir( wxT( "doc" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
fn.RemoveLastDir(); // "../../" up twice, removing symbols/doc/
}
// Add PCB library file path to search path list.
if( aId == KIWAY::FACE_PCB || aId == KIWAY::FACE_CVPCB )
{
fn.AppendDir( wxT( "modules" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
fn.AppendDir( wxT( "footprints" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
// Add 3D module library file path to search path list.
fn.AppendDir( wxT( "3dmodels" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
}
// Add KiCad template file path to search path list.
fn.AppendDir( wxT( "template" ) );
aDst->AddPaths( fn.GetPath() );
}
#ifndef __WXMAC__
aDst->AddPaths( wxT( "/usr/local/share" ) );
#endif
}
bool KIFACE_BASE::start_common( int aCtlBits )
{
m_start_flags = aCtlBits;
m_bm.Init();
setSearchPaths( &m_bm.m_search, m_id );
GlobalPathsAppend( &m_bm.m_search, m_id );
return true;
}

View File

@ -25,6 +25,7 @@
#include <wx/stdpaths.h>
#include <systemdirsappend.h>
#include <common.h>
#include <kiplatform/environment.h>
#include <search_stack.h>
@ -172,3 +173,67 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
aSearchStack->Show( __func__ );
#endif
}
void GlobalPathsAppend( SEARCH_STACK* aDst, KIWAY::FACE_T aId )
{
SEARCH_STACK bases;
SystemDirsAppend( &bases );
aDst->Clear();
for( unsigned i = 0; i < bases.GetCount(); ++i )
{
wxFileName fn( bases[i], wxEmptyString );
// Add schematic library file path to search path list.
// we must add <kicad path>/library and <kicad path>/library/doc
if( aId == KIWAY::FACE_SCH )
{
// Add schematic doc file path (library/doc) to search path list.
fn.AppendDir( wxT( "library" ) );
aDst->AddPaths( fn.GetPath() );
fn.AppendDir( wxT( "doc" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
fn.RemoveLastDir(); // "../../" up twice, removing library/doc/
fn.AppendDir( wxT( "symbols" ) );
aDst->AddPaths( fn.GetPath() );
fn.AppendDir( wxT( "doc" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
fn.RemoveLastDir(); // "../../" up twice, removing symbols/doc/
}
// Add PCB library file path to search path list.
if( aId == KIWAY::FACE_PCB || aId == KIWAY::FACE_CVPCB )
{
fn.AppendDir( wxT( "modules" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
fn.AppendDir( wxT( "footprints" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
// Add 3D module library file path to search path list.
fn.AppendDir( wxT( "3dmodels" ) );
aDst->AddPaths( fn.GetPath() );
fn.RemoveLastDir();
}
// Add KiCad template file path to search path list.
fn.AppendDir( wxT( "template" ) );
aDst->AddPaths( fn.GetPath() );
}
#ifndef __WXMAC__
aDst->AddPaths( wxT( "/usr/local/share" ) );
#endif
}

View File

@ -22,13 +22,14 @@
#include <confirm.h>
#include <kiface_base.h>
#include <kiway.h>
#include <macros.h>
#include "symbol_lib_table.h"
DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG( wxWindow* aParent ) :
DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "symbol" ) )
DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "symbol" ), KIWAY::FACE_SCH )
{
}

View File

@ -23,13 +23,15 @@
#include "dialog_global_lib_table_config_base.h"
#include <kiway.h>
#include <wx/filename.h>
class DIALOG_GLOBAL_LIB_TABLE_CONFIG : public DIALOG_GLOBAL_LIB_TABLE_CONFIG_BASE
{
public:
DIALOG_GLOBAL_LIB_TABLE_CONFIG( wxWindow* aParent, const wxString& aTableName );
DIALOG_GLOBAL_LIB_TABLE_CONFIG( wxWindow* aParent, const wxString& aTableName,
const KIWAY::FACE_T aFaceType );
virtual ~DIALOG_GLOBAL_LIB_TABLE_CONFIG();
virtual wxFileName GetGlobalTableFileName() = 0;
@ -42,6 +44,7 @@ protected:
wxString m_tableName;
bool m_defaultFileFound;
KIWAY::FACE_T m_faceType;
};
#endif // _DIALOG_GLOBAL_LIB_TABLE_CONFIG_H_

View File

@ -29,6 +29,8 @@
#ifndef INCLUDE__SYSTEM_DIRS_APPEND_H_
#define INCLUDE__SYSTEM_DIRS_APPEND_H_
#include <kiway.h>
class SEARCH_STACK;
/**
@ -37,4 +39,10 @@ class SEARCH_STACK;
*/
void SystemDirsAppend( SEARCH_STACK* aSearchStack );
/**
* Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
* Adds libraries, docs, template paths to the search stack.
*/
void GlobalPathsAppend( SEARCH_STACK* aDst, KIWAY::FACE_T aId );
#endif // INCLUDE__SYSTEM_DIRS_APPEND_H_

View File

@ -22,12 +22,13 @@
#include <confirm.h>
#include <kiface_base.h>
#include <kiway.h>
#include "fp_lib_table.h"
DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG( wxWindow* aParent ) :
DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "footprint" ) )
DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "footprint" ), KIWAY::FACE_PCB )
{
}