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

Enhancement in copper zones dialog, useful for large boards having a lot of nets

parents 84ce064e 027c4cca
Loading
Loading
Loading
Loading
+120 −92
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@

#include "dialog_copper_zones.h"

wxString dialog_copper_zone::m_netNameShowFilter("*");    /* the filter to show nets (default * "*").
                                             *  static to keep this pattern for an entire pcbnew session
                                             */

/************************************************************************************************/
dialog_copper_zone::dialog_copper_zone( WinEDA_PcbFrame* parent, ZONE_SETTING* zone_setting ) :
@@ -31,11 +34,6 @@ dialog_copper_zone::dialog_copper_zone( WinEDA_PcbFrame* parent, ZONE_SETTING* z
    m_NetSorting   = 1;     // 0 = alphabetic sort, 1 = pad count sort, and filtering net names
    m_OnExitCode   = ZONE_ABORT;

    if( m_Config )
    {
        m_NetSorting = m_Config->Read( ZONE_NET_SORT_OPTION_KEY, 1l );
    }

    SetReturnCode( ZONE_ABORT ); // Will be changed on buttons click

    initDialog();
@@ -148,57 +146,22 @@ void dialog_copper_zone::initDialog( )
            m_LayerSelectionCtrl->SetSelection( ii );
    }

    m_NetSortingOption->SetSelection( m_NetSorting );

    wxString NetNameFilter = wxT( "N_0*" );
    wxString netNameDoNotShowFilter = wxT( "N-*" );
    if( m_Config )
    {
        NetNameFilter =
            m_Config->Read( ZONE_NET_FILTER_STRING_KEY );
    }

    // Build list of nets:
    m_NetNameFilter->SetValue( NetNameFilter );
    wxArrayString ListNetName;
    m_Parent->GetBoard()->ReturnSortedNetnamesList(
        ListNetName,
        m_NetSorting == 0 ? false : true );

    if( m_NetSorting != 0 )
    {
        wxString Filter = m_NetNameFilter->GetValue();
        for( unsigned ii = 0; ii < ListNetName.GetCount(); ii++ )
        {
            if( ListNetName[ii].Matches( Filter.GetData() ) )
            {
                ListNetName.RemoveAt( ii );
                ii--;
            }
        }
        int opt = m_Config->Read( ZONE_NET_SORT_OPTION_KEY, 1l );
        m_NetDisplayOption->SetSelection( opt );
        m_Config->Read( ZONE_NET_FILTER_STRING_KEY, netNameDoNotShowFilter );
    }
    else
        m_NetDisplayOption->SetSelection( 1 );

    ListNetName.Insert( wxT( "<no net>" ), 0 );
    m_ListNetNameSelection->InsertItems( ListNetName, 0 );
    m_ShowNetNameFilter->SetValue(m_netNameShowFilter);
    initListNetsParams();

    // Select net:
    int net_select = m_Zone_Setting->m_NetcodeSelection;

    if( net_select > 0 )
    {
        NETINFO_ITEM* equipot = m_Parent->GetBoard()->FindNet( net_select );
        if( equipot )  // Search net in list and select it
        {
            for( unsigned ii = 0; ii < ListNetName.GetCount(); ii++ )
            {
                if( ListNetName[ii] == equipot->GetNetname() )
                {
                    m_ListNetNameSelection->SetSelection( ii );
                    m_ListNetNameSelection->EnsureVisible( ii );
                    break;
                }
            }
        }
    }
    // Build list of nets:
    m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
    buildAvailableListOfNets();
}


@@ -258,10 +221,11 @@ bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportab
    {
        m_Config->Write( ZONE_NET_OUTLINES_HATCH_OPTION_KEY,
                         (long) m_Zone_Setting->m_Zone_HatchingStyle );
        wxString Filter = m_NetNameFilter->GetValue();
        wxString Filter = m_DoNotShowNetNameFilter->GetValue();
        m_Config->Write( ZONE_NET_FILTER_STRING_KEY, Filter );
    }

    m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
    m_Zone_Setting->m_FillMode = (m_FillModeCtrl->GetSelection() == 0) ? 0 : 1;

    wxString txtvalue = m_ZoneClearanceCtrl->GetValue();
@@ -365,50 +329,16 @@ bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportab
void dialog_copper_zone::OnNetSortingOptionSelected( wxCommandEvent& event )
/***************************************************************************/
{
    wxArrayString ListNetName;
    initListNetsParams();
    buildAvailableListOfNets();

    m_NetSorting = m_NetSortingOption->GetSelection();
    m_Parent->GetBoard()->ReturnSortedNetnamesList(
        ListNetName, m_NetSorting == 0 ? false : true );
    if( m_NetSorting != 0 )
    {
        wxString Filter = m_NetNameFilter->GetValue();
        for( unsigned ii = 0; ii < ListNetName.GetCount(); ii++ )
        {
            if( ListNetName[ii].Matches( Filter.GetData() ) )
            {
                ListNetName.RemoveAt( ii );
                ii--;
            }
        }
    }
    m_ListNetNameSelection->Clear();
    m_ListNetNameSelection->InsertItems( ListNetName, 0 );
    m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
    if( m_Config )
    {
        m_Config->Write( ZONE_NET_SORT_OPTION_KEY, (long) m_NetSorting );
        wxString Filter = m_NetNameFilter->GetValue();
        m_Config->Write( ZONE_NET_SORT_OPTION_KEY, (long) m_NetDisplayOption->GetSelection() );
        wxString Filter = m_DoNotShowNetNameFilter->GetValue();
        m_Config->Write( ZONE_NET_FILTER_STRING_KEY, Filter );
    }

    // Select and display current zone net name in listbox:
    int net_select = m_Zone_Setting->m_NetcodeSelection;
    if( net_select > 0 )
    {
        NETINFO_ITEM* equipot = m_Parent->GetBoard()->FindNet( net_select );
        if( equipot )  // Search net in list and select it
        {
            for( unsigned ii = 0; ii < ListNetName.GetCount(); ii++ )
            {
                if( ListNetName[ii] == equipot->GetNetname() )
                {
                    m_ListNetNameSelection->SetSelection( ii );
                    m_ListNetNameSelection->EnsureVisible( ii );
                    break;
                }
            }
        }
    }
}


@@ -416,6 +346,7 @@ void dialog_copper_zone::OnNetSortingOptionSelected( wxCommandEvent& event )
void dialog_copper_zone::OnButtonOkClick( wxCommandEvent& event )
/*****************************************************************/
{
    m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
    if( AcceptOptions( true ) )
        EndModal( ZONE_OK );
}
@@ -458,3 +389,100 @@ void dialog_copper_zone::OnPadsInZoneClick( wxCommandEvent& event )
        break;
    }
}


/** init m_NetSorting and m_NetFiltering values
 * according to m_NetDisplayOption selection
 */
void dialog_copper_zone::initListNetsParams()
{
    switch( m_NetDisplayOption->GetSelection() )
    {
    case 0:
        m_NetSorting   = true;
        m_NetFiltering = false;
        break;

    case 1:
        m_NetSorting   = false;
        m_NetFiltering = false;
        break;

    case 2:
        m_NetSorting   = true;
        m_NetFiltering = true;
        break;

    case 3:
        m_NetSorting   = false;
        m_NetFiltering = true;
        break;
    }
}


/* Called when clicking on Apply Filter button
 * Rebuild the list of nets with the currents filters settings.
 * If the net display options is not a filtered option, force this option
 */
void dialog_copper_zone::OnRunFiltersButtonClick( wxCommandEvent& event )
{
    m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
    // Ensure filtered option for nets:
    if( m_NetDisplayOption->GetSelection() == 0 )
        m_NetDisplayOption->SetSelection( 2 );
    else if( m_NetDisplayOption->GetSelection() == 1 )
        m_NetDisplayOption->SetSelection( 3 );
    initListNetsParams();
    buildAvailableListOfNets();
}


void dialog_copper_zone::buildAvailableListOfNets()
{
    wxArrayString listNetName;

    m_Parent->GetBoard()->ReturnSortedNetnamesList(
        listNetName, m_NetSorting == 0 ? false : true );

    if( m_NetFiltering )
    {
        wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue();
        wxString ShowFilter = m_ShowNetNameFilter->GetValue();
        for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
        {
            if( listNetName[ii].Matches( doNotShowFilter ) )
            {
                listNetName.RemoveAt( ii );
                ii--;
            }
            else if( !listNetName[ii].Matches( ShowFilter ) )
            {
                listNetName.RemoveAt( ii );
                ii--;
            }
        }
    }
    m_ListNetNameSelection->Clear();
    listNetName.Insert( wxT( "<no net>" ), 0 );
    m_ListNetNameSelection->InsertItems( listNetName, 0 );

    // Ensure current select net for the zone is visible:
    int net_select = m_Zone_Setting->m_NetcodeSelection;
    if( net_select > 0 )
    {
        NETINFO_ITEM* equipot = m_Parent->GetBoard()->FindNet( net_select );
        if( equipot )  // Search net in list and select it
        {
            for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ )
            {
                if( listNetName[ii] == equipot->GetNetname() )
                {
                    m_ListNetNameSelection->SetSelection( ii );
                    m_ListNetNameSelection->EnsureVisible( ii );
                    break;
                }
            }
        }
    }
}
+11 −5
Original line number Diff line number Diff line
@@ -19,7 +19,11 @@ private:

    ZONE_SETTING*   m_Zone_Setting;
    long            m_NetSorting;
    long            m_NetFiltering;
    int             m_LayerId[LAYER_COUNT]; // Handle the real layer number from layer name position in m_LayerSelectionCtrl
    static wxString m_netNameShowFilter;    /* the filter to show nets (default * "*").
                                             *  static to keep this pattern for an entire pcbnew session
                                             */

public:
    dialog_copper_zone( WinEDA_PcbFrame* parent, ZONE_SETTING* zone_setting );
@@ -31,6 +35,8 @@ private:
    void OnNetSortingOptionSelected( wxCommandEvent& event );
    void ExportSetupToOtherCopperZones( wxCommandEvent& event );
    void OnPadsInZoneClick( wxCommandEvent& event );
    void OnRunFiltersButtonClick( wxCommandEvent& event );
    void buildAvailableListOfNets();
    void initListNetsParams();
};

#endif      // #ifndef DIALOG_COPPER_ZONES
+240 −227
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ BEGIN_EVENT_TABLE( dialog_copper_zone_base, wxDialog )
	EVT_BUTTON( wxID_OK, dialog_copper_zone_base::_wxFB_OnButtonOkClick )
	EVT_BUTTON( wxID_CANCEL, dialog_copper_zone_base::_wxFB_OnButtonCancelClick )
	EVT_RADIOBOX( ID_NET_SORTING_OPTION, dialog_copper_zone_base::_wxFB_OnNetSortingOptionSelected )
	EVT_BUTTON( wxID_ANY, dialog_copper_zone_base::_wxFB_OnRunFiltersButtonClick )
END_EVENT_TABLE()

dialog_copper_zone_base::dialog_copper_zone_base( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
@@ -164,22 +165,34 @@ dialog_copper_zone_base::dialog_copper_zone_base( wxWindow* parent, wxWindowID i
	wxStaticBoxSizer* m_NetSortOptSizer;
	m_NetSortOptSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Nets Display Options:") ), wxVERTICAL );
	
	wxString m_NetSortingOptionChoices[] = { _("Alphabetic"), _("Advanced") };
	int m_NetSortingOptionNChoices = sizeof( m_NetSortingOptionChoices ) / sizeof( wxString );
	m_NetSortingOption = new wxRadioBox( this, ID_NET_SORTING_OPTION, _("Net sorting:"), wxDefaultPosition, wxDefaultSize, m_NetSortingOptionNChoices, m_NetSortingOptionChoices, 1, wxRA_SPECIFY_COLS );
	m_NetSortingOption->SetSelection( 0 );
	m_NetSortingOption->SetToolTip( _("Nets can be sorted:\nBy alphabetic order\nBy number of pads in the net (advanced)") );
	wxString m_NetDisplayOptionChoices[] = { _("Show all, alphabetic"), _("Show all, advanced"), _("Filtered, alphabetic"), _("Filtered, advanced") };
	int m_NetDisplayOptionNChoices = sizeof( m_NetDisplayOptionChoices ) / sizeof( wxString );
	m_NetDisplayOption = new wxRadioBox( this, ID_NET_SORTING_OPTION, _("Net list options:"), wxDefaultPosition, wxDefaultSize, m_NetDisplayOptionNChoices, m_NetDisplayOptionChoices, 1, wxRA_SPECIFY_COLS );
	m_NetDisplayOption->SetSelection( 2 );
	m_NetDisplayOption->SetToolTip( _("Nets can be sorted:\nBy alphabetic order\nBy number of pads in the net (advanced)") );
	
	m_NetSortOptSizer->Add( m_NetSortingOption, 0, wxALL|wxEXPAND, 5 );
	m_NetSortOptSizer->Add( m_NetDisplayOption, 0, wxALL|wxEXPAND, 5 );
	
	m_staticText5 = new wxStaticText( this, wxID_ANY, _("Filter"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText5 = new wxStaticText( this, wxID_ANY, _("Filter: Hidden Nets"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText5->Wrap( -1 );
	m_NetSortOptSizer->Add( m_staticText5, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_NetNameFilter = new wxTextCtrl( this, ID_TEXTCTRL_NETNAMES_FILTER, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_NetNameFilter->SetToolTip( _("Pattern in advanced mode, to filter net names in list\nNet names matching this pattern are not displayed") );
	m_DoNotShowNetNameFilter = new wxTextCtrl( this, ID_TEXTCTRL_NETNAMES_FILTER, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_DoNotShowNetNameFilter->SetToolTip( _("Pattern in advanced mode, to filter net names in list\nNet names matching this pattern are not displayed") );
	
	m_NetSortOptSizer->Add( m_NetNameFilter, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	m_NetSortOptSizer->Add( m_DoNotShowNetNameFilter, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
	
	m_staticText51 = new wxStaticText( this, wxID_ANY, _("Filter: Allowed Nets"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText51->Wrap( -1 );
	m_NetSortOptSizer->Add( m_staticText51, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_ShowNetNameFilter = new wxTextCtrl( this, ID_TEXTCTRL_NETNAMES_FILTER, _("*"), wxDefaultPosition, wxDefaultSize, 0 );
	m_ShowNetNameFilter->SetToolTip( _("Pattern in advanced mode, to filter net names in list\nOnly net names matching this pattern are displayed") );
	
	m_NetSortOptSizer->Add( m_ShowNetNameFilter, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
	
	m_buttonRunFilter = new wxButton( this, wxID_ANY, _("Apply Filters"), wxDefaultPosition, wxDefaultSize, 0 );
	m_NetSortOptSizer->Add( m_buttonRunFilter, 0, wxALL|wxEXPAND, 5 );
	
	m_RightBoxSizer->Add( m_NetSortOptSizer, 1, wxEXPAND, 5 );