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 <stambaughw@gmail.com>
5  * Copyright (C) 2019-2020 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 
27 #include <wx/stdpaths.h>
28 
29 
31  const wxString& aTableName ) :
33  m_defaultFileFound( false )
34 {
35  m_tableName = aTableName;
36 
37  wxString tmp;
38 
39  tmp.Printf( _( "Configure Global %s Library Table" ), aTableName.Capitalize() );
40  SetTitle( tmp );
41 
42  tmp.Printf( _( "KiCad has been run for the first time using the new %s library table for\n"
43  "accessing libraries. In order for KiCad to access %s libraries,\n"
44  "you must configure your global %s library table. Please select from one\n"
45  "of the options below. If you are not sure which option to select, please\n"
46  "use the default selection." ), aTableName, aTableName, aTableName );
47  m_staticText1->SetLabel( tmp );
48 
49  tmp.Printf( _( "Copy default global %s library table (recommended)"), aTableName );
50  m_defaultRb->SetLabel( tmp );
51  tmp.Printf( _( "Select this option if you not sure about configuring the global %s library "
52  "table" ), aTableName );
53  m_defaultRb->SetToolTip( tmp );
54 
55  tmp.Printf( _( "Copy custom global %s library table" ), aTableName );
56  m_customRb->SetLabel( tmp );
57  tmp.Printf( _( "Select this option to copy a %s library table file other than the default" ),
58  aTableName );
59  m_customRb->SetToolTip( tmp );
60 
61  tmp.Printf( _( "Create an empty global %s library table" ), aTableName );
62  m_emptyRb->SetLabel( tmp );
63  tmp.Printf( _( "Select this option to define %s libraries in project specific library tables" ),
64  aTableName );
65  m_emptyRb->SetToolTip( tmp );
66 
67  tmp.Printf( _( "Select global %s library table file:" ), aTableName );
68  m_staticText2->SetLabel( tmp );
69 
70  m_filePicker1->Connect( wxEVT_UPDATE_UI,
72  NULL, this );
73 
74  wxButton* okButton = (wxButton *) FindWindowById( wxID_OK );
75 
76  if( okButton )
77  okButton->SetDefault();
78 
80 }
81 
82 
84 {
85  m_filePicker1->Disconnect( wxEVT_UPDATE_UI,
87  NULL, this );
88 }
89 
90 
92 {
93  aEvent.Enable( m_customRb->GetValue() );
94 }
95 
96 
98 {
99  aEvent.Enable( m_defaultFileFound );
100 }
101 
102 
104 {
105  if( !wxDialog::TransferDataToWindow() )
106  return false;
107 
108  wxFileName fn = GetGlobalTableFileName();
109 
110  SEARCH_STACK ss;
111 
112  SystemDirsAppend( &ss );
113 
114  wxString templatePath =
115  Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_TEMPLATE_DIR" ) ).GetValue();
116 
117  if( !templatePath.IsEmpty() )
118  ss.AddPaths( templatePath, 0 );
119  else
120  templatePath = wxStandardPaths::Get().GetUserConfigDir();
121 
122  m_filePicker1->SetInitialDirectory( templatePath );
123 
124  // Attempt to find the default global file table from the KiCad template folder.
125  wxString fileName = ss.FindValidPath( fn.GetName() );
126 
127  m_defaultFileFound = wxFileName::FileExists( fileName );
128 
129  if( m_defaultFileFound )
130  {
131  m_filePicker1->SetPath(fileName );
132  m_filePicker1->Enable( false );
133  }
134  else
135  {
136  m_customRb->SetValue( true );
137  }
138 
139  return true;
140 }
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:70
virtual void onUpdateFilePicker(wxUpdateUIEvent &aEvent) override
System directories search utilities.
DIALOG_GLOBAL_LIB_TABLE_CONFIG(wxWindow *aParent, const wxString &aTableName)
Look for files in a number of paths.
Definition: search_stack.h:41
Class DIALOG_GLOBAL_LIB_TABLE_CONFIG_BASE.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
#define NULL
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
virtual wxFileName GetGlobalTableFileName()=0
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
see class PGM_BASE
#define _(s)
Definition: 3d_actions.cpp:33
virtual void onUpdateDefaultSelection(wxUpdateUIEvent &aEvent) override
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).