KiCad PCB EDA Suite
Loading...
Searching...
No Matches
io_base.h
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, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <map>
23#include <vector>
24#include <string>
25
26#include <kicommon.h>
27#include <core/utf8.h>
28#include <wx/string.h>
30
31class REPORTER;
33class DIALOG_SHIM;
34class wxWindow;
35
37{
38public:
43 {
44 wxString m_Description;
45
47 std::vector<std::string> m_FileExtensions;
48
50 std::vector<std::string> m_ExtensionsInDir;
51 bool m_IsFile;
52 bool m_CanRead;
54
55 IO_FILE_DESC( const wxString& aDescription, const std::vector<std::string>& aFileExtensions,
56 const std::vector<std::string>& aExtsInFolder = {}, bool aIsFile = true,
57 bool aCanRead = true, bool aCanWrite = true ) :
58 m_Description( aDescription ),
59 m_FileExtensions( aFileExtensions ), m_ExtensionsInDir( aExtsInFolder ),
60 m_IsFile( aIsFile ), m_CanRead( aCanRead ), m_CanWrite( aCanWrite )
61 {
62 }
63
64 IO_FILE_DESC() : IO_FILE_DESC( wxEmptyString, {} ) {}
65
69 wxString FileFilter() const;
70
71 operator bool() const { return !m_Description.empty(); }
72 };
73
74 virtual ~IO_BASE() = default;
75
79 const wxString& GetName() const { return m_name; }
80
84 virtual bool IsPCB_IO() const { return false; }
85
89 virtual void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
90
94 virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter )
95 {
96 m_progressReporter = aReporter;
97 }
98
100 // Library-related functions
102
108 virtual const IO_FILE_DESC GetLibraryDesc() const = 0;
109
117 virtual const IO_FILE_DESC GetLibraryFileDesc() const { return GetLibraryDesc(); }
118
123 virtual bool CanReadLibrary( const wxString& aFileName ) const;
124
141 virtual void CreateLibrary( const wxString& aLibraryPath,
142 const std::map<std::string, UTF8>* aProperties = nullptr );
143
161 virtual bool DeleteLibrary( const wxString& aLibraryPath,
162 const std::map<std::string, UTF8>* aProperties = nullptr );
163
174 virtual bool IsLibraryWritable( const wxString& aLibraryPath );
175
200 virtual void GetLibraryOptions( std::map<std::string, UTF8>* aListToAppendTo ) const;
201
202
207 virtual bool SupportsConfigurationDialog() const { return false; }
208
213 virtual DIALOG_SHIM* CreateConfigurationDialog( wxWindow* aParent ) { return nullptr; }
214
215 virtual void Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
216
217 virtual void AdvanceProgressPhase();
218
219 // Delete the zero-argument base constructor to force proper construction
220 IO_BASE() = delete;
221
222protected:
226 IO_BASE( const wxString& aName ) :
227 m_name( aName ),
228 m_reporter( nullptr ),
229 m_progressReporter( nullptr )
230 {}
231
232protected:
234 wxString m_name;
235
238
241};
242
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
virtual bool IsPCB_IO() const
Work-around for lack of dynamic_cast across compile units on Mac.
Definition io_base.h:84
IO_BASE()=delete
const wxString & GetName() const
Return a brief hard coded name for this IO interface.
Definition io_base.h:79
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition io_base.h:237
wxString m_name
Name of the IO loader.
Definition io_base.h:234
virtual const IO_FILE_DESC GetLibraryFileDesc() const
Get the descriptor for the individual library elements that this IO plugin operates on.
Definition io_base.h:117
IO_BASE(const wxString &aName)
Definition io_base.h:226
virtual bool SupportsConfigurationDialog() const
Definition io_base.h:207
virtual ~IO_BASE()=default
virtual const IO_FILE_DESC GetLibraryDesc() const =0
Get the descriptor for the library container that this IO plugin operates on.
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition io_base.h:89
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition io_base.h:94
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:240
virtual DIALOG_SHIM * CreateConfigurationDialog(wxWindow *aParent)
Definition io_base.h:213
A progress reporter interface for use in multi-threaded environments.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
#define KICOMMON_API
Definition kicommon.h:28
SEVERITY
@ RPT_SEVERITY_UNDEFINED
Container that describes file type info.
Definition io_base.h:43
std::vector< std::string > m_ExtensionsInDir
Definition io_base.h:50
IO_FILE_DESC(const wxString &aDescription, const std::vector< std::string > &aFileExtensions, const std::vector< std::string > &aExtsInFolder={}, bool aIsFile=true, bool aCanRead=true, bool aCanWrite=true)
Definition io_base.h:55
bool m_IsFile
Whether the library is a folder or a file.
Definition io_base.h:51
wxString m_Description
Description shown in the file picker dialog.
Definition io_base.h:44
bool m_CanWrite
Whether the IO can write this file type.
Definition io_base.h:53
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition io_base.h:47
bool m_CanRead
Whether the IO can read this file type.
Definition io_base.h:52