kicad/pcbnew/export_gencad.cpp

855 lines
28 KiB
C++
Raw Normal View History

/***************************************************/
/* export_gencad.cpp - export en formay GenCAD 1.4 */
/***************************************************/
#include "fctsys.h"
#include "common.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "gestfich.h"
#include "appl_wxstruct.h"
#include "pcbnew.h"
#include "trigo.h"
#include "bitmaps.h"
#include "protos.h"
#include "id.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 );
static void ModuleWriteShape( FILE* File, MODULE* module );
// layer name pour extensions fichiers de tracewxString
2007-08-23 04:28:46 +00:00
static const wxString GenCAD_Layer_Name[32] = {
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( "--" )
};
int offsetX, offsetY;
D_PAD* PadList;
/* routines de conversion des coord ( sous GenCAD axe Y vers le haut) */
2007-08-23 04:28:46 +00:00
static int mapXto( int x )
{
2007-08-23 04:28:46 +00:00
return x - offsetX;
}
2007-08-23 04:28:46 +00:00
static int mapYto( int y )
{
2007-08-23 04:28:46 +00:00
return offsetY - y;
}
/***********************************************************/
2007-08-23 04:28:46 +00:00
void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
/***********************************************************/
2007-08-23 04:28:46 +00:00
/*
2007-08-23 04:28:46 +00:00
* Exporte le board au format GenCAD 1.4
*/
{
wxFileName fn = GetScreen()->m_FileName;
wxString msg, ext, wildcard;
2007-08-23 04:28:46 +00:00
FILE* file;
ext = wxT( "gcd" );
wildcard = _( "GenCAD board files (.gcd)|*.gcd" );
fn.SetExt( ext );
2009-05-23 15:53:47 +00:00
wxFileDialog dlg( this, _( "Save GenCAD Board File" ), wxGetCwd(),
fn.GetFullName(), wildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
2007-08-23 04:28:46 +00:00
return;
if( ( file = wxFopen( dlg.GetPath(), wxT( "wt" ) ) ) == NULL )
2007-08-23 04:28:46 +00:00
{
msg = _( "Unable to create " ) + dlg.GetPath();
2007-08-23 04:28:46 +00:00
DisplayError( this, msg ); return;
}
/* Mise a jour des infos PCB: */
GetBoard()->ComputeBoundaryBox();
2007-08-23 04:28:46 +00:00
offsetX = m_Auxiliary_Axis_Position.x;
offsetY = m_Auxiliary_Axis_Position.y;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
Compile_Ratsnest( &dc, TRUE );
/* Mise des modules vus en miroir en position "normale"
* (necessaire pour decrire les formes sous GenCAD,
* qui sont decrites en vue normale, orientation 0)) */
MODULE* module;
for( module = GetBoard()->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
module->flag = 0;
if( module->GetLayer() == COPPER_LAYER_N )
2007-08-23 04:28:46 +00:00
{
GetBoard()->Change_Side_Module( module, NULL );
2007-08-23 04:28:46 +00:00
module->flag = 1;
}
}
// Creation de l'entete:
CreateHeaderInfoData( file, this );
CreateBoardSection( file, GetBoard() );
2007-08-23 04:28:46 +00:00
/* Creation liste des TRACKS
* (section $TRACK) id liste des outils de tracage de pistes */
CreateTracksInfoData( file, GetBoard() );
2007-08-23 04:28:46 +00:00
/* Creation de la liste des formes utilisees
* (formes des composants principalement */
CreatePadsShapesSection( file, GetBoard() ); // doit etre appele avant CreateShapesSection()
CreateShapesSection( file, GetBoard() );
2007-08-23 04:28:46 +00:00
/* Creation de la liste des equipotentielles: */
CreateSignalsSection( file, GetBoard() );
2007-08-23 04:28:46 +00:00
CreateDevicesSection( file, GetBoard() );
CreateComponentsSection( file, GetBoard() );
CreateRoutesSection( file, GetBoard() );
2007-08-23 04:28:46 +00:00
fclose( file );
/* Remise en place des modules vus en miroir */
for( module = GetBoard()->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
if( module->flag )
{
GetBoard()->Change_Side_Module( module, NULL );
2007-08-23 04:28:46 +00:00
module->flag = 0;
}
}
}
/**************************************************************************/
2007-08-23 04:28:46 +00:00
static int Pad_list_Sort_by_Shapes( const void* refptr, const void* objptr )
/**************************************************************************/
{
2008-01-24 21:50:12 +00:00
const D_PAD* padref = *(D_PAD**)refptr;
const D_PAD* padcmp = *(D_PAD**)objptr;
return D_PAD::Compare( padref, padcmp );
}
2007-08-23 04:28:46 +00:00
/*****************************************************/
2007-08-23 04:28:46 +00:00
void CreatePadsShapesSection( FILE* file, BOARD* pcb )
/*****************************************************/
2007-08-23 04:28:46 +00:00
/* Cree la liste des formes des pads ( 1 forme par pad )
* initialise le membre .GetSubRatsnest de la struct pad, la valeur 1 ..n
2007-08-23 04:28:46 +00:00
* pour les formes de pad PAD1 a PADn
*/
{
std::vector<D_PAD*> pads;
const char* pad_type;
2007-08-23 04:28:46 +00:00
fputs( "$PADS\n", file );
if( pcb->m_Pads.size() > 0 )
{
pads.insert( pads.end(), pcb->m_Pads.begin(), pcb->m_Pads.end() );
qsort( &pads[0], pcb->m_Pads.size(), sizeof( D_PAD* ), Pad_list_Sort_by_Shapes );
}
2007-08-23 04:28:46 +00:00
D_PAD* old_pad = NULL;
int pad_name_number = 0;
for( unsigned i=0; i<pads.size(); ++i )
2007-08-23 04:28:46 +00:00
{
D_PAD* pad = pads[i];
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 ) )
2007-08-23 04:28:46 +00:00
continue; // Forme deja generee
old_pad = pad;
pad_name_number++;
pad->SetSubRatsnest( pad_name_number );
2007-08-23 04:28:46 +00:00
fprintf( file, "PAD PAD%d", pad->GetSubRatsnest() );
2007-08-23 04:28:46 +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",
pad->m_Offset.x, -pad->m_Offset.y, pad->m_Size.x / 2 );
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",
-dx + pad->m_Offset.x, -dy - pad->m_Offset.y,
dx + pad->m_Offset.x, -pad->m_Offset.y + dy );
break;
2008-01-05 17:30:56 +00:00
case PAD_OVAL: /* description du contour par 2 linges et 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;
if( dr >= 0 ) // ovale horizontal
{
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 );
}
else // ovale vertical
{
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-08-23 04:28:46 +00:00
void CreateShapesSection( FILE* file, BOARD* pcb )
/**************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la liste des formes des composants.
2007-08-23 04:28:46 +00:00
* Comme la forme de base (module de librairie peut etre modifiee,
* une forme est creee par composant
* La forme est donnee normalisee, c'est a dire orientation 0, position 0 non miroir
* Il y aura donc des formes indentiques redondantes
*
2007-08-23 04:28:46 +00:00
* Syntaxe:
* $SHAPES
* SHAPE <shape_name>
* shape_descr (line, arc ..)
* PIN <pin_name> <pad_name> <x_y_ref> <layer> <rot> <mirror>
*
2007-08-23 04:28:46 +00:00
* SHAPE <shape_name>
* ..
* $ENDSHAPES
*/
{
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 );
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
ModuleWriteShape( file, module );
for( pad = module->m_Pads; pad != NULL; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
layer = "ALL";
if( (pad->m_Masque_Layer & ALL_CU_LAYERS) == CUIVRE_LAYER )
{
if( module->GetLayer() == CMP_N )
layer = "BOTTOM";
else
layer = "TOP";
}
else if( (pad->m_Masque_Layer & ALL_CU_LAYERS) == CMP_LAYER )
{
if( module->GetLayer() == CMP_N )
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",
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-08-23 04:28:46 +00:00
/******************************************************/
2007-08-23 04:28:46 +00:00
void CreateComponentsSection( FILE* file, BOARD* pcb )
/******************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la section $COMPONENTS (Placement des composants
2007-08-23 04:28:46 +00:00
* Composants cote CUIVRE:
* Les formes sont donnees avec l'option "FLIP", c.a.d.:
* - ils sont decrits en vue normale (comme s'ils etaient sur cote COMPOSANT)
* - leur orientation est donn<EFBFBD>e comme s'ils etaient cote composant.
2007-08-23 04:28:46 +00:00
*/
{
2007-08-23 04:28:46 +00:00
MODULE* module = pcb->m_Modules;
TEXTE_MODULE* PtTexte;
const char* mirror;
const char* flip;
2007-08-23 04:28:46 +00:00
int ii;
fputs( "$COMPONENTS\n", file );
for( ; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
int orient = module->m_Orient;
if( module->flag )
{
mirror = "MIRRORX"; // Miroir selon axe X
flip = "FLIP"; // Description normale ( formes a afficher en miroir X)
NEGATE_AND_NORMALIZE_ANGLE_POS( orient );
}
else
{
mirror = "0";
flip = "0";
}
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 ) );
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 );
/* Generation des elements textes (ref et valeur seulement) */
PtTexte = module->m_Reference;
for( ii = 0; ii < 2; ii++ )
{
int orient = PtTexte->m_Orient;
wxString layer = GenCAD_Layer_Name[SILKSCREEN_N_CMP];
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;
}
// commentaire:
fprintf( file, "SHEET Part %s %s\n", CONV_TO_UTF8( module->m_Reference->m_Text ),
CONV_TO_UTF8( module->m_Value->m_Text ) );
}
fputs( "$ENDCOMPONENTS\n\n", file );
}
2007-08-23 04:28:46 +00:00
/***************************************************/
2007-08-23 04:28:46 +00:00
void CreateSignalsSection( FILE* file, BOARD* pcb )
/***************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la liste des equipotentielles:
2007-08-23 04:28:46 +00:00
* $SIGNALS
* SIGNAL <equipot name>
* NODE <component name> <pin name>
* ...
* NODE <component name> <pin name>
* $ENDSIGNALS
*/
{
2007-08-23 04:28:46 +00:00
wxString msg;
NETINFO_ITEM* net;
2007-08-23 04:28:46 +00:00
D_PAD* pad;
MODULE* module;
int NbNoConn = 1;
fputs( "$SIGNALS\n", file );
for( unsigned ii = 0; ii < pcb->m_NetInfo->GetCount() ; ii++ )
2007-08-23 04:28:46 +00:00
{
net = pcb->m_NetInfo->GetItem(ii);
if( net->GetNetname() == wxEmptyString ) // dummy equipot (non connexion)
2007-08-23 04:28:46 +00:00
{
wxString msg; msg << wxT( "NoConnection" ) << NbNoConn++;
net->SetNetname(msg); ;
2007-08-23 04:28:46 +00:00
}
if( net->GetNet() <= 0 ) // dummy equipot (non connexion)
2007-08-23 04:28:46 +00:00
continue;
msg = wxT( "\nSIGNAL " ) + net->GetNetname();
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
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
for( pad = module->m_Pads; pad != NULL; pad = pad->Next() )
2007-08-23 04:28:46 +00:00
{
wxString padname;
if( pad->GetNet() != net->GetNet() )
2007-08-23 04:28:46 +00:00
continue;
2007-08-23 04:28:46 +00:00
pad->ReturnStringPadName( padname );
msg.Printf( wxT( "NODE %s %.4s" ),
module->m_Reference->m_Text.GetData(), padname.GetData() );
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-08-23 04:28:46 +00:00
/*************************************************************/
2007-08-23 04:28:46 +00:00
bool CreateHeaderInfoData( FILE* file, WinEDA_PcbFrame* frame )
/*************************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la section $HEADER ... $ENDHEADER
2007-08-23 04:28:46 +00:00
*/
{
2007-08-23 04:28:46 +00:00
wxString msg;
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 );
msg = wxT( "USER " ) + wxGetApp().GetAppName() + wxT( " " ) +
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 );
msg = wxT( "REVISION " ) + screen->m_Revision + wxT( " " ) + screen->m_Date;
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 );
msg.Printf( wxT( "ORIGIN %d %d" ), mapXto( frame->m_Auxiliary_Axis_Position.x ),
mapYto( frame->m_Auxiliary_Axis_Position.y ) );
fputs( CONV_TO_UTF8( msg ), file ); fputs( "\n", file );
fputs( "INTERTRACK 0\n", file );
fputs( "$ENDHEADER\n\n", file );
return TRUE;
}
/**************************************************************************/
2007-08-23 04:28:46 +00:00
static int Track_list_Sort_by_Netcode( const void* refptr, const void* objptr )
/**************************************************************************/
2007-08-23 04:28:46 +00:00
/*
2007-08-23 04:28:46 +00:00
* Routine de tri de la liste des piste par netcode,
* puis par largeur puis par layer
*/
{
2007-08-23 04:28:46 +00:00
const TRACK* ref, * cmp;
int diff;
ref = *( (TRACK**) refptr );
cmp = *( (TRACK**) objptr );
2007-10-13 06:18:44 +00:00
if( (diff = ref->GetNet() - cmp->GetNet()) )
2007-08-23 04:28:46 +00:00
return diff;
if( (diff = ref->m_Width - cmp->m_Width) )
return diff;
if( (diff = ref->GetLayer() - cmp->GetLayer()) )
return diff;
return 0;
}
2007-08-23 04:28:46 +00:00
/*************************************************/
2007-08-23 04:28:46 +00:00
void CreateRoutesSection( FILE* file, BOARD* pcb )
/*************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la liste des pistes, vias et zones
2007-08-23 04:28:46 +00:00
* section:
* $ROUTE
* ...
* $ENROUTE
* Les segments de piste doivent etre regroupes par nets
*/
{
2007-08-23 04:28:46 +00:00
TRACK* track, ** tracklist;
int vianum = 1;
int old_netcode, old_width, old_layer;
int nbitems, ii;
// Calcul du nombre de segments a ecrire
nbitems = 0;
for( track = pcb->m_Track; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
nbitems++;
for( track = pcb->m_Zone; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( track->Type() == TYPE_ZONE )
2007-08-23 04:28:46 +00:00
nbitems++;
}
tracklist = (TRACK**) MyMalloc( (nbitems + 1) * sizeof(TRACK *) );
nbitems = 0;
for( track = pcb->m_Track; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
tracklist[nbitems++] = track;
for( track = pcb->m_Zone; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
if( track->Type() == TYPE_ZONE )
2007-08-23 04:28:46 +00:00
tracklist[nbitems++] = track;
}
tracklist[nbitems] = NULL;
qsort( tracklist, nbitems, sizeof(TRACK *), Track_list_Sort_by_Netcode );
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();
NETINFO_ITEM* net = pcb->FindNet( track->GetNet() );
2007-08-23 04:28:46 +00:00
wxString netname;
if( net && (net->GetNetname() != wxEmptyString) )
netname = net->GetNetname();
2007-08-23 04:28:46 +00:00
else
netname = wxT( "_noname_" );
fprintf( file, "\nROUTE %s\n", CONV_TO_UTF8( netname ) );
}
if( old_width != track->m_Width )
{
old_width = track->m_Width;
fprintf( file, "TRACK TRACK%d\n", track->m_Width );
}
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",
CONV_TO_UTF8( GenCAD_Layer_Name[track->GetLayer() & 0x1F] ) );
}
fprintf( file, "LINE %d %d %d %d\n",
mapXto( track->m_Start.x ), mapYto( track->m_Start.y ),
mapXto( track->m_End.x ), mapYto( track->m_End.y ) );
}
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 ),
g_DesignSettings.m_ViaDrill, vianum++ );
}
}
fputs( "$ENDROUTES\n\n", file );
free( tracklist );
}
/***************************************************/
2007-08-23 04:28:46 +00:00
void CreateDevicesSection( FILE* file, BOARD* pcb )
/***************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la section de description des proprietes des composants
2007-08-23 04:28:46 +00:00
* ( la forme des composants est dans la section shape )
*/
{
2007-08-23 04:28:46 +00:00
MODULE* module;
D_PAD* pad;
fputs( "$DEVICES\n", file );
for( module = pcb->m_Modules; module != NULL; module = module->Next() )
2007-08-23 04:28:46 +00:00
{
fprintf( file, "DEVICE %s\n", CONV_TO_UTF8( module->m_Reference->m_Text ) );
fprintf( file, "PART %s\n", CONV_TO_UTF8( module->m_LibRef ) );
fprintf( file, "TYPE %s\n", "UNKNOWN" );
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 );
if( pad->GetNetname() == wxEmptyString )
2007-08-23 04:28:46 +00:00
fputs( " NoConn\n", file );
else
fprintf( file, " %.4s\n", pad->m_Padname );
}
fprintf( file, "ATTRIBUTE %s\n", CONV_TO_UTF8( module->m_Value->m_Text ) );
}
fputs( "$ENDDEVICES\n\n", file );
}
/*************************************************/
2007-08-23 04:28:46 +00:00
void CreateBoardSection( FILE* file, BOARD* pcb )
/*************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la section $BOARD.
2007-08-23 04:28:46 +00:00
* On ne cree ici que le rectangle d'encadrement du Board
*/
{
2007-08-23 04:28:46 +00:00
fputs( "$BOARD\n", file );
fprintf( file, "LINE %d %d %d %d\n",
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 ) );
fprintf( file, "LINE %d %d %d %d\n",
mapXto( pcb->m_BoundaryBox.GetRight() ), mapYto( pcb->m_BoundaryBox.m_Pos.y ),
mapXto( pcb->m_BoundaryBox.GetRight() ), mapYto( pcb->m_BoundaryBox.GetBottom() ) );
fprintf( file, "LINE %d %d %d %d\n",
mapXto( pcb->m_BoundaryBox.GetRight() ), mapYto( pcb->m_BoundaryBox.GetBottom() ),
mapXto( pcb->m_BoundaryBox.m_Pos.x ), mapYto( pcb->m_BoundaryBox.GetBottom() ) );
fprintf( file, "LINE %d %d %d %d\n",
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 ) );
fputs( "$ENDBOARD\n\n", file );
}
/****************************************************/
2009-05-23 15:53:47 +00:00
void CreateTracksInfoData( FILE* file, BOARD* pcb )
/****************************************************/
2007-08-23 04:28:46 +00:00
/* Creation de la section "$TRACKS"
2007-08-23 04:28:46 +00:00
* Cette section definit les largeurs de pistes utilsees
* format:
* $TRACK
* TRACK <name> <width>
* $ENDTRACK
*
2009-05-23 15:53:47 +00:00
* on attribue ici comme nom l'epaisseur des traits precede de "TRACK": ex
2007-08-23 04:28:46 +00:00
* pour une largeur de 120 : nom = "TRACK120".
*/
{
2007-08-23 04:28:46 +00:00
TRACK* track;
2009-05-23 15:53:47 +00:00
int last_width = -1;
2007-08-23 04:28:46 +00:00
/* recherche des epaisseurs utilisees pour les traces: */
2009-05-23 15:53:47 +00:00
std::vector <int> trackinfo;
2007-08-23 04:28:46 +00:00
2009-05-23 15:53:47 +00:00
unsigned ii;
for( track = pcb->m_Track; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
2009-05-23 15:53:47 +00:00
if( last_width != track->m_Width ) // recherche d'une epaisseur deja utilisee
2007-08-23 04:28:46 +00:00
{
2009-05-23 15:53:47 +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 )
break;
2007-08-23 04:28:46 +00:00
}
2009-05-23 15:53:47 +00:00
if ( ii == trackinfo.size() ) // not found
trackinfo.push_back(track->m_Width);
last_width = track->m_Width;
}
2007-08-23 04:28:46 +00:00
}
for( track = pcb->m_Zone; track != NULL; track = track->Next() )
2007-08-23 04:28:46 +00:00
{
2009-05-23 15:53:47 +00:00
if( last_width != track->m_Width ) // recherche d'une epaisseur deja utilisee
2007-08-23 04:28:46 +00:00
{
2009-05-23 15:53:47 +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 )
break;
2007-08-23 04:28:46 +00:00
}
2009-05-23 15:53:47 +00:00
if ( ii == trackinfo.size() ) // not found
trackinfo.push_back(track->m_Width);
last_width = track->m_Width;
2007-08-23 04:28:46 +00:00
}
}
// Write data
fputs( "$TRACKS\n", file );
2009-05-23 15:53:47 +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-08-23 04:28:46 +00:00
void ModuleWriteShape( FILE* file, MODULE* module )
/***************************************************/
2007-08-23 04:28:46 +00:00
/* Sauvegarde de la forme d'un MODULE (section SHAPE)
2007-08-23 04:28:46 +00:00
* La forme est donnee "normalisee" (Orient 0, vue normale ( non miroir)
* Syntaxe:
* SHAPE <shape_name>
* shape_descr (line, arc ..):
* LINE startX startY endX endY
* ARC startX startY endX endY centreX scentreY
2008-01-05 17:30:56 +00:00
* PAD_CIRCLE centreX scentreY radius
2007-08-23 04:28:46 +00:00
*/
{
2007-08-23 04:28:46 +00:00
EDGE_MODULE* PtEdge;
EDA_BaseStruct* PtStruct;
int Yaxis_sign = -1; // Controle changement signe axe Y (selon module normal/miroir et conevtions d'axe)
/* Generation du fichier module: */
fprintf( file, "\nSHAPE %s\n", CONV_TO_UTF8( module->m_Reference->m_Text ) );
/* Attributs du module */
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" );
}
/* Generation des elements Drawing modules */
PtStruct = module->m_Drawings;
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
2007-08-23 04:28:46 +00:00
{
2007-09-01 12:00:30 +00:00
switch( PtStruct->Type() )
2007-08-23 04:28:46 +00:00
{
case TYPE_TEXTE_MODULE:
2007-08-23 04:28:46 +00:00
break;
case TYPE_EDGE_MODULE:
2007-08-23 04:28:46 +00:00
PtEdge = (EDGE_MODULE*) PtStruct;
switch( PtEdge->m_Shape )
{
case S_SEGMENT:
fprintf( file, "LINE %d %d %d %d\n",
PtEdge->m_Start0.x, Yaxis_sign * PtEdge->m_Start0.y,
PtEdge->m_End0.x, Yaxis_sign * PtEdge->m_End0.y );
break;
case S_CIRCLE:
{
int rayon = (int) hypot(
(double) (PtEdge->m_End0.x - PtEdge->m_Start0.x),
(double) (PtEdge->m_End0.y - PtEdge->m_Start0.y) );
fprintf( file, "CIRCLE %d %d %d\n",
PtEdge->m_Start0.x, Yaxis_sign * PtEdge->m_Start0.y,
rayon );
break;
}
case S_ARC: /* print ARC x,y start x,y end x,y centre */
{
int arcendx, arcendy;
arcendx = PtEdge->m_Start0.x;
arcendy = PtEdge->m_Start0.y;
RotatePoint( &arcendx, &arcendy, PtEdge->m_Angle );
fprintf( file, "ARC %d %d %d %d %d %d\n",
PtEdge->m_End0.x, Yaxis_sign * PtEdge->m_End0.y,
arcendx, Yaxis_sign * arcendy,
PtEdge->m_Start0.x, Yaxis_sign * PtEdge->m_Start0.y );
break;
}
default:
DisplayError( NULL, wxT( "Type Edge Module inconnu" ) );
break;
}
/* Fin switch type edge */
break;
default:
break;
}
/* Fin switch gestion des Items draw */
}
}