Commit e4a74213 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Add wizard to fp lib dialog to easily add entries to this table.

parent 1393bcaf
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -36,6 +36,21 @@ option( KICAD_KEEPCASE
    ON
    )

# The footprint library wizard uses wxWEBVIEW, which needs a system webkit to be built
# The default build option in wxWidgets is to build wxWEBVIEW, but it colud be not built
# if web kit devel tools are missing
# So this option disable use of wxWEBVIEW, if building wxWEBVIEW creates issues
# see:
# http://docs.wxwidgets.org/3.0/classwx_web_view.html
# No issues on Windows, needs webkitgtk-devel package installed on Linux.
# (I don't know the OSX status)
# However the default option is on
# This option could be removed soon, if no serious issue happens on Linux or OSX
option( KICAD_USE_WEBKIT
    "Use system web kit to build a web viewer in footprint library wizard to easily select github libraries (default ON)."
    ON
    )

option( USE_WX_GRAPHICS_CONTEXT
    "Use wxGraphicsContext for rendering (default OFF).  Warning, this is experimental" )

@@ -403,7 +418,13 @@ add_definitions( -DWX_COMPATIBILITY )
# See line 41 of CMakeModules/FindwxWidgets.cmake
set( wxWidgets_CONFIG_OPTIONS --static=no )

find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml REQUIRED )
if( KICAD_USE_WEBKIT )
    set( webkitlib "webview" )
else()
    set( webkitlib "" )
endif()

find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml ${webkitlib} stc REQUIRED )

# Include wxWidgets macros.
include( ${wxWidgets_USE_FILE} )
@@ -684,6 +705,9 @@ add_subdirectory( cvpcb )
add_subdirectory( eeschema )
add_subdirectory( gerbview )
add_subdirectory( lib_dxf )
if( KICAD_USE_WEBKIT )
    add_subdirectory( webviewer )
endif()
add_subdirectory( pcbnew )
add_subdirectory( polygon )
add_subdirectory( pagelayout_editor )
+11 −0
Original line number Diff line number Diff line
@@ -8,6 +8,12 @@ endif()

add_definitions( -DCVPCB )

if( KICAD_USE_WEBKIT )
    set( WEBVIEWERTOOL "webviewer" )
    add_definitions( -DKICAD_USE_WEBKIT )
endif()


include_directories( BEFORE ${INC_BEFORE} )
include_directories(
    ./dialogs
@@ -29,6 +35,8 @@ set( CVPCB_DIALOGS
    ../pcbnew/dialogs/dialog_fp_lib_table_base.cpp
    ../pcbnew/dialogs/dialog_fp_plugin_options.cpp
    ../pcbnew/dialogs/dialog_fp_plugin_options_base.cpp
    ../pcbnew/dialogs/wizard_add_fplib_base.cpp
    ../pcbnew/dialogs/wizard_add_fplib.cpp
    )

set( CVPCB_SRCS
@@ -75,9 +83,11 @@ add_executable( cvpcb WIN32 MACOSX_BUNDLE
    ../common/pgm_base.cpp
    ${CVPCB_RESOURCES}
    )

set_source_files_properties( ../common/single_top.cpp PROPERTIES
    COMPILE_DEFINITIONS "TOP_FRAME=FRAME_CVPCB;PGM_DATA_FILE_EXT=\"net\";BUILD_KIWAY_DLL"
    )

target_link_libraries( cvpcb
    #singletop  # replaces common, giving us restrictive control and link warnings.
    # There's way too much crap coming in from common yet.
@@ -107,6 +117,7 @@ target_link_libraries( cvpcb_kiface
    pcbcommon
    pcad2kicadpcb
    common
    ${WEBVIEWERTOOL}   # before bitmaps, because it uses some bitmaps defined in bitmaps
    bitmaps
    polygon
    gal
+11 −0
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ set( PCBNEW_DIALOGS
    footprint_wizard_frame.cpp
    dialogs/dialog_footprint_wizard_list_base.cpp
    dialogs/dialog_footprint_wizard_list.cpp
    dialogs/wizard_add_fplib_base.cpp
    dialogs/wizard_add_fplib.cpp
    )

set( PCBNEW_IMPORT_DXF
@@ -368,6 +370,11 @@ if( UNIX AND NOT APPLE )
    list( APPEND PCBNEW_EXTRA_LIBS rt )
endif()

if( KICAD_USE_WEBKIT )
    set( WEBVIEWERTOOL "webviewer" )
    add_definitions( -DKICAD_USE_WEBKIT )
endif()


if( KICAD_SCRIPTING_MODULES )

@@ -375,6 +382,7 @@ if( KICAD_SCRIPTING_MODULES )

    set( CMAKE_SWIG_FLAGS ${SWIG_FLAGS} )
    set_source_files_properties( scripting/pcbnew.i PROPERTIES CPLUSPLUS ON )

    swig_add_module( pcbnew
        python
        scripting/pcbnew.i
@@ -383,6 +391,7 @@ if( KICAD_SCRIPTING_MODULES )
        ${PCBNEW_SRCS}
        ${PCBNEW_COMMON_SRCS}
        )

    swig_link_libraries( pcbnew
        3d-viewer
        pcbcommon
@@ -393,6 +402,7 @@ if( KICAD_SCRIPTING_MODULES )
        idf3
        ${GITHUB_PLUGIN_LIBRARIES}
        polygon
        ${WEBVIEWERTOOL}
        bitmaps
        gal
        ${GLEW_LIBRARIES}
@@ -559,6 +569,7 @@ target_link_libraries( pcbnew_kiface
    common
    pcad2kicadpcb
    polygon
    ${WEBVIEWERTOOL}    # before bitmaps, because it uses some bitmaps defined in bitmap
    bitmaps
    gal
    lib_dxf
+80 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@
#include <invoke_pcb_dialog.h>
#include <grid_tricks.h>
#include <confirm.h>
#include <wizard_add_fplib.h>


/// grid column order is established by this sequence
enum COL_ORDER
@@ -356,6 +358,11 @@ public:
        wxAuiNotebookEvent uneventful;
        pageChangedHandler( uneventful );

        // Gives a selection for each grid, mainly for delete lib button.
        // Without that, we do not see what lib will be deleted
        m_global_grid->SelectRow(0);
        m_project_grid->SelectRow(0);

        // for ALT+A handling, we want the initial focus to be on the first selected grid.
        m_cur_grid->SetFocus();
    }
@@ -512,11 +519,32 @@ private:
            // wx documentation is wrong, SetGridCursor does not make visible.
            m_cur_grid->MakeCellVisible( last_row, 0 );
            m_cur_grid->SetGridCursor( last_row, 0 );
            m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() );
        }
    }

    void deleteRowHandler( wxMouseEvent& event )
    {
#if 1
        int currRow = getCursorRow();
        wxArrayInt selectedRows	= m_cur_grid->GetSelectedRows();

        if( selectedRows.size() == 0 && getCursorRow() >= 0 )
            selectedRows.Add( getCursorRow() );

        std::sort( selectedRows.begin(), selectedRows.end() );

        for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
        {
            int row = selectedRows[ii];
            m_cur_grid->DeleteRows( row, 1 );
        }

        if( currRow >= m_cur_grid->GetNumberRows() )
            m_cur_grid->SetGridCursor(m_cur_grid->GetNumberRows()-1, getCursorCol() );

        m_cur_grid->SelectRow( m_cur_grid->GetGridCursorRow() );
#else
        int rowCount = m_cur_grid->GetNumberRows();
        int curRow   = getCursorRow();

@@ -525,9 +553,12 @@ private:
            m_cur_grid->DeleteRows( curRow );

            if( curRow && curRow == rowCount - 1 )
            {
                m_cur_grid->SetGridCursor( curRow-1, getCursorCol() );
            }
        }
#endif
    }

    void moveUpHandler( wxMouseEvent& event )
    {
@@ -557,6 +588,7 @@ private:

            m_cur_grid->MakeCellVisible( curRow, curCol );
            m_cur_grid->SetGridCursor( curRow, curCol );
            m_cur_grid->SelectRow( getCursorRow() );
        }
    }

@@ -588,6 +620,7 @@ private:

            m_cur_grid->MakeCellVisible( curRow, curCol );
            m_cur_grid->SetGridCursor( curRow, curCol );
            m_cur_grid->SelectRow( getCursorRow() );
        }
    }

@@ -623,6 +656,8 @@ private:
        }
    }

	void OnClickLibraryWizard( wxCommandEvent& event );

    void onCancelButtonClick( wxCommandEvent& event )
    {
        EndModal( 0 );
@@ -719,7 +754,7 @@ private:
        // the current project.
        unique.insert( PROJECT_VAR_NAME );
        unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );
        // This special environment variable is used to locad 3d shapes
        // This special environment variable is used to locate 3d shapes
        unique.insert( KISYS3DMOD );
        unique.insert( FP_LIB_TABLE::GlobalPathEnvVariableName() );

@@ -757,6 +792,50 @@ private:
int DIALOG_FP_LIB_TABLE::m_pageNdx = 0;


void DIALOG_FP_LIB_TABLE::OnClickLibraryWizard( wxCommandEvent& event )
{
    wxArrayString envVariableList;

    // Build the environment variables in use:
    for( int ii = 0; ii <  m_path_subs_grid->GetTable()->GetRowsCount(); ii ++ )
        envVariableList.Add( m_path_subs_grid->GetCellValue( wxGridCellCoords( ii, 0 ) ) );

    WIZARD_FPLIB_TABLE dlg( this, envVariableList );

    if( ! dlg.RunWizard( dlg.GetFirstPage() ) )
        return;     // Aborted by user

    wxGrid* libgrid = m_cur_grid;
    FP_TBL_MODEL*  tbl = (FP_TBL_MODEL*) libgrid->GetTable();

    // Import fp library list
    int idx = 0;
    wxArrayString libDescr;   // Will contain nickname, URI, plugin

    while( dlg.GetLibDescr( idx++, libDescr ) )
    {
        if( ! libDescr[0].IsEmpty() && m_cur_grid->AppendRows( 1 ) )
        {
            int last_row = libgrid->GetNumberRows() - 1;

            // Add the nickname: currently make it from filename
            tbl->SetValue( last_row, COL_NICKNAME, libDescr[0] );
            // Add the full path:
            tbl->SetValue( last_row, COL_URI, libDescr[1] );
            // Add the plugin name:
            tbl->SetValue( last_row, COL_TYPE, libDescr[2] );

            libgrid->MakeCellVisible( last_row, 0 );
            libgrid->SetGridCursor( last_row, 0 );
        }

        libDescr.Clear();
    }

    libgrid->SelectRow( libgrid->GetGridCursorRow() );
}


int InvokePcbLibTableEditor( wxTopLevelWindow* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject )
{
    DIALOG_FP_LIB_TABLE dlg( aParent, aGlobal, aProject );
+5 −0
Original line number Diff line number Diff line
@@ -103,6 +103,9 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	
	bSizer51->Add( m_append_button, 0, wxALL, 5 );
	
	m_buttonWizard = new wxButton( this, wxID_ANY, _("Append with Wizard"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer51->Add( m_buttonWizard, 0, wxALL, 5 );
	
	m_delete_button = new wxButton( this, wxID_ANY, _("Remove Library"), wxDefaultPosition, wxDefaultSize, 0 );
	m_delete_button->SetToolTip( _("Remove a PCB library from this library table") );
	
@@ -194,6 +197,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	this->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_FP_LIB_TABLE_BASE::onKeyDown ) );
	m_auinotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_FP_LIB_TABLE_BASE::pageChangedHandler ), NULL, this );
	m_append_button->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
	m_buttonWizard->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::OnClickLibraryWizard ), NULL, this );
	m_delete_button->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::deleteRowHandler ), NULL, this );
	m_move_up_button->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
	m_move_down_button->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveDownHandler ), NULL, this );
@@ -209,6 +213,7 @@ DIALOG_FP_LIB_TABLE_BASE::~DIALOG_FP_LIB_TABLE_BASE()
	this->Disconnect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_FP_LIB_TABLE_BASE::onKeyDown ) );
	m_auinotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( DIALOG_FP_LIB_TABLE_BASE::pageChangedHandler ), NULL, this );
	m_append_button->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::appendRowHandler ), NULL, this );
	m_buttonWizard->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_LIB_TABLE_BASE::OnClickLibraryWizard ), NULL, this );
	m_delete_button->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::deleteRowHandler ), NULL, this );
	m_move_up_button->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveUpHandler ), NULL, this );
	m_move_down_button->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_LIB_TABLE_BASE::moveDownHandler ), NULL, this );
Loading