Commit 8fd0c322 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

more fp lib table work

parent 75072f43
Loading
Loading
Loading
Loading
+130 −12
Original line number Diff line number Diff line
@@ -24,12 +24,27 @@
 */


/*  TODO:

*)  Check for duplicate nicknames per table

*)  Grab text from any pending ChoiceEditor when OK button pressed.

*)  Test wxRE_ADVANCED on Windows.

*/



#include <fctsys.h>
#include <dialog_fp_lib_table_base.h>
#include <fp_lib_table.h>
#include <wx/grid.h>
#include <wx/clipbrd.h>
#include <wx/tokenzr.h>
#include <wx/arrstr.h>
#include <wx/regex.h>
#include <set>

/**
 * Class FP_TBL_MODEL
@@ -184,18 +199,32 @@ public:
        {
        case COL_NICKNAME:  return _( "Nickname" );
        case COL_URI:       return _( "Library Path" );
        case COL_TYPE:      return _( "Plugin" );

        // keep this 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" );
        default:            return wxEmptyString;
        }
    }

    /*
    wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) const // overload
    {
        if( aCol != COL_TYPE )
            return wxGridTableBase::GetAttr( aRow, aCol, aKind );
        else
        {

        }
    }
    */

    //-----</wxGridTableBase overloads>------------------------------------------
};


// It works for table data on clipboard for an excell spreadsheet,
// It works for table data on clipboard for an Excell spreadsheet,
// why not us too for now.
#define COL_SEP     wxT( '\t' )
#define ROW_SEP     wxT( '\n' )
@@ -509,6 +538,71 @@ class DIALOG_FP_LIB_TABLE : public DIALOG_FP_LIB_TABLE_BASE
        event.Skip();
    }

    /// Populate the readonly environment variable table with names and values
    /// by examining all the full_uri columns.
    void populateEnvironReadOnlyTable()
    {
        wxRegEx re( wxT( ".*?\\$\\{(.+?)\\}.*?" ), wxRE_ADVANCED );
        wxASSERT( re.IsValid() );   // wxRE_ADVANCED is required.

        std::set< wxString >        unique;
        typedef std::set<wxString>::const_iterator      SET_CITER;

        m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() );

        int gblRowCount = m_global_model.GetNumberRows();
        int prjRowCount = m_project_model.GetNumberRows();
        int row;

        for( row = 0;  row < gblRowCount;  ++row )
        {
            wxString uri = m_global_model.GetValue( row, FP_TBL_MODEL::COL_URI );

            while( re.Matches( uri ) )
            {
                wxString envvar = re.GetMatch( uri, 1 );

                // ignore duplicates
                unique.insert( envvar );

                // delete the last match and search again
                uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
            }
        }

        for( row = 0;  row < prjRowCount;  ++row )
        {
            wxString uri = m_project_model.GetValue( row, FP_TBL_MODEL::COL_URI );

            while( re.Matches( uri ) )
            {
                wxString envvar = re.GetMatch( uri, 1 );

                // ignore duplicates
                unique.insert( envvar );

                // delete the last match and search again
                uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
            }
        }

        m_path_subs_grid->AppendRows( unique.size() );

        row = 0;
        for( SET_CITER it = unique.begin();  it != unique.end();  ++it, ++row )
        {
            wxString    evName = *it;
            wxString    evValue;

            m_path_subs_grid->SetCellValue( row, 0, evName );

            if( wxGetEnv( evName, &evValue ) )
                m_path_subs_grid->SetCellValue( row, 1, evValue );
        }

        m_path_subs_grid->AutoSizeColumns();
    }

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

    // caller's tables are modified only on OK button.
@@ -540,14 +634,38 @@ public:
        m_project_grid->SetTable( (wxGridTableBase*) &m_project_model );

        m_global_grid->AutoSizeColumns( false );

        m_project_grid->AutoSizeColumns( false );

        m_path_subs_grid->AutoSizeColumns( false );
        wxArrayString choices;
        choices.Add( IO_MGR::ShowType( IO_MGR::KICAD ) );
        choices.Add( IO_MGR::ShowType( IO_MGR::LEGACY ) );
        choices.Add( IO_MGR::ShowType( IO_MGR::EAGLE ) );
        //choices.Add( IO_MGR::ShowType( IO_MGR::GEDA_PCB ) );

        wxGridCellAttr* attr;

        attr = new wxGridCellAttr;
        attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
        m_project_grid->SetColAttr( FP_TBL_MODEL::COL_TYPE, attr );

        attr = new wxGridCellAttr;
        attr->SetEditor( new wxGridCellChoiceEditor( choices ) );
        m_global_grid->SetColAttr(  FP_TBL_MODEL::COL_TYPE, attr );

        m_global_grid->AutoSizeColumns();
        m_project_grid->AutoSizeColumns();

        m_path_subs_grid->AutoSizeColumns();

        Connect( ID_CUT, ID_PASTE, wxEVT_COMMAND_MENU_SELECTED,
            wxCommandEventHandler( DIALOG_FP_LIB_TABLE::onPopupSelection ), NULL, this );

        populateEnvironReadOnlyTable();

        /* This scrunches the dialog hideously
        Fit();
        */

        // fire pageChangedHandler() so m_cur_grid gets set
        wxAuiNotebookEvent uneventful;
        pageChangedHandler( uneventful );
@@ -555,18 +673,18 @@ public:

    ~DIALOG_FP_LIB_TABLE()
    {
        // Destroy the gui stuff first, with a goal of destroying the two wxGrids now,
        // since the ~wxGrid() wants the wxGridTableBase to still be non-destroyed.
        // Without this call, the wxGridTableBase objects are destroyed first
        // (i.e. destructor called) and there is a segfault since wxGridTableBase's vtable
        // is then no longer valid.  If ~wxGrid() would not examine a wxGridTableBase that
        // it does not own, then this would not be a concern.  But it is, since it does.
        DestroyChildren();
        Disconnect( ID_CUT, ID_PASTE, wxEVT_COMMAND_MENU_SELECTED,
            wxCommandEventHandler( DIALOG_FP_LIB_TABLE::onPopupSelection ), NULL, this );

        // ~wxGrid() examines its table, and the tables will have been destroyed before
        // the wxGrids are, so remove the tables from the wxGrids' awareness.
        // Otherwise there is a segfault.
        m_global_grid->SetTable( NULL );
        m_project_grid->SetTable( NULL );
    }
};



int InvokePcbLibTableEditor( wxFrame* aParent, FP_LIB_TABLE* aGlobal, FP_LIB_TABLE* aProject )
{
    DIALOG_FP_LIB_TABLE dlg( aParent, aGlobal, aProject );
+3 −5
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	m_path_subs_grid = new wxGrid( m_bottom, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
	
	// Grid
	m_path_subs_grid->CreateGrid( 2, 2 );
	m_path_subs_grid->CreateGrid( 1, 2 );
	m_path_subs_grid->EnableEditing( true );
	m_path_subs_grid->EnableGridLines( true );
	m_path_subs_grid->EnableDragGridSize( false );
@@ -155,15 +155,13 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	m_path_subs_grid->EnableDragColMove( false );
	m_path_subs_grid->EnableDragColSize( true );
	m_path_subs_grid->SetColLabelSize( 30 );
	m_path_subs_grid->SetColLabelValue( 0, _("Category") );
	m_path_subs_grid->SetColLabelValue( 0, _("Environment Variable") );
	m_path_subs_grid->SetColLabelValue( 1, _("Path Segment") );
	m_path_subs_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
	
	// Rows
	m_path_subs_grid->EnableDragRowSize( true );
	m_path_subs_grid->SetRowLabelSize( 40 );
	m_path_subs_grid->SetRowLabelValue( 0, _("%S") );
	m_path_subs_grid->SetRowLabelValue( 1, _("%P") );
	m_path_subs_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
	
	// Label Appearance
@@ -188,7 +186,7 @@ DIALOG_FP_LIB_TABLE_BASE::DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID
	m_bottom->SetSizer( m_bottom_sizer );
	m_bottom->Layout();
	m_bottom_sizer->Fit( m_bottom );
	m_splitter->SplitHorizontally( m_top, m_bottom, 343 );
	m_splitter->SplitHorizontally( m_top, m_bottom, 398 );
	bSizer1->Add( m_splitter, 2, wxEXPAND, 5 );
	
	
+5 −5
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
            <property name="minimum_size"></property>
            <property name="name">DIALOG_FP_LIB_TABLE_BASE</property>
            <property name="pos"></property>
            <property name="size">864,652</property>
            <property name="size">996,652</property>
            <property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
            <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
            <property name="title">PCB Library Tables</property>
@@ -140,7 +140,7 @@
                        <property name="pos"></property>
                        <property name="resize">Resizable</property>
                        <property name="sashgravity">0.0</property>
                        <property name="sashpos">343</property>
                        <property name="sashpos">398</property>
                        <property name="sashsize">-1</property>
                        <property name="show">1</property>
                        <property name="size"></property>
@@ -1297,7 +1297,7 @@
                                                    <property name="close_button">1</property>
                                                    <property name="col_label_horiz_alignment">wxALIGN_CENTRE</property>
                                                    <property name="col_label_size">30</property>
                                                    <property name="col_label_values">&quot;Category&quot; &quot;Path Segment&quot;</property>
                                                    <property name="col_label_values">&quot;Environment Variable&quot; &quot;Path Segment&quot;</property>
                                                    <property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
                                                    <property name="cols">2</property>
                                                    <property name="column_sizes">150,500</property>
@@ -1343,10 +1343,10 @@
                                                    <property name="resize">Resizable</property>
                                                    <property name="row_label_horiz_alignment">wxALIGN_CENTRE</property>
                                                    <property name="row_label_size">40</property>
                                                    <property name="row_label_values">&quot;%S&quot; &quot;%P&quot;</property>
                                                    <property name="row_label_values"></property>
                                                    <property name="row_label_vert_alignment">wxALIGN_CENTRE</property>
                                                    <property name="row_sizes"></property>
                                                    <property name="rows">2</property>
                                                    <property name="rows">1</property>
                                                    <property name="show">1</property>
                                                    <property name="size"></property>
                                                    <property name="subclass"></property>
+2 −2
Original line number Diff line number Diff line
@@ -75,12 +75,12 @@ class DIALOG_FP_LIB_TABLE_BASE : public DIALOG_SHIM
	
	public:
		
		DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("PCB Library Tables"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 864,652 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); 
		DIALOG_FP_LIB_TABLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("PCB Library Tables"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 996,652 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); 
		~DIALOG_FP_LIB_TABLE_BASE();
		
		void m_splitterOnIdle( wxIdleEvent& )
		{
			m_splitter->SetSashPosition( 343 );
			m_splitter->SetSashPosition( 398 );
			m_splitter->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_FP_LIB_TABLE_BASE::m_splitterOnIdle ), NULL, this );
		}
	
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ public:
        LEGACY,             //< Legacy Pcbnew file formats prior to s-expression.
        KICAD,              //< S-expression Pcbnew file format.
        EAGLE,
        PCAD,
        GEDA_PCB,           //< Geda PCB file formats.

        // add your type here.

Loading