Skip to content

Commit

Permalink
Revamp component chooser and add footprint preview
Browse files Browse the repository at this point in the history
This commit brings several changes:

- Add a footprint preview pane to the eeschema component selector
- Upgrade component list to wxTreeListCtrl
- Factor out wxTreeListCtrl subclass TWO_COLUMN_TREE_LIST which
  patches a column size bug
- Linkify datasheet URL in info pane
  • Loading branch information
Chris Pavlina committed Feb 19, 2017
1 parent d99da20 commit 2632b1d
Show file tree
Hide file tree
Showing 20 changed files with 1,608 additions and 216 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." ON )

option( KICAD_SPICE "Build Kicad with internal Spice simulator." OFF )

option( KICAD_FOOTPRINT_SELECTOR "Build experimental eeschema footprint selector." OFF )

# Global setting: exports are explicit
set( CMAKE_CXX_VISIBILITY_PRESET "hidden" )
set( CMAKE_VISIBILITY_INLINES_HIDDEN ON )
Expand Down Expand Up @@ -307,6 +309,10 @@ if( KICAD_SPICE )
add_definitions( -DKICAD_SPICE )
endif()

if( KICAD_FOOTPRINT_SELECTOR )
add_definitions( -DKICAD_FOOTPRINT_SELECTOR )
endif()

if( KICAD_USE_SCH_IO_MANAGER )
add_definitions( -DKICAD_USE_SCH_IO_MANAGER )
endif()
Expand Down
2 changes: 2 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ set( COMMON_DLG_SRCS
set( COMMON_WIDGET_SRCS
widgets/mathplot.cpp
widgets/widget_hotkey_list.cpp
widgets/two_column_tree_list.cpp
widgets/footprint_preview_panel.cpp
)

set( COMMON_PAGE_LAYOUT_SRCS
Expand Down
62 changes: 62 additions & 0 deletions common/widgets/footprint_preview_panel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017 Chris Pavlina <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <widgets/footprint_preview_panel.h>
#include <wx/stattext.h>
#include <kiway.h>


FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::AddToPanel(
KIWAY& aKiway, wxPanel* aPanel, bool aIndicator )
{
FOOTPRINT_PREVIEW_PANEL* fpp = NULL;

KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
if( !kiface )
return NULL;

try {
fpp = static_cast<FOOTPRINT_PREVIEW_PANEL*>(
kiface->CreateWindow( aPanel, FRAME_PCB_FOOTPRINT_PREVIEW, &aKiway ) );
} catch( ... )
{
return NULL;
}

auto sizer = new wxBoxSizer( wxVERTICAL );
sizer->Add( fpp, 1, wxALL | wxEXPAND, 0 );

if( aIndicator )
{
auto label = new wxStaticText( aPanel, -1, wxEmptyString );
auto sizer2 = new wxBoxSizer( wxVERTICAL );
sizer2->Add( 0, 0, 1 );
sizer2->Add( label, 0, wxALL | wxALIGN_CENTER, 0 );
sizer2->Add( 0, 0, 1 );
sizer->Add( sizer2, 1, wxALL | wxALIGN_CENTER, 0 );
sizer2->ShowItems( false );
fpp->LinkErrorLabel( label );
fpp->SetHideSizer( sizer2 );
}

aPanel->SetSizer( sizer );

return fpp;
}
110 changes: 110 additions & 0 deletions common/widgets/two_column_tree_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Chris Pavlina <[email protected]>
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

/**
* @file two_column_tree_list.cpp
*/

#include <wx/dataview.h>
#include <widgets/two_column_tree_list.h>

/**
* Extra margin to compensate for vertical scrollbar
*/
static const int HORIZ_MARGIN = 30;


TWO_COLUMN_TREE_LIST::TWO_COLUMN_TREE_LIST( wxWindow* aParent, wxWindowID aID,
const wxPoint & aPos, const wxSize & aSize, long aStyle, const wxString & aName )
: wxTreeListCtrl( aParent, aID, aPos, aSize, aStyle, aName ),
m_rubber_band_column( 0 ),
m_clamped_min_width( 50 )
{
Bind( wxEVT_SIZE, &TWO_COLUMN_TREE_LIST::OnSize, this );
GetDataView()->SetIndent( 10 );
}

void TWO_COLUMN_TREE_LIST::OnSize( wxSizeEvent& aEvent )
{
wxDataViewCtrl* view = GetDataView();

if( !view )
return;

wxRect rect = GetClientRect();
view->SetSize( rect );

#ifdef wxHAS_GENERIC_DATAVIEWCTRL
{
wxWindow* win_view = GetView();
win_view->Refresh();
win_view->Update();
}
#endif

// Find the maximum width of both columns
int clamped_column = ( m_rubber_band_column == 0 ) ? 1 : 0;
int clamped_column_width = 0;
int rubber_max_width = 0;

for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
{
const wxString& text = GetItemText( item, clamped_column );
int width = WidthFor( text );

if( clamped_column == 0 )
{
width += 4 * view->GetIndent();
}

if( width > clamped_column_width )
clamped_column_width = width;

width = WidthFor( GetItemText( item, m_rubber_band_column ) );
if( width > rubber_max_width )
rubber_max_width = width;
}

if( clamped_column_width < m_clamped_min_width )
clamped_column_width = m_clamped_min_width;

// Rubber column width is only limited if the rubber column is on the LEFT.
// If on the right, let the horiz scrollbar show.

int rubber_width = 0;

if( m_rubber_band_column == 0 )
rubber_width = rect.width - clamped_column_width - HORIZ_MARGIN;
else
rubber_width = rubber_max_width;

if( rubber_width <= 0 )
rubber_width = 1;

wxASSERT( m_rubber_band_column == 0 || m_rubber_band_column == 1 );

SetColumnWidth( m_rubber_band_column, rubber_width );
SetColumnWidth( clamped_column, clamped_column_width );
}

60 changes: 5 additions & 55 deletions common/widgets/widget_hotkey_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Chris Pavlina <[email protected]>
* Copyright (C) 2016 KiCad Developers, see CHANGELOG.TXT for contributors.
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -26,7 +26,6 @@

#include <widgets/widget_hotkey_list.h>

#include <wx/dataview.h>
#include <wx/statline.h>

#include <draw_frame.h>
Expand All @@ -39,12 +38,6 @@
static const int HOTKEY_MIN_WIDTH = 100;


/**
* Extra margin to compensate for vertical scrollbar
*/
static const int HORIZ_MARGIN = 30;


/**
* Menu IDs for the hotkey context menu
*/
Expand Down Expand Up @@ -327,7 +320,7 @@ void WIDGET_HOTKEY_LIST::EditItem( wxTreeListItem aItem )

// Trigger a resize in case column widths have changed
wxSizeEvent dummy_evt;
OnSize( dummy_evt );
TWO_COLUMN_TREE_LIST::OnSize( dummy_evt );
}
}

Expand Down Expand Up @@ -424,50 +417,6 @@ void WIDGET_HOTKEY_LIST::OnMenu( wxCommandEvent& aEvent )
}


void WIDGET_HOTKEY_LIST::OnSize( wxSizeEvent& aEvent )
{
// Handle this manually - wxTreeListCtrl screws up the width of the first column
wxDataViewCtrl* view = GetDataView();

if( !view )
return;

wxRect rect = GetClientRect();
view->SetSize( rect );

#ifdef wxHAS_GENERIC_DATAVIEWCTRL
{
wxWindow* win_view = GetView();
win_view->Refresh();
win_view->Update();
}
#endif

// Find the maximum width of the hotkey column
int hk_column_width = 0;

for( wxTreeListItem item = GetFirstItem(); item.IsOk(); item = GetNextItem( item ) )
{
const wxString& text = GetItemText( item, 1 );
int width = WidthFor( text );

if( width > hk_column_width )
hk_column_width = width;
}

if( hk_column_width < HOTKEY_MIN_WIDTH )
hk_column_width = HOTKEY_MIN_WIDTH;

int name_column_width = rect.width - hk_column_width - HORIZ_MARGIN;

if( name_column_width <= 0 )
name_column_width = 1;

SetColumnWidth( 1, hk_column_width );
SetColumnWidth( 0, name_column_width );
}


bool WIDGET_HOTKEY_LIST::CheckKeyConflicts( long aKey, const wxString& aSectionTag,
EDA_HOTKEY** aConfKey, EDA_HOTKEY_CONFIG** aConfSect )
{
Expand Down Expand Up @@ -558,16 +507,17 @@ bool WIDGET_HOTKEY_LIST::ResolveKeyConflicts( long aKey, const wxString& aSectio


WIDGET_HOTKEY_LIST::WIDGET_HOTKEY_LIST( wxWindow* aParent, const HOTKEY_SECTIONS& aSections )
: wxTreeListCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
: TWO_COLUMN_TREE_LIST( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_SINGLE ),
m_sections( aSections )
{
AppendColumn( _( "Command" ) );
AppendColumn( _( "Hotkey" ) );
SetRubberBandColumn( 0 );
SetClampedMinWidth( HOTKEY_MIN_WIDTH );

Bind( wxEVT_TREELIST_ITEM_ACTIVATED, &WIDGET_HOTKEY_LIST::OnActivated, this );
Bind( wxEVT_TREELIST_ITEM_CONTEXT_MENU, &WIDGET_HOTKEY_LIST::OnContextMenu, this );
Bind( wxEVT_MENU, &WIDGET_HOTKEY_LIST::OnMenu, this );
Bind( wxEVT_SIZE, &WIDGET_HOTKEY_LIST::OnSize, this );
}


Expand Down
Loading

0 comments on commit 2632b1d

Please sign in to comment.