KiCad PCB EDA Suite
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 <stambaughw@gmail.com>
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_i.h>
25 #include <macros.h>
26 
27 #include "fp_lib_table.h"
28 
29 
31  DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "footprint" ) )
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,
61  wxString::Format( _( "Error occurred writing empty footprint library "
62  "table file.\n\n%s" ),
64  ioe.What() ) );
65  return false;
66  }
67 
68  return true;
69  }
70 
71  wxString fileName = m_filePicker1->GetPath();
72 
73  if( fileName.IsEmpty() )
74  {
75  DisplayError( this, _( "Please select a footprint library table file." ) );
76  return false;
77  }
78 
79  wxFileName fn = fileName;
80 
81  // Make sure the footprint library table to copy actually exists.
82  if( !fn.FileExists() )
83  {
84  DisplayError( this,
85  wxString::Format( _( "File \"%s\" not found." ), fn.GetFullPath() ) );
86  return false;
87  }
88 
89  // Make sure the footprint library table to copy is a valid footprint library table file.
90  FP_LIB_TABLE tmpTable;
91 
92  try
93  {
94  tmpTable.Load( fn.GetFullPath() );
95  }
96  catch( const IO_ERROR& ioe )
97  {
98  DisplayError( this,
99  wxString::Format( _( "File \"%s\" is not a valid footprint library table "
100  "file.\n\n%s" ), fn.GetFullPath(), ioe.What() ) );
101  return false;
102  }
103 
104  // Create the config path if it doesn't already exist.
105  wxFileName fpTableFileName = FP_LIB_TABLE::GetGlobalTableFileName();
106 
107  if( !fpTableFileName.DirExists() && !fpTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
108  {
109  DisplayError( this,
110  wxString::Format( _( "Cannot create global library table path \"%s\"." ),
111  fpTableFileName.GetPath() ) );
112  return false;
113  }
114 
115  // Copy the global footprint library table file to the user config.
116  if( !::wxCopyFile( fn.GetFullPath(), fpTableFileName.GetFullPath() ) )
117  {
118  DisplayError( this,
119  wxString::Format( _( "Cannot copy global footprint library table "
120  "file:\n\n \"%s\"\n\n:to:\n\n\"%s\"." ),
121  fn.GetFullPath(), fpTableFileName.GetFullPath() ) );
122  return false;
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,
136  wxString::Format( _( "Error occurred loading global footprint library table:"
137  "\n\n%s" ), ioe.What() ) );
138  return false;
139  }
140 
141  return true;
142 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
This file is part of the common library.
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
This file contains miscellaneous commonly used macros and functions.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Function LoadGlobalTable loads the global footprint library table into aTable.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.