2009-11-14 22:15:22 +00:00
|
|
|
/************************************************/
|
|
|
|
/* export_gencad.cpp - export GenCAD 1.4 format */
|
|
|
|
/************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "gestfich.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "trigo.h"
|
|
|
|
|
2010-01-05 08:48:49 +00:00
|
|
|
#include "build_version.h"
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
bool CreateHeaderInfoData( FILE* file, WinEDA_PcbFrame* frame );
|
2009-05-23 15:53:47 +00:00
|
|
|
static void CreateTracksInfoData( FILE* file, BOARD* pcb );
|
2007-08-23 04:28:46 +00:00
|
|
|
static void CreateBoardSection( FILE* file, BOARD* pcb );
|
|
|
|
static void CreateComponentsSection( FILE* file, BOARD* pcb );
|
|
|
|
static void CreateDevicesSection( FILE* file, BOARD* pcb );
|
|
|
|
static void CreateRoutesSection( FILE* file, BOARD* pcb );
|
|
|
|
static void CreateSignalsSection( FILE* file, BOARD* pcb );
|
|
|
|
static void CreateShapesSection( FILE* file, BOARD* pcb );
|
|
|
|
static void CreatePadsShapesSection( FILE* file, BOARD* pcb );
|
2009-11-12 10:18:02 +00:00
|
|
|
static void CreatePadsStacksSection( FILE* file, BOARD* pcb );
|
2009-11-02 20:36:20 +00:00
|
|
|
static void FootprintWriteShape( FILE* File, MODULE* module );
|
|
|
|
|
|
|
|
// layer name for Gencad export
|
|
|
|
static const wxString GenCAD_Layer_Name[32] =
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
wxT( "BOTTOM" ), wxT( "INNER1" ), wxT( "INNER2" ),
|
|
|
|
wxT( "INNER3" ), wxT( "INNER4" ), wxT( "INNER5" ),
|
|
|
|
wxT( "INNER6" ), wxT( "INNER7" ), wxT( "INNER8" ),
|
|
|
|
wxT( "INNER9" ), wxT( "INNER10" ), wxT( "INNER11" ),
|
|
|
|
wxT( "INNER12" ), wxT( "INNER13" ), wxT( "INNER14" ),
|
|
|
|
wxT( "TOP" ), wxT( "adhecu" ), wxT( "adhecmp" ),
|
|
|
|
wxT( "SOLDERPASTE_BOTTOM" ), wxT( "SOLDERPASTE_TOP" ),
|
|
|
|
wxT( "SILKSCREEN_BOTTOM" ), wxT( "SILKSCREEN_TOP" ),
|
|
|
|
wxT( "SOLDERMASK_BOTTOM" ), wxT( "SOLDERMASK_TOP" ), wxT( "drawings" ),
|
|
|
|
wxT( "comments" ), wxT( "eco1" ), wxT( "eco2" ),
|
|
|
|
wxT( "edges" ), wxT( "--" ), wxT( "--" ),
|
|
|
|
wxT( "--" )
|
2007-08-23 04:28:46 +00:00
|
|
|
};
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
int offsetX, offsetY;
|
|
|
|
D_PAD* PadList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* 2 helper functions to calculate coordinates of modules in gencad values (
|
|
|
|
* GenCAD Y axis from bottom to top)
|
2009-11-02 20:36:20 +00:00
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
static int mapXto( int x )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
return x - offsetX;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int mapYto( int y )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
return offsetY - y;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* Creates an Export file (format GenCAD 1.4) from the current board.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn = GetScreen()->m_FileName;
|
2009-11-02 20:36:20 +00:00
|
|
|
wxString msg, ext, wildcard;
|
|
|
|
FILE* file;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
ext = wxT( "cad" );
|
|
|
|
wildcard = _( "GenCAD 1.4 board files (.cad)|*.cad" );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ext );
|
|
|
|
|
2009-05-23 15:53:47 +00:00
|
|
|
wxFileDialog dlg( this, _( "Save GenCAD Board File" ), wxGetCwd(),
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.GetFullName(), wildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( file = wxFopen( dlg.GetPath(), wxT( "wt" ) ) ) == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Unable to create " ) + dlg.GetPath();
|
2007-08-23 04:28:46 +00:00
|
|
|
DisplayError( this, msg ); return;
|
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Update some board data, to ensure a reliable gencad export: */
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->ComputeBoundaryBox();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
offsetX = m_Auxiliary_Axis_Position.x;
|
|
|
|
offsetY = m_Auxiliary_Axis_Position.y;
|
2009-12-20 19:48:58 +00:00
|
|
|
Compile_Ratsnest( NULL, TRUE );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Temporary modification of footprints that are flipped (i.e. on bottom
|
|
|
|
* layer) to convert them to non flipped footprints.
|
2009-11-02 20:36:20 +00:00
|
|
|
* This is necessary to easily export shapes to GenCAD,
|
|
|
|
* that are given as normal orientation (non flipped, rotation = 0))
|
|
|
|
* these changes will be undone later
|
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
MODULE* module;
|
2009-01-05 05:21:35 +00:00
|
|
|
for( module = GetBoard()->m_Modules; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
module->flag = 0;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( module->GetLayer() == LAYER_N_BACK )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
module->Flip( module->m_Pos );
|
2007-08-23 04:28:46 +00:00
|
|
|
module->flag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
// Create file header:
|
2007-08-23 04:28:46 +00:00
|
|
|
CreateHeaderInfoData( file, this );
|
2009-01-05 05:21:35 +00:00
|
|
|
CreateBoardSection( file, GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Create TRACKS list
|
|
|
|
* This is the section $TRACK) (track width sizes) */
|
2009-01-05 05:21:35 +00:00
|
|
|
CreateTracksInfoData( file, GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Create the shapes list
|
|
|
|
* (shapes of pads and footprints */
|
2009-11-12 10:18:02 +00:00
|
|
|
CreatePadsShapesSection( file, GetBoard() ); /* Must be called
|
2009-11-14 22:15:22 +00:00
|
|
|
* before
|
|
|
|
* CreatePadsStacksSection
|
|
|
|
* and
|
2009-11-12 10:18:02 +00:00
|
|
|
* CreateShapesSection()
|
|
|
|
*/
|
|
|
|
CreatePadsStacksSection( file, GetBoard() );
|
2009-01-05 05:21:35 +00:00
|
|
|
CreateShapesSection( file, GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
CreateDevicesSection( file, GetBoard() );
|
|
|
|
CreateComponentsSection( file, GetBoard() );
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Create the list of Nets: */
|
2009-01-05 05:21:35 +00:00
|
|
|
CreateSignalsSection( file, GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Creates the Routes section (i.e. the list of board tracks)
|
2009-01-05 05:21:35 +00:00
|
|
|
CreateRoutesSection( file, GetBoard() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fclose( file );
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Undo the footprints modifications (flipped footprints) */
|
2009-01-05 05:21:35 +00:00
|
|
|
for( module = GetBoard()->m_Modules; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( module->flag )
|
|
|
|
{
|
2009-08-06 07:11:04 +00:00
|
|
|
module->Flip( module->m_Pos );
|
2007-08-23 04:28:46 +00:00
|
|
|
module->flag = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
static int Pad_list_Sort_by_Shapes( const void* refptr, const void* objptr )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
const D_PAD* padref = *(D_PAD**) refptr;
|
|
|
|
const D_PAD* padcmp = *(D_PAD**) objptr;
|
2008-01-24 21:50:12 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
return D_PAD::Compare( padref, padcmp );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the pads shapes list ( 1 shape per pad )
|
2009-11-14 22:15:22 +00:00
|
|
|
* Uses .GetSubRatsnest member of class D_PAD, to handle the shape id (value 1
|
|
|
|
* ..n) for pads shapes PAD1 to PADn
|
2009-11-12 10:18:02 +00:00
|
|
|
*
|
2009-11-14 22:15:22 +00:00
|
|
|
* The PADS section is used to describe the shape of all the pads used on the
|
|
|
|
* printed circuit board. The PADS section must be included, even if only a
|
|
|
|
* default pad is described and used for all pads.
|
|
|
|
* The keywords used in the PADS section are:
|
2009-11-12 10:18:02 +00:00
|
|
|
* $PADS
|
|
|
|
* PAD <pad_name> <pad_type> <drill_size>
|
|
|
|
* LINE <line_ref>
|
|
|
|
* ARC <arc_ref>
|
|
|
|
* CIRCLE <circle_ref>
|
|
|
|
* RECTANGLE <rectangle_ref>
|
|
|
|
* ATTRIBUTE <attrib_ref>
|
|
|
|
* $ENDPADS
|
2009-11-14 22:15:22 +00:00
|
|
|
* $PADS and $ENDPADS mark the PADS section of the GenCAD file. Each pad
|
|
|
|
* description must start with a PAD keyword.
|
|
|
|
* The layer in which a pad lies is defined in the SHAPE section of the GenCAD
|
|
|
|
* specification.
|
|
|
|
* The pad is always placed on a shape at the pad origin, or in a pad stack at
|
|
|
|
* the pad stack origin.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreatePadsShapesSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
std::vector<D_PAD*> pads;
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
const char* pad_type;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$PADS\n", file );
|
|
|
|
|
2009-06-06 18:08:49 +00:00
|
|
|
if( pcb->GetPadsCount() > 0 )
|
2008-01-23 01:18:41 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
pads.insert( pads.end(),
|
2009-11-14 22:15:22 +00:00
|
|
|
pcb->m_NetInfo->m_PadsFullList.begin(),
|
|
|
|
pcb->m_NetInfo->m_PadsFullList.end() );
|
|
|
|
qsort( &pads[0], pcb->GetPadsCount(), sizeof( D_PAD* ),
|
|
|
|
Pad_list_Sort_by_Shapes );
|
2008-01-23 01:18:41 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
D_PAD* old_pad = NULL;
|
|
|
|
int pad_name_number = 0;
|
2009-11-14 22:15:22 +00:00
|
|
|
for( unsigned i = 0; i<pads.size(); ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
D_PAD* pad = pads[i];
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
pad->SetSubRatsnest( pad_name_number );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-01-24 21:50:12 +00:00
|
|
|
if( old_pad && 0==D_PAD::Compare( old_pad, pad ) )
|
2009-11-14 22:15:22 +00:00
|
|
|
continue; // already created
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
old_pad = pad;
|
|
|
|
|
|
|
|
pad_name_number++;
|
2008-11-18 18:13:55 +00:00
|
|
|
pad->SetSubRatsnest( pad_name_number );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
fprintf( file, "PAD PAD%d", pad->GetSubRatsnest() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
int dx = pad->m_Size.x / 2;
|
|
|
|
int dy = pad->m_Size.y / 2;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
switch( pad->m_PadShape )
|
|
|
|
{
|
|
|
|
default:
|
2008-01-05 17:30:56 +00:00
|
|
|
case PAD_CIRCLE:
|
2007-08-23 04:28:46 +00:00
|
|
|
pad_type = "ROUND";
|
|
|
|
fprintf( file, " %s %d\n", pad_type, pad->m_Drill.x );
|
|
|
|
fprintf( file, "CIRCLE %d %d %d\n",
|
2009-11-02 20:36:20 +00:00
|
|
|
pad->m_Offset.x, -pad->m_Offset.y, dx );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
2008-01-05 17:30:56 +00:00
|
|
|
case PAD_RECT:
|
2007-08-23 04:28:46 +00:00
|
|
|
pad_type = "RECTANGULAR";
|
|
|
|
fprintf( file, " %s %d\n", pad_type, pad->m_Drill.x );
|
|
|
|
fprintf( file, "RECTANGLE %d %d %d %d\n",
|
2010-10-26 11:47:16 +00:00
|
|
|
pad->m_Offset.x - dx, -pad->m_Offset.y - dy,
|
2010-10-18 10:49:09 +00:00
|
|
|
pad->m_Size.x, pad->m_Size.y );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
case PAD_OVAL: /* Create outline by 2 lines and 2 arcs */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
pad_type = "FINGER";
|
|
|
|
fprintf( file, " %s %d\n", pad_type, pad->m_Drill.x );
|
|
|
|
int dr = dx - dy;
|
2009-11-02 20:36:20 +00:00
|
|
|
if( dr >= 0 ) // Horizontal oval
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
int rayon = dy;
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
|
|
|
-dr + pad->m_Offset.x, -pad->m_Offset.y - rayon,
|
|
|
|
dr + pad->m_Offset.x, -pad->m_Offset.y - rayon );
|
|
|
|
fprintf( file, "ARC %d %d %d %d %d %d\n",
|
|
|
|
dr + pad->m_Offset.x, -pad->m_Offset.y - rayon,
|
|
|
|
dr + pad->m_Offset.x, -pad->m_Offset.y + rayon,
|
|
|
|
dr + pad->m_Offset.x, -pad->m_Offset.y );
|
|
|
|
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
|
|
|
dr + pad->m_Offset.x, -pad->m_Offset.y + rayon,
|
|
|
|
-dr + pad->m_Offset.x, -pad->m_Offset.y + rayon );
|
|
|
|
fprintf( file, "ARC %d %d %d %d %d %d\n",
|
|
|
|
-dr + pad->m_Offset.x, -pad->m_Offset.y + rayon,
|
|
|
|
-dr + pad->m_Offset.x, -pad->m_Offset.y - rayon,
|
|
|
|
-dr + pad->m_Offset.x, -pad->m_Offset.y );
|
|
|
|
}
|
2009-11-02 20:36:20 +00:00
|
|
|
else // Vertical oval
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
dr = -dr;
|
|
|
|
int rayon = dx;
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
|
|
|
-rayon + pad->m_Offset.x, -pad->m_Offset.y - dr,
|
|
|
|
-rayon + pad->m_Offset.x, -pad->m_Offset.y + dr );
|
|
|
|
fprintf( file, "ARC %d %d %d %d %d %d\n",
|
|
|
|
-rayon + pad->m_Offset.x, -pad->m_Offset.y + dr,
|
|
|
|
rayon + pad->m_Offset.x, -pad->m_Offset.y + dr,
|
|
|
|
pad->m_Offset.x, -pad->m_Offset.y + dr );
|
|
|
|
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
|
|
|
rayon + pad->m_Offset.x, -pad->m_Offset.y + dr,
|
|
|
|
rayon + pad->m_Offset.x, -pad->m_Offset.y - dr );
|
|
|
|
fprintf( file, "ARC %d %d %d %d %d %d\n",
|
|
|
|
rayon + pad->m_Offset.x, -pad->m_Offset.y - dr,
|
|
|
|
-rayon + pad->m_Offset.x, -pad->m_Offset.y - dr,
|
|
|
|
pad->m_Offset.x, -pad->m_Offset.y - dr );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-01-05 17:30:56 +00:00
|
|
|
case PAD_TRAPEZOID:
|
2007-08-23 04:28:46 +00:00
|
|
|
pad_type = "POLYGON";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDPADS\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/*The PADSTACKS section is optional, and is used to describe how a group of
|
|
|
|
* pads are
|
2009-11-12 10:18:02 +00:00
|
|
|
* arranged. The keywords used in the PADSTACKS section are:
|
|
|
|
* $PADSTACKS
|
|
|
|
* PADSTACK <pad_name> <drill_size>
|
|
|
|
* PAD <pad_name> <layer> <rot> <mirror>
|
|
|
|
* ATTRIBUTE <attrib_ref>
|
|
|
|
* $ENDPADSTACKS
|
|
|
|
* $PADSTACKS and $ENDPADSTACKS mark the PADSTACKS section of the GenCAD file.
|
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreatePadsStacksSection( FILE* file, BOARD* pcb )
|
2009-11-12 10:18:02 +00:00
|
|
|
{
|
|
|
|
fputs( "$PADSTACKS\n", file );
|
|
|
|
fputs( "$ENDPADSTACKS\n\n", file );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the footprint shape list.
|
2009-11-14 22:15:22 +00:00
|
|
|
* We must use one shape for identical footprint (i.e. come from the same
|
|
|
|
* footprint in lib)
|
2009-11-02 20:36:20 +00:00
|
|
|
* But because pads shapes and positions can be easily modified on board,
|
|
|
|
* a shape is created by footprint found.
|
2009-11-14 22:15:22 +00:00
|
|
|
* (todo : compare footprints shapes and creates only one shape for all
|
|
|
|
* footprints found having the same shape)
|
2009-11-02 20:36:20 +00:00
|
|
|
* The shape is always given in orientation 0, position 0 not flipped
|
2008-11-18 18:13:55 +00:00
|
|
|
*
|
2009-11-14 22:15:22 +00:00
|
|
|
* Syntax:
|
2007-08-23 04:28:46 +00:00
|
|
|
* $SHAPES
|
|
|
|
* SHAPE <shape_name>
|
2009-11-12 10:18:02 +00:00
|
|
|
* INSERT <string> here <string> = "TH"
|
2007-08-23 04:28:46 +00:00
|
|
|
* shape_descr (line, arc ..)
|
|
|
|
* PIN <pin_name> <pad_name> <x_y_ref> <layer> <rot> <mirror>
|
2008-11-18 18:13:55 +00:00
|
|
|
*
|
2007-08-23 04:28:46 +00:00
|
|
|
* SHAPE <shape_name>
|
|
|
|
* ..
|
|
|
|
* $ENDSHAPES
|
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateShapesSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
MODULE* module;
|
|
|
|
D_PAD* pad;
|
|
|
|
const char* layer;
|
|
|
|
int orient;
|
|
|
|
wxString pinname;
|
|
|
|
const char* mirror = "0";
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$SHAPES\n", file );
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
FootprintWriteShape( file, module );
|
2008-11-24 06:53:43 +00:00
|
|
|
for( pad = module->m_Pads; pad != NULL; pad = pad->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
layer = "ALL";
|
2009-12-21 13:05:11 +00:00
|
|
|
if( ( pad->m_Masque_Layer & ALL_CU_LAYERS ) == LAYER_BACK )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-12-07 03:46:13 +00:00
|
|
|
if( module->GetLayer() == LAYER_N_FRONT )
|
2007-08-23 04:28:46 +00:00
|
|
|
layer = "BOTTOM";
|
|
|
|
else
|
|
|
|
layer = "TOP";
|
|
|
|
}
|
2009-12-21 13:05:11 +00:00
|
|
|
else if( ( pad->m_Masque_Layer & ALL_CU_LAYERS ) == LAYER_FRONT )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-12-07 03:46:13 +00:00
|
|
|
if( module->GetLayer() == LAYER_N_FRONT )
|
2007-08-23 04:28:46 +00:00
|
|
|
layer = "TOP";
|
|
|
|
else
|
|
|
|
layer = "BOTTOM";
|
|
|
|
}
|
|
|
|
|
|
|
|
pad->ReturnStringPadName( pinname );
|
|
|
|
if( pinname.IsEmpty() )
|
|
|
|
pinname = wxT( "noname" );
|
|
|
|
|
|
|
|
orient = pad->m_Orient - module->m_Orient;
|
|
|
|
NORMALIZE_ANGLE_POS( orient );
|
|
|
|
fprintf( file, "PIN %s PAD%d %d %d %s %d %s",
|
2008-11-18 18:13:55 +00:00
|
|
|
CONV_TO_UTF8( pinname ), pad->GetSubRatsnest(),
|
2007-08-23 04:28:46 +00:00
|
|
|
pad->m_Pos0.x, -pad->m_Pos0.y,
|
|
|
|
layer, orient / 10, mirror );
|
|
|
|
if( orient % 10 )
|
|
|
|
fprintf( file, " .%d", orient % 10 );
|
|
|
|
fprintf( file, "\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDSHAPES\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the section $COMPONENTS (Footprints placement)
|
|
|
|
* When a footprint is on bottom side of the board::
|
|
|
|
* shapes are given with option "FLIP" and "MIRRORX".
|
|
|
|
* - But shapes remain given like component not mirrored and not flipped
|
2009-11-14 22:15:22 +00:00
|
|
|
* - orientation is given like if where not mirrored and not flipped.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateComponentsSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
MODULE* module = pcb->m_Modules;
|
|
|
|
TEXTE_MODULE* PtTexte;
|
2007-11-08 10:00:38 +00:00
|
|
|
const char* mirror;
|
|
|
|
const char* flip;
|
2007-08-23 04:28:46 +00:00
|
|
|
int ii;
|
|
|
|
|
|
|
|
fputs( "$COMPONENTS\n", file );
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
int orient = module->m_Orient;
|
|
|
|
if( module->flag )
|
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
mirror = "MIRRORX"; // Mirrored relative to X axis
|
2009-11-14 22:15:22 +00:00
|
|
|
flip = "FLIP"; // Normal shape description ( gencad
|
|
|
|
// viewer must show it flipped and
|
|
|
|
// mirrored)
|
2007-08-23 04:28:46 +00:00
|
|
|
NEGATE_AND_NORMALIZE_ANGLE_POS( orient );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mirror = "0";
|
|
|
|
flip = "0";
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
fprintf( file, "COMPONENT %s\n",
|
|
|
|
CONV_TO_UTF8( module->m_Reference->m_Text ) );
|
|
|
|
fprintf( file, "DEVICE %s\n",
|
|
|
|
CONV_TO_UTF8( module->m_Reference->m_Text ) );
|
|
|
|
fprintf( file, "PLACE %d %d\n", mapXto( module->m_Pos.x ),
|
|
|
|
mapYto( module->m_Pos.y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "LAYER %s\n", (module->flag) ? "BOTTOM" : "TOP" );
|
|
|
|
|
|
|
|
fprintf( file, "ROTATION %d", orient / 10 );
|
|
|
|
if( orient % 10 )
|
|
|
|
fprintf( file, ".%d", orient % 10 );
|
|
|
|
fputs( "\n", file );
|
|
|
|
|
|
|
|
fprintf( file, "SHAPE %s %s %s\n",
|
|
|
|
CONV_TO_UTF8( module->m_Reference->m_Text ), mirror, flip );
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* creates texts (ref and value) */
|
2007-08-23 04:28:46 +00:00
|
|
|
PtTexte = module->m_Reference;
|
|
|
|
for( ii = 0; ii < 2; ii++ )
|
|
|
|
{
|
|
|
|
int orient = PtTexte->m_Orient;
|
2009-12-21 17:56:25 +00:00
|
|
|
wxString layer = GenCAD_Layer_Name[SILKSCREEN_N_FRONT];
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "TEXT %d %d %d %d.%d %s %s \"%s\"",
|
|
|
|
PtTexte->m_Pos0.x, -PtTexte->m_Pos0.y,
|
|
|
|
PtTexte->m_Size.x,
|
|
|
|
orient / 10, orient % 10,
|
|
|
|
mirror,
|
|
|
|
CONV_TO_UTF8( layer ),
|
|
|
|
CONV_TO_UTF8( PtTexte->m_Text )
|
|
|
|
);
|
|
|
|
|
|
|
|
fprintf( file, " 0 0 %d %d\n",
|
|
|
|
(int) ( PtTexte->m_Size.x * PtTexte->m_Text.Len() ),
|
|
|
|
(int) PtTexte->m_Size.y );
|
|
|
|
|
|
|
|
PtTexte = module->m_Value;
|
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
//put a comment:
|
2009-11-14 22:15:22 +00:00
|
|
|
fprintf( file, "SHEET Part %s %s\n",
|
|
|
|
CONV_TO_UTF8( module->m_Reference->m_Text ),
|
|
|
|
CONV_TO_UTF8( module->m_Value->m_Text ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDCOMPONENTS\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the list of Nets:
|
2007-08-23 04:28:46 +00:00
|
|
|
* $SIGNALS
|
2009-11-14 22:15:22 +00:00
|
|
|
* SIGNAL <net name>
|
2007-08-23 04:28:46 +00:00
|
|
|
* NODE <component name> <pin name>
|
|
|
|
* ...
|
|
|
|
* NODE <component name> <pin name>
|
|
|
|
* $ENDSIGNALS
|
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateSignalsSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
wxString msg;
|
2009-05-24 18:28:36 +00:00
|
|
|
NETINFO_ITEM* net;
|
2009-11-02 20:36:20 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
MODULE* module;
|
|
|
|
int NbNoConn = 1;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$SIGNALS\n", file );
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
for( unsigned ii = 0; ii < pcb->m_NetInfo->GetCount(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-02 20:36:20 +00:00
|
|
|
net = pcb->m_NetInfo->GetNetItem( ii );
|
2009-11-14 22:15:22 +00:00
|
|
|
if( net->GetNetname() == wxEmptyString ) // dummy netlist (no
|
|
|
|
// connection)
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
wxString msg; msg << wxT( "NoConnection" ) << NbNoConn++;
|
2009-11-02 20:36:20 +00:00
|
|
|
net->SetNetname( msg );;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( net->GetNet() <= 0 ) // dummy netlist (no connection)
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
msg = wxT( "SIGNAL " ) + net->GetNetname();
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
fputs( CONV_TO_UTF8( msg ), file );
|
2008-02-03 15:22:22 +00:00
|
|
|
fputs( "\n", file );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
for( pad = module->m_Pads; pad != NULL; pad = pad->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
wxString padname;
|
2009-05-24 18:28:36 +00:00
|
|
|
if( pad->GetNet() != net->GetNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
pad->ReturnStringPadName( padname );
|
|
|
|
msg.Printf( wxT( "NODE %s %.4s" ),
|
2009-11-14 22:15:22 +00:00
|
|
|
GetChars( module->m_Reference->m_Text ),
|
|
|
|
GetChars( padname ) );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
|
|
|
fputs( CONV_TO_UTF8( msg ), file );
|
2008-02-03 15:22:22 +00:00
|
|
|
fputs( "\n", file );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDSIGNALS\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the section $HEADER ... $ENDHEADER
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
bool CreateHeaderInfoData( FILE* file, WinEDA_PcbFrame* frame )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString msg;
|
2009-11-12 10:18:02 +00:00
|
|
|
PCB_SCREEN* screen = (PCB_SCREEN*) ( frame->GetScreen() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$HEADER\n", file );
|
|
|
|
fputs( "GENCAD 1.4\n", file );
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = wxT( "USER " ) + wxGetApp().GetAppName() + wxT( " " ) +
|
2009-11-02 20:36:20 +00:00
|
|
|
GetBuildVersion();
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( CONV_TO_UTF8( msg ), file ); fputs( "\n", file );
|
|
|
|
msg = wxT( "DRAWING " ) + screen->m_FileName;
|
|
|
|
fputs( CONV_TO_UTF8( msg ), file ); fputs( "\n", file );
|
2009-11-14 22:15:22 +00:00
|
|
|
msg = wxT( "REVISION " ) + screen->m_Revision + wxT( " " ) +
|
|
|
|
screen->m_Date;
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( CONV_TO_UTF8( msg ), file ); fputs( "\n", file );
|
|
|
|
msg.Printf( wxT( "UNITS USER %d" ), PCB_INTERNAL_UNIT );
|
|
|
|
fputs( CONV_TO_UTF8( msg ), file ); fputs( "\n", file );
|
2009-11-14 22:15:22 +00:00
|
|
|
msg.Printf( wxT( "ORIGIN %d %d" ),
|
|
|
|
mapXto( frame->m_Auxiliary_Axis_Position.x ),
|
|
|
|
mapYto( frame->m_Auxiliary_Axis_Position.y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( CONV_TO_UTF8( msg ), file ); fputs( "\n", file );
|
|
|
|
fputs( "INTERTRACK 0\n", file );
|
|
|
|
fputs( "$ENDHEADER\n\n", file );
|
|
|
|
|
|
|
|
return TRUE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-02 20:36:20 +00:00
|
|
|
* Sort function used to sort tracks segments:
|
|
|
|
* items are sorted by netcode, then by width then by layer
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
static int Track_list_Sort_by_Netcode( const void* refptr, const void* objptr )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
const TRACK* ref, * cmp;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
ref = *( (TRACK**) refptr );
|
|
|
|
cmp = *( (TRACK**) objptr );
|
2009-11-02 20:36:20 +00:00
|
|
|
if( ( diff = ref->GetNet() - cmp->GetNet() ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return diff;
|
2009-11-14 22:15:22 +00:00
|
|
|
if( ( diff = ref->m_Width - cmp->m_Width ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return diff;
|
2009-11-02 20:36:20 +00:00
|
|
|
if( ( diff = ref->GetLayer() - cmp->GetLayer() ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return diff;
|
|
|
|
|
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
/* Creates the section ROUTES
|
|
|
|
* that handles tracks, vias
|
2009-11-02 20:36:20 +00:00
|
|
|
* TODO: add zones
|
2007-08-23 04:28:46 +00:00
|
|
|
* section:
|
|
|
|
* $ROUTE
|
|
|
|
* ...
|
|
|
|
* $ENROUTE
|
2009-11-02 20:36:20 +00:00
|
|
|
* Track segments must be sorted by nets
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateRoutesSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
TRACK* track, ** tracklist;
|
|
|
|
int vianum = 1;
|
|
|
|
int old_netcode, old_width, old_layer;
|
|
|
|
int nbitems, ii;
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
// Count items
|
2007-08-23 04:28:46 +00:00
|
|
|
nbitems = 0;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( track = pcb->m_Track; track != NULL; track = track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
nbitems++;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( track = pcb->m_Zone; track != NULL; track = track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->Type() == TYPE_ZONE )
|
2007-08-23 04:28:46 +00:00
|
|
|
nbitems++;
|
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
tracklist = (TRACK**) MyMalloc( (nbitems + 1) * sizeof(TRACK*) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
nbitems = 0;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( track = pcb->m_Track; track != NULL; track = track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
tracklist[nbitems++] = track;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( track = pcb->m_Zone; track != NULL; track = track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->Type() == TYPE_ZONE )
|
2007-08-23 04:28:46 +00:00
|
|
|
tracklist[nbitems++] = track;
|
|
|
|
}
|
|
|
|
|
|
|
|
tracklist[nbitems] = NULL;
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
qsort( tracklist, nbitems, sizeof(TRACK*), Track_list_Sort_by_Netcode );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$ROUTES\n", file );
|
|
|
|
|
|
|
|
old_netcode = -1; old_width = -1; old_layer = -1;
|
|
|
|
for( ii = 0; ii < nbitems; ii++ )
|
|
|
|
{
|
|
|
|
track = tracklist[ii];
|
2007-10-13 06:18:44 +00:00
|
|
|
if( old_netcode != track->GetNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
old_netcode = track->GetNet();
|
2009-05-24 18:28:36 +00:00
|
|
|
NETINFO_ITEM* net = pcb->FindNet( track->GetNet() );
|
2009-11-02 20:36:20 +00:00
|
|
|
wxString netname;
|
2009-05-24 18:28:36 +00:00
|
|
|
if( net && (net->GetNetname() != wxEmptyString) )
|
|
|
|
netname = net->GetNetname();
|
2007-08-23 04:28:46 +00:00
|
|
|
else
|
|
|
|
netname = wxT( "_noname_" );
|
2009-11-12 10:18:02 +00:00
|
|
|
fprintf( file, "ROUTE %s\n", CONV_TO_UTF8( netname ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( old_width != track->m_Width )
|
|
|
|
{
|
|
|
|
old_width = track->m_Width;
|
|
|
|
fprintf( file, "TRACK TRACK%d\n", track->m_Width );
|
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( (track->Type() == TYPE_TRACK) || (track->Type() == TYPE_ZONE) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( old_layer != track->GetLayer() )
|
|
|
|
{
|
|
|
|
old_layer = track->GetLayer();
|
|
|
|
fprintf( file, "LAYER %s\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
CONV_TO_UTF8( GenCAD_Layer_Name[track->GetLayer() &
|
|
|
|
0x1F] ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
mapXto( track->m_Start.x ), mapYto( track->m_Start.y ),
|
|
|
|
mapXto( track->m_End.x ), mapYto( track->m_End.y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->Type() == TYPE_VIA )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
fprintf( file, "VIA viapad%d %d %d ALL %d via%d\n",
|
|
|
|
track->m_Width,
|
|
|
|
mapXto( track->m_Start.x ), mapYto( track->m_Start.y ),
|
2009-10-21 19:16:25 +00:00
|
|
|
track->GetDrillValue(), vianum++ );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDROUTES\n\n", file );
|
|
|
|
|
|
|
|
free( tracklist );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
/* Creates the section $DEVICES
|
2009-11-02 20:36:20 +00:00
|
|
|
* This is a list of footprints properties
|
|
|
|
* ( Shapes are in section $SHAPE )
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateDevicesSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
MODULE* module;
|
|
|
|
D_PAD* pad;
|
|
|
|
|
|
|
|
fputs( "$DEVICES\n", file );
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
fprintf( file, "DEVICE %s\n",
|
|
|
|
CONV_TO_UTF8( module->m_Reference->m_Text ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "PART %s\n", CONV_TO_UTF8( module->m_LibRef ) );
|
|
|
|
fprintf( file, "TYPE %s\n", "UNKNOWN" );
|
2008-11-24 06:53:43 +00:00
|
|
|
for( pad = module->m_Pads; pad != NULL; pad = pad->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
fprintf( file, "PINDESCR %.4s", pad->m_Padname );
|
2008-12-14 19:45:05 +00:00
|
|
|
if( pad->GetNetname() == wxEmptyString )
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( " NoConn\n", file );
|
|
|
|
else
|
|
|
|
fprintf( file, " %.4s\n", pad->m_Padname );
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
fprintf( file, "ATTRIBUTE %s\n",
|
|
|
|
CONV_TO_UTF8( module->m_Value->m_Text ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDDEVICES\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 10:18:02 +00:00
|
|
|
/* Creates the section $BOARD.
|
2009-11-14 22:15:22 +00:00
|
|
|
* We output here only the board boundary box
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateBoardSection( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( "$BOARD\n", file );
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
mapXto( pcb->m_BoundaryBox.m_Pos.x ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.m_Pos.y ),
|
|
|
|
mapXto( pcb->m_BoundaryBox.GetRight() ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.m_Pos.y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
mapXto( pcb->m_BoundaryBox.GetRight() ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.m_Pos.y ),
|
|
|
|
mapXto( pcb->m_BoundaryBox.GetRight() ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.GetBottom() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
mapXto( pcb->m_BoundaryBox.GetRight() ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.GetBottom() ),
|
|
|
|
mapXto( pcb->m_BoundaryBox.m_Pos.x ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.GetBottom() ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
2009-11-14 22:15:22 +00:00
|
|
|
mapXto( pcb->m_BoundaryBox.m_Pos.x ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.GetBottom() ),
|
|
|
|
mapXto( pcb->m_BoundaryBox.m_Pos.x ),
|
|
|
|
mapYto( pcb->m_BoundaryBox.m_Pos.y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
fputs( "$ENDBOARD\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the section "$TRACKS"
|
|
|
|
* This sections give the list of widths (tools) used in tracks and vias
|
2007-08-23 04:28:46 +00:00
|
|
|
* format:
|
|
|
|
* $TRACK
|
|
|
|
* TRACK <name> <width>
|
|
|
|
* $ENDTRACK
|
2008-11-18 18:13:55 +00:00
|
|
|
*
|
2009-11-02 20:36:20 +00:00
|
|
|
* Each tool name is build like this: "TRACK" + track width.
|
|
|
|
* For instance for a width = 120 : name = "TRACK120".
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void CreateTracksInfoData( FILE* file, BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
TRACK* track;
|
2009-11-02 20:36:20 +00:00
|
|
|
int last_width = -1;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Find thickness used for traces. */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-23 15:53:47 +00:00
|
|
|
std::vector <int> trackinfo;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
unsigned ii;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( track = pcb->m_Track; track != NULL; track = track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( last_width != track->m_Width ) // Find a thickness already used.
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
for( ii = 0; ii < trackinfo.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-23 15:53:47 +00:00
|
|
|
if( trackinfo[ii] == track->m_Width )
|
2009-11-02 20:36:20 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
if( ii == trackinfo.size() ) // not found
|
|
|
|
trackinfo.push_back( track->m_Width );
|
2009-05-23 15:53:47 +00:00
|
|
|
|
|
|
|
last_width = track->m_Width;
|
2009-11-02 20:36:20 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( track = pcb->m_Zone; track != NULL; track = track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( last_width != track->m_Width ) // Find a thickness already used.
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
for( ii = 0; ii < trackinfo.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-23 15:53:47 +00:00
|
|
|
if( trackinfo[ii] == track->m_Width )
|
2009-11-02 20:36:20 +00:00
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
if( ii == trackinfo.size() ) // not found
|
|
|
|
trackinfo.push_back( track->m_Width );
|
2009-05-23 15:53:47 +00:00
|
|
|
|
|
|
|
last_width = track->m_Width;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write data
|
|
|
|
fputs( "$TRACKS\n", file );
|
2009-11-14 22:15:22 +00:00
|
|
|
for( ii = 0; ii < trackinfo.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-23 15:53:47 +00:00
|
|
|
fprintf( file, "TRACK TRACK%d %d\n", trackinfo[ii], trackinfo[ii] );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs( "$ENDTRACKS\n\n", file );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* Creates the shape of a footprint (section SHAPE)
|
|
|
|
* The shape is always given "normal" (Orient 0, not mirrored)
|
|
|
|
* Syntax:
|
2007-08-23 04:28:46 +00:00
|
|
|
* SHAPE <shape_name>
|
2009-11-12 10:18:02 +00:00
|
|
|
* INSERT <string> here <string> = "TH"
|
2007-08-23 04:28:46 +00:00
|
|
|
* shape_descr (line, arc ..):
|
|
|
|
* LINE startX startY endX endY
|
2009-11-02 20:36:20 +00:00
|
|
|
* ARC startX startY endX endY centreX centreY
|
2008-01-05 17:30:56 +00:00
|
|
|
* PAD_CIRCLE centreX scentreY radius
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void FootprintWriteShape( FILE* file, MODULE* module )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDGE_MODULE* edge;
|
|
|
|
EDA_ITEM* item;
|
|
|
|
int y_axis_sign = -1; // Control Y axis change sign (as normal
|
|
|
|
// module / mirror axis and conventions)
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* creates header: */
|
2009-11-12 10:18:02 +00:00
|
|
|
fprintf( file, "SHAPE %s\n", CONV_TO_UTF8( module->m_Reference->m_Text ) );
|
2009-11-14 22:15:22 +00:00
|
|
|
fprintf( file, "INSERT %s\n",
|
|
|
|
(module->m_Attributs & MOD_CMS) ? "SMD" : "TH" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* creates Attributes */
|
2007-08-23 04:28:46 +00:00
|
|
|
if( module->m_Attributs != MOD_DEFAULT )
|
|
|
|
{
|
|
|
|
fprintf( file, "ATTRIBUTE" );
|
|
|
|
if( module->m_Attributs & MOD_CMS )
|
2008-01-05 17:30:56 +00:00
|
|
|
fprintf( file, " PAD_SMD" );
|
2007-08-23 04:28:46 +00:00
|
|
|
if( module->m_Attributs & MOD_VIRTUAL )
|
|
|
|
fprintf( file, " VIRTUAL" );
|
|
|
|
fprintf( file, "\n" );
|
|
|
|
}
|
|
|
|
|
2009-11-02 20:36:20 +00:00
|
|
|
/* creates Drawing */
|
2010-10-25 07:43:50 +00:00
|
|
|
item = module->m_Drawings;
|
|
|
|
for( ; item != NULL; item = item->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2010-10-25 07:43:50 +00:00
|
|
|
switch( item->Type() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE_MODULE:
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_EDGE_MODULE:
|
2010-10-25 07:43:50 +00:00
|
|
|
edge = (EDGE_MODULE*) item;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2010-10-25 07:43:50 +00:00
|
|
|
switch( edge->m_Shape )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
fprintf( file, "LINE %d %d %d %d\n",
|
2010-10-25 07:43:50 +00:00
|
|
|
edge->m_Start0.x, y_axis_sign * edge->m_Start0.y,
|
|
|
|
edge->m_End0.x, y_axis_sign * edge->m_End0.y );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
|
|
|
int rayon = (int) hypot(
|
2010-10-25 07:43:50 +00:00
|
|
|
(double) ( edge->m_End0.x - edge->m_Start0.x ),
|
|
|
|
(double) ( edge->m_End0.y - edge->m_Start0.y ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "CIRCLE %d %d %d\n",
|
2010-10-25 07:43:50 +00:00
|
|
|
edge->m_Start0.x, y_axis_sign * edge->m_Start0.y,
|
2007-08-23 04:28:46 +00:00
|
|
|
rayon );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
case S_ARC: /* print ARC x,y start x,y end x,y center */
|
2010-10-25 07:43:50 +00:00
|
|
|
{ // Arcs are defined counter clockwise (positive trigonometric)
|
|
|
|
// from the start point to the end point (0 to 360 degrees)
|
|
|
|
wxPoint arcStart, arcEnd;
|
|
|
|
// edge->m_Start0 is the arc center relative to the shape position
|
|
|
|
// edge->m_End0 is the arc start point relative to the shape position
|
|
|
|
arcStart = edge->m_End0;
|
|
|
|
// calculate arcEnd arc end point relative to the shape position, in pcbnew coordinates
|
|
|
|
arcEnd = arcStart;
|
|
|
|
RotatePoint( &arcEnd, edge->m_Start0, -edge->m_Angle );
|
|
|
|
// due to difference between pcbnew and gencad, swap arc start and arc end
|
|
|
|
EXCHG(arcEnd, arcStart);
|
|
|
|
// print arc shape:
|
2007-08-23 04:28:46 +00:00
|
|
|
fprintf( file, "ARC %d %d %d %d %d %d\n",
|
2010-10-25 07:43:50 +00:00
|
|
|
arcStart.x, y_axis_sign * arcStart.y, // Start point
|
|
|
|
arcEnd.x, y_axis_sign * arcEnd.y, // End point
|
|
|
|
edge->m_Start0.x, y_axis_sign * edge->m_Start0.y );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2009-11-14 22:15:22 +00:00
|
|
|
DisplayError( NULL, wxT( "Type Edge Module invalid." ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
2009-11-02 20:36:20 +00:00
|
|
|
} /* end switch PtEdge->m_Shape */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-11-02 20:36:20 +00:00
|
|
|
} /* End switch Items type */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|