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 by linking schematic items to external data providers." ) );
51 m_description->Wrap( FromDIP( 480 ) );
52 m_description->SetFont( KIUI::GetInfoFont( this ) );
53 topSizer->Add( m_description, 0, wxBOTTOM | wxEXPAND, FromDIP( 12 ) );
54
55 m_sourcesList = new wxListBox( this, wxID_ANY );
56 m_sourcesList->SetMinSize( FromDIP( wxSize( -1, 160 ) ) );
57 topSizer->Add( m_sourcesList, 1, wxBOTTOM | wxEXPAND, FromDIP( 12 ) );
58
59 m_status = new wxStaticText( this, wxID_ANY, wxEmptyString );
60 m_status->SetFont( KIUI::GetSmallInfoFont( this ).Italic() );
61 topSizer->Add( m_status, 0, wxBOTTOM | wxEXPAND, FromDIP( 12 ) );
62
63 m_manageButton = new wxButton( this, wxID_ANY, _( "Manage Data Sources..." ) );
64 topSizer->Add( m_manageButton, 0, wxALIGN_RIGHT );
65
66 SetSizer( topSizer );
67
68 m_manageButton->Bind( wxEVT_BUTTON, &PANEL_SCH_DATA_SOURCES::OnManageDataSources, this );
69}
70
71
73{
75 m_pcm->SetRepositoryList( cfg->m_PcmRepositories );
76
78
79 return true;
80}
81
82
87
88
93
94
96{
97 m_sourcesList->Clear();
98
99 std::vector<wxString> entries;
100
101 for( const PCM_INSTALLATION_ENTRY& entry : m_pcm->GetInstalledPackages() )
102 {
103 PCM_PACKAGE_TYPE type = entry.package.category && entry.package.category.value() == PC_FAB
104 ? PT_FAB
105 : entry.package.type;
106
107 if( type != PT_DATASOURCE )
108 continue;
109
110 wxString label = entry.package.name;
111
112 if( !entry.current_version.IsEmpty() )
113 label << wxS( " (" ) << entry.current_version << wxS( ")" );
114
115 if( !entry.repository_name.IsEmpty() )
116 label << wxS( " — " ) << entry.repository_name;
117
118 entries.push_back( label );
119 }
120
121 if( entries.empty() )
122 {
123 m_status->SetLabel( _( "No data sources are currently installed." ) );
124 return;
125 }
126
127 std::sort( entries.begin(), entries.end(),
128 []( const wxString& a, const wxString& b )
129 {
130 return a.CmpNoCase( b ) < 0;
131 } );
132
133 for( const wxString& label : entries )
134 m_sourcesList->Append( label );
135
136 m_status->SetLabel( _( "Installed data sources are listed above." ) );
137}
138
139
141{
142 EDA_BASE_FRAME* parentFrame = m_frame ? m_frame
143 : dynamic_cast<EDA_BASE_FRAME*>( wxGetTopLevelParent( this ) );
144
145 DIALOG_PCM dialog( parentFrame, m_pcm );
147 dialog.ShowModal();
148
150}
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.