Commit 76fed4f9 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

*) Add PLUGIN::FootprintLibOptions( PROPERTIES* ), and extend DIALOG_FP_PLUGIN_OPTIONS to use it.

*) Move button handlers to LEFT MOUSE CLICK from COMMAND events, so wxGrid focus is not lost.
*) Sketch out the concept of COW support for the GITHUB_PLUGIN in its @todo.
parent 1f1a8853
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -68,9 +68,6 @@ int DIALOG_DESIGN_RULES::s_LastTabSelection = -1;

// methods for the helper class NETS_LIST_CTRL

/** OnGetItemText (overlaid method)
 * needed by wxListCtrl with wxLC_VIRTUAL options
 */
wxString NETS_LIST_CTRL::OnGetItemText( long item, long column ) const
{
    if( column == 0 )
@@ -87,14 +84,7 @@ wxString NETS_LIST_CTRL::OnGetItemText( long item, long column ) const
}


/**
 * Function setRowItems
 * Initialize the net name and the net class name at row aRow
 * @param aRow = row index (if aRow > number of stored row, empty rows will be created)
 * @param aNetname = the string to display in row aRow, column 0
 * @param aNetclassName = the string to display in row aRow, column 1
 */
void NETS_LIST_CTRL::setRowItems( unsigned        aRow,
void NETS_LIST_CTRL::SetRowItems( unsigned        aRow,
                                  const wxString& aNetname,
                                  const wxString& aNetclassName )
{
@@ -422,7 +412,7 @@ void DIALOG_DESIGN_RULES::FillListBoxWithNetNames( NETS_LIST_CTRL* aListCtrl,
        wxSize   class_needed = sDC.GetTextExtent( (*i)->clazz );
        net_colsize = std::max( net_colsize, net_needed.x );
        class_colsize = std::max( class_colsize, class_needed.x );
        aListCtrl->setRowItems( row, (*i)->net, (*i)->clazz );
        aListCtrl->SetRowItems( row, (*i)->net, (*i)->clazz );
    }

    int margin = sDC.GetTextExtent( wxT("XX") ).x;;
+33 −21
Original line number Diff line number Diff line
@@ -7,31 +7,26 @@

#include <wx/listctrl.h>

/* helper class to display lists of nets and associated netclasses
/**
 * Class NETS_LIST_CTRL
 * is a helper to display lists of nets and associated netclasses
 * used in dialog design rules.
 * It s needed because the 2 wxListCtlr used to display lists of nets
 * use the wxLC_VIRTUAL option.
 *  The virtual wxString OnGetItemText(long item, long column) const method
 * must be overlaid.
 * It's needed because the 2 "wxListCtl"s used to display lists of nets
 * uses the wxLC_VIRTUAL option. The method:
 *
 *   virtual wxString OnGetItemText( long item, long column ) const
 *
 * must be overloaded.
 */
class NETS_LIST_CTRL: public wxListCtrl
{
private:
    wxArrayString           m_Netnames;             ///< an array to store the list of nets (column 0)
    wxArrayString           m_Classnames;            ///< an array to store the list of netclasse (column 1)
public:
    NETS_LIST_CTRL(wxWindow* parent, wxWindowID id,
                const wxPoint& pos = wxDefaultPosition,
                const wxSize& size = wxDefaultSize,
                long style = wxLC_ICON):
    NETS_LIST_CTRL( wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
            const wxSize& size = wxDefaultSize, long style = wxLC_ICON ):
        wxListCtrl( parent, id, pos, size, style )
    {
    };

    NETS_LIST_CTRL()
    {
    };
    void setRowItems(unsigned aRow, const wxString & aNetname, const wxString & aNetclassName ); 
    void ClearList()
    {
        SetItemCount( 0 );
@@ -39,7 +34,24 @@ public:
        m_Classnames.Clear();
    }

    /**
     * Function OnGetItemText
     * is an overloaded method needed by wxListCtrl with wxLC_VIRTUAL options
     */
    virtual wxString OnGetItemText( long item, long column ) const;

    /**
     * Function SetRowItems
     * sets the net name and the net class name at @a aRow.
     * @param aRow = row index (if aRow > number of stored row, empty rows will be created)
     * @param aNetname = the string to display in row aRow, column 0
     * @param aNetclassName = the string to display in row aRow, column 1
     */
    void SetRowItems( unsigned aRow, const wxString& aNetname, const wxString& aNetclassName );

private:
    wxArrayString   m_Netnames;     ///< column 0: nets
    wxArrayString   m_Classnames;   ///< column 1: netclasses
};


+7 −3
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ public:
        case COL_NICKNAME:  return _( "Nickname" );
        case COL_URI:       return _( "Library Path" );

        // keep this text fairly long so column is sized wide enough
        // keep this "Plugin Type" text fairly long so column is sized wide enough
        case COL_TYPE:      return _( "Plugin Type" );
        case COL_OPTIONS:   return _( "Options" );
        case COL_DESCR:     return _( "Description" );
@@ -583,12 +583,16 @@ private:
        wxString        result;
        const wxString& options = row.GetOptions();

        InvokePluginOptionsEditor( this, row.GetNickName(), options, &result );
        InvokePluginOptionsEditor( this, row.GetNickName(), row.GetType(), options, &result );

        if( options != result )
        {
            row.SetOptions( result );
            m_cur_grid->AutoSizeColumn( COL_OPTIONS, false );

            // all but options:
            m_cur_grid->AutoSizeColumn( COL_NICKNAME, false );
            m_cur_grid->AutoSizeColumn( COL_URI, false );
            m_cur_grid->AutoSizeColumn( COL_TYPE, false );
        }
    }

+72 −10
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ class DIALOG_FP_PLUGIN_OPTIONS : public DIALOG_FP_PLUGIN_OPTIONS_BASE

public:
    DIALOG_FP_PLUGIN_OPTIONS( wxTopLevelWindow* aParent,
            const wxString& aNickname, const wxString& aOptions, wxString* aResult ) :
            const wxString& aNickname, const wxString& aPluginType,
            const wxString& aOptions, wxString* aResult ) :
        DIALOG_FP_PLUGIN_OPTIONS_BASE( aParent ),
        m_callers_options( aOptions ),
        m_result( aResult )
@@ -61,6 +62,7 @@ public:
        // add Cut, Copy, and Paste to wxGrid
        m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );

        // Fill the grid with aOptions
        string options = TO_UTF8( aOptions );

        PROPERTIES* props = FP_LIB_TABLE::ParseOptions( options );
@@ -80,6 +82,31 @@ public:
            delete props;
        }

        // Option Choices Panel:

        IO_MGR::PCB_FILE_T  pi_type = IO_MGR::EnumFromStr( aPluginType );
        PLUGIN::RELEASER    pi( IO_MGR::PluginFind( pi_type ) );
        PROPERTIES          choices;

        pi->FootprintLibOptions( &choices );

        if( choices.size() )
        {
            int needed_rows = (int) choices.size() - m_option_choices->GetNumberRows();
            if( needed_rows > 0 )
                m_option_choices->AppendRows( needed_rows );

            int row = 0;
            for( PROPERTIES::const_iterator it = choices.begin();  it != choices.end();  ++it, ++row )
            {
                DBG(printf( "[%s]:'%s'\n", it->first.c_str(), it->second.c_str() );)
                m_option_choices->SetCellValue( row, 0, FROM_UTF8( it->first.c_str() ) );
                m_option_choices->SetCellValue( row, 1, FROM_UTF8( it->second.c_str() ) );
            }
        }

        m_option_choices->AutoSizeColumns( false );

        if( !col_width_option )
        {
            m_grid->AutoSizeColumns( false );
@@ -176,10 +203,7 @@ private:
        EndModal( 0 );
    }



    //-----<event handlers>------------------------------------------------------
    void onAddRow( wxCommandEvent& event )
    int appendRow()
    {
        if( m_grid->AppendRows( 1 ) )
        {
@@ -188,10 +212,47 @@ private:
            // wx documentation is wrong, SetGridCursor does not make visible.
            m_grid->MakeCellVisible( last_row, 0 );
            m_grid->SetGridCursor( last_row, 0 );

            return last_row;
        }

        return -1;
    }

    //-----<event handlers>------------------------------------------------------

    void onAppendOption( wxMouseEvent& event )
    {
        int selected_row = m_option_choices->GetCursorRow();
        if( selected_row >= 0 )
        {
            wxString    option = m_option_choices->GetCellValue( selected_row, 0 );

            int row_count = m_grid->GetNumberRows();
            int row;

            for( row=0;  row<row_count;  ++row )
            {
                wxString col0 = m_grid->GetCellValue( row, 0 );

                if( !col0 )     // empty col0
                    break;
            }

            if( row == row_count )
                row = appendRow();

            m_grid->SetCellValue( row, 0, option );
            m_grid->AutoSizeColumns( false );
        }
    }

    void onAppendRow( wxMouseEvent& event )
    {
        appendRow();
    }

    void onDeleteRow( wxCommandEvent& event )
    void onDeleteRow( wxMouseEvent& event )
    {
        int rowCount = m_grid->GetNumberRows();
        int curRow   = getCursorRow();
@@ -205,7 +266,7 @@ private:
        }
    }

    void onMoveUp( wxCommandEvent& event )
    void onMoveUp( wxMouseEvent& event )
    {
        int curRow = getCursorRow();
        if( curRow >= 1 )
@@ -238,7 +299,7 @@ private:
        }
    }

    void onMoveDown( wxCommandEvent& event )
    void onMoveDown( wxMouseEvent& event )
    {
        int curRow = getCursorRow();
        if( curRow + 1 < m_grid->GetNumberRows() )
@@ -292,9 +353,10 @@ private:


void InvokePluginOptionsEditor( wxTopLevelWindow* aCaller,
        const wxString& aNickname, const wxString& aOptions, wxString* aResult )
        const wxString& aNickname, const wxString& aPluginType,
        const wxString& aOptions, wxString* aResult )
{
    DIALOG_FP_PLUGIN_OPTIONS    dlg( aCaller, aNickname, aOptions, aResult );
    DIALOG_FP_PLUGIN_OPTIONS    dlg( aCaller, aNickname, aPluginType, aOptions, aResult );

    dlg.ShowModal();
}
+74 −33
Original line number Diff line number Diff line
@@ -19,13 +19,14 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent,
	wxBoxSizer* m_horizontal_sizer;
	m_horizontal_sizer = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticBoxSizer* sbSizer1;
	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Plugin Options:") ), wxVERTICAL );
	wxStaticBoxSizer* m_grid_sizer;
	m_grid_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Plugin Options:") ), wxVERTICAL );
	
	m_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
	m_grid_sizer->SetMinSize( wxSize( -1,300 ) ); 
	m_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
	
	// Grid
	m_grid->CreateGrid( 5, 2 );
	m_grid->CreateGrid( 1, 2 );
	m_grid->EnableEditing( true );
	m_grid->EnableGridLines( true );
	m_grid->EnableDragGridSize( false );
@@ -41,53 +42,91 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent,
	
	// Rows
	m_grid->EnableDragRowSize( false );
	m_grid->SetRowLabelSize( 80 );
	m_grid->SetRowLabelSize( 40 );
	m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
	
	// Label Appearance
	
	// Cell Defaults
	m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
	sbSizer1->Add( m_grid, 1, wxEXPAND, 5 );
	m_grid_sizer->Add( m_grid, 1, wxEXPAND|wxTOP, 5 );
	
	wxBoxSizer* bSizer6;
	bSizer6 = new wxBoxSizer( wxHORIZONTAL );
	wxBoxSizer* m_button_sizer;
	m_button_sizer = new wxBoxSizer( wxHORIZONTAL );
	
	m_add_row = new wxButton( this, wxID_ANY, _("Add Row"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer6->Add( m_add_row, 0, wxALL, 5 );
	m_add_row = new wxButton( this, wxID_ANY, _("Append"), wxDefaultPosition, wxDefaultSize, 0 );
	m_add_row->SetToolTip( _("Append a blank row") );
	
	m_delete_row = new wxButton( this, wxID_ANY, _("Delete Row"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer6->Add( m_delete_row, 0, wxALL, 5 );
	m_button_sizer->Add( m_add_row, 0, wxALL, 5 );
	
	m_delete_row = new wxButton( this, wxID_ANY, _("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
	m_delete_row->SetToolTip( _("Delete the selected row") );
	
	m_button_sizer->Add( m_delete_row, 0, wxALL, 5 );
	
	m_move_up = new wxButton( this, wxID_ANY, _("Move Up"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer6->Add( m_move_up, 0, wxALL, 5 );
	m_move_up->SetToolTip( _("Move the selected row up one position") );
	
	m_button_sizer->Add( m_move_up, 0, wxALL, 5 );
	
	m_move_down = new wxButton( this, wxID_ANY, _("Move Down"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer6->Add( m_move_down, 0, wxALL, 5 );
	m_move_down->SetToolTip( _("Move the selected row down one position") );
	
	m_button_sizer->Add( m_move_down, 0, wxALL, 5 );
	
	
	sbSizer1->Add( bSizer6, 0, wxALIGN_CENTER, 5 );
	m_grid_sizer->Add( m_button_sizer, 0, wxALIGN_CENTER, 5 );
	
	
	m_horizontal_sizer->Add( sbSizer1, 1, wxEXPAND, 5 );
	m_horizontal_sizer->Add( m_grid_sizer, 3, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer3;
	bSizer3 = new wxBoxSizer( wxHORIZONTAL );
	wxGridSizer* m_choose_size;
	m_choose_size = new wxGridSizer( 1, 1, 0, 0 );
	
	m_button1 = new wxButton( this, wxID_ANY, _("<<"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer3->Add( m_button1, 0, wxALIGN_CENTER|wxALL, 5 );
	m_button1->SetMaxSize( wxSize( 50,-1 ) );
	
	m_choose_size->Add( m_button1, 0, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
	
	m_horizontal_sizer->Add( bSizer3, 0, wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
	
	wxStaticBoxSizer* sbSizer3;
	sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Option Choices:") ), wxHORIZONTAL );
	m_horizontal_sizer->Add( m_choose_size, 0, wxEXPAND, 5 );
	
	wxStaticBoxSizer* m_options_sizer;
	m_options_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Option Choices:") ), wxHORIZONTAL );
	
	m_options_sizer->SetMinSize( wxSize( 200,-1 ) ); 
	m_option_choices = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
	
	// Grid
	m_option_choices->CreateGrid( 0, 2 );
	m_option_choices->EnableEditing( false );
	m_option_choices->EnableGridLines( true );
	m_option_choices->EnableDragGridSize( false );
	m_option_choices->SetMargins( 0, 0 );
	
	m_listCtrl1 = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxVSCROLL );
	sbSizer3->Add( m_listCtrl1, 1, wxEXPAND, 5 );
	// Columns
	m_option_choices->AutoSizeColumns();
	m_option_choices->EnableDragColMove( false );
	m_option_choices->EnableDragColSize( true );
	m_option_choices->SetColLabelSize( 30 );
	m_option_choices->SetColLabelValue( 0, _("Option") );
	m_option_choices->SetColLabelValue( 1, _("Description") );
	m_option_choices->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
	
	// Rows
	m_option_choices->AutoSizeRows();
	m_option_choices->EnableDragRowSize( true );
	m_option_choices->SetRowLabelSize( 0 );
	m_option_choices->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
	
	// Label Appearance
	
	// Cell Defaults
	m_option_choices->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
	m_options_sizer->Add( m_option_choices, 1, wxEXPAND|wxTOP, 5 );
	
	
	m_horizontal_sizer->Add( sbSizer3, 1, wxEXPAND, 5 );
	m_horizontal_sizer->Add( m_options_sizer, 4, wxEXPAND, 5 );
	
	
	bSizer4->Add( m_horizontal_sizer, 1, wxALL|wxEXPAND, 5 );
@@ -110,10 +149,11 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE( wxWindow* parent,
	
	// Connect Events
	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelButtonClick ) );
	m_add_row->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAddRow ), NULL, this );
	m_delete_row->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
	m_move_up->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveUp ), NULL, this );
	m_move_down->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveDown ), NULL, this );
	m_add_row->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this );
	m_delete_row->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
	m_move_up->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveUp ), NULL, this );
	m_move_down->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveDown ), NULL, this );
	m_button1->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this );
	m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelButtonClick ), NULL, this );
	m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onOKButtonClick ), NULL, this );
}
@@ -122,10 +162,11 @@ DIALOG_FP_PLUGIN_OPTIONS_BASE::~DIALOG_FP_PLUGIN_OPTIONS_BASE()
{
	// Disconnect Events
	this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelButtonClick ) );
	m_add_row->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAddRow ), NULL, this );
	m_delete_row->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
	m_move_up->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveUp ), NULL, this );
	m_move_down->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveDown ), NULL, this );
	m_add_row->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendRow ), NULL, this );
	m_delete_row->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onDeleteRow ), NULL, this );
	m_move_up->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveUp ), NULL, this );
	m_move_down->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onMoveDown ), NULL, this );
	m_button1->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onAppendOption ), NULL, this );
	m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onCancelButtonClick ), NULL, this );
	m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_PLUGIN_OPTIONS_BASE::onOKButtonClick ), NULL, this );
	
Loading