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

Gerbview: fix scaling error in x.6 file format. Minor cleaning code.

Better separation between Pcbnew code and Gerber code.
Update export to Pcb code (uses now the version 4  kicad_pcb file format).
parent c5e14ef1
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -50,12 +50,13 @@ set( GERBVIEW_SRCS
    gerbview_config.cpp
    gerbview_config.cpp
    gerbview_frame.cpp
    gerbview_frame.cpp
    hotkeys.cpp
    hotkeys.cpp
    initpcb.cpp
    init_gbr_drawlayers.cpp
    locate.cpp
    locate.cpp
    menubar.cpp
    menubar.cpp
    onleftclick.cpp
    onleftclick.cpp
    onrightclick.cpp
    onrightclick.cpp
    pcbplot.cpp
    pcbplot.cpp
    printout_control.cpp
    readgerb.cpp
    readgerb.cpp
    rs274_read_XY_and_IJ_coordinates.cpp
    rs274_read_XY_and_IJ_coordinates.cpp
    rs274d.cpp
    rs274d.cpp
@@ -71,7 +72,6 @@ set( GERBVIEW_EXTRA_SRCS
    ../common/class_layer_box_selector.cpp
    ../common/class_layer_box_selector.cpp
    ../common/class_page_info.cpp
    ../common/class_page_info.cpp
    ../pcbnew/layer_widget.cpp
    ../pcbnew/layer_widget.cpp
    ../pcbnew/printout_controler.cpp
)
)


if( MINGW )
if( MINGW )
+103 −80
Original line number Original line Diff line number Diff line
@@ -7,8 +7,12 @@
#include <gerbview_frame.h>
#include <gerbview_frame.h>
#include <select_layers_to_pcb.h>
#include <select_layers_to_pcb.h>


#define NB_PCB_LAYERS LAYER_ID_COUNT
#define FIRST_COPPER_LAYER 0
#define LAST_COPPER_LAYER 31

// Exported function
// Exported function
const wxString GetPCBDefaultLayerName( int aLayerNumber );
const wxString GetPCBDefaultLayerName( int aLayerId );




enum layer_sel_id {
enum layer_sel_id {
@@ -21,9 +25,8 @@ enum layer_sel_id {
class SELECT_LAYER_DIALOG : public wxDialog
class SELECT_LAYER_DIALOG : public wxDialog
{
{
private:
private:
    GERBVIEW_FRAME* m_Parent;
    wxRadioBox*     m_layerList;
    wxRadioBox*     m_LayerList;
    std::vector <int> m_layerId;
    int m_LayerId[int(GERBER_DRAWLAYERS_COUNT) + 1]; // One extra element for "(Deselect)" radiobutton


public:
public:
    // Constructor and destructor
    // Constructor and destructor
@@ -64,12 +67,11 @@ END_EVENT_TABLE()
int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
int GERBVIEW_FRAME::SelectPCBLayer( int aDefaultLayer, int aCopperLayerCount,
                                          bool aShowDeselectOption )
                                          bool aShowDeselectOption )
{
{
    int layer;
    SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer,
    SELECT_LAYER_DIALOG* frame = new SELECT_LAYER_DIALOG( this, aDefaultLayer,
                                                          aCopperLayerCount,
                                                          aCopperLayerCount,
                                                          aShowDeselectOption );
                                                          aShowDeselectOption );


    layer = frame->ShowModal();
    int layer = frame->ShowModal();
    frame->Destroy();
    frame->Destroy();
    return layer;
    return layer;
}
}
@@ -88,85 +90,73 @@ SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent,
              wxSize( 470, 250 ),
              wxSize( 470, 250 ),
              wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
              wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
{
{
    #define NB_PCB_LAYERS 64
    wxButton* button;
    #define FIRST_COPPER_LAYER 0
    #define LAST_COPPER_LAYER 31
    wxButton* Button;
    int ii;
    int ii;
    wxString  LayerList[NB_PCB_LAYERS + 1]; // One extra element for "(Deselect)"
    wxArrayString  layerList;
                                        // radiobutton
    int layerSelect = -1;
    int       LayerCount, LayerSelect = -1;

    m_Parent = parent;


    // Build the layer list; first build copper layers list
    // Build the layer list; first build copper layers list
    LayerCount = 0;
    int layerCount = 0;


    for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
    for( ii = FIRST_COPPER_LAYER; ii <= LAST_COPPER_LAYER; ++ii )
    {
    {
        m_LayerId[ii] = 0;

        if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
        if( ii == FIRST_COPPER_LAYER || ii == LAST_COPPER_LAYER || ii < aCopperLayerCount-1 )
        {
        {
            LayerList[LayerCount] = GetPCBDefaultLayerName( ii );
            layerList.Add( GetPCBDefaultLayerName( ii ) );


            if( ii == aDefaultLayer )
            if( ii == aDefaultLayer )
                LayerSelect = LayerCount;
                layerSelect = layerCount;


            m_LayerId[LayerCount] = ii;
            m_layerId.push_back( ii );
            LayerCount++;
            layerCount++;
        }
        }
    }
    }


    // Build the layer list; build non copper layers list
    // Build the layer list; build non copper layers list
    for( ; ii < NB_PCB_LAYERS; ++ii )
    for( ; ii < NB_PCB_LAYERS; ++ii )
    {
    {
        m_LayerId[ii] = 0;
        layerList.Add( GetPCBDefaultLayerName( ii ) );

        LayerList[LayerCount] = GetPCBDefaultLayerName( ii );


        if( ii == aDefaultLayer )
        if( ii == aDefaultLayer )
            LayerSelect = LayerCount;
            layerSelect = layerCount;


        m_LayerId[LayerCount] = ii;
        m_layerId.push_back( ii );
        LayerCount++;
        layerCount++;
    }
    }


    // When appropriate, also provide a "(Deselect)" radiobutton
    // When appropriate, also provide a "(Deselect)" radiobutton
    if( aShowDeselectOption )
    if( aShowDeselectOption )
    {
    {
        LayerList[LayerCount] = _( "(Deselect)" );
        layerList.Add( _( "Do not export" ) );


        if( NB_PCB_LAYERS == aDefaultLayer )
        if( UNSELECTED_LAYER == aDefaultLayer )
            LayerSelect = LayerCount;
            layerSelect = layerCount;


        m_LayerId[LayerCount] = NB_PCB_LAYERS;
        m_layerId.push_back( UNSELECTED_LAYER );
        LayerCount++;
        layerCount++;
    }
    }


    m_LayerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
    m_layerList = new wxRadioBox( this, ID_LAYER_SELECT, _( "Layer" ),
                                  wxPoint( -1, -1 ), wxSize( -1, -1 ),
                                  wxPoint( -1, -1 ), wxSize( -1, -1 ),
                                  LayerCount, LayerList,
                                  layerList,
                                  (LayerCount < 8) ? LayerCount : 8,
                                  (layerCount < 8) ? layerCount : 8,
                                  wxRA_SPECIFY_ROWS );
                                  wxRA_SPECIFY_ROWS );


    if( LayerSelect >= 0 )
    if( layerSelect >= 0 )
        m_LayerList->SetSelection( LayerSelect );
        m_layerList->SetSelection( layerSelect );


    wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer* FrameBoxSizer = new wxBoxSizer( wxHORIZONTAL );
    SetSizer( FrameBoxSizer );
    SetSizer( FrameBoxSizer );
    FrameBoxSizer->Add( m_LayerList, 0, wxALIGN_TOP | wxALL, 5 );
    FrameBoxSizer->Add( m_layerList, 0, wxALIGN_TOP | wxALL, 5 );
    wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer* ButtonBoxSizer = new wxBoxSizer( wxVERTICAL );
    FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );
    FrameBoxSizer->Add( ButtonBoxSizer, 0, wxALIGN_BOTTOM | wxALL, 0 );


    Button = new wxButton( this, wxID_OK, _( "OK" ) );
    button = new wxButton( this, wxID_OK, _( "OK" ) );
    Button->SetDefault();
    button->SetDefault();
    ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
    ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );

    Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
    ButtonBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );


    SetFocus();
    button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
    ButtonBoxSizer->Add( button, 0, wxGROW | wxALL, 5 );


    GetSizer()->SetSizeHints( this );
    GetSizer()->SetSizeHints( this );


@@ -176,7 +166,7 @@ SELECT_LAYER_DIALOG::SELECT_LAYER_DIALOG( GERBVIEW_FRAME* parent,


void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
void SELECT_LAYER_DIALOG::OnLayerSelected( wxCommandEvent& event )
{
{
    int ii = m_LayerId[m_LayerList->GetSelection()];
    int ii = m_layerId[m_layerList->GetSelection()];


    EndModal( ii );
    EndModal( ii );
}
}
@@ -187,12 +177,15 @@ void SELECT_LAYER_DIALOG::OnCancelClick( wxCommandEvent& event )
    EndModal( -1 );
    EndModal( -1 );
}
}


const wxString GetPCBDefaultLayerName( int aLayerNumber )
// This function is a duplicate of
// const wxChar* LSET::Name( LAYER_ID aLayerId )
// However it avoids a dependency to Pcbnew code.
const wxString GetPCBDefaultLayerName( int aLayerId )
{
{
    const wxChar* txt;
    const wxChar* txt;


    // Use a switch to explicitly show the mapping more clearly
    // using a switch to explicitly show the mapping more clearly
    switch( aLayerNumber )
    switch( aLayerId )
    {
    {
    case F_Cu:              txt = wxT( "F.Cu" );            break;
    case F_Cu:              txt = wxT( "F.Cu" );            break;
    case In1_Cu:            txt = wxT( "In1.Cu" );          break;
    case In1_Cu:            txt = wxT( "In1.Cu" );          break;
@@ -209,7 +202,25 @@ const wxString GetPCBDefaultLayerName( int aLayerNumber )
    case In12_Cu:           txt = wxT( "In12.Cu" );         break;
    case In12_Cu:           txt = wxT( "In12.Cu" );         break;
    case In13_Cu:           txt = wxT( "In13.Cu" );         break;
    case In13_Cu:           txt = wxT( "In13.Cu" );         break;
    case In14_Cu:           txt = wxT( "In14.Cu" );         break;
    case In14_Cu:           txt = wxT( "In14.Cu" );         break;
    case In15_Cu:           txt = wxT( "In15.Cu" );         break;
    case In16_Cu:           txt = wxT( "In16.Cu" );         break;
    case In17_Cu:           txt = wxT( "In17.Cu" );         break;
    case In18_Cu:           txt = wxT( "In18.Cu" );         break;
    case In19_Cu:           txt = wxT( "In19.Cu" );         break;
    case In20_Cu:           txt = wxT( "In20.Cu" );         break;
    case In21_Cu:           txt = wxT( "In21.Cu" );         break;
    case In22_Cu:           txt = wxT( "In22.Cu" );         break;
    case In23_Cu:           txt = wxT( "In23.Cu" );         break;
    case In24_Cu:           txt = wxT( "In24.Cu" );         break;
    case In25_Cu:           txt = wxT( "In25.Cu" );         break;
    case In26_Cu:           txt = wxT( "In26.Cu" );         break;
    case In27_Cu:           txt = wxT( "In27.Cu" );         break;
    case In28_Cu:           txt = wxT( "In28.Cu" );         break;
    case In29_Cu:           txt = wxT( "In29.Cu" );         break;
    case In30_Cu:           txt = wxT( "In30.Cu" );         break;
    case B_Cu:              txt = wxT( "B.Cu" );            break;
    case B_Cu:              txt = wxT( "B.Cu" );            break;

    // Technicals
    case B_Adhes:           txt = wxT( "B.Adhes" );         break;
    case B_Adhes:           txt = wxT( "B.Adhes" );         break;
    case F_Adhes:           txt = wxT( "F.Adhes" );         break;
    case F_Adhes:           txt = wxT( "F.Adhes" );         break;
    case B_Paste:           txt = wxT( "B.Paste" );         break;
    case B_Paste:           txt = wxT( "B.Paste" );         break;
@@ -218,12 +229,24 @@ const wxString GetPCBDefaultLayerName( int aLayerNumber )
    case F_SilkS:           txt = wxT( "F.SilkS" );         break;
    case F_SilkS:           txt = wxT( "F.SilkS" );         break;
    case B_Mask:            txt = wxT( "B.Mask" );          break;
    case B_Mask:            txt = wxT( "B.Mask" );          break;
    case F_Mask:            txt = wxT( "F.Mask" );          break;
    case F_Mask:            txt = wxT( "F.Mask" );          break;

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

    // Footprint
    case F_CrtYd:           txt = wxT( "F.CrtYd" );         break;
    case B_CrtYd:           txt = wxT( "B.CrtYd" );         break;
    case F_Fab:             txt = wxT( "F.Fab" );           break;
    case B_Fab:             txt = wxT( "B.Fab" );           break;

    default:
        wxASSERT_MSG( 0, wxT( "aLayerId out of range" ) );
                            txt = wxT( "BAD INDEX!" );      break;
    }
    }


    return wxString( txt );
    return wxString( txt );
+1 −1
Original line number Original line Diff line number Diff line
@@ -164,7 +164,7 @@ void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
        break;
        break;


    case ID_GERBVIEW_GLOBAL_DELETE:
    case ID_GERBVIEW_GLOBAL_DELETE:
        Erase_Current_Layer( true );
        Erase_Current_DrawLayer( true );
        ClearMsgPanel();
        ClearMsgPanel();
        break;
        break;


+120 −79
Original line number Original line Diff line number Diff line
@@ -19,10 +19,12 @@
#include <build_version.h>
#include <build_version.h>
#include <wildcards_and_files_ext.h>
#include <wildcards_and_files_ext.h>


#define TO_PCB_UNIT( x ) KiROUND( x / IU_PER_DECIMILS )
// Imported function
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );

#define TO_PCB_UNIT( x ) ( x / IU_PER_MM)


#define TRACK_TYPE  0
#define TRACK_TYPE  0
#define VIA_TYPE    1


/* A helper class to export a Gerber set of files to Pcbnew
/* A helper class to export a Gerber set of files to Pcbnew
 */
 */
@@ -44,7 +46,7 @@ public:
     * Function ExportPcb
     * Function ExportPcb
     * saves a board from a set of Gerber images.
     * saves a board from a set of Gerber images.
     */
     */
    bool    ExportPcb( LAYER_NUM* LayerLookUpTable, int aCopperLayers );
    bool    ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers );


private:
private:
    /**
    /**
@@ -89,17 +91,25 @@ private:


    /**
    /**
     * function writePcbLineItem
     * function writePcbLineItem
     * basic write function to write a DRAWSEGMENT item or a TRACK/VIA item
     * basic write function to write a DRAWSEGMENT item or a TRACK item
     * to the board file
     * to the board file, from a non flashed item
     */
     */
    void    writePcbLineItem( int aShape, int aType, wxPoint& aStart, wxPoint& aEnd,
    void    writePcbLineItem( bool aIsArc, wxPoint& aStart, wxPoint& aEnd,
                              int aWidth, LAYER_NUM aLayer, int aDrill, int aAngle = 0 );
                              int aWidth, LAYER_NUM aLayer, double aAngle = 0 );

    /**
     * function writeCopperLineItem
     * basic write function to write a a TRACK item
     * to the board file, from a non flashed item
     */
    void    writeCopperLineItem( wxPoint& aStart, wxPoint& aEnd,
                                 int aWidth, LAYER_NUM aLayer );


    /**
    /**
     * function writePcbHeader
     * function writePcbHeader
     * Write a very basic header to the board file
     * Write a very basic header to the board file
     */
     */
    void    writePcbHeader();
    void    writePcbHeader( LAYER_NUM* aLayerLookUpTable );
};
};




@@ -140,7 +150,7 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
    wxString        path = wxGetCwd();;
    wxString        path = wxGetCwd();;


    wxFileDialog    filedlg( this, _( "Board file name:" ),
    wxFileDialog    filedlg( this, _( "Board file name:" ),
                             path, fileName, LegacyPcbFileWildcard,
                             path, fileName, PcbFileWildcard,
                             wxFD_SAVE );
                             wxFD_SAVE );


    if( filedlg.ShowModal() == wxID_CANCEL )
    if( filedlg.ShowModal() == wxID_CANCEL )
@@ -171,21 +181,23 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
}
}




bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* LayerLookUpTable, int aCopperLayers )
bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers )
{
{
    LOCALE_IO   toggle;     // toggles on, then off, the C locale.

    m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );
    m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) );


    if( m_fp == NULL )
    if( m_fp == NULL )
    {
    {
        wxString msg;
        wxString msg;
        msg.Printf( _( "Cannot create file <%s>" ), GetChars( m_pcb_file_name ) );
        msg.Printf( _( "Cannot create file '%s'" ), GetChars( m_pcb_file_name ) );
        DisplayError( m_gerbview_frame, msg );
        DisplayError( m_gerbview_frame, msg );
        return false;
        return false;
    }
    }


    m_pcbCopperLayersCount = aCopperLayers;
    m_pcbCopperLayersCount = aCopperLayers;


    writePcbHeader();
    writePcbHeader( aLayerLookUpTable );


    // create an image of gerber data
    // create an image of gerber data
    // First: non copper layers:
    // First: non copper layers:
@@ -195,7 +207,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* LayerLookUpTable, int aCopperLay
    for( ; gerb_item; gerb_item = gerb_item->Next() )
    for( ; gerb_item; gerb_item = gerb_item->Next() )
    {
    {
        int layer = gerb_item->GetLayer();
        int layer = gerb_item->GetLayer();
        LAYER_NUM pcb_layer_number = LayerLookUpTable[layer];
        LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];


        if( !IsPcbLayer( pcb_layer_number ) )
        if( !IsPcbLayer( pcb_layer_number ) )
            continue;
            continue;
@@ -205,13 +217,12 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* LayerLookUpTable, int aCopperLay
    }
    }


    // Copper layers
    // Copper layers
    fprintf( m_fp, "$TRACK\n" );
    gerb_item = m_gerbview_frame->GetItemsList();
    gerb_item = m_gerbview_frame->GetItemsList();


    for( ; gerb_item; gerb_item = gerb_item->Next() )
    for( ; gerb_item; gerb_item = gerb_item->Next() )
    {
    {
        int layer = gerb_item->GetLayer();
        int layer = gerb_item->GetLayer();
        LAYER_NUM pcb_layer_number = LayerLookUpTable[layer];
        LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer];


        if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
        if( pcb_layer_number < 0 || pcb_layer_number > pcbCopperLayerMax )
            continue;
            continue;
@@ -220,8 +231,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* LayerLookUpTable, int aCopperLay
            export_copper_item( gerb_item, pcb_layer_number );
            export_copper_item( gerb_item, pcb_layer_number );
    }
    }


    fprintf( m_fp, "$EndTRACK\n" );
    fprintf( m_fp, ")\n" );
    fprintf( m_fp, "$EndBOARD\n" );


    fclose( m_fp );
    fclose( m_fp );
    m_fp = NULL;
    m_fp = NULL;
@@ -231,16 +241,11 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* LayerLookUpTable, int aCopperLay


void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer )
void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer )
{
{
    #define SEG_SHAPE   0
    bool isArc = false;
    #define ARC_SHAPE   2
    int     shape   = SEG_SHAPE;


    // please note: the old PCB format only has integer support for angles
    double     angle   = 0;
    int     angle   = 0;
    wxPoint seg_start   = aGbrItem->m_Start;
    wxPoint seg_start, seg_end;
    wxPoint seg_end     = aGbrItem->m_End;

    seg_start   = aGbrItem->m_Start;
    seg_end     = aGbrItem->m_End;


    if( aGbrItem->m_Shape == GBR_ARC )
    if( aGbrItem->m_Shape == GBR_ARC )
    {
    {
@@ -249,21 +254,19 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LA
        double  b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
        double  b = atan2( (double) ( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
                           (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
                           (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );


        shape       = ARC_SHAPE;
        isArc       = true;
        angle       = KiROUND( RAD2DECIDEG(a - b) );
        angle       = RAD2DEG(b - a);
        seg_start   = aGbrItem->m_ArcCentre;
        seg_start   = aGbrItem->m_ArcCentre;


        // Ensure arc orientation is CCW
        if( angle < 0 )
        if( angle < 0 )
        {
            angle += 360.0;
            NEGATE( angle );
            seg_end = aGbrItem->m_Start;
        }
    }
    }


    // Reverse Y axis:
    // Reverse Y axis:
    NEGATE( seg_start.y );
    NEGATE( seg_start.y );
    NEGATE( seg_end.y );
    NEGATE( seg_end.y );
    writePcbLineItem( shape, 0, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, -2, angle );
    writePcbLineItem( isArc, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, angle );
}
}




@@ -300,7 +303,20 @@ void GBR_TO_PCB_EXPORTER::export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem
    NEGATE( seg_start.y );
    NEGATE( seg_start.y );
    NEGATE( seg_end.y );
    NEGATE( seg_end.y );


    writePcbLineItem( 0, TRACK_TYPE, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, -1 );
    writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
}


void GBR_TO_PCB_EXPORTER::writeCopperLineItem( wxPoint& aStart, wxPoint& aEnd,
                                               int aWidth, LAYER_NUM aLayer )
{
  fprintf( m_fp, "(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
                  Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
                  Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
                  Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
                  Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
                  Double2Str( TO_PCB_UNIT( aWidth ) ).c_str(),
                  TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) );
}
}




@@ -316,7 +332,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem,


    /* Because Pcbnew does not know arcs in tracks,
    /* Because Pcbnew does not know arcs in tracks,
     * approximate arc by segments (SEG_COUNT__CIRCLE segment per 360 deg)
     * approximate arc by segments (SEG_COUNT__CIRCLE segment per 360 deg)
     * The arc is drawn in an anticlockwise direction from the start point to the end point.
     * The arc is drawn anticlockwise from the start point to the end point.
     */
     */
    #define SEG_COUNT_CIRCLE    16
    #define SEG_COUNT_CIRCLE    16
    #define DELTA_ANGLE         2 * M_PI / SEG_COUNT_CIRCLE
    #define DELTA_ANGLE         2 * M_PI / SEG_COUNT_CIRCLE
@@ -341,7 +357,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem,
        // Reverse Y axis:
        // Reverse Y axis:
        NEGATE( seg_start.y );
        NEGATE( seg_start.y );
        NEGATE( seg_end.y );
        NEGATE( seg_end.y );
        writePcbLineItem( 0, TRACK_TYPE, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, -1 );
        writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
        curr_start = curr_end;
        curr_start = curr_end;
    }
    }


@@ -352,7 +368,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem,
        // Reverse Y axis:
        // Reverse Y axis:
        NEGATE( seg_start.y );
        NEGATE( seg_start.y );
        NEGATE( seg_end.y );
        NEGATE( seg_end.y );
        writePcbLineItem( 0, TRACK_TYPE, seg_start, seg_end, aGbrItem->m_Size.x, aLayer, -1 );
        writeCopperLineItem( seg_start, seg_end, aGbrItem->m_Size.x, aLayer );
    }
    }
}
}


@@ -373,59 +389,84 @@ void GBR_TO_PCB_EXPORTER::export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem


    m_vias_coordinates.push_back( aGbrItem->m_Start );
    m_vias_coordinates.push_back( aGbrItem->m_Start );


    wxPoint via_pos;
    wxPoint via_pos = aGbrItem->m_Start;
    int     width;
    int width   = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2;

    via_pos = aGbrItem->m_Start;
    width   = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2;
    // Reverse Y axis:
    // Reverse Y axis:
    NEGATE( via_pos.y );
    NEGATE( via_pos.y );
    // Layers are 0 to 15 (Cu/Cmp) = 0x0F
    #define IS_VIA 1
    #define SHAPE_VIA_THROUGH 3
    // XXX EVIL usage of LAYER
    writePcbLineItem( SHAPE_VIA_THROUGH, IS_VIA, via_pos, via_pos, width,
                      0x0F, -1 );
}


    // Layers are Front to Back
    fprintf( m_fp, " (via (at %s %s) (size %s)",
                  Double2Str( TO_PCB_UNIT(via_pos.x) ).c_str(),
                  Double2Str( TO_PCB_UNIT(via_pos.y) ).c_str(),
                  Double2Str( TO_PCB_UNIT( width ) ).c_str() );


void GBR_TO_PCB_EXPORTER::writePcbHeader()
    fprintf( m_fp, " (layers %s %s))\n",
                  TO_UTF8( GetPCBDefaultLayerName( F_Cu ) ),
                  TO_UTF8( GetPCBDefaultLayerName( B_Cu ) ) );
}

void GBR_TO_PCB_EXPORTER::writePcbHeader( LAYER_NUM* aLayerLookUpTable )
{
{
    fprintf( m_fp, "PCBNEW-BOARD Version 1 date %s\n\n# Created by GerbView %s\n\n",
    fprintf( m_fp, "(kicad_pcb (version 4) (host Gerbview \"%s\")\n\n",
             TO_UTF8( DateAndTime() ), TO_UTF8( GetBuildVersion() ) );
             TO_UTF8( GetBuildVersion() ) );
    fprintf( m_fp, "$GENERAL\n" );
    fprintf( m_fp, "encoding utf-8\n" );
    fprintf( m_fp, "Units deci-mils\n" );


    // Write copper layer count
    // Write layers section
    fprintf( m_fp, "LayerCount %d\n", m_pcbCopperLayersCount );
    fprintf( m_fp, "  (layers \n" );


    fprintf( m_fp, "$EndGENERAL\n\n" );
    for( int ii = 0; ii < m_pcbCopperLayersCount; ii++ )
    {
        int id = ii;


    // Creates void setup
        if( ii == m_pcbCopperLayersCount-1)
    fprintf( m_fp, "$SETUP\n" );
            id = B_Cu;
    fprintf( m_fp, "$EndSETUP\n\n" );
}


        fprintf( m_fp, "    (%d %s signal)\n", id, TO_UTF8( GetPCBDefaultLayerName( id ) ) );
    }


void GBR_TO_PCB_EXPORTER::writePcbLineItem( int aShape, int aType, wxPoint& aStart, wxPoint& aEnd,
    for( int ii = B_Adhes; ii < LAYER_ID_COUNT; ii++ )
                                            int aWidth, LAYER_NUM aLayer, int aDrill, int aAngle )
    {
    {
    if( aDrill <= -2 )
        fprintf( m_fp, "    (%d %s user)\n", ii, TO_UTF8( GetPCBDefaultLayerName( ii ) ) );
        fprintf( m_fp, "$DRAWSEGMENT\n" );
    }

    fprintf( m_fp, "Po %d %d %d %d %d %d\n", aShape,
             TO_PCB_UNIT( aStart.x ), TO_PCB_UNIT( aStart.y ),
             TO_PCB_UNIT( aEnd.x ), TO_PCB_UNIT( aEnd.y ),
             TO_PCB_UNIT( aWidth ) );
    fprintf( m_fp, "De %d %d %d %lX %X",
             aLayer, aType, aAngle, 0l, 0 );


    if( aDrill > -2 )
    fprintf( m_fp, "  )\n\n" );
        fprintf( m_fp, " %d", aDrill );
}


    fprintf( m_fp, "\n" );


    if( aDrill <= -2 )
void GBR_TO_PCB_EXPORTER::writePcbLineItem( bool aIsArc, wxPoint& aStart, wxPoint& aEnd,
        fprintf( m_fp, "$EndDRAWSEGMENT\n" );
                                            int aWidth, LAYER_NUM aLayer, double aAngle )
{
    if( aIsArc && ( aAngle == 360.0 ||  aAngle == 0 ) )
    {
        fprintf( m_fp, "(gr_circle (center %s %s) (end %s %s)(layer %s) (width %s))\n",
                 Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
                 TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
                 Double2Str( TO_PCB_UNIT( aWidth ) ).c_str()
                 );
    }
    else if( aIsArc )
    {
        fprintf( m_fp, "(gr_arc (start %s %s) (end %s %s) (angle %s)(layer %s) (width %s))\n",
                 Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
                 Double2Str( aAngle ).c_str(),
                 TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
                 Double2Str( TO_PCB_UNIT( aWidth ) ).c_str()
                 );
    }
    else
    {
        fprintf( m_fp, "(gr_line (start %s %s) (end %s %s)(layer %s) (width %s))\n",
                 Double2Str( TO_PCB_UNIT(aStart.x) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aStart.y) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aEnd.x) ).c_str(),
                 Double2Str( TO_PCB_UNIT(aEnd.y) ).c_str(),
                 TO_UTF8( GetPCBDefaultLayerName( aLayer ) ),
                 Double2Str( TO_PCB_UNIT( aWidth ) ).c_str()
                 );
    }
}
}
+4 −4
Original line number Original line Diff line number Diff line
@@ -47,7 +47,7 @@ void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )


    if( !fn.IsEmpty() )
    if( !fn.IsEmpty() )
    {
    {
        Erase_Current_Layer( false );
        Erase_Current_DrawLayer( false );
        LoadGerberFiles( fn );
        LoadGerberFiles( fn );
    }
    }
}
}
@@ -61,7 +61,7 @@ void GERBVIEW_FRAME::OnDrlFileHistory( wxCommandEvent& event )


    if( !fn.IsEmpty() )
    if( !fn.IsEmpty() )
    {
    {
        Erase_Current_Layer( false );
        Erase_Current_DrawLayer( false );
        LoadExcellonFiles( fn );
        LoadExcellonFiles( fn );
    }
    }
}
}
@@ -75,12 +75,12 @@ void GERBVIEW_FRAME::Files_io( wxCommandEvent& event )
    switch( id )
    switch( id )
    {
    {
    case wxID_FILE:
    case wxID_FILE:
        Erase_Current_Layer( false );
        Erase_Current_DrawLayer( false );
        LoadGerberFiles( wxEmptyString );
        LoadGerberFiles( wxEmptyString );
        break;
        break;


    case ID_GERBVIEW_ERASE_ALL:
    case ID_GERBVIEW_ERASE_ALL:
        Clear_Pcb( true );
        Clear_DrawLayers( true );
        Zoom_Automatique( false );
        Zoom_Automatique( false );
        m_canvas->Refresh();
        m_canvas->Refresh();
        ClearMsgPanel();
        ClearMsgPanel();
Loading