KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_global_sym_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) 2017-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#include <macros.h>
27
28#include "symbol_lib_table.h"
29
30
32 DIALOG_GLOBAL_LIB_TABLE_CONFIG( aParent, _( "symbol" ), KIWAY::FACE_SCH )
33{
34}
35
36
38{
39}
40
41
43{
45}
46
47
49{
50 // Create an empty table if requested by the user.
51 if( m_emptyRb->GetValue() )
52 {
53 SYMBOL_LIB_TABLE emptyTable;
54
55 try
56 {
58 }
59 catch( const IO_ERROR& ioe )
60 {
61 DisplayError( this, wxString::Format( _( "Error creating symbol library table '%s'.\n"
62 "%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 symbol library table file." ) );
76 return false;
77 }
78
79 wxFileName fn = fileName;
80
81 // Make sure the symbol library table to copy actually exists.
82 if( !fn.FileExists() )
83 {
84 DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
85 return false;
86 }
87
88 // Make sure the symbol library table to copy is a valid symbol library table file.
89 SYMBOL_LIB_TABLE tmpTable;
90
91 try
92 {
93 tmpTable.Load( fn.GetFullPath() );
94 }
95 catch( const IO_ERROR& ioe )
96 {
97 DisplayError( this, wxString::Format( _( "Error reading symbol library table '%s'.\n"
98 "%s" ),
99 fn.GetFullPath(),
100 ioe.What() ) );
101 return false;
102 }
103
104 // Create the config path if it doesn't already exist.
105 wxFileName symTableFileName = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
106
107 if( !symTableFileName.DirExists() && !symTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
108 {
109 DisplayError( this, wxString::Format( _( "Cannot create global library table '%s'." ),
110 symTableFileName.GetPath() ) );
111 return false;
112 }
113
114 // Copy the global symbol library table file to the user config.
115 if( !::wxCopyFile( fn.GetFullPath(), symTableFileName.GetFullPath() ) )
116 {
117 DisplayError( this, wxString::Format( _( "Error copying global symbol library table '%s' "
118 "to '%s'." ),
119 fn.GetFullPath(),
120 symTableFileName.GetFullPath() ) );
121 return false;
122 }
123
124 // Load the successfully copied symbol library table file. This should not fail since the
125 // file was tested above. Check for failure anyway to keep the compiler from complaining.
126 try
127 {
129 return false;
130 }
131 catch( const IO_ERROR& )
132 {
133 return false;
134 }
135
136 return true;
137}
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:279
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.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
This file is part of the common library.
#define _(s)
This file contains miscellaneous commonly used macros and functions.