KiCad PCB EDA Suite
PANEL_PACKAGE Class Reference

#include <panel_package.h>

Inheritance diagram for PANEL_PACKAGE:
PANEL_PACKAGE_BASE

Public Member Functions

 PANEL_PACKAGE (wxWindow *parent, const ActionCallback &aCallback, const PACKAGE_VIEW_DATA &aData)
 Sets callback for OnClick action. More...
 
void SetSelectCallback (const std::function< void()> &aCallback)
 Marks panel as selected. More...
 
void SetSelected (bool aSelected)
 
void OnButtonClicked (wxCommandEvent &event) override
 Changes state of the (un)install button. More...
 
void SetState (PCM_PACKAGE_STATE aState)
 Called when anywhere on the panel is clicked (except install button) More...
 
void OnClick (wxMouseEvent &event) override
 
void OnSize (wxSizeEvent &event) override
 Get preferred version. If criteria are not met, return wxEmptyString. More...
 
wxString GetPreferredVersion () const
 
const PACKAGE_VIEW_DATAGetPackageData () const
 

Protected Attributes

wxStaticBitmap * m_bitmap
 
wxStaticText * m_name
 
wxStaticText * m_desc
 
wxButton * m_button
 

Private Member Functions

void OnPaint (wxPaintEvent &event) override
 

Private Attributes

std::function< void()> m_selectCallback
 
bool m_selected = false
 
const ActionCallbackm_actionCallback
 
PACKAGE_VIEW_DATA m_data
 
int m_minHeight
 

Detailed Description

Definition at line 56 of file panel_package.h.

Constructor & Destructor Documentation

◆ PANEL_PACKAGE()

PANEL_PACKAGE::PANEL_PACKAGE ( wxWindow *  parent,
const ActionCallback aCallback,
const PACKAGE_VIEW_DATA aData 
)

Sets callback for OnClick action.

Definition at line 26 of file panel_package.cpp.

27  :
28  PANEL_PACKAGE_BASE( parent ),
29  m_actionCallback( aCallback ),
30  m_data( aData )
31 {
32  // Propagate clicks on static elements to the panel handler.
33  m_name->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( PANEL_PACKAGE::OnClick ), NULL, this );
34  m_desc->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( PANEL_PACKAGE::OnClick ), NULL, this );
35  m_bitmap->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( PANEL_PACKAGE::OnClick ), NULL, this );
36 
37  wxColour bgColor = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
38  m_desc->SetBackgroundColour( bgColor );
39  m_name->SetBackgroundColour( bgColor );
40  m_bitmap->SetBackgroundColour( bgColor );
41 
42  m_name->SetFont( m_name->GetFont().Bold() );
43 
44  m_name->SetLabel( m_data.package.name );
45  m_bitmap->SetBitmap( *m_data.bitmap );
46 
47  // Set min width to 0 otherwise wxStaticLabel really doesn't want to shrink on resize
48  m_desc->SetMinSize( wxSize( 0, -1 ) );
49 
50  m_minHeight = GetMinHeight();
51 
52  wxSizeEvent dummy;
53  OnSize( dummy );
54 
56 }
wxStaticBitmap * m_bitmap
void SetState(PCM_PACKAGE_STATE aState)
Called when anywhere on the panel is clicked (except install button)
const PCM_PACKAGE package
Definition: panel_package.h:32
const ActionCallback & m_actionCallback
Definition: panel_package.h:89
wxStaticText * m_name
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
wxBitmap * bitmap
Definition: panel_package.h:33
wxString name
Definition: pcm_data.h:95
void OnClick(wxMouseEvent &event) override
PCM_PACKAGE_STATE state
Definition: panel_package.h:34
void OnSize(wxSizeEvent &event) override
Get preferred version. If criteria are not met, return wxEmptyString.
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90
wxStaticText * m_desc
PANEL_PACKAGE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxBORDER_NONE|wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)

References PACKAGE_VIEW_DATA::bitmap, dummy(), PANEL_PACKAGE_BASE::m_bitmap, m_data, PANEL_PACKAGE_BASE::m_desc, m_minHeight, PANEL_PACKAGE_BASE::m_name, PCM_PACKAGE::name, OnClick(), OnSize(), PACKAGE_VIEW_DATA::package, SetState(), and PACKAGE_VIEW_DATA::state.

Member Function Documentation

◆ GetPackageData()

const PACKAGE_VIEW_DATA& PANEL_PACKAGE::GetPackageData ( ) const
inline

Definition at line 81 of file panel_package.h.

81 { return m_data; };
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90

References m_data.

Referenced by PANEL_PACKAGES_VIEW::canInstall(), PANEL_PACKAGES_VIEW::OnInstallVersionClicked(), and PANEL_PACKAGES_VIEW::SetData().

◆ GetPreferredVersion()

wxString PANEL_PACKAGE::GetPreferredVersion ( ) const

Definition at line 166 of file panel_package.cpp.

167 {
168  // Versions are already presorted in descending order
169 
170  // Find last stable compatible version
171  auto ver_it = std::find_if( m_data.package.versions.begin(), m_data.package.versions.end(),
172  []( const PACKAGE_VERSION& ver )
173  {
174  return ver.compatible && ver.status == PVS_STABLE;
175  } );
176 
177  // If not found then find any compatible version
178  if( ver_it == m_data.package.versions.end() )
179  {
180  ver_it = std::find_if( m_data.package.versions.begin(), m_data.package.versions.end(),
181  []( const PACKAGE_VERSION& ver )
182  {
183  return ver.compatible;
184  } );
185  }
186 
187  if( ver_it == m_data.package.versions.end() )
188  return wxEmptyString; // Shouldn't happen
189 
190  return ver_it->version;
191 }
< Package version metadata Package metadata
Definition: pcm_data.h:73
const PCM_PACKAGE package
Definition: panel_package.h:32
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:105
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90

References m_data, PACKAGE_VIEW_DATA::package, PVS_STABLE, and PCM_PACKAGE::versions.

Referenced by OnButtonClicked(), and PANEL_PACKAGES_VIEW::setPackageDetails().

◆ OnButtonClicked()

void PANEL_PACKAGE::OnButtonClicked ( wxCommandEvent &  event)
overridevirtual

Changes state of the (un)install button.

Reimplemented from PANEL_PACKAGE_BASE.

Definition at line 112 of file panel_package.cpp.

113 {
114  if( m_data.state == PPS_AVAILABLE )
115  {
116  wxString version = GetPreferredVersion();
117 
118  if( version.IsEmpty() )
119  return;
120 
121  m_actionCallback( m_data, PPA_INSTALL, version );
122  }
123  else
124  {
126  }
127 }
const ActionCallback & m_actionCallback
Definition: panel_package.h:89
PCM_PACKAGE_STATE state
Definition: panel_package.h:34
wxString current_version
Definition: panel_package.h:37
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90
wxString GetPreferredVersion() const

References PACKAGE_VIEW_DATA::current_version, GetPreferredVersion(), m_actionCallback, m_data, PPA_INSTALL, PPA_UNINSTALL, PPS_AVAILABLE, and PACKAGE_VIEW_DATA::state.

◆ OnClick()

void PANEL_PACKAGE::OnClick ( wxMouseEvent &  event)
overridevirtual

Reimplemented from PANEL_PACKAGE_BASE.

Definition at line 136 of file panel_package.cpp.

137 {
139 }
std::function< void()> m_selectCallback
Definition: panel_package.h:87

References m_selectCallback.

Referenced by PANEL_PACKAGES_VIEW::OnShowAllVersionsClicked(), PANEL_PACKAGE(), and PANEL_PACKAGES_VIEW::SetPackageState().

◆ OnPaint()

void PANEL_PACKAGE::OnPaint ( wxPaintEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_PACKAGE_BASE.

Definition at line 142 of file panel_package.cpp.

143 {
144  wxRect rect( wxPoint( 1, 1 ), GetClientSize() - wxSize( 1, 1 ) );
145  wxPaintDC dc( this );
146  dc.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK ) );
147  dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ), 1 ) );
148 
149  if( m_selected )
150  {
151  rect.Deflate( 1 );
152  dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_HOTLIGHT ), 3 ) );
153  }
154 
155  dc.DrawRectangle( rect );
156 }

References m_selected.

◆ OnSize()

void PANEL_PACKAGE::OnSize ( wxSizeEvent &  event)
overridevirtual

Get preferred version. If criteria are not met, return wxEmptyString.

Reimplemented from PANEL_PACKAGE_BASE.

Definition at line 59 of file panel_package.cpp.

60 {
61  Layout();
62 
63  int nameLineHeight = m_name->GetTextExtent( wxT( "X" ) ).GetHeight();
64  double descLineHeight = m_desc->GetTextExtent( wxT( "X" ) ).GetHeight() * 1.2 /* leading */;
65 
66  m_desc->SetLabel( m_data.package.description );
67  m_desc->Wrap( m_desc->GetClientSize().GetWidth() - 10 );
68  descLineHeight = wxSplit( m_desc->GetLabel(), '\n' ).size() * descLineHeight;
69 
70  wxSize minSize = GetMinSize();
71  minSize.y = std::max( nameLineHeight + KiROUND( descLineHeight ) + 15, m_minHeight );
72  SetMinSize( minSize );
73 
74  Layout();
75 }
wxString description
Definition: pcm_data.h:96
const int minSize
Push and Shove router track width and via size dialog.
const PCM_PACKAGE package
Definition: panel_package.h:32
wxStaticText * m_name
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
wxStaticText * m_desc

References PCM_PACKAGE::description, KiROUND(), m_data, PANEL_PACKAGE_BASE::m_desc, m_minHeight, PANEL_PACKAGE_BASE::m_name, minSize, and PACKAGE_VIEW_DATA::package.

Referenced by PANEL_PACKAGE(), and SetState().

◆ SetSelectCallback()

void PANEL_PACKAGE::SetSelectCallback ( const std::function< void()> &  aCallback)

Marks panel as selected.

Definition at line 130 of file panel_package.cpp.

131 {
132  m_selectCallback = aCallback;
133 }
std::function< void()> m_selectCallback
Definition: panel_package.h:87

References m_selectCallback.

Referenced by PANEL_PACKAGES_VIEW::SetData().

◆ SetSelected()

void PANEL_PACKAGE::SetSelected ( bool  aSelected)

Definition at line 159 of file panel_package.cpp.

160 {
161  m_selected = aSelected;
162  Refresh();
163 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References m_selected, and Refresh().

Referenced by PANEL_PACKAGES_VIEW::OnSearchTextChanged(), and PANEL_PACKAGES_VIEW::SetData().

◆ SetState()

void PANEL_PACKAGE::SetState ( PCM_PACKAGE_STATE  aState)

Called when anywhere on the panel is clicked (except install button)

Definition at line 78 of file panel_package.cpp.

79 {
80  m_data.state = aState;
81 
82  switch( aState )
83  {
85  m_button->SetLabel( _( "Install" ) );
86  m_button->Enable();
87  break;
89  m_button->SetLabel( _( "Install" ) );
90  m_button->Disable();
91  break;
93  m_button->SetLabel( _( "Uninstall" ) );
94  m_button->Enable();
95  break;
97  m_button->SetLabel( _( "Pending install" ) );
98  m_button->Disable();
99  break;
101  m_button->SetLabel( _( "Pending uninstall" ) );
102  m_button->Disable();
103  break;
104  }
105 
106  // Relayout to change button size to fit the label.
107  wxSizeEvent dummy;
108  OnSize( dummy );
109 }
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
#define _(s)
PCM_PACKAGE_STATE state
Definition: panel_package.h:34
void OnSize(wxSizeEvent &event) override
Get preferred version. If criteria are not met, return wxEmptyString.
PACKAGE_VIEW_DATA m_data
Definition: panel_package.h:90

References _, dummy(), PANEL_PACKAGE_BASE::m_button, m_data, OnSize(), PPS_AVAILABLE, PPS_INSTALLED, PPS_PENDING_INSTALL, PPS_PENDING_UNINSTALL, PPS_UNAVAILABLE, and PACKAGE_VIEW_DATA::state.

Referenced by PANEL_PACKAGE().

Member Data Documentation

◆ m_actionCallback

const ActionCallback& PANEL_PACKAGE::m_actionCallback
private

Definition at line 89 of file panel_package.h.

Referenced by OnButtonClicked().

◆ m_bitmap

wxStaticBitmap* PANEL_PACKAGE_BASE::m_bitmap
protectedinherited

Definition at line 38 of file panel_package_base.h.

Referenced by PANEL_PACKAGE(), and PANEL_PACKAGE_BASE::PANEL_PACKAGE_BASE().

◆ m_button

wxButton* PANEL_PACKAGE_BASE::m_button
protectedinherited

◆ m_data

PACKAGE_VIEW_DATA PANEL_PACKAGE::m_data
private

◆ m_desc

wxStaticText* PANEL_PACKAGE_BASE::m_desc
protectedinherited

◆ m_minHeight

int PANEL_PACKAGE::m_minHeight
private

Definition at line 91 of file panel_package.h.

Referenced by OnSize(), and PANEL_PACKAGE().

◆ m_name

wxStaticText* PANEL_PACKAGE_BASE::m_name
protectedinherited

◆ m_selectCallback

std::function<void()> PANEL_PACKAGE::m_selectCallback
private

Definition at line 87 of file panel_package.h.

Referenced by OnClick(), and SetSelectCallback().

◆ m_selected

bool PANEL_PACKAGE::m_selected = false
private

Definition at line 88 of file panel_package.h.

Referenced by OnPaint(), and SetSelected().


The documentation for this class was generated from the following files: