KiCad PCB EDA Suite
Loading...
Searching...
No Matches
startwizard_provider_libraries.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 * @author Jon Evans <[email protected]>
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
21#include <pgm_base.h>
26#include <paths.h>
30
31
33{
34public:
35 PANEL_STARTWIZARD_LIBRARIES( const std::shared_ptr<STARTWIZARD_PROVIDER_LIBRARIES_MODEL>& aModel,
36 wxWindow* aParent, STARTWIZARD* aWizard ) :
38 m_model( aModel ),
39 m_wizard( aWizard )
40 {
41 wxWindowBase::SetMaxSize( { FromDIP( 640 ), -1 } );
43 m_sizerWarning->Layout();
44
46 }
47
48 bool TransferDataFromWindow() override
49 {
50 if( m_rbDefaultTables->GetValue() )
52 else if( m_rbImport->GetValue() )
54 else
56
57 return true;
58 }
59
60 bool TransferDataToWindow() override
61 {
62 switch( m_model->mode )
63 {
65 case STARTWIZARD_LIBRARIES_MODE::IMPORT: m_rbImport->SetValue( true ); break;
66 case STARTWIZARD_LIBRARIES_MODE::CREATE_BLANK: m_rbBlankTables->SetValue( true ); break;
67 }
68
69 if( auto settings = dynamic_cast<STARTWIZARD_PROVIDER_SETTINGS*>( m_wizard->GetProvider( "settings" ) ) )
70 {
71 if( !settings->NeedsUserInput() )
72 {
73 // If the user didn't see the settings screen at all, just hide this option; we
74 // only offer import when we have the context of a previous version settings
75 // path selected by the user
76 m_rbImport->Show( false );
77 }
78 else if( settings->GetModel().mode == STARTWIZARD_SETTINGS_MODE::USE_DEFAULTS )
79 {
80 // But if they did see the screen and chose not to import, show the option but
81 // disable it as a breadcrumb that they can go back and choose to import settings
82 m_rbImport->Disable();
83
84 if( m_rbImport->GetValue() )
85 m_rbDefaultTables->SetValue( true );
86 }
87 else
88 {
89 m_rbImport->Enable();
90 }
91 }
92
95
96 return true;
97 }
98
100 {
101 wxString missingTablesText;
102 m_showWarning = false;
103
104 for( const LIBRARY_TABLE_TYPE& type : m_model->missing_tables )
105 {
107 m_showWarning = true;
108
109 switch( type )
110 {
112 missingTablesText.Append( _( "Symbol library table" ) + "\n" );
113 break;
114
116 missingTablesText.Append( _( "Footprint library table" ) + "\n" );
117 break;
118
120 missingTablesText.Append( _( "Design Block library table" ) + "\n" );
121 break;
122
124 break;
125 }
126 }
127
128 m_stRequiredTables->SetLabel( missingTablesText.BeforeLast( '\n' ) );
129 }
130
131 void OnSize( wxSizeEvent& aEvt ) override
132 {
133 aEvt.Skip();
134 m_stIntro->Wrap( GetClientSize().x - FromDIP( 20 ) );
135 m_stWarning->Wrap( GetClientSize().x - m_bmpWarning->GetSize().x - FromDIP( 28 ) );
136 }
137
138private:
139 std::shared_ptr<STARTWIZARD_PROVIDER_LIBRARIES_MODEL> m_model;
142};
143
144
149
150
155
156
157wxPanel* STARTWIZARD_PROVIDER_LIBRARIES::GetWizardPanel( wxWindow* aParent, STARTWIZARD* aWizard )
158{
159 m_model = std::make_shared<STARTWIZARD_PROVIDER_LIBRARIES_MODEL>();
161 return new PANEL_STARTWIZARD_LIBRARIES( m_model, aParent, aWizard );
162}
163
164
166{
167 // TODO(JE) handle importing tables from previous version and sanitizing them
168
169 bool populateTables = m_model->mode == STARTWIZARD_LIBRARIES_MODE::USE_DEFAULTS;
170
172 {
173 LIBRARY_MANAGER::CreateGlobalTable( type, populateTables );
174 }
175}
176
177
185
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
static std::vector< LIBRARY_TABLE_TYPE > InvalidGlobalTables()
static bool GlobalTablesValid()
static bool CreateGlobalTable(LIBRARY_TABLE_TYPE aType, bool aPopulateDefaultLibraries)
static wxString StockTablePath(LIBRARY_TABLE_TYPE aType)
static bool IsTableValid(const wxString &aPath)
PANEL_STARTWIZARD_LIBRARIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
PANEL_STARTWIZARD_LIBRARIES(const std::shared_ptr< STARTWIZARD_PROVIDER_LIBRARIES_MODEL > &aModel, wxWindow *aParent, STARTWIZARD *aWizard)
std::shared_ptr< STARTWIZARD_PROVIDER_LIBRARIES_MODEL > m_model
void OnSize(wxSizeEvent &aEvt) override
std::shared_ptr< STARTWIZARD_PROVIDER_LIBRARIES_MODEL > m_model
wxPanel * GetWizardPanel(wxWindow *aParent, STARTWIZARD *aWizard) override
void ApplyDefaults() override
Apply whatever actions and settings should happen if the user cancels the startup wizard.
STARTWIZARD_PROVIDER(const wxString &aPageName)
#define _(s)
LIBRARY_TABLE_TYPE
see class PGM_BASE