2007-08-23 04:28:46 +00:00
|
|
|
|
/*************************************/
|
|
|
|
|
/* fichier gen_modules_placefile.cpp */
|
|
|
|
|
/*************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2007-08-23 04:28:46 +00:00
|
|
|
|
* 1 - create ascii files for automatic placement of smd components
|
|
|
|
|
* 2 - create a module report (pos and module descr) (ascii file)
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "confirm.h"
|
|
|
|
|
#include "kicad_string.h"
|
|
|
|
|
#include "gestfich.h"
|
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"
|
2009-04-05 20:49:15 +00:00
|
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
class LIST_MOD /* Permet de lister les elements utiles des modules */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2007-08-23 04:28:46 +00:00
|
|
|
|
MODULE* m_Module;
|
|
|
|
|
const wxChar* m_Reference;
|
|
|
|
|
const wxChar* m_Value;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* variables locale : */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
static wxPoint File_Place_Offset; /* Offset des coord de placement pour le fichier g<>n<EFBFBD>r<EFBFBD> */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
/* Routines Locales */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
static void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
/* Routine de tri utilisee par GenereModulesPosition() */
|
2008-10-01 23:35:31 +00:00
|
|
|
|
static int ListeModCmp( const void* o1, const void* o2 )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2008-10-01 23:35:31 +00:00
|
|
|
|
LIST_MOD* ref = (LIST_MOD*) o1;
|
|
|
|
|
LIST_MOD* cmp = (LIST_MOD*) o2;
|
|
|
|
|
|
|
|
|
|
return StrLenNumCmp( ref->m_Reference, cmp->m_Reference, 16 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-23 18:11:36 +00:00
|
|
|
|
#if defined(DEBUG)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function HasNonSMDPins
|
|
|
|
|
* returns true if the given module has any non smd pins, such as through hole
|
|
|
|
|
* and therefore cannot be placed automatically.
|
|
|
|
|
*/
|
|
|
|
|
static bool HasNonSMDPins( MODULE* aModule )
|
|
|
|
|
{
|
|
|
|
|
D_PAD* pad;
|
|
|
|
|
|
|
|
|
|
for( pad = aModule->m_Pads; pad; pad = pad->Next() )
|
|
|
|
|
{
|
|
|
|
|
if( pad->m_Attribut != PAD_SMD )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/**************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_PcbFrame::GenModulesPosition( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/**************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/* Routine de generation du fichier de positionnement des modules,
|
2007-08-23 04:28:46 +00:00
|
|
|
|
* utilis<EFBFBD> pour les machines de placement de composants
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
bool doBoardBack = false;
|
|
|
|
|
MODULE* module;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
LIST_MOD* Liste = 0;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
char line[1024];
|
|
|
|
|
char Buff[80];
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxFileName fnFront;
|
|
|
|
|
wxFileName fnBack;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
wxString frontLayerName;
|
|
|
|
|
wxString backLayerName;
|
|
|
|
|
wxString Title;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
FILE* fpFront = 0;
|
|
|
|
|
FILE* fpBack = 0;
|
2008-10-01 16:05:20 +00:00
|
|
|
|
bool switchedLocale = false;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
/* Calcul des echelles de conversion */
|
2009-03-15 21:11:12 +00:00
|
|
|
|
double conv_unit = 0.0001; /* unites = INCHES */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
// if(IF_DRILL_METRIC) conv_unit = 0.000254; /* unites = mm */
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
File_Place_Offset = m_Auxiliary_Axis_Position;
|
|
|
|
|
|
|
|
|
|
/* Calcul du nombre de modules utiles ( Attribut CMS, non VIRTUAL ) ) */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
int moduleCount = 0;
|
2008-04-23 18:11:36 +00:00
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
|
for( module = GetBoard()->m_Modules; module; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( module->m_Attributs & MOD_VIRTUAL )
|
2008-04-23 18:11:36 +00:00
|
|
|
|
{
|
2008-10-01 23:35:31 +00:00
|
|
|
|
D(printf("skipping module %s because it's virtual\n", CONV_TO_UTF8(module->GetReference()) );)
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2008-04-23 18:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( (module->m_Attributs & MOD_CMS) == 0 )
|
2008-04-23 18:11:36 +00:00
|
|
|
|
{
|
2008-10-01 23:35:31 +00:00
|
|
|
|
#if 1 && defined(DEBUG) // enable this code to fix a bunch of mis-labeled modules:
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( !HasNonSMDPins( module ) )
|
2008-10-01 23:35:31 +00:00
|
|
|
|
{
|
|
|
|
|
// all module's pins are SMD, mark the part for pick and place
|
|
|
|
|
module->m_Attributs |= MOD_CMS;
|
|
|
|
|
}
|
2008-04-23 18:11:36 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
printf( "skipping %s because its attribute is not CMS and it has non SMD pins\n", CONV_TO_UTF8(module->GetReference()) );
|
2008-04-23 18:11:36 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
#else
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2008-04-23 18:11:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( module->GetLayer() == COPPER_LAYER_N )
|
|
|
|
|
doBoardBack = true;
|
|
|
|
|
|
|
|
|
|
moduleCount++;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( moduleCount == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
DisplayError( this, _( "No Modules for Automated Placement" ), 20 );
|
|
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fnFront = GetScreen()->m_FileName;
|
2009-01-05 05:21:35 +00:00
|
|
|
|
frontLayerName = GetBoard()->GetLayerName( CMP_N );
|
2009-04-13 05:58:11 +00:00
|
|
|
|
fnFront.SetName( fnFront.GetName() + frontLayerName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fnFront.SetExt( wxT( "pos") );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fpFront = wxFopen( fnFront.GetFullPath(), wxT( "wt" ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( fpFront == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
msg = _( "Unable to create " ) + fnFront.GetFullPath();
|
2008-10-01 16:00:35 +00:00
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
goto exit;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( doBoardBack )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fnBack = GetScreen()->m_FileName;
|
2009-01-05 05:21:35 +00:00
|
|
|
|
backLayerName = GetBoard()->GetLayerName( COPPER_LAYER_N );
|
2009-04-13 05:58:11 +00:00
|
|
|
|
fnBack.SetName( fnBack.GetName() + backLayerName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fnBack.SetExt( wxT( "pos" ) );
|
|
|
|
|
|
|
|
|
|
fpBack = wxFopen( fnBack.GetFullPath(), wxT( "wt" ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
|
|
|
|
if( fpBack == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
msg = _( "Unable to create " ) + fnBack.GetFullPath();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
DisplayError( this, msg );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
goto exit;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
|
2008-06-06 16:39:45 +00:00
|
|
|
|
SetLocaleTo_C_standard( );
|
2008-10-01 16:05:20 +00:00
|
|
|
|
switchedLocale = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
/* Affichage du bilan : */
|
|
|
|
|
MsgPanel->EraseMsgBox();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Affiche_1_Parametre( this, 0, _( "Component side place file:" ),
|
|
|
|
|
fnFront.GetFullPath(), BLUE );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( doBoardBack )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Affiche_1_Parametre( this, 32, _( "Copper side place file:" ),
|
|
|
|
|
fnBack.GetFullPath(), BLUE );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
msg.Empty(); msg << moduleCount;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
Affiche_1_Parametre( this, 65, _( "Module count" ), msg, RED );
|
|
|
|
|
|
|
|
|
|
/* Etablissement de la liste des modules par ordre alphabetique */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
Liste = (LIST_MOD*) MyZMalloc( moduleCount * sizeof(LIST_MOD) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
|
module = GetBoard()->m_Modules;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
for( int ii = 0; module; module = module->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( module->m_Attributs & MOD_VIRTUAL )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( (module->m_Attributs & MOD_CMS) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
Liste[ii].m_Module = module;
|
|
|
|
|
Liste[ii].m_Reference = module->m_Reference->m_Text;
|
2008-10-01 23:35:31 +00:00
|
|
|
|
Liste[ii].m_Value = module->m_Value->m_Text;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
ii++;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 23:35:31 +00:00
|
|
|
|
qsort( Liste, moduleCount, sizeof(LIST_MOD), ListeModCmp );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
/* Generation entete du fichier 'commentaires) */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "### Module positions - created on %s ###\n",
|
2007-08-23 04:28:46 +00:00
|
|
|
|
DateAndTime( Buff ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, fpFront );
|
|
|
|
|
if( doBoardBack )
|
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "### Printed by PcbNew version %s\n", CONV_TO_UTF8( Title ) );
|
|
|
|
|
fputs( line, fpFront );
|
|
|
|
|
if( doBoardBack )
|
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "## Unit = inches, Angle = deg.\n" );
|
|
|
|
|
fputs( line, fpFront );
|
|
|
|
|
if( doBoardBack )
|
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "## Side : %s\n", CONV_TO_UTF8( frontLayerName ) );
|
|
|
|
|
fputs( line, fpFront );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( doBoardBack )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "## Side : %s\n", CONV_TO_UTF8( backLayerName ) );
|
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line,
|
2007-08-23 04:28:46 +00:00
|
|
|
|
"# Ref Val PosX PosY Rot Side\n" );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, fpFront );
|
|
|
|
|
if( doBoardBack )
|
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
/* Generation lignes utiles du fichier */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
for( int ii = 0; ii < moduleCount; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
|
|
|
|
wxPoint module_pos;
|
|
|
|
|
wxString ref = Liste[ii].m_Reference;
|
|
|
|
|
wxString val = Liste[ii].m_Value;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "%-8.8s %-16.16s ", CONV_TO_UTF8( ref ), CONV_TO_UTF8( val ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
module_pos = Liste[ii].m_Module->m_Pos;
|
|
|
|
|
module_pos.x -= File_Place_Offset.x;
|
|
|
|
|
module_pos.y -= File_Place_Offset.y;
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
char* text = line + strlen( line );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
sprintf( text, " %9.4f %9.4f %8.1f ",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
module_pos.x * conv_unit,
|
|
|
|
|
module_pos.y * conv_unit,
|
|
|
|
|
double(Liste[ii].m_Module->m_Orient) / 10 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 23:35:31 +00:00
|
|
|
|
int layer = Liste[ii].m_Module->GetLayer();
|
|
|
|
|
|
|
|
|
|
wxASSERT( layer==CMP_N || layer==COPPER_LAYER_N );
|
|
|
|
|
|
|
|
|
|
if( layer == CMP_N )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
strcat( line, CONV_TO_UTF8( frontLayerName ) );
|
|
|
|
|
strcat( line, "\n" );
|
|
|
|
|
fputs( line, fpFront );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2008-10-01 23:35:31 +00:00
|
|
|
|
else if( layer == COPPER_LAYER_N )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
strcat( line, CONV_TO_UTF8( backLayerName ) );
|
|
|
|
|
strcat( line, "\n" );
|
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Generation fin du fichier */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( "## End\n", fpFront );
|
|
|
|
|
|
|
|
|
|
if( doBoardBack )
|
|
|
|
|
fputs( "## End\n", fpBack );
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
msg = frontLayerName + wxT( " File: " ) + fnFront.GetFullPath();
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
|
|
|
|
if( doBoardBack )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
msg += wxT("\n\n") + backLayerName + wxT( " File: " ) +
|
|
|
|
|
fnBack.GetFullPath();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
|
DisplayInfoMessage( this, msg );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
2008-10-01 23:35:31 +00:00
|
|
|
|
|
|
|
|
|
exit: // the only safe way out of here, no returns please.
|
|
|
|
|
|
|
|
|
|
if( Liste )
|
|
|
|
|
MyFree( Liste );
|
|
|
|
|
|
2008-10-01 16:05:20 +00:00
|
|
|
|
if( switchedLocale )
|
|
|
|
|
SetLocaleTo_Default( ); // revert to the current locale
|
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
if( fpFront )
|
|
|
|
|
fclose( fpFront );
|
|
|
|
|
|
|
|
|
|
if( fpBack )
|
|
|
|
|
fclose( fpBack );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_PcbFrame::GenModuleReport( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/**************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/* Print a module report.
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-03-15 21:11:12 +00:00
|
|
|
|
double conv_unit;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
MODULE* Module;
|
|
|
|
|
D_PAD* pad;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
char line[1024], Buff[80];
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxFileName fn;
|
|
|
|
|
wxString fnFront, msg;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
FILE* rptfile;
|
|
|
|
|
wxPoint module_pos;
|
|
|
|
|
|
|
|
|
|
/* Calcul des echelles de conversion */
|
|
|
|
|
conv_unit = 0.0001; /* unites = INCHES */
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
// if(IF_DRILL_METRIC) conv_unit = 0.000254; /* unites = mm */
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
File_Place_Offset = wxPoint( 0, 0 );
|
|
|
|
|
|
|
|
|
|
/* Init nom fichier */
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fn = GetScreen()->m_FileName;
|
|
|
|
|
fn.SetExt( wxT( "rpt" ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
rptfile = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( rptfile == NULL )
|
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
msg = _( "Unable to create " ) + fn.GetFullPath();
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
|
2008-06-06 16:39:45 +00:00
|
|
|
|
SetLocaleTo_C_standard( );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
/* Generation entete du fichier 'commentaires) */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "## Module report - date %s\n", DateAndTime( Buff ) );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxString Title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "## Created by PcbNew version %s\n", CONV_TO_UTF8( Title ) );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
fputs( "## Unit = inches, Angle = deg.\n", rptfile );
|
|
|
|
|
|
|
|
|
|
/* Generation lignes utiles du fichier */
|
|
|
|
|
fputs( "##\n", rptfile );
|
|
|
|
|
fputs( "\n$BeginDESCRIPTION\n", rptfile );
|
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
|
GetBoard()->ComputeBoundaryBox();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
fputs( "\n$BOARD\n", rptfile );
|
|
|
|
|
fputs( "unit INCH\n", rptfile );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "upper_left_corner %9.6f %9.6f\n",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
GetBoard()->m_BoundaryBox.GetX() * conv_unit,
|
|
|
|
|
GetBoard()->m_BoundaryBox.GetY() * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "lower_right_corner %9.6f %9.6f\n",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
GetBoard()->m_BoundaryBox.GetRight() * conv_unit,
|
|
|
|
|
GetBoard()->m_BoundaryBox.GetBottom() * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
fputs( "$EndBOARD\n\n", rptfile );
|
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
|
|
|
|
{
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "$MODULE \"%s\"\n", CONV_TO_UTF8( Module->m_Reference->m_Text ) );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "reference \"%s\"\n", CONV_TO_UTF8( Module->m_Reference->m_Text ) );
|
|
|
|
|
fputs( line, rptfile );
|
|
|
|
|
sprintf( line, "value \"%s\"\n", CONV_TO_UTF8( Module->m_Value->m_Text ) );
|
|
|
|
|
fputs( line, rptfile );
|
|
|
|
|
sprintf( line, "footprint \"%s\"\n", CONV_TO_UTF8( Module->m_LibRef ) );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
msg = wxT( "attribut" );
|
|
|
|
|
if( Module->m_Attributs & MOD_VIRTUAL )
|
|
|
|
|
msg += wxT( " virtual" );
|
|
|
|
|
if( Module->m_Attributs & MOD_CMS )
|
|
|
|
|
msg += wxT( " smd" );
|
|
|
|
|
if( ( Module->m_Attributs & (MOD_VIRTUAL | MOD_CMS) ) == 0 )
|
|
|
|
|
msg += wxT( " none" );
|
|
|
|
|
msg += wxT( "\n" );
|
|
|
|
|
fputs( CONV_TO_UTF8( msg ), rptfile );
|
|
|
|
|
|
|
|
|
|
module_pos = Module->m_Pos;
|
|
|
|
|
module_pos.x -= File_Place_Offset.x;
|
|
|
|
|
module_pos.y -= File_Place_Offset.y;
|
2009-03-15 21:11:12 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "position %9.6f %9.6f\n",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
module_pos.x * conv_unit,
|
|
|
|
|
module_pos.y * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-03-15 21:11:12 +00:00
|
|
|
|
sprintf( line, "orientation %.2f\n", (double) Module->m_Orient / 10 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( Module->GetLayer() == CMP_N )
|
2008-10-01 16:00:35 +00:00
|
|
|
|
strcat( line, "layer component\n" );
|
2007-10-07 18:24:15 +00:00
|
|
|
|
else if( Module->GetLayer() == COPPER_LAYER_N )
|
2008-10-01 16:00:35 +00:00
|
|
|
|
strcat( line, "layer copper\n" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
else
|
2008-10-01 16:00:35 +00:00
|
|
|
|
strcat( line, "layer other\n" );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
Module->Write_3D_Descr( rptfile );
|
|
|
|
|
|
|
|
|
|
for( pad = Module->m_Pads; pad != NULL; pad = pad->Next() )
|
|
|
|
|
{
|
|
|
|
|
fprintf( rptfile, "$PAD \"%.4s\"\n", pad->m_Padname );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "position %9.6f %9.6f\n",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
pad->m_Pos0.x * conv_unit,
|
|
|
|
|
pad->m_Pos0.y * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "size %9.6f %9.6f\n",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
pad->m_Size.x * conv_unit,
|
|
|
|
|
pad->m_Size.y * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2009-03-15 21:11:12 +00:00
|
|
|
|
sprintf( line, "drill %9.6f\n", pad->m_Drill.x * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
|
|
|
|
sprintf( line, "shape_offset %9.6f %9.6f\n",
|
2009-03-15 21:11:12 +00:00
|
|
|
|
pad->m_Offset.x * conv_unit,
|
|
|
|
|
pad->m_Offset.y * conv_unit );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-03-15 21:11:12 +00:00
|
|
|
|
sprintf( line, "orientation %.2f\n", double(pad->m_Orient - Module->m_Orient) / 10 );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
fputs( line, rptfile );
|
2007-10-31 08:34:05 +00:00
|
|
|
|
const char* shape_name[6] =
|
2008-04-17 16:25:29 +00:00
|
|
|
|
{ "??? ", "Circ", "Rect", "Oval", "trap", "spec" };
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "Shape %s\n", shape_name[pad->m_PadShape] );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
int layer = 0;
|
|
|
|
|
if( pad->m_Masque_Layer & CUIVRE_LAYER )
|
|
|
|
|
layer = 1;
|
|
|
|
|
if( pad->m_Masque_Layer & CMP_LAYER )
|
|
|
|
|
layer |= 2;
|
2007-11-08 10:00:38 +00:00
|
|
|
|
const char* layer_name[4] = { "??? ", "copper", "component", "all" };
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "Layer %s\n", layer_name[layer] );
|
|
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
fprintf( rptfile, "$EndPAD\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf( rptfile, "$EndMODULE %s\n\n",
|
|
|
|
|
(const char*) Module->m_Reference->m_Text.GetData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write board Edges */
|
|
|
|
|
EDA_BaseStruct* PtStruct;
|
2009-01-05 05:21:35 +00:00
|
|
|
|
for( PtStruct = GetBoard()->m_Drawings; PtStruct != NULL; PtStruct = PtStruct->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
|
if( PtStruct->Type() != TYPE_DRAWSEGMENT )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
if( ( (DRAWSEGMENT*) PtStruct )->GetLayer() != EDGE_N )
|
|
|
|
|
continue;
|
|
|
|
|
WriteDrawSegmentPcb( (DRAWSEGMENT*) PtStruct, rptfile );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Generation fin du fichier */
|
|
|
|
|
fputs( "$EndDESCRIPTION\n", rptfile );
|
|
|
|
|
fclose( rptfile );
|
2008-06-06 16:39:45 +00:00
|
|
|
|
SetLocaleTo_Default( ); // revert to the current locale
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*******************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-01-18 15:51:06 +00:00
|
|
|
|
/* Sortie sur rptfile d'un segment type drawing PCB:
|
2007-08-23 04:28:46 +00:00
|
|
|
|
* Les contours sont de differents type:
|
|
|
|
|
* segment
|
|
|
|
|
* cercle
|
|
|
|
|
* arc
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
|
double conv_unit, ux0, uy0, dx, dy;
|
|
|
|
|
double rayon, width;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
char line[1024];
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
/* Calcul des echelles de conversion */
|
|
|
|
|
conv_unit = 0.0001; /* unites = INCHES */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
/* coord de depart */
|
|
|
|
|
ux0 = PtDrawSegment->m_Start.x * conv_unit;
|
|
|
|
|
uy0 = PtDrawSegment->m_Start.y * conv_unit;
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
/* coord d'arrivee */
|
|
|
|
|
dx = PtDrawSegment->m_End.x * conv_unit;
|
|
|
|
|
dy = PtDrawSegment->m_End.y * conv_unit;
|
|
|
|
|
|
|
|
|
|
width = PtDrawSegment->m_Width * conv_unit;
|
|
|
|
|
|
|
|
|
|
switch( PtDrawSegment->m_Shape )
|
|
|
|
|
{
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
|
rayon = hypot( dx - ux0, dy - uy0 );
|
2009-01-18 15:51:06 +00:00
|
|
|
|
fprintf( rptfile, "$CIRCLE \n" );
|
|
|
|
|
fprintf( rptfile, "centre %.6lf %.6lf\n", ux0, uy0 );
|
|
|
|
|
fprintf( rptfile, "radius %.6lf\n", rayon );
|
|
|
|
|
fprintf( rptfile, "width %.6lf\n", width );
|
|
|
|
|
fprintf( rptfile, "$EndCIRCLE \n" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case S_ARC:
|
2008-10-01 16:00:35 +00:00
|
|
|
|
{
|
|
|
|
|
int endx = PtDrawSegment->m_End.x, endy = PtDrawSegment->m_End.y;
|
|
|
|
|
rayon = hypot( dx - ux0, dy - uy0 );
|
|
|
|
|
RotatePoint( &endx,
|
|
|
|
|
&endy,
|
|
|
|
|
PtDrawSegment->m_Start.x,
|
|
|
|
|
PtDrawSegment->m_Start.y,
|
|
|
|
|
PtDrawSegment->m_Angle );
|
|
|
|
|
|
2009-01-18 15:51:06 +00:00
|
|
|
|
fprintf( rptfile, "$ARC \n" );
|
|
|
|
|
fprintf( rptfile, "centre %.6lf %.6lf\n", ux0, uy0 );
|
|
|
|
|
fprintf( rptfile, "start %.6lf %.6lf\n", endx * conv_unit, endy * conv_unit );
|
|
|
|
|
fprintf( rptfile, "end %.6lf %.6lf\n", dx, dy );
|
|
|
|
|
fprintf( rptfile, "width %.6lf\n", width );
|
|
|
|
|
fprintf( rptfile, "$EndARC \n" );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2008-10-01 16:00:35 +00:00
|
|
|
|
sprintf( line, "$LINE \n" );
|
|
|
|
|
fputs( line, rptfile );
|
|
|
|
|
|
2009-01-18 15:51:06 +00:00
|
|
|
|
fprintf( rptfile, "start %.6lf %.6lf\n", ux0, uy0 );
|
|
|
|
|
fprintf( rptfile, "end %.6lf %.6lf\n", dx, dy );
|
|
|
|
|
fprintf( rptfile, "width %.6lf\n", width );
|
|
|
|
|
fprintf( rptfile, "$EndLINE \n" );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|