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 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, convertName( desc.SchematicName, desc.SchematicId ) );
53
54 ++row;
55 }
56
57 // Auto select the first item to improve ease-of-use
58 m_listCtrl->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
59
60 m_listCtrl->SetColumnWidth( comboNameColId, wxLIST_AUTOSIZE_USEHEADER );
61 m_listCtrl->SetColumnWidth( pcbNameColId, wxLIST_AUTOSIZE_USEHEADER );
62 m_listCtrl->SetColumnWidth( schNameColId, wxLIST_AUTOSIZE_USEHEADER );
63
65
66 Fit();
68}
69
70
72{
73 EndModal( wxID_OK );
74}
75
76
77void DIALOG_IMPORT_CHOOSE_PROJECT::onClose( wxCloseEvent& event )
78{
79 EndModal( wxID_CANCEL );
80}
81
82
83std::vector<IMPORT_PROJECT_DESC> DIALOG_IMPORT_CHOOSE_PROJECT::GetProjects()
84{
85 std::vector<IMPORT_PROJECT_DESC> result;
86
87 long selected = -1;
88
89 do
90 {
91 selected = m_listCtrl->GetNextItem( selected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
92
93 if( selected != -1 && selected < long( m_project_desc.size() ) )
94 result.emplace_back( m_project_desc[selected] );
95
96 } while( selected != -1 );
97
98 return result;
99}
100
101
102std::vector<IMPORT_PROJECT_DESC>
104 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.GetProjects();
112}
Class DIALOG_IMPORT_CHOOSE_PROJECT_BASE.
void onItemActivated(wxListEvent &event) override
static std::vector< IMPORT_PROJECT_DESC > RunModal(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
Create and show a dialog (modal) and returns the data from it after completion.
void onClose(wxCloseEvent &event) override
DIALOG_IMPORT_CHOOSE_PROJECT(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
std::vector< IMPORT_PROJECT_DESC > GetProjects()
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.