KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_import_choose_project.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 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
21
22#include <wx/msgdlg.h>
23#include <wx/listctrl.h>
24
25
27 wxWindow* aParent, const std::vector<IMPORT_PROJECT_DESC>& aProjectDesc ) :
29{
30 m_project_desc = aProjectDesc;
31
32 // Initialize columns in the wxListCtrl elements:
33 int comboNameColId = m_listCtrl->AppendColumn( _( "Project Name" ) );
34 int pcbNameColId = m_listCtrl->AppendColumn( _( "PCB" ) );
35 int schNameColId = m_listCtrl->AppendColumn( _( "Schematic" ) );
36
37 // Load the project/PCB/schematic names
38 int row = 0;
39
40 auto convertName = []( const wxString& aName, const wxString& aId ) -> wxString
41 {
42 if( aId.empty() )
43 return wxEmptyString;
44
45 return aName;
46 };
47
48 for( const IMPORT_PROJECT_DESC& desc : m_project_desc )
49 {
50 m_listCtrl->InsertItem( row, convertName( desc.ComboName, desc.ComboId ) );
51 m_listCtrl->SetItem( row, pcbNameColId, convertName( desc.PCBName, desc.PCBId ) );
52 m_listCtrl->SetItem( row, schNameColId,
53 convertName( desc.SchematicName, desc.SchematicId ) );
54
55 ++row;
56 }
57
58 // Auto select the first item to improve ease-of-use
59 m_listCtrl->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
60
61 m_listCtrl->SetColumnWidth( comboNameColId, wxLIST_AUTOSIZE_USEHEADER );
62 m_listCtrl->SetColumnWidth( pcbNameColId, wxLIST_AUTOSIZE_USEHEADER );
63 m_listCtrl->SetColumnWidth( schNameColId, wxLIST_AUTOSIZE_USEHEADER );
64
66
67 Fit();
69}
70
71
73{
74 EndModal( wxID_OK );
75}
76
77
78void DIALOG_IMPORT_CHOOSE_PROJECT::onClose( wxCloseEvent& event )
79{
80 EndModal( wxID_CANCEL );
81}
82
83
85{
86 std::vector<IMPORT_PROJECT_DESC> result;
87
88 long selected = -1;
89
90 do
91 {
92 selected = m_listCtrl->GetNextItem( selected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
93
94 if( selected != -1 && selected < long( m_project_desc.size() ) )
95 result.emplace_back( m_project_desc[selected] );
96
97 } while( selected != -1 );
98
99 return result;
100}
101
102
104 wxWindow* aParent, const std::vector<IMPORT_PROJECT_DESC>& aProjectDesc )
105{
106 DIALOG_IMPORT_CHOOSE_PROJECT dlg( aParent, aProjectDesc );
107
108 if( dlg.ShowModal() != wxID_OK )
109 return {};
110
111 return dlg.GetProjectSelections();
112}
Class DIALOG_IMPORT_CHOOSE_PROJECT_BASE.
void onItemActivated(wxListEvent &event) override
std::vector< IMPORT_PROJECT_DESC > GetProjectSelections()
void onClose(wxCloseEvent &event) override
static std::vector< IMPORT_PROJECT_DESC > GetSelectionsModal(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
Create and show a dialog (modal) and returns the data from it after completion.
DIALOG_IMPORT_CHOOSE_PROJECT(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
std::vector< IMPORT_PROJECT_DESC > m_project_desc
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
#define _(s)
Describes how non-KiCad boards and schematics should be imported as KiCad projects.