KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_sch_data_sources.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
22
23#include <algorithm>
24#include <vector>
25
26#include <dialogs/dialog_pcm.h>
27#include <eda_base_frame.h>
30#include <widgets/ui_common.h>
31#include <wx/button.h>
32#include <wx/intl.h>
33#include <wx/listbox.h>
34#include <wx/sizer.h>
35#include <wx/stattext.h>
36
37
39 RESETTABLE_PANEL( aParent ),
40 m_frame( aFrame ),
41 m_pcm( std::make_shared<PLUGIN_CONTENT_MANAGER>( []( int ) {} ) ),
42 m_description( nullptr ),
43 m_status( nullptr ),
44 m_sourcesList( nullptr ),
45 m_manageButton( nullptr )
46{
47 wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL );
48
49 m_description = new wxStaticText( this, wxID_ANY,
50 _( "Install schematic data sources from the Plugin and Content Manager. Data sources extend KiCad "
51 "by linking schematic items to external data providers." ) );
52 m_description->Wrap( FromDIP( 480 ) );
53 m_description->SetFont( KIUI::GetInfoFont( this ) );
54 topSizer->Add( m_description, 0, wxALL | wxEXPAND, FromDIP( 12 ) );
55
56 m_sourcesList = new wxListBox( this, wxID_ANY );
57 m_sourcesList->SetMinSize( FromDIP( wxSize( -1, 160 ) ) );
58 topSizer->Add( m_sourcesList, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, FromDIP( 12 ) );
59
60 m_status = new wxStaticText( this, wxID_ANY, wxEmptyString );
61 m_status->SetFont( KIUI::GetSmallInfoFont( this ).Italic() );
62 topSizer->Add( m_status, 0, wxLEFT | wxBOTTOM | wxEXPAND, FromDIP( 12 ) );
63
64 m_manageButton = new wxButton( this, wxID_ANY, _( "Manage Data Sources..." ) );
65 topSizer->Add( m_manageButton, 0, wxRIGHT | wxALIGN_RIGHT, FromDIP( 12 ) );
66
67 SetSizer( topSizer );
68
69 m_manageButton->Bind( wxEVT_BUTTON, &PANEL_SCH_DATA_SOURCES::OnManageDataSources, this );
70}
71
72
74{
76 m_pcm->SetRepositoryList( cfg->m_PcmRepositories );
77
79
80 return true;
81}
82
83
88
89
94
95
97{
98 m_sourcesList->Clear();
99
100 std::vector<wxString> entries;
101
102 for( const PCM_INSTALLATION_ENTRY& entry : m_pcm->GetInstalledPackages() )
103 {
104 PCM_PACKAGE_TYPE type = entry.package.category && entry.package.category.value() == PC_FAB
105 ? PT_FAB
106 : entry.package.type;
107
108 if( type != PT_DATASOURCE )
109 continue;
110
111 wxString label = entry.package.name;
112
113 if( !entry.current_version.IsEmpty() )
114 label << wxS( " (" ) << entry.current_version << wxS( ")" );
115
116 if( !entry.repository_name.IsEmpty() )
117 label << wxS( " — " ) << entry.repository_name;
118
119 entries.push_back( label );
120 }
121
122 if( entries.empty() )
123 {
124 m_status->SetLabel( _( "No data sources are currently installed." ) );
125 return;
126 }
127
128 std::sort( entries.begin(), entries.end(),
129 []( const wxString& a, const wxString& b )
130 {
131 return a.CmpNoCase( b ) < 0;
132 } );
133
134 for( const wxString& label : entries )
135 m_sourcesList->Append( label );
136
137 m_status->SetLabel( _( "Installed data sources are listed above." ) );
138}
139
140
142{
143 EDA_BASE_FRAME* parentFrame = m_frame ? m_frame
144 : dynamic_cast<EDA_BASE_FRAME*>( wxGetTopLevelParent( this ) );
145
146 DIALOG_PCM dialog( parentFrame, m_pcm );
148 dialog.ShowModal();
149
151}
Implementing pcm main dialog.
Definition dialog_pcm.h:38
void SetActivePackageType(PCM_PACKAGE_TYPE aType)
int ShowModal() override
The base frame for deriving all KiCad main window classes.
void OnManageDataSources(wxCommandEvent &aEvent)
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
void ResetPanel() override
Reset the contents of this panel.
PANEL_SCH_DATA_SOURCES(wxWindow *aParent, EDA_BASE_FRAME *aFrame)
Main class of Plugin and Content Manager subsystem.
Definition pcm.h:106
RESETTABLE_PANEL(wxWindow *aParent, wxWindowID aId=wxID_ANY, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxSize(-1,-1), long aStyle=wxTAB_TRAVERSAL, const wxString &aName=wxEmptyString)
#define _(s)
Base window classes and related definitions.
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
STL namespace.
@ PC_FAB
Definition pcm_data.h:56
PCM_PACKAGE_TYPE
< Supported package types
Definition pcm_data.h:42
@ PT_DATASOURCE
Definition pcm_data.h:47
@ PT_FAB
Definition pcm_data.h:45
T * GetAppSettings(const char *aFilename)
Definition pcm_data.h:158
Functions to provide common constants and other functions to assist in making a consistent UI.