Commit 1e2af7fe authored by Miguel Angel Ajo's avatar Miguel Angel Ajo
Browse files

Add GetLayerID method to BOARD.

This method is added for scripting purposes, to be able to query
specific board layer names thru a board object.

If no board specific layer name is found, it will fallback to
standard layer names.
parent b1ace160
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -314,6 +314,32 @@ bool BOARD::SetLayerDescr( LAYER_ID aIndex, const LAYER& aLayer )
    return false;
}

#include <stdio.h>

const LAYER_ID BOARD::GetLayerID(wxString aLayerName) const
{

    // Look for the BOARD specific copper layer names
    for( LAYER_NUM layer = 0; layer < LAYER_ID_COUNT; ++layer )
    {
        if ( IsCopperLayer( layer ) &&
             ( m_Layer[ layer ].m_name == aLayerName) )
        {
            return ToLAYER_ID( layer );
        }
    }

    // Otherwise fall back to the system standard layer names
    for ( LAYER_NUM layer = 0; layer < LAYER_ID_COUNT; ++layer )
    {
        if ( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName )
        {
            return ToLAYER_ID( layer );
        }
    }

    return UNDEFINED_LAYER;
}

const wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
{
@@ -331,7 +357,6 @@ const wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
    return GetStandardLayerName( aLayer );
}


bool BOARD::SetLayerName( LAYER_ID aLayer, const wxString& aLayerName )
{
    if( !IsCopperLayer( aLayer ) )
+12 −0
Original line number Diff line number Diff line
@@ -621,6 +621,18 @@ public:
     */
    void ConvertBrdLayerToPolygonalContours( LAYER_ID aLayer, CPOLYGONS_LIST& aOutlines );

    /**
     * Function GetLayerID
     * returns the ID of a layer given by aLayerName.  Copper layers may
     * have custom names.
     *
     * @param aLayerName = A layer name, like wxT("B.Cu"), etc.
     *
     * @return LAYER_ID -   the layer id, which for copper layers may
     *                      be custom, else standard.
     */
    const LAYER_ID GetLayerID( wxString aLayerName ) const;

    /**
     * Function GetLayerName
     * returns the name of a layer given by aLayer.  Copper layers may
+28 −1
Original line number Diff line number Diff line
@@ -8,6 +8,12 @@ import tempfile

from pcbnew import *


BACK_COPPER = 'Back_Copper'
B_CU = 'B.Cu'
NEW_NAME = 'My_Fancy_Layer_Name'


class TestBoardClass(unittest.TestCase):

    def setUp(self):
@@ -97,6 +103,27 @@ class TestBoardClass(unittest.TestCase):

        os.remove(self.FILENAME)

    def test_pcb_layer_name_set_get(self):
        pcb = BOARD()
        pcb.SetLayerName(31, BACK_COPPER)
        self.assertEqual(pcb.GetLayerName(31), BACK_COPPER)

    def test_pcb_layer_name_set_get(self):
        pcb = BOARD()
        pcb.SetLayerName(31, BACK_COPPER)
        self.assertEqual(pcb.GetLayerName(31), BACK_COPPER)

    def test_pcb_layer_id_get(self):
        pcb = BOARD()
        b_cu_id = pcb.GetLayerID(B_CU)
        pcb.SetLayerName(b_cu_id, NEW_NAME)

        # ensure we can get the ID for the new name
        self.assertEqual(pcb.GetLayerID(NEW_NAME), b_cu_id)

        # ensure we can get to the ID via the STD name too
        self.assertEqual(pcb.GetLayerID(B_CU), b_cu_id)

    #def test_interactive(self):
    # 	code.interact(local=locals())