KiCad PCB EDA Suite
dialog_global_lib_table_config.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019 Wayne Stambaugh <[email protected]>
5 * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22
23#include <pgm_base.h>
24#include <search_stack.h>
25#include <systemdirsappend.h>
26
28
29
31 const wxString& aTableName,
32 const KIWAY::FACE_T aFaceType ) :
34 m_tableName( aTableName ),
35 m_defaultFileFound( false ),
36 m_faceType( aFaceType )
37{
38 wxString tmp;
39
40 tmp.Printf( _( "Configure Global %s Library Table" ), aTableName.Capitalize() );
41 SetTitle( tmp );
42
43 tmp.Printf( _( "KiCad has been run for the first time using the new %s library table for\n"
44 "accessing libraries. In order for KiCad to access %s libraries,\n"
45 "you must configure your global %s library table. Please select from one\n"
46 "of the options below. If you are not sure which option to select, please\n"
47 "use the default selection." ), aTableName, aTableName, aTableName );
48 m_staticText1->SetLabel( tmp );
49
50 tmp.Printf( _( "Copy default global %s library table (recommended)"), aTableName );
51 m_defaultRb->SetLabel( tmp );
52 tmp.Printf( _( "Select this option if you not sure about configuring the global %s library "
53 "table" ), aTableName );
54 m_defaultRb->SetToolTip( tmp );
55
56 tmp.Printf( _( "Copy custom global %s library table" ), aTableName );
57 m_customRb->SetLabel( tmp );
58 tmp.Printf( _( "Select this option to copy a %s library table file other than the default" ),
59 aTableName );
60 m_customRb->SetToolTip( tmp );
61
62 tmp.Printf( _( "Create an empty global %s library table" ), aTableName );
63 m_emptyRb->SetLabel( tmp );
64 tmp.Printf( _( "Select this option to define %s libraries in project specific library tables" ),
65 aTableName );
66 m_emptyRb->SetToolTip( tmp );
67
68 tmp.Printf( _( "Select global %s library table file:" ), aTableName );
69 m_staticText2->SetLabel( tmp );
70
71 m_filePicker1->Connect( wxEVT_UPDATE_UI,
73 nullptr, this );
74
76
78}
79
80
82{
83 m_filePicker1->Disconnect( wxEVT_UPDATE_UI,
85 nullptr, this );
86}
87
88
90{
91 aEvent.Enable( m_customRb->GetValue() );
92}
93
94
96{
97 aEvent.Enable( m_defaultFileFound );
98}
99
100
102{
103 if( !wxDialog::TransferDataToWindow() )
104 return false;
105
106 wxFileName fn = GetGlobalTableFileName();
107
108 SEARCH_STACK ss;
109
111
112 wxString templatePath =
113 Pgm().GetLocalEnvVariables().at( wxT( "KICAD7_TEMPLATE_DIR" ) ).GetValue();
114
115 if( !templatePath.IsEmpty() )
116 ss.AddPaths( templatePath, 0 );
117 else
118 templatePath = KIPLATFORM::ENV::GetUserConfigPath();
119
120 m_filePicker1->SetInitialDirectory( templatePath );
121
122 // Attempt to find the default global file table from the KiCad template folder.
123 wxString fileName = ss.FindValidPath( fn.GetName() );
124
125 m_defaultFileFound = wxFileName::FileExists( fileName );
126
128 {
129 m_filePicker1->SetPath(fileName );
130 m_filePicker1->Enable( false );
131 }
132 else
133 {
134 m_customRb->SetValue( true );
135 }
136
137 return true;
138}
Class DIALOG_GLOBAL_LIB_TABLE_CONFIG_BASE.
virtual void onUpdateDefaultSelection(wxUpdateUIEvent &aEvent) override
DIALOG_GLOBAL_LIB_TABLE_CONFIG(wxWindow *aParent, const wxString &aTableName, const KIWAY::FACE_T aFaceType)
virtual void onUpdateFilePicker(wxUpdateUIEvent &aEvent) override
virtual wxFileName GetGlobalTableFileName()=0
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
FACE_T
Known KIFACE implementations.
Definition: kiway.h:280
Look for files in a number of paths.
Definition: search_stack.h:42
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
#define _(s)
wxString GetUserConfigPath()
Retrieves the operating system specific path for a user's configuration store.
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
void GlobalPathsAppend(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
System directories search utilities.