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 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
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 =
41 []( const wxString& aName, const wxString& aId ) -> wxString
42 {
43 if( aId.empty() )
44 return wxEmptyString;
45
46 return aName;
47 };
48
49 for( const IMPORT_PROJECT_DESC& desc : m_project_desc )
50 {
51 m_listCtrl->InsertItem( row, convertName( desc.ComboName, desc.ComboId ) );
52 m_listCtrl->SetItem( row, pcbNameColId, convertName( desc.PCBName, desc.PCBId ) );
53 m_listCtrl->SetItem( row, schNameColId, convertName( desc.SchematicName,
54 desc.SchematicId ) );
55
56 ++row;
57 }
58
59 // Auto select the first item to improve ease-of-use
60 m_listCtrl->SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
61
62 m_listCtrl->SetColumnWidth( comboNameColId, wxLIST_AUTOSIZE_USEHEADER );
63 m_listCtrl->SetColumnWidth( pcbNameColId, wxLIST_AUTOSIZE_USEHEADER );
64 m_listCtrl->SetColumnWidth( schNameColId, wxLIST_AUTOSIZE_USEHEADER );
65
67
68 Fit();
70}
71
72
74{
75 EndModal( wxID_OK );
76}
77
78
79void DIALOG_IMPORT_CHOOSE_PROJECT::onClose( wxCloseEvent& event )
80{
81 EndModal( wxID_CANCEL );
82}
83
84
85std::vector<IMPORT_PROJECT_DESC> DIALOG_IMPORT_CHOOSE_PROJECT::GetProjects()
86{
87 std::vector<IMPORT_PROJECT_DESC> result;
88
89 long selected = -1;
90
91 do
92 {
93 selected = m_listCtrl->GetNextItem( selected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
94
95 if( selected != -1 && selected < long( m_project_desc.size() ) )
96 result.emplace_back( m_project_desc[selected] );
97
98 } while( selected != -1 );
99
100 return result;
101}
102
103
104std::vector<IMPORT_PROJECT_DESC>
105DIALOG_IMPORT_CHOOSE_PROJECT::RunModal( wxWindow* aParent, const std::vector<IMPORT_PROJECT_DESC>& aProjectDesc )
106{
107 DIALOG_IMPORT_CHOOSE_PROJECT dlg( aParent, aProjectDesc );
108
109 if( dlg.ShowModal() != wxID_OK )
110 return {};
111
112 return dlg.GetProjects();
113}
DIALOG_IMPORT_CHOOSE_PROJECT_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Choose Project to Import"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxCAPTION|wxCLOSE_BOX|wxRESIZE_BORDER)
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...
int ShowModal() override
#define _(s)
Describes how non-KiCad boards and schematics should be imported as KiCad projects.
wxString result
Test unit parsing edge cases and error handling.