KiCad PCB EDA Suite
Loading...
Searching...
No Matches
startwizard.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) 2023 Mark Roszko <[email protected]>
5 * Copyright (C) 1992-2023 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
21#include <build_version.h>
22#include <confirm.h>
23#include <kiface_base.h>
24#include <pgm_base.h>
25#include <wx/statline.h>
26#include <wx/wx.h>
27#include <wx/wizard.h>
33#include <wx/hyperlink.h>
34
35
36class STARTWIZARD_PAGE : public wxWizardPageSimple
37{
38public:
39 STARTWIZARD_PAGE( wxWizard* aParent, const wxString& aPageTitle ) :
40 wxWizardPageSimple( aParent )
41 {
42 m_mainSizer = new wxBoxSizer( wxVERTICAL );
43
44 wxStaticText* pageTitle = new wxStaticText( this, -1, aPageTitle );
45 pageTitle->SetFont(
46 wxFont( 14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
47 m_mainSizer->Add( pageTitle, 0, wxALIGN_CENTRE | wxALL, 5 );
48
49 wxStaticLine* pageDivider = new wxStaticLine( this, wxID_ANY, wxDefaultPosition,
50 wxDefaultSize, wxLI_HORIZONTAL );
51 m_mainSizer->Add( pageDivider, 0, wxEXPAND | wxALL, 5 );
52 }
53
54 void AddContent( wxPanel* aContent )
55 {
56 m_mainSizer->Add( aContent );
57
58 SetSizerAndFit( m_mainSizer );
59 }
60
61private:
62 wxBoxSizer* m_mainSizer;
63};
64
65
66class STARTWIZARD_WELCOME_PAGE : public wxWizardPageSimple
67{
68public:
69 STARTWIZARD_WELCOME_PAGE( wxWizard* aParent ) : wxWizardPageSimple( aParent )
70 {
71 m_mainSizer = new wxBoxSizer( wxVERTICAL );
72
73 wxStaticText* pageTitle = new wxStaticText(
74 this, -1, wxString::Format( _( "Welcome to KiCad %s" ), GetMajorMinorVersion() ) );
75 pageTitle->SetFont(
76 wxFont( 14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) );
77 m_mainSizer->Add( pageTitle, 0, wxALIGN_CENTRE | wxALL, 5 );
78
79 wxStaticLine* pageDivider = new wxStaticLine( this, wxID_ANY, wxDefaultPosition,
80 wxDefaultSize, wxLI_HORIZONTAL );
81 m_mainSizer->Add( pageDivider, 0, wxEXPAND | wxALL, 5 );
82
83 m_welcomeText = new wxStaticText( this, -1,
84 _( "KiCad is starting for the first time, or some of its configuration files are missing.\n\n"
85 "Let's take a moment to configure some basic settings. You can always modify these "
86 "settings later by opening the Preferences dialog." ) );
87 m_mainSizer->Add( m_welcomeText, 0, wxEXPAND | wxALL, 5 );
88
89 wxBoxSizer* helpSizer = new wxBoxSizer( wxHORIZONTAL );
90 wxStaticText* helpLabel = new wxStaticText( this, -1, _( "For help, please visit " ) );
91 wxString docsUrl = wxString::Format( "https://go.kicad.org/docs/%s", GetMajorMinorVersion() );
92 wxHyperlinkCtrl* helpLink = new wxHyperlinkCtrl( this, -1, wxT( "docs.kicad.org" ), docsUrl );
93 helpSizer->Add( helpLabel, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 5 );
94 helpSizer->Add( helpLink, 0, wxEXPAND | wxRIGHT | wxTOP | wxBOTTOM, 5 );
95 m_mainSizer->Add( helpSizer, 0, wxEXPAND, 5 );
96
97 SetSizerAndFit( m_mainSizer );
98 }
99
100 void SetWrap( int aWidth ) const
101 {
102 m_welcomeText->Wrap( aWidth );
103 }
104
105private:
106 wxBoxSizer* m_mainSizer;
107 wxStaticText* m_welcomeText;
108};
109
110
112 m_wizard( nullptr )
113{
114}
115
116
120
121
123{
124 if( auto it = std::ranges::find_if( m_providers,
125 [&]( const std::unique_ptr<STARTWIZARD_PROVIDER>& aProvider )
126 {
127 return aProvider->Name() == aName;
128 } ); it != m_providers.end() )
129 {
130 return it->get();
131 }
132
133 return nullptr;
134}
135
136
137void STARTWIZARD::CheckAndRun( wxWindow* aParent )
138{
139 m_providers.clear();
140
141 m_providers.push_back( std::make_unique<STARTWIZARD_PROVIDER_SETTINGS>() );
142 m_providers.push_back( std::make_unique<STARTWIZARD_PROVIDER_LIBRARIES>() );
143 m_providers.push_back( std::make_unique<STARTWIZARD_PROVIDER_PRIVACY>() );
144 //providers.push_back( std::make_unique<STARTWIZARD_PROVIDER_LOOK_AND_FEEL>() );
145
146 if( m_providers.size() == 0 )
147 return;
148
149 bool wizardRequired = std::ranges::any_of( std::as_const( m_providers ),
150 []( const std::unique_ptr<STARTWIZARD_PROVIDER>& aProvider ) -> bool
151 {
152 return aProvider->NeedsUserInput();
153 } );
154
155 if( !wizardRequired )
156 return;
157
158 Pgm().HideSplash();
159
160 m_wizard = new wxWizard( aParent, wxID_ANY, _( "KiCad Setup" ) );
161
163 wxWizardPageSimple* lastPage = nullptr;
164 wxSize minPageSize;
165
166 for( std::unique_ptr<STARTWIZARD_PROVIDER>& provider : m_providers )
167 {
168 if( !provider->NeedsUserInput() )
169 continue;
170
171 STARTWIZARD_PAGE* page = new STARTWIZARD_PAGE( m_wizard, provider->GetPageName() );
172 wxPanel* panel = provider->GetWizardPanel( page, this );
173 page->AddContent( panel );
174
175 if( lastPage != nullptr )
176 {
177 lastPage->Chain( page );
178 }
179 else
180 {
181 firstPage->Chain( page );
182 }
183
184 lastPage = page;
185
186 wxSize size = page->GetSizer()->CalcMin();
187
188 if( size.x > minPageSize.x )
189 minPageSize.x = size.x;
190
191 if( size.y > minPageSize.y )
192 minPageSize.y = size.y;
193 }
194
195 m_wizard->SetPageSize( minPageSize + wxSize( 10, 10 ) );
196 firstPage->SetWrap( minPageSize.x );
197
198 m_wizard->Bind( wxEVT_WIZARD_CANCEL,
199 [&]( wxWizardEvent& aEvt )
200 {
201 if( IsOK( aParent, _( "Are you sure? If you cancel KiCad setup, default settings "
202 "will be chosen for you." ) ) )
203 {
204 for( std::unique_ptr<STARTWIZARD_PROVIDER>& provider : m_providers )
205 {
206 provider->ApplyDefaults();
207 }
208 }
209 else
210 {
211 aEvt.Veto();
212 }
213 } );
214
215 if( m_wizard->RunWizard( firstPage ) )
216 {
217 for( std::unique_ptr<STARTWIZARD_PROVIDER>& provider : m_providers )
218 {
219 if( !provider->NeedsUserInput() )
220 continue;
221
222 provider->Finish();
223 }
224 }
225
226 m_wizard->Destroy();
227 m_wizard = nullptr;
228}
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
void HideSplash()
Definition pgm_base.cpp:297
STARTWIZARD_PAGE(wxWizard *aParent, const wxString &aPageTitle)
wxBoxSizer * m_mainSizer
void AddContent(wxPanel *aContent)
void SetWrap(int aWidth) const
wxStaticText * m_welcomeText
STARTWIZARD_WELCOME_PAGE(wxWizard *aParent)
STARTWIZARD_PROVIDER * GetProvider(const wxString &aName)
std::vector< std::unique_ptr< STARTWIZARD_PROVIDER > > m_providers
Definition startwizard.h:46
void CheckAndRun(wxWindow *parent)
wxWizard * m_wizard
Definition startwizard.h:45
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:251
This file is part of the common library.
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
see class PGM_BASE