2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file export_to_pcbnew.cpp
|
2011-09-30 18:15:37 +00:00
|
|
|
* @brief Export the layers to Pcbnew.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2011-09-09 19:30:59 +00:00
|
|
|
#include "macros.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2011-04-23 19:01:41 +00:00
|
|
|
#include "trigo.h"
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "../pcbnew/class_track.h"
|
|
|
|
#include "../pcbnew/class_drawsegment.h"
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "gerbview.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2010-09-28 14:42:05 +00:00
|
|
|
#include "class_gerber_draw_item.h"
|
2011-04-26 08:30:16 +00:00
|
|
|
#include "select_layers_to_pcb.h"
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
#include "build_version.h" // BOARD_FILE_VERSION
|
2011-04-23 19:01:41 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
/* A helper class to export a Gerber set of files to Pcbnew
|
|
|
|
*/
|
|
|
|
class GBR_TO_PCB_EXPORTER
|
|
|
|
{
|
|
|
|
GERBVIEW_FRAME* m_gerbview_frame; // the maint gerber frame
|
|
|
|
FILE * m_file; // .brd file to write to
|
|
|
|
BOARD* m_pcb; // the board to populate and export
|
|
|
|
|
|
|
|
public:
|
|
|
|
GBR_TO_PCB_EXPORTER(GERBVIEW_FRAME * aFrame, FILE * aFile );
|
|
|
|
~GBR_TO_PCB_EXPORTER();
|
|
|
|
bool ExportPcb( int* LayerLookUpTable );
|
2011-04-26 08:30:16 +00:00
|
|
|
BOARD* GetBoard() { return m_pcb; }
|
2011-04-23 19:01:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool WriteSetup( ); // Write the SETUP section data file
|
|
|
|
bool WriteGeneralDescrPcb( );
|
|
|
|
void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
|
|
|
|
void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
|
|
|
|
void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
|
|
|
|
void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
|
|
|
|
void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer );
|
|
|
|
void cleanBoard();
|
|
|
|
};
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME * aFrame, FILE * aFile )
|
|
|
|
{
|
|
|
|
m_gerbview_frame = aFrame;
|
|
|
|
m_file = aFile;
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
m_pcb = new BOARD();
|
2011-04-23 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER()
|
|
|
|
{
|
|
|
|
delete m_pcb;
|
|
|
|
}
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/* Export data in Pcbnew format
|
2011-09-09 19:30:59 +00:00
|
|
|
* remember Pcbnew uses a Y reversed axis, so we must negate all Y coordinates
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-12 09:50:21 +00:00
|
|
|
void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
int layercount = 0;
|
2007-10-07 03:08:24 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
// Count the Gerber layers which are actually currently used
|
|
|
|
for( int ii = 0; ii < 32; ii++ )
|
2007-11-22 00:40:17 +00:00
|
|
|
{
|
2008-11-08 06:44:07 +00:00
|
|
|
if( g_GERBER_List[ii] != NULL )
|
2011-11-24 19:57:41 +00:00
|
|
|
layercount++;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
if( layercount == 0 )
|
2007-10-07 03:08:24 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
DisplayInfoMessage( this,
|
2011-11-08 16:37:25 +00:00
|
|
|
_( "None of the Gerber layers contain any data" ) );
|
2007-10-07 03:08:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString FullFileName, msg;
|
|
|
|
|
|
|
|
wxString PcbExt( wxT( ".brd" ) );
|
|
|
|
|
|
|
|
msg = wxT( "*" ) + PcbExt;
|
|
|
|
FullFileName = EDA_FileSelector( _( "Board file name:" ),
|
2009-11-09 14:00:22 +00:00
|
|
|
wxEmptyString,
|
|
|
|
wxEmptyString,
|
|
|
|
PcbExt,
|
|
|
|
msg,
|
2007-08-23 04:28:46 +00:00
|
|
|
this,
|
|
|
|
wxFD_SAVE,
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
if( FullFileName == wxEmptyString )
|
|
|
|
return;
|
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
/* Install a dialog frame to choose the mapping
|
2011-09-30 18:15:37 +00:00
|
|
|
* between gerber layers and Pcbnew layers
|
2011-04-26 08:30:16 +00:00
|
|
|
*/
|
|
|
|
LAYERS_MAP_DIALOG* dlg = new LAYERS_MAP_DIALOG( this );
|
|
|
|
int ok = dlg->ShowModal();
|
|
|
|
dlg->Destroy();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
if( ok != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( wxFileExists( FullFileName ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-04-26 08:30:16 +00:00
|
|
|
if( !IsOK( this, _( "Ok to change the existing file ?" ) ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-26 08:30:16 +00:00
|
|
|
|
|
|
|
FILE * file = wxFopen( FullFileName, wxT( "wt" ) );
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
if( file == NULL )
|
|
|
|
{
|
|
|
|
msg = _( "Unable to create " ) + FullFileName;
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-26 08:30:16 +00:00
|
|
|
GBR_TO_PCB_EXPORTER gbr_exporter( this, file );
|
|
|
|
gbr_exporter.ExportPcb( dlg->GetLayersLookUpTable() );
|
|
|
|
fclose( file );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
void GBR_TO_PCB_EXPORTER::cleanBoard()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2011-04-23 19:01:41 +00:00
|
|
|
// delete redundant vias
|
|
|
|
for( TRACK * track = m_pcb->m_Track; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( track->m_Shape != VIA_THROUGH )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Search and delete others vias
|
|
|
|
TRACK* next_track;
|
|
|
|
TRACK* alt_track = track->Next();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
for( ; alt_track; alt_track = next_track )
|
|
|
|
{
|
|
|
|
next_track = alt_track->Next();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
if( alt_track->m_Shape != VIA_THROUGH )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( alt_track->m_Start != track->m_Start )
|
|
|
|
continue;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
// delete track
|
|
|
|
alt_track->UnLink();
|
|
|
|
delete alt_track;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
bool GBR_TO_PCB_EXPORTER::WriteSetup( )
|
|
|
|
{
|
|
|
|
fprintf( m_file, "$SETUP\n" );
|
|
|
|
fprintf( m_file, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
fprintf( m_file, "Layers %d\n", m_pcb->GetCopperLayerCount() );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
fprintf( m_file, "$EndSETUP\n\n" );
|
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
bool GBR_TO_PCB_EXPORTER::WriteGeneralDescrPcb( )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2011-04-23 19:01:41 +00:00
|
|
|
int nbLayers;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
// Print the copper layer count
|
2011-04-23 19:01:41 +00:00
|
|
|
nbLayers = m_pcb->GetCopperLayerCount();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
if( nbLayers <= 1 ) // Minimal layers count in Pcbnew is 2
|
|
|
|
{
|
|
|
|
nbLayers = 2;
|
|
|
|
m_pcb->SetCopperLayerCount(2);
|
|
|
|
}
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
fprintf( m_file, "$GENERAL\n" );
|
|
|
|
fprintf( m_file, "encoding utf-8\n");
|
|
|
|
fprintf( m_file, "LayerCount %d\n", nbLayers );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
// Compute and print the board bounding box
|
|
|
|
EDA_RECT bbbox = m_pcb->ComputeBoundingBox();
|
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
fprintf( m_file, "Di %d %d %d %d\n",
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
bbbox.GetX(), bbbox.GetY(),
|
|
|
|
bbbox.GetRight(),
|
|
|
|
bbbox.GetBottom() );
|
2011-04-23 19:01:41 +00:00
|
|
|
|
|
|
|
fprintf( m_file, "$EndGENERAL\n\n" );
|
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 14:28:20 +00:00
|
|
|
/* Routine to save the board
|
|
|
|
* @param frame = pointer to the main frame
|
|
|
|
* @param File = FILE * pointer to an already opened file
|
2011-09-30 18:15:37 +00:00
|
|
|
* @param LayerLookUpTable = look up table: Pcbnew layer for each gerber layer
|
2007-09-04 14:28:20 +00:00
|
|
|
* @return 1 if OK, 0 if fail
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-04-23 19:01:41 +00:00
|
|
|
bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2011-04-23 19:01:41 +00:00
|
|
|
BOARD* gerberPcb = m_gerbview_frame->GetBoard();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
// create an image of gerber data
|
2010-09-28 14:42:05 +00:00
|
|
|
BOARD_ITEM* item = gerberPcb->m_Drawings;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
for( ; item; item = item->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2010-09-28 14:42:05 +00:00
|
|
|
GERBER_DRAW_ITEM* gerb_item = (GERBER_DRAW_ITEM*) item;
|
2010-09-29 09:25:48 +00:00
|
|
|
int layer = gerb_item->GetLayer();
|
2007-08-23 04:28:46 +00:00
|
|
|
int pcb_layer_number = LayerLookUpTable[layer];
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-11-22 00:40:17 +00:00
|
|
|
if( pcb_layer_number < 0 || pcb_layer_number > LAST_NO_COPPER_LAYER )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-11-08 06:44:07 +00:00
|
|
|
|
2007-11-01 05:27:31 +00:00
|
|
|
if( pcb_layer_number > LAST_COPPER_LAYER )
|
2011-04-23 19:01:41 +00:00
|
|
|
export_non_copper_item( gerb_item, pcb_layer_number );
|
|
|
|
else
|
|
|
|
export_copper_item( gerb_item, pcb_layer_number );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
cleanBoard();
|
2011-11-24 19:57:41 +00:00
|
|
|
m_pcb->SetCopperLayerCount( LayerLookUpTable[32] );
|
2008-11-08 06:44:07 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point numbers)
|
|
|
|
SetLocaleTo_C_standard();
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
// write PCB header
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
fprintf( m_file, "PCBNEW-BOARD Version %d date %s\n\n", BOARD_FILE_VERSION,
|
2011-11-08 16:37:25 +00:00
|
|
|
TO_UTF8( DateAndTime() ) );
|
2011-04-23 19:01:41 +00:00
|
|
|
WriteGeneralDescrPcb( );
|
|
|
|
WriteSetup( );
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
// write items on file
|
|
|
|
m_pcb->Save( m_file );
|
|
|
|
|
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
DRAWSEGMENT* drawitem = new DRAWSEGMENT( m_pcb, PCB_LINE_T );
|
2011-04-23 19:01:41 +00:00
|
|
|
|
|
|
|
drawitem->SetLayer( aLayer );
|
|
|
|
drawitem->m_Start = aGbrItem->m_Start;
|
|
|
|
drawitem->m_End = aGbrItem->m_End;
|
|
|
|
drawitem->m_Width = aGbrItem->m_Size.x;
|
|
|
|
|
|
|
|
if( aGbrItem->m_Shape == GBR_ARC )
|
|
|
|
{
|
|
|
|
double a = atan2( (double)( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y),
|
|
|
|
(double)( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
|
|
|
|
double b = atan2( (double)( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
|
2011-10-01 19:24:27 +00:00
|
|
|
(double)( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
|
2011-04-23 19:01:41 +00:00
|
|
|
|
|
|
|
drawitem->m_Shape = S_ARC;
|
|
|
|
drawitem->m_Angle = wxRound( (a - b) / M_PI * 1800.0 );
|
|
|
|
drawitem->m_Start = aGbrItem->m_ArcCentre;
|
2011-10-01 19:24:27 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
if( drawitem->m_Angle < 0 )
|
|
|
|
{
|
|
|
|
NEGATE( drawitem->m_Angle );
|
|
|
|
drawitem->m_End = aGbrItem->m_Start;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-09 19:30:59 +00:00
|
|
|
// Reverse Y axis:
|
|
|
|
NEGATE( drawitem->m_Start.y );
|
|
|
|
NEGATE( drawitem->m_End.y );
|
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
m_pcb->Add( drawitem );
|
|
|
|
}
|
2008-11-08 06:44:07 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
void GBR_TO_PCB_EXPORTER::export_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer )
|
|
|
|
{
|
|
|
|
switch( aGbrItem->m_Shape )
|
|
|
|
{
|
|
|
|
case GBR_SPOT_CIRCLE:
|
|
|
|
case GBR_SPOT_RECT:
|
|
|
|
case GBR_SPOT_OVAL:
|
|
|
|
// replace spots with vias when possible
|
|
|
|
export_flashed_copper_item( aGbrItem, aLayer );
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
case GBR_ARC:
|
2011-11-24 19:57:41 +00:00
|
|
|
export_segarc_copper_item( aGbrItem, aLayer );
|
2011-04-23 19:01:41 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
default:
|
|
|
|
export_segline_copper_item( aGbrItem, aLayer );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
void GBR_TO_PCB_EXPORTER::export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer )
|
|
|
|
{
|
|
|
|
TRACK * newtrack = new TRACK( m_pcb );
|
|
|
|
newtrack->SetLayer( aLayer );
|
|
|
|
newtrack->m_Start = aGbrItem->m_Start;
|
|
|
|
newtrack->m_End = aGbrItem->m_End;
|
|
|
|
newtrack->m_Width = aGbrItem->m_Size.x;
|
2011-09-09 19:30:59 +00:00
|
|
|
|
|
|
|
// Reverse Y axis:
|
|
|
|
NEGATE( newtrack->m_Start.y );
|
|
|
|
NEGATE( newtrack->m_End.y );
|
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
m_pcb->Add( newtrack );
|
|
|
|
}
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer )
|
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
#if 0 // TODO: does not work in all cases, so needs some work
|
2011-04-23 19:01:41 +00:00
|
|
|
double a = atan2( (double)( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ),
|
|
|
|
(double)( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) );
|
|
|
|
double b = atan2( (double)( aGbrItem->m_End.y - aGbrItem->m_ArcCentre.y ),
|
|
|
|
(double)( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );
|
|
|
|
|
|
|
|
int arc_angle = wxRound( ( (a - b) / M_PI * 1800.0 ) );
|
|
|
|
wxPoint start = aGbrItem->m_Start;
|
|
|
|
wxPoint end = aGbrItem->m_End;
|
|
|
|
/* Because Pcbnew does not know arcs in tracks,
|
|
|
|
* approximate arc by segments (16 segment per 360 deg)
|
|
|
|
*/
|
|
|
|
#define DELTA 3600/16
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
if( arc_angle < 0 )
|
|
|
|
{
|
|
|
|
NEGATE( arc_angle );
|
|
|
|
EXCHG( start, end );
|
|
|
|
}
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
wxPoint curr_start = start;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
for( int rot = DELTA; rot < (arc_angle - DELTA); rot += DELTA )
|
|
|
|
{
|
|
|
|
TRACK * newtrack = new TRACK( m_pcb );
|
|
|
|
newtrack->SetLayer( aLayer );
|
|
|
|
newtrack->m_Start = curr_start;
|
|
|
|
wxPoint curr_end = start;
|
|
|
|
RotatePoint( &curr_end, aGbrItem->m_ArcCentre, rot );
|
|
|
|
newtrack->m_End = curr_end;
|
|
|
|
newtrack->m_Width = aGbrItem->m_Size.x;
|
2011-09-09 19:30:59 +00:00
|
|
|
// Reverse Y axis:
|
|
|
|
NEGATE( newtrack->m_Start.y );
|
|
|
|
NEGATE( newtrack->m_End.y );
|
2011-04-23 19:01:41 +00:00
|
|
|
m_pcb->Add( newtrack );
|
|
|
|
curr_start = curr_end;
|
|
|
|
}
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2011-04-23 19:01:41 +00:00
|
|
|
if( end != curr_start )
|
|
|
|
{
|
|
|
|
TRACK * newtrack = new TRACK( m_pcb );
|
|
|
|
newtrack->SetLayer( aLayer );
|
|
|
|
newtrack->m_Start = curr_start;
|
|
|
|
newtrack->m_End = end;
|
|
|
|
newtrack->m_Width = aGbrItem->m_Size.x;
|
2011-09-09 19:30:59 +00:00
|
|
|
// Reverse Y axis:
|
|
|
|
NEGATE( newtrack->m_Start.y );
|
|
|
|
NEGATE( newtrack->m_End.y );
|
2011-04-23 19:01:41 +00:00
|
|
|
m_pcb->Add( newtrack );
|
|
|
|
}
|
2011-11-24 19:57:41 +00:00
|
|
|
#endif
|
2011-04-23 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* creates a via from a flashed gerber item.
|
|
|
|
* Flashed items are usually pads or vias, so we try to export all of them
|
|
|
|
* using vias
|
|
|
|
*/
|
|
|
|
void GBR_TO_PCB_EXPORTER::export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, int aLayer )
|
|
|
|
{
|
|
|
|
SEGVIA * newtrack = new SEGVIA( m_pcb );
|
|
|
|
|
|
|
|
newtrack->m_Shape = VIA_THROUGH;
|
|
|
|
newtrack->SetLayer( 0x0F ); // Layers are 0 to 15 (Cu/Cmp)
|
|
|
|
newtrack->SetDrillDefault();
|
|
|
|
newtrack->m_Start = newtrack->m_End = aGbrItem->m_Start;
|
|
|
|
newtrack->m_Width = (aGbrItem->m_Size.x + aGbrItem->m_Size.y) / 2;
|
2011-09-09 19:30:59 +00:00
|
|
|
// Reverse Y axis:
|
|
|
|
NEGATE( newtrack->m_Start.y );
|
|
|
|
NEGATE( newtrack->m_End.y );
|
2011-04-23 19:01:41 +00:00
|
|
|
m_pcb->Add( newtrack );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|