Commit e460b4a5 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

fix export_gencad.cpp

parent 516c386a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
 *
@@ -106,7 +107,7 @@ enum LAYER_ID
    Edge_Cuts,
    Margin,

    F_CrtYd,        // CrtYd & Body are footprint only
    F_CrtYd,        // CrtYd & Fab are footprint only
    B_CrtYd,
    F_Fab,
    B_Fab,
+1 −4
Original line number Diff line number Diff line
@@ -323,11 +323,8 @@ bool BOARD::SetLayer( LAYER_ID aIndex, const LAYER& aLayer )
}


wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
const wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
{
    if( !IsPcbLayer( aLayer ) )
        return wxEmptyString;

    // All layer names are stored in the BOARD.
    if( IsLayerEnabled( aLayer ) )
    {
+1 −1
Original line number Diff line number Diff line
@@ -644,7 +644,7 @@ public:
     * @return wxString -   the layer name, which for copper layers may
     *                      be custom, else standard.
     */
    wxString GetLayerName( LAYER_ID aLayer ) const;
    const wxString GetLayerName( LAYER_ID aLayer ) const;

    /**
     * Function SetLayerName
+3 −1
Original line number Diff line number Diff line
@@ -262,7 +262,9 @@ void DIALOG_COPPER_ZONE::initDialog()

        m_LayerId.push_back( layer );

        msg = board->GetLayerName( layer ).Trim();
        msg = board->GetLayerName( layer );

        msg.Trim();

        EDA_COLOR_T layerColor = board->GetLayerColor( layer );

+125 −138
Original line number Diff line number Diff line
@@ -99,24 +99,20 @@ static const wxString GenCADLayerNameFlipped[32] =

static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
{
    char tmp[60];

    if( IsCopperLayer( aId ) )
    {
        if( aId == F_Cu )
            return "TOP";
        else if( aId == B_Cu )
            return "BOTTON";
            return "BOTTOM";

        else if( aId <= 14 )
        {
            int len = sprintf( tmp, "INNER%d", aCuCount - aId );
            return std::string( tmp, len );
            return StrPrintf(  "INNER%d", aCuCount - aId - 1 );
        }
        else
        {
            int len = sprintf( tmp, "LAYER%d", aId );
            return std::string( tmp, len );
            return StrPrintf( "LAYER%d", aId );
        }
    }

@@ -161,73 +157,65 @@ static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
};


// flipped layer name for Gencad export (to make CAM350 imports correct)
static std::string GenCADLayerNameFlipped( int aCuCount, LAYER_ID aId )
{
    char tmp[60];
static const LAYER_ID gc_seq[] = {
    B_Cu,
    In30_Cu,
    In29_Cu,
    In28_Cu,
    In27_Cu,
    In26_Cu,
    In25_Cu,
    In24_Cu,
    In23_Cu,
    In22_Cu,
    In21_Cu,
    In20_Cu,
    In19_Cu,
    In18_Cu,
    In17_Cu,
    In16_Cu,
    In15_Cu,
    In14_Cu,
    In13_Cu,
    In12_Cu,
    In11_Cu,
    In10_Cu,
    In9_Cu,
    In8_Cu,
    In7_Cu,
    In6_Cu,
    In5_Cu,
    In4_Cu,
    In3_Cu,
    In2_Cu,
    In1_Cu,
    F_Cu,
};

    if( IsCopperLayer( aId ) )
    {
        if( aId == F_Cu )
            return "BOTTOM";
        else if( aId == B_Cu )
            return "TOP";

        else if( aId <= 14 )
        {
            int len = sprintf( tmp, "INNER%d", aId );
            return std::string( tmp, len );
        }
        else
        {
            int len = sprintf( tmp, "LAYER%d", aId );   // this is probably wrong, need help.
            return std::string( tmp, len );
        }
    }

    else
// flipped layer name for Gencad export (to make CAM350 imports correct)
static std::string GenCADLayerNameFlipped( int aCuCount, LAYER_ID aId )
{
        const char* txt;

        // using a switch to clearly show mapping & catch out of bounds index.
        switch( aId )
    if( 1<= aId && aId <= 14 )
    {
        // Technicals
        case F_Adhes:   txt = "B.Adhes";                break;
        case B_Adhes:   txt = "F.Adhes";                break;
        case F_Paste:   txt = "SOLDERPASTE_BOTTOM";     break;
        case B_Paste:   txt = "SOLDERPASTE_TOP";        break;
        case F_SilkS:   txt = "SILKSCREEN_BOTTOM";      break;
        case B_SilkS:   txt = "SILKSCREEN_TOP";         break;
        case F_Mask:    txt = "SOLDERMASK_BOTTOM";      break;
        case B_Mask:    txt = "SOLDERMASK_TOP";         break;

        // Users
        case Dwgs_User: txt = "Dwgs.User";              break;
        case Cmts_User: txt = "Cmts.User";              break;
        case Eco1_User: txt = "Eco1.User";              break;
        case Eco2_User: txt = "Eco2.User";              break;
        case Edge_Cuts: txt = "Edge.Cuts";              break;
        case Margin:    txt = "Margin";                 break;

        // Footprint
        case B_CrtYd:   txt = "F_CrtYd";                break;
        case F_CrtYd:   txt = "B_CrtYd";                break;
        case B_Fab:     txt = "F_Fab";                  break;
        case F_Fab:     txt = "B_Fab";                  break;

        default:
            wxASSERT_MSG( 0, wxT( "aId UNEXPECTED" ) );
                        txt = "BAD-INDEX!";             break;
        return StrPrintf(  "INNER%d", 14 - aId );
    }

        return txt;
    }
    return GenCADLayerName( aCuCount, aId );
};


#endif

static std::string fmt_mask( LSET aSet )
{
#if 0
    return aSet.FmtHex();
#else
    return StrPrintf( "%08x", (unsigned) ( aSet & LSET::AllCuMask() ).to_ulong() );
#endif
}


// These are the export origin (the auxiliary axis)
static int GencadOffsetX, GencadOffsetY;
@@ -255,9 +243,6 @@ static double MapYTo( int aY )
/* Driver function: processing starts here */
void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
{

#if 0   // working on this 30-Jun-14, not ready yet, failed the initial testing.

    wxFileName  fn = GetBoard()->GetFileName();
    FILE*       file;

@@ -347,8 +332,6 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
            module->SetFlag( 0 );
        }
    }
#endif

}


@@ -426,9 +409,11 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )

    // Emit vias pads
    TRACK* old_via = 0;

    for( unsigned i = 0; i < vias.size(); i++ )
    {
        VIA* via = vias[i];

        if( old_via && 0 == ViaSort( &old_via, &via ) )
            continue;

@@ -436,7 +421,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
        viastacks.push_back( via );
        fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
                via->GetWidth(), via->GetDrillValue(),
                via->GetLayerSet().FmtHex().c_str(),
                fmt_mask( via->GetLayerSet() ).c_str(),
                via->GetDrillValue() / SCALE_FACTOR,
                via->GetWidth() / (SCALE_FACTOR * 2) );
    }
@@ -557,8 +542,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
                             pad->GetOffset().x / SCALE_FACTOR,
                             (-pad->GetOffset().y - dr) / SCALE_FACTOR );
                }
            break;
            }
            break;

        case PAD_TRAPEZOID:
            fprintf( aFile, " POLYGON %g\n",
@@ -583,16 +568,16 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )

        fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n",
                 via->GetWidth(), via->GetDrillValue(),
                 mask.FmtHex().c_str(),
                 fmt_mask( mask ).c_str(),
                 via->GetDrillValue() / SCALE_FACTOR );

        for( LSEQ seq = mask.Seq();  seq;  ++seq )
        for( LSEQ seq = mask.Seq( gc_seq, DIM( gc_seq ) );  seq;  ++seq )
        {
            LAYER_ID layer = *seq;

            fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
                    via->GetWidth(), via->GetDrillValue(),
                    mask.FmtHex().c_str(),
                    fmt_mask( mask ).c_str(),
                    GenCADLayerName( cu_count, layer ).c_str()
                    );
        }
@@ -612,7 +597,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )

        LSET pad_set = pad->GetLayerSet() & master_layermask;

        for( LSEQ seq = pad_set.Seq();  seq;  ++seq )
        // the special gc_seq
        for( LSEQ seq = pad_set.Seq( gc_seq, DIM( gc_seq ) );  seq;  ++seq )
        {
            LAYER_ID layer = *seq;

@@ -622,6 +608,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
        // Flipped padstack
        fprintf( aFile, "PADSTACK PAD%dF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );

        // the normal LAYER_ID sequence is inverted from gc_seq[]
        for( LSEQ seq = pad_set.Seq();  seq;  ++seq )
        {
            LAYER_ID layer = *seq;
@@ -990,7 +977,7 @@ static void CreateRoutesSection( FILE* aFile, BOARD* aPcb )

            fprintf( aFile, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
                     via->GetWidth(), via->GetDrillValue(),
                     vset.FmtHex().c_str(),
                     fmt_mask( vset ).c_str(),
                     MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
                     via->GetDrillValue() / SCALE_FACTOR, vianum++ );
        }
Loading