KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_global_fp_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 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 <confirm.h>
24#include <kiface_base.h>
25#include <kiway.h>
26
27#include "fp_lib_table.h"
28
29
31 DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "footprint" ), KIWAY::FACE_PCB )
32{
33}
34
35
37{
38}
39
40
42{
44}
45
46
48{
49 // Create an empty table if requested by the user.
50 if( m_emptyRb->GetValue() )
51 {
52 FP_LIB_TABLE emptyTable;
53
54 try
55 {
57 }
58 catch( const IO_ERROR& ioe )
59 {
60 DisplayError( this, wxString::Format( _( "Error occurred writing empty footprint "
61 "library table '%s'." ),
63 + wxS( "\n" ) + ioe.What() );
64 return false;
65 }
66 }
67 else
68 {
69 wxString fileName = m_filePicker1->GetPath();
70
71 if( fileName.IsEmpty() )
72 {
73 DisplayError( this, _( "Please select a footprint library table file." ) );
74 return false;
75 }
76
77 wxFileName fn = fileName;
78
79 // Make sure the footprint library table to copy actually exists.
80 if( !fn.FileExists() )
81 {
82 DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
83 return false;
84 }
85
86 // Make sure the footprint library table to copy is a valid footprint library table file.
87 FP_LIB_TABLE tmpTable;
88
89 try
90 {
91 tmpTable.Load( fn.GetFullPath() );
92 }
93 catch( const IO_ERROR& ioe )
94 {
95 DisplayError( this,
96 wxString::Format( _( "'%s' is not a valid footprint library table." ),
97 fn.GetFullPath() )
98 + wxS( "\n" ) + ioe.What() );
99 return false;
100 }
101
102 // Create the config path if it doesn't already exist.
103 wxFileName fpTableFileName = FP_LIB_TABLE::GetGlobalTableFileName();
104
105 if( !fpTableFileName.DirExists() && !fpTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
106 {
107 DisplayError( this, wxString::Format( _( "Cannot create library table path '%s'." ),
108 fpTableFileName.GetPath() ) );
109 return false;
110 }
111
112 // Copy the global footprint library table file to the user config.
113 if( !::wxCopyFile( fn.GetFullPath(), fpTableFileName.GetFullPath() ) )
114 {
115 DisplayError( this,
116 wxString::Format( _( "Cannot copy footprint library table from:\n"
117 "%s\n"
118 "to:\n"
119 "%s." ),
120 fn.GetFullPath(), fpTableFileName.GetFullPath() ) );
121 return false;
122 }
123 }
124
125 // Load the successfully copied footprint library table file. This should not fail
126 // since the file was tested above. Check for failure anyway to keep the compiler
127 // from complaining.
128 try
129 {
131 return false;
132 }
133 catch( const IO_ERROR& ioe )
134 {
135 DisplayError( this, _( "Error loading footprint library table." )
136 + wxS( "\n" ) + ioe.What() );
137 return false;
138 }
139
140 return true;
141}
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
static wxString GetGlobalTableFileName()
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:285
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:150
#define _(s)