Commit 997270d8 authored by charras's avatar charras
Browse files

First work about net classes. This is a work in progress and a moving target

parent e7c9ae2b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ email address.
================================================================================
++pcbnew
    First work about net classes. This is a work in progress and a moving target.
    Manual routing and DRC do not used yet this feature
    Manual routing and DRC do not use yet this feature


2009-Jul-13 UPDATE Dick Hollenbeck <dick@softplc.com>
+221 −113
Original line number Diff line number Diff line
@@ -48,11 +48,11 @@ void DIALOG_DESIGN_RULES::Init()
/********************************************************************/
{
    SetFocus();
    SetReturnCode( 0 );

    // Initialize the layers grid:
    m_ActivesLayersCount = g_DesignSettings.m_CopperLayerCount;
    m_Pcb = m_Parent->GetBoard();
    m_Changes = 0;

    m_LayersCountSelection->SetSelection( m_ActivesLayersCount / 2 );

@@ -100,7 +100,7 @@ void DIALOG_DESIGN_RULES::Init()
    InitRulesList();

    /* Initialize the list of nets buffers
    (note the netcode 0 is not a real net, so it is not loaded)
     *  (note the netcode 0 is not a real net, so it is not loaded)
     */
    for( unsigned ii = 1; ; ii++ )
    {
@@ -108,22 +108,26 @@ void DIALOG_DESIGN_RULES::Init()
        if( net == NULL )
            break;
        m_StockNets.push_back( net );

        // search the index in rules list for this net
        int rules_idx = 0;
        for( int jj = 0; jj < m_gridNetClassesProperties->GetNumberRows(); jj++ )
        {
            if( m_gridNetClassesProperties->GetRowLabelValue(jj).CmpNoCase(net->GetClassName()) == 0 )
            if( m_gridNetClassesProperties->GetRowLabelValue( jj ).CmpNoCase( net->GetClassName() )
                == 0 )
            {
                rules_idx = jj;
                break;
            }
        }

        m_NetsLinkToClasses.push_back( rules_idx ); // All nets are set to default net class
    }

    InitializeRulesSelectionBoxes();
}


/** Function FillListBoxWithNetsNames
 * populates the aListBox with net names members of the aNetclassIndex net class
 * the "Client Data pointer" is used to store the index of nets in ne nets lists
@@ -137,6 +141,7 @@ void DIALOG_DESIGN_RULES::FillListBoxWithNetsNames(wxListBox* aListBox, int aNet
        if( aNetclassIndex == m_NetsLinkToClasses[ii] )
        {
            aListBox->Append( m_StockNets[ii]->GetNetname() );

            // Store the index of this net
            aListBox->SetClientData( idx, (void*) ii );
            idx++;
@@ -144,6 +149,7 @@ void DIALOG_DESIGN_RULES::FillListBoxWithNetsNames(wxListBox* aListBox, int aNet
    }
}


/* Initialize the combno boxes by the list of existing net classes
 */
void DIALOG_DESIGN_RULES::InitializeRulesSelectionBoxes()
@@ -155,6 +161,7 @@ void DIALOG_DESIGN_RULES::InitializeRulesSelectionBoxes()
        m_CBoxRightSelection->Append( m_gridNetClassesProperties->GetRowLabelValue( ii ) );
        m_CBoxLeftSelection->Append( m_gridNetClassesProperties->GetRowLabelValue( ii ) );
    }

    m_CBoxRightSelection->Select( 0 );
    m_CBoxLeftSelection->Select( 0 );
    m_buttonRightToLeft->Enable( false );
@@ -179,12 +186,14 @@ void DIALOG_DESIGN_RULES::SetRoutableLayerStatus()
            value = wxT( "1" );
        m_gridLayersProperties->SetCellValue( ii, LAYERS_GRID_ROUTABLE_POSITION, value );
        m_gridLayersProperties->SetReadOnly( ii, LAYERS_GRID_ROUTABLE_POSITION );

        // Set to Read Only cell for non existing copper layers:
        m_gridLayersProperties->SetReadOnly( ii, LAYERS_GRID_STATUS_POSITION, value != wxT( "1" ) );
        m_gridLayersProperties->SetReadOnly( ii, LAYERS_GRID_NAME_POSITION, value != wxT( "1" ) );
    }
}


/* Initialize the rules list from board
 */
void DIALOG_DESIGN_RULES::InitRulesList()
@@ -194,11 +203,14 @@ void DIALOG_DESIGN_RULES::InitRulesList()
        const NETCLASS* netclass = m_Pcb->m_NetClassesList.GetNetClass( ii );
        if( netclass == NULL )
            break;

        // Creates one entry if needed
        if( ii >= m_gridNetClassesProperties->GetNumberRows() )
            m_gridNetClassesProperties->AppendRows();

        // Init name
        m_gridNetClassesProperties->SetRowLabelValue( ii, netclass->m_Name );

        // Init data
        wxString msg;
        msg = ReturnStringFromValue( g_UnitMetric,
@@ -224,6 +236,7 @@ void DIALOG_DESIGN_RULES::InitRulesList()
    }
}


/* Copy the rules list to board
 */
void DIALOG_DESIGN_RULES::CopyRulesListToBoard()
@@ -234,31 +247,38 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard()
        NETCLASS* netclass = new NETCLASS( m_Pcb,
                                          m_gridNetClassesProperties->GetRowLabelValue( ii ) );
        m_Pcb->m_NetClassesList.AddNetclass( netclass );

        // Init data
        netclass->m_NetParams.m_TracksWidth =
            ReturnValueFromString( g_UnitMetric,
                        m_gridNetClassesProperties->GetCellValue(ii, RULE_GRID_TRACKSIZE_POSITION),
                                   m_gridNetClassesProperties->GetCellValue( ii,
                                                                             RULE_GRID_TRACKSIZE_POSITION ),
                                   m_Parent->m_InternalUnits );

        netclass->m_NetParams.m_ViasSize =
            ReturnValueFromString( g_UnitMetric,
                        m_gridNetClassesProperties->GetCellValue(ii, RULE_GRID_VIASIZE_POSITION),
                                   m_gridNetClassesProperties->GetCellValue( ii,
                                                                             RULE_GRID_VIASIZE_POSITION ),
                                   m_Parent->m_InternalUnits );

        netclass->m_NetParams.m_Clearance =
            ReturnValueFromString( g_UnitMetric,
                        m_gridNetClassesProperties->GetCellValue(ii, RULE_GRID_CLEARANCE_POSITION),
                                   m_gridNetClassesProperties->GetCellValue( ii,
                                                                             RULE_GRID_CLEARANCE_POSITION ),
                                   m_Parent->m_InternalUnits );

        netclass->m_NetParams.m_TracksMinWidth =
            ReturnValueFromString( g_UnitMetric,
                        m_gridNetClassesProperties->GetCellValue(ii, RULE_GRID_MINTRACKSIZE_POSITION),
                                   m_gridNetClassesProperties->GetCellValue( ii,
                                                                             RULE_GRID_MINTRACKSIZE_POSITION ),
                                   m_Parent->m_InternalUnits );

        netclass->m_NetParams.m_ViasMinSize =
            ReturnValueFromString( g_UnitMetric,
                        m_gridNetClassesProperties->GetCellValue(ii, RULE_GRID_MINVIASIZE_POSITION),
                                   m_gridNetClassesProperties->GetCellValue( ii,
                                                                             RULE_GRID_MINVIASIZE_POSITION ),
                                   m_Parent->m_InternalUnits );

        // Copy the list of nets associated to this netclass:
        for( unsigned idx = 0; idx < m_StockNets.size(); idx++ )
        {
@@ -270,6 +290,7 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard()
    m_Pcb->TransfertDesignRulesToNets();
}


/*****************************************************************/
void DIALOG_DESIGN_RULES::OnCancelButtonClick( wxCommandEvent& event )
/*****************************************************************/
@@ -282,6 +303,12 @@ void DIALOG_DESIGN_RULES::OnCancelButtonClick( wxCommandEvent& event )
void DIALOG_DESIGN_RULES::OnOkButtonClick( wxCommandEvent& event )
/**************************************************************************/
{
    if( !TestDataValidity() )
    {
        DisplayError( this, _( "Errors detected, Abort" ) );
        return;
    }

    g_DesignSettings.m_CopperLayerCount = m_ActivesLayersCount;

    // Initialize the new layer name
@@ -311,7 +338,7 @@ void DIALOG_DESIGN_RULES::OnOkButtonClick( wxCommandEvent& event )

    CopyRulesListToBoard();

    EndModal( 1 );
    EndModal( wxID_OK );
}


@@ -333,6 +360,7 @@ void DIALOG_DESIGN_RULES::OnAddNetclassClick( wxCommandEvent& event )
/**************************************************************************/
{
    wxString class_name;

    if( Get_Message( _( "New Net Class Name:" ),
                     wxEmptyString,
                     class_name,
@@ -346,7 +374,7 @@ void DIALOG_DESIGN_RULES::OnAddNetclassClick( wxCommandEvent& event )
        value = m_gridNetClassesProperties->GetRowLabelValue( ii );
        if( class_name.CmpNoCase( value ) == 0 )       // Already exists!
        {
            DisplayError(this, _("This NetClass is alerady existing, cannot add it") );
            DisplayError( this, _( "This NetClass is already existing, cannot add it; Aborted" ) );
            return;
        }
    }
@@ -355,6 +383,7 @@ void DIALOG_DESIGN_RULES::OnAddNetclassClick( wxCommandEvent& event )
    m_gridNetClassesProperties->SetRowLabelValue(
        m_gridNetClassesProperties->GetNumberRows() - 1,
        class_name );

    // Copy values of the previous class:
    int irow = m_gridNetClassesProperties->GetNumberRows() - 1;
    for( int icol = 0; icol < m_gridNetClassesProperties->GetNumberCols(); icol++ )
@@ -363,6 +392,7 @@ void DIALOG_DESIGN_RULES::OnAddNetclassClick( wxCommandEvent& event )
        value = m_gridNetClassesProperties->GetCellValue( irow - 1, icol );
        m_gridNetClassesProperties->SetCellValue( irow, icol, value );
    }

    InitializeRulesSelectionBoxes();
}

@@ -372,11 +402,13 @@ void DIALOG_DESIGN_RULES::OnRemoveNetclassClick( wxCommandEvent& event )
/**************************************************************************/
{
    wxArrayInt select = m_gridNetClassesProperties->GetSelectedRows();

    for( int ii = select.GetCount() - 1; ii >= 0; ii-- )
    {
        if( select[ii] != 0 )   // Do not remove the default class
        {
            m_gridNetClassesProperties->DeleteRows( select[ii] );

            // reset the net class to default for nets member of the removed net class
            for( unsigned jj = 0; jj< m_NetsLinkToClasses.size(); jj++ )
                if( m_NetsLinkToClasses[jj] == ii )
@@ -384,9 +416,11 @@ void DIALOG_DESIGN_RULES::OnRemoveNetclassClick( wxCommandEvent& event )

        }
    }

    InitializeRulesSelectionBoxes();
}


/*
 * Called on the left Choice Box selection
 */
@@ -405,6 +439,7 @@ void DIALOG_DESIGN_RULES::OnLeftCBSelection( wxCommandEvent& event )
    }
}


/*
 * Called on the Right Choice Box selection
 */
@@ -431,6 +466,7 @@ void DIALOG_DESIGN_RULES::OnRightCBSelection( wxCommandEvent& event )
void DIALOG_DESIGN_RULES::OnRightToLeftCopyButton( wxCommandEvent& event )
{
    int idx_class = m_CBoxLeftSelection->GetCurrentSelection();

    if( idx_class == wxNOT_FOUND )
        return;
    for( unsigned ii = 0; ii < m_listBoxRightNetSelect->GetCount(); ii++ )
@@ -446,12 +482,14 @@ void DIALOG_DESIGN_RULES::OnRightToLeftCopyButton( wxCommandEvent& event )
    FillListBoxWithNetsNames( m_listBoxRightNetSelect, m_CBoxRightSelection->GetCurrentSelection() );
}


/* Called on clicking the ">>>" or Copy Left to Right button:
 * Selected items are moved from the left list to the right list
 */
void DIALOG_DESIGN_RULES::OnLeftToRightCopyButton( wxCommandEvent& event )
{
    int idx_class = m_CBoxRightSelection->GetCurrentSelection();

    if( idx_class == wxNOT_FOUND )
        return;
    for( unsigned ii = 0; ii < m_listBoxLeftNetSelect->GetCount(); ii++ )
@@ -467,6 +505,7 @@ void DIALOG_DESIGN_RULES::OnLeftToRightCopyButton( wxCommandEvent& event )
    FillListBoxWithNetsNames( m_listBoxRightNetSelect, m_CBoxRightSelection->GetCurrentSelection() );
}


/* Called on clicking the left "select all" button:
 * select alls items of the left netname list lisxt box
 */
@@ -476,6 +515,7 @@ void DIALOG_DESIGN_RULES::OnLeftSelectAllButton( wxCommandEvent& event )
        m_listBoxLeftNetSelect->SetSelection( ii );
}


/* Called on clicking the right "select all" button:
 * select alls items of the right netname list lisxt box
 */
@@ -485,3 +525,71 @@ void DIALOG_DESIGN_RULES::OnRightSelectAllButton( wxCommandEvent& event )
        m_listBoxRightNetSelect->SetSelection( ii );
}


/* TestDataValidity
 * Performs a control of data validity
 * set the background of a bad cell in RED and display an info message
 * @return true if Ok, false if error
 */
bool DIALOG_DESIGN_RULES::TestDataValidity()
{
    bool success = true;
    m_MessagesList->SetPage(wxEmptyString); // Clear message list

    //  Test duplicate layers names
    for( int ii = 0; ii < m_gridLayersProperties->GetNumberRows() - 1; ii++ )
    {
        wxString value = m_gridLayersProperties->GetCellValue( ii, LAYERS_GRID_NAME_POSITION );
        for( int jj = ii+1; jj < m_gridLayersProperties->GetNumberRows(); jj++ )
        {
            wxString othervalue = m_gridLayersProperties->GetCellValue( ii,
                                                                        LAYERS_GRID_NAME_POSITION );
            othervalue = m_gridLayersProperties->GetCellValue( jj, LAYERS_GRID_NAME_POSITION );
            if( value.CmpNoCase( othervalue ) == 0 )   // Already exists!
            {
                wxString text;
                text.Printf( _(
                                "<small>This layer name <b>%s</b> is already existing<br>" ),
                            value.GetData() );
                m_MessagesList->AppendToPage( text );
                success = false;
            }
        }
    }

    int value;
    int minvalue;

    for( int ii = 0; ii < m_gridNetClassesProperties->GetNumberRows(); ii++ )
    {
        value = ReturnValueFromString( g_UnitMetric,
                                       m_gridNetClassesProperties->GetCellValue(
                                           ii, RULE_GRID_TRACKSIZE_POSITION ),
                                       m_Parent->m_InternalUnits );
        minvalue = ReturnValueFromString( g_UnitMetric,
                                          m_gridNetClassesProperties->GetCellValue( ii,
                                                                                    RULE_GRID_MINTRACKSIZE_POSITION ),
                                          m_Parent->m_InternalUnits );
        if( value < minvalue )
        {
            success = false;
            m_MessagesList->AppendToPage( _( "The <b>track</b> minimum size is bigger than the size<br>" ) );
        }

        value = ReturnValueFromString( g_UnitMetric,
                                       m_gridNetClassesProperties->GetCellValue(
                                           ii, RULE_GRID_VIASIZE_POSITION ),
                                       m_Parent->m_InternalUnits );
        minvalue = ReturnValueFromString( g_UnitMetric,
                                          m_gridNetClassesProperties->GetCellValue( ii,
                                                                                    RULE_GRID_MINVIASIZE_POSITION ),
                                          m_Parent->m_InternalUnits );
        if( value < minvalue )
        {
            success = false;
            m_MessagesList->AppendToPage( _( "The <b>via</b> minimum size is bigger than the size<br>" ) );
        }
    }

    return success;
}
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ class DIALOG_DESIGN_RULES : public DIALOG_DESIGN_RULES_BASE
        WinEDA_PcbFrame * m_Parent;
        int m_ActivesLayersCount;
        BOARD * m_Pcb;
        int m_Changes;
        LAYER_T m_LayersType[4];
        wxString m_LayersTypeName[4];
        std::vector<NETINFO_ITEM*> m_StockNets;     // full list of nets on board
@@ -36,6 +35,7 @@ class DIALOG_DESIGN_RULES : public DIALOG_DESIGN_RULES_BASE
		void OnLeftToRightCopyButton( wxCommandEvent& event );
		void OnLeftSelectAllButton( wxCommandEvent& event );
		void OnRightSelectAllButton( wxCommandEvent& event );
		bool TestDataValidity( );
        void Init();
        void InitRulesList();
        void InitializeRulesSelectionBoxes();
+12 −12
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@

DIALOG_DESIGN_RULES_BASE::DIALOG_DESIGN_RULES_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxSize( 600,450 ), wxDefaultSize );
	this->SetSizeHints( wxSize( 600,520 ), wxDefaultSize );
	
	wxBoxSizer* bMainSizer;
	bMainSizer = new wxBoxSizer( wxVERTICAL );
@@ -124,7 +124,7 @@ DIALOG_DESIGN_RULES_BASE::DIALOG_DESIGN_RULES_BASE( wxWindow* parent, wxWindowID
	
	// Cell Defaults
	m_gridNetClassesProperties->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
	m_gridNetClassesProperties->SetMinSize( wxSize( -1,100 ) );
	m_gridNetClassesProperties->SetMinSize( wxSize( -1,150 ) );
	
	sbSizer1->Add( m_gridNetClassesProperties, 1, wxALL|wxEXPAND, 5 );
	
@@ -139,7 +139,7 @@ DIALOG_DESIGN_RULES_BASE::DIALOG_DESIGN_RULES_BASE( wxWindow* parent, wxWindowID
	
	sbSizer1->Add( bSizerButtons, 0, wxALIGN_CENTER_VERTICAL, 5 );
	
	bmainSizerNclasses->Add( sbSizer1, 1, wxEXPAND, 5 );
	bmainSizerNclasses->Add( sbSizer1, 0, wxEXPAND, 5 );
	
	wxBoxSizer* bSizerNetSelect;
	bSizerNetSelect = new wxBoxSizer( wxHORIZONTAL );
@@ -194,15 +194,6 @@ DIALOG_DESIGN_RULES_BASE::DIALOG_DESIGN_RULES_BASE( wxWindow* parent, wxWindowID
	
	bmainSizerNclasses->Add( bSizerNetSelect, 1, wxEXPAND, 5 );
	
	m_staticTextMsg = new wxStaticText( m_panelNetClasses, wxID_ANY, _("Messages:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticTextMsg->Wrap( -1 );
	bmainSizerNclasses->Add( m_staticTextMsg, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_MessagesList = new wxHtmlWindow( m_panelNetClasses, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxSUNKEN_BORDER );
	m_MessagesList->SetMinSize( wxSize( -1,100 ) );
	
	bmainSizerNclasses->Add( m_MessagesList, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
	
	m_panelNetClasses->SetSizer( bmainSizerNclasses );
	m_panelNetClasses->Layout();
	bmainSizerNclasses->Fit( m_panelNetClasses );
@@ -210,6 +201,15 @@ DIALOG_DESIGN_RULES_BASE::DIALOG_DESIGN_RULES_BASE( wxWindow* parent, wxWindowID
	
	bMainSizer->Add( m_notebook, 1, wxALL|wxEXPAND, 5 );
	
	m_staticTextMsg = new wxStaticText( this, wxID_ANY, _("Messages:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticTextMsg->Wrap( -1 );
	bMainSizer->Add( m_staticTextMsg, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
	
	m_MessagesList = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxSUNKEN_BORDER );
	m_MessagesList->SetMinSize( wxSize( -1,100 ) );
	
	bMainSizer->Add( m_MessagesList, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
	
	m_sdbSizer1 = new wxStdDialogButtonSizer();
	m_sdbSizer1OK = new wxButton( this, wxID_OK );
	m_sdbSizer1->AddButton( m_sdbSizer1OK );
+107 −107
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@
            <property name="hidden">0</property>
            <property name="id">wxID_ANY</property>
            <property name="maximum_size"></property>
            <property name="minimum_size">600,450</property>
            <property name="minimum_size">600,520</property>
            <property name="name">DIALOG_DESIGN_RULES_BASE</property>
            <property name="pos"></property>
            <property name="size">684,486</property>
            <property name="size">684,568</property>
            <property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
            <property name="subclass"></property>
            <property name="title">Design Rules Editor</property>
@@ -398,7 +398,7 @@
                                    <object class="sizeritem" expanded="1">
                                        <property name="border">5</property>
                                        <property name="flag">wxEXPAND</property>
                                        <property name="proportion">1</property>
                                        <property name="proportion">0</property>
                                        <object class="wxStaticBoxSizer" expanded="1">
                                            <property name="id">wxID_ANY</property>
                                            <property name="label">Net classes:</property>
@@ -445,7 +445,7 @@
                                                    <property name="margin_height">0</property>
                                                    <property name="margin_width">0</property>
                                                    <property name="maximum_size"></property>
                                                    <property name="minimum_size">-1,100</property>
                                                    <property name="minimum_size">-1,150</property>
                                                    <property name="name">m_gridNetClassesProperties</property>
                                                    <property name="permission">protected</property>
                                                    <property name="pos"></property>
@@ -1104,6 +1104,11 @@
                                            </object>
                                        </object>
                                    </object>
                                </object>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem" expanded="1">
                    <property name="border">5</property>
                    <property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
@@ -1207,11 +1212,6 @@
                        <event name="OnUpdateUI"></event>
                    </object>
                </object>
                                </object>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem" expanded="1">
                    <property name="border">5</property>
                    <property name="flag">wxALIGN_RIGHT</property>
Loading