KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_remote_symbol_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <common.h>
28#include <pgm_base.h>
30#include <widgets/ui_common.h>
31
32#include <wx/button.h>
33#include <wx/dirdlg.h>
34#include <wx/filename.h>
35#include <wx/intl.h>
36#include <wx/msgdlg.h>
37#include <wx/radiobut.h>
38#include <wx/sizer.h>
39#include <wx/stattext.h>
40#include <wx/textctrl.h>
41
42
44 DIALOG_SHIM( aParent, wxID_ANY, _( "Remote Symbol Settings" ), wxDefaultPosition,
45 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
46 m_destinationCtrl( nullptr ),
47 m_prefixCtrl( nullptr ),
48 m_prefixHint( nullptr ),
49 m_projectRadio( nullptr ),
50 m_globalRadio( nullptr ),
51 m_resetButton( nullptr ),
52 m_browseButton( nullptr ),
54{
55 wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL );
56
57 wxStaticText* intro = new wxStaticText( this, wxID_ANY,
58 _( "Configure where downloaded remote libraries are stored and how they are named." ) );
59 intro->Wrap( FromDIP( 420 ) );
60 topSizer->Add( intro, 0, wxALL | wxEXPAND, FromDIP( 10 ) );
61
62 wxFlexGridSizer* gridSizer = new wxFlexGridSizer( 2, FromDIP( 6 ), FromDIP( 6 ) );
63 gridSizer->AddGrowableCol( 1, 1 );
64
65 gridSizer->Add( new wxStaticText( this, wxID_ANY, _( "Destination directory:" ) ),
66 0, wxALIGN_CENTER_VERTICAL );
67
68 wxBoxSizer* destSizer = new wxBoxSizer( wxHORIZONTAL );
69 m_destinationCtrl = new wxTextCtrl( this, wxID_ANY );
70 m_destinationCtrl->SetMinSize( FromDIP( wxSize( 320, -1 ) ) );
71 m_destinationCtrl->SetToolTip( _( "Directory where downloaded symbol, footprint, and 3D model data will be written." ) );
72 destSizer->Add( m_destinationCtrl, 1, wxALIGN_CENTER_VERTICAL );
73
74 m_browseButton = new wxButton( this, wxID_ANY, _( "Browse…" ) );
75 destSizer->Add( m_browseButton, 0, wxLEFT, FromDIP( 4 ) );
76 gridSizer->Add( destSizer, 1, wxEXPAND );
77
78 gridSizer->Add( new wxStaticText( this, wxID_ANY, _( "Library prefix:" ) ),
79 0, wxALIGN_CENTER_VERTICAL );
80 m_prefixCtrl = new wxTextCtrl( this, wxID_ANY );
81 m_prefixCtrl->SetToolTip( _( "Prefix that will be applied to the generated libraries." ) );
82 gridSizer->Add( m_prefixCtrl, 0, wxEXPAND );
83
84 gridSizer->AddSpacer( 0 );
85 m_prefixHint = new wxStaticText( this, wxID_ANY, wxString() );
86 m_prefixHint->SetFont( KIUI::GetSmallInfoFont( this ).Italic() );
87 gridSizer->Add( m_prefixHint, 0, wxEXPAND );
88
89 gridSizer->Add( new wxStaticText( this, wxID_ANY, _( "Add libraries to:" ) ),
90 0, wxALIGN_CENTER_VERTICAL );
91
92 wxBoxSizer* radioSizer = new wxBoxSizer( wxHORIZONTAL );
93 m_projectRadio = new wxRadioButton( this, wxID_ANY, _( "Project library table" ),
94 wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
95 m_projectRadio->SetToolTip( _( "Adds the generated libraries to the project's library tables." ) );
96 radioSizer->Add( m_projectRadio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP( 12 ) );
97
98 m_globalRadio = new wxRadioButton( this, wxID_ANY, _( "Global library table" ) );
99 m_globalRadio->SetToolTip( _( "Adds the generated libraries to the global library tables." ) );
100 radioSizer->Add( m_globalRadio, 0, wxALIGN_CENTER_VERTICAL );
101
102 gridSizer->Add( radioSizer, 0, wxEXPAND );
103
104 topSizer->Add( gridSizer, 0, wxALL | wxEXPAND, FromDIP( 10 ) );
105
106 m_resetButton = new wxButton( this, wxID_ANY, _( "Reset to Defaults" ) );
107 m_resetButton->SetToolTip( _( "Restore the default destination and prefix." ) );
108 topSizer->Add( m_resetButton, 0, wxLEFT | wxBOTTOM, FromDIP( 10 ) );
109
110 wxStdDialogButtonSizer* buttonSizer = CreateStdDialogButtonSizer( wxOK | wxCANCEL );
111 topSizer->Add( buttonSizer, 0, wxALL | wxEXPAND, FromDIP( 10 ) );
112
113 SetSizer( topSizer );
114 topSizer->Fit( this );
115
118
120
124}
125
126
128{
129 if( m_settings )
130 applyRemoteSettings( m_settings->m_RemoteSymbol );
131 else
132 {
134 applyRemoteSettings( defaults );
135 }
136
137 return true;
138}
139
140
142{
143 wxString destination = m_destinationCtrl->GetValue();
144 wxString prefix = m_prefixCtrl->GetValue();
145
146 destination.Trim( true ).Trim( false );
147 prefix.Trim( true ).Trim( false );
148
149 if( destination.IsEmpty() )
150 {
151 wxMessageBox( _( "Please choose a destination directory." ), GetTitle(), wxOK | wxICON_WARNING, this );
152 m_destinationCtrl->SetFocus();
153 return false;
154 }
155
156 if( prefix.IsEmpty() )
157 {
158 wxMessageBox( _( "Please enter a library prefix." ), GetTitle(), wxOK | wxICON_WARNING, this );
159 m_prefixCtrl->SetFocus();
160 return false;
161 }
162
163 if( !m_settings )
165
166 if( !m_settings )
167 return true;
168
169 m_settings->m_RemoteSymbol.destination_dir = destination;
170 m_settings->m_RemoteSymbol.library_prefix = prefix;
171 m_settings->m_RemoteSymbol.add_to_global_table = m_globalRadio->GetValue();
172
173 return true;
174}
175
176
178{
179 wxUnusedVar( aEvent );
180
181 wxString initialPath = ExpandEnvVarSubstitutions( m_destinationCtrl->GetValue(), &Prj() );
182
183 if( initialPath.IsEmpty() )
184 {
185 if( Prj().IsNullProject() )
186 initialPath = KIPLATFORM::ENV::GetDocumentsPath();
187 else
188 initialPath = Prj().GetProjectPath();
189 }
190
191 wxDirDialog dlg( this, _( "Select Destination Directory" ), initialPath );
192
193 if( dlg.ShowModal() != wxID_OK )
194 return;
195
196 wxString path = dlg.GetPath();
197
198 if( !Prj().IsNullProject() )
199 {
200 wxString projectRoot = Prj().GetProjectPath();
201
202 wxFileName selectedDir = wxFileName::DirName( path );
203
204 if( selectedDir.MakeRelativeTo( projectRoot ) )
205 {
206 wxString relative = selectedDir.GetFullPath();
207
208 if( relative.IsEmpty() || relative == wxS( "." ) )
209 path = wxS( "${KIPRJMOD}" );
210 else
211 path = wxString::Format( wxS( "${KIPRJMOD}/%s" ), relative );
212 }
213 }
214
215 path.Replace( wxS( "\\" ), wxS( "/" ) );
216 m_destinationCtrl->ChangeValue( path );
217}
218
219
221{
222 wxUnusedVar( aEvent );
223
225 applyRemoteSettings( defaults );
226}
227
228
230{
231 wxUnusedVar( aEvent );
233}
234
235
238{
239 m_destinationCtrl->ChangeValue( aConfig.destination_dir );
240 m_prefixCtrl->ChangeValue( aConfig.library_prefix );
241
242 if( aConfig.add_to_global_table )
243 m_globalRadio->SetValue( true );
244 else
245 m_projectRadio->SetValue( true );
246
248}
249
250
252{
253 const wxString prefix = m_prefixCtrl->GetValue();
254
255 if( prefix.IsEmpty() )
256 {
257 m_prefixHint->SetLabel(
258 _( "Library names will be created with suffixes such as _symbols, _fp, and _3d." ) );
259 }
260 else
261 {
262 m_prefixHint->SetLabel( wxString::Format(
263 _( "Will create libraries like %1$s_symbols, %1$s_fp, %1$s_3d, etc." ), prefix ) );
264 }
265
266 m_prefixHint->Wrap( FromDIP( 360 ) );
267}
void onResetDefaults(wxCommandEvent &aEvent)
void applyRemoteSettings(const EESCHEMA_SETTINGS::REMOTE_SYMBOL_CONFIG &aConfig)
void onBrowseDestination(wxCommandEvent &aEvent)
void onPrefixChanged(wxCommandEvent &aEvent)
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:82
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...
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:167
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:509
The common library.
#define _(s)
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
see class PGM_BASE
T * GetAppSettings(const char *aFilename)
std::string path
Functions to provide common constants and other functions to assist in making a consistent UI.