2009-11-14 22:15:22 +00:00
|
|
|
/*****************************/
|
|
|
|
/* 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"
|
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
|
|
|
|
2010-01-05 08:48:49 +00:00
|
|
|
#include "build_version.h"
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
class LIST_MOD /* Can list the elements of useful 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
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
static wxPoint File_Place_Offset; /* Offset coordinates for generated file. */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
static void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
/* Sort function use by 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
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Generate the module positions, used component placement.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
|
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
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate conversion scales. */
|
2009-03-15 21:11:12 +00:00
|
|
|
double conv_unit = 0.0001; /* unites = INCHES */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// if(IF_DRILL_METRIC) conv_unit = 0.000254; /* unites = mm */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
File_Place_Offset = m_Auxiliary_Axis_Position;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculating the number of useful modules (CMS attribute, not 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
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
D( printf( "skipping module %s because it's virtual\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( module->GetReference() ) );)
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-04-23 18:11:36 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +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
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
printf( "skipping %s because its attribute is not CMS and it has non SMD pins\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( module->GetLayer() == LAYER_N_BACK )
|
2008-10-01 16:00:35 +00:00
|
|
|
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
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
DisplayError( this, _( "No modules for automated placement." ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
wxString boardFilePath = ( (wxFileName) GetScreen()->GetFileName()).GetPath();
|
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), boardFilePath );
|
|
|
|
|
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
fnFront = GetScreen()->GetFileName();
|
2011-02-27 23:25:07 +00:00
|
|
|
fnFront.SetPath( dirDialog.GetPath() );
|
2009-12-07 03:46:13 +00:00
|
|
|
frontLayerName = GetBoard()->GetLayerName( LAYER_N_FRONT );
|
2011-02-27 23:25:07 +00:00
|
|
|
fnFront.SetName( fnFront.GetName() + wxT( "_" ) + frontLayerName );
|
2009-04-05 20:49:15 +00:00
|
|
|
fnFront.SetExt( wxT( "pos") );
|
|
|
|
fpFront = wxFopen( fnFront.GetFullPath(), wxT( "wt" ) );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
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
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
fnBack = GetScreen()->GetFileName();
|
2011-02-27 23:25:07 +00:00
|
|
|
fnBack.SetPath( dirDialog.GetPath() );
|
2009-12-07 03:46:13 +00:00
|
|
|
backLayerName = GetBoard()->GetLayerName( LAYER_N_BACK );
|
2011-02-27 23:25:07 +00:00
|
|
|
fnBack.SetName( fnBack.GetName() + wxT( "_" ) + 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +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
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
// Display results
|
2011-04-12 14:19:59 +00:00
|
|
|
ClearMsgPanel();
|
|
|
|
AppendMsgPanel( _( "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 )
|
2011-04-12 14:19:59 +00:00
|
|
|
AppendMsgPanel( _( "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;
|
2011-04-12 14:19:59 +00:00
|
|
|
AppendMsgPanel( _( "Module count" ), msg, RED );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
// Sort the list of modules alphabetically
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
// Write file header
|
2011-09-07 19:41:04 +00:00
|
|
|
sprintf( line, "### Module positions - created on %s ###\n", DateAndTime( Buff ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, fpFront );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
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();
|
2011-02-28 18:36:19 +00:00
|
|
|
sprintf( line, "### Printed by PcbNew version %s\n", TO_UTF8( Title ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, fpFront );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
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 );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
if( doBoardBack )
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
sprintf( line, "## Side : %s\n", TO_UTF8( frontLayerName ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
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
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
sprintf( line, "## Side : %s\n", TO_UTF8( backLayerName ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
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 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
if( doBoardBack )
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
sprintf( line, "%-8.8s %-16.16s ", TO_UTF8( ref ), 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();
|
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
wxASSERT( layer==LAYER_N_FRONT || layer==LAYER_N_BACK );
|
2008-10-01 23:35:31 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( layer == LAYER_N_FRONT )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
strcat( line, TO_UTF8( frontLayerName ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
strcat( line, "\n" );
|
|
|
|
fputs( line, fpFront );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-12-07 03:46:13 +00:00
|
|
|
else if( layer == LAYER_N_BACK )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
strcat( line, TO_UTF8( backLayerName ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
strcat( line, "\n" );
|
|
|
|
fputs( line, fpBack );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
// Write EOF
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( "## End\n", fpFront );
|
|
|
|
|
|
|
|
if( doBoardBack )
|
|
|
|
fputs( "## End\n", fpBack );
|
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
msg = _( "Module position files created:" );
|
|
|
|
msg.Append( wxT( "\n\n" ) + frontLayerName + wxT( ":\n" ) );
|
|
|
|
msg.Append( fnFront.GetFullPath() );
|
2008-10-01 16:00:35 +00:00
|
|
|
|
|
|
|
if( doBoardBack )
|
2011-02-27 23:25:07 +00:00
|
|
|
{
|
|
|
|
msg.Append( wxT( "\n\n" ) + backLayerName + wxT( ":\n" ) );
|
|
|
|
msg.Append( fnBack.GetFullPath() );
|
|
|
|
}
|
2008-10-01 16:00:35 +00:00
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
wxMessageBox( msg, _( "Module Position File" ), wxICON_INFORMATION );
|
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 )
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default( ); // revert to the current locale
|
2008-10-01 16:05:20 +00:00
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
if( fpFront )
|
|
|
|
fclose( fpFront );
|
|
|
|
|
|
|
|
if( fpBack )
|
|
|
|
fclose( fpBack );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Print a module report.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event )
|
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;
|
|
|
|
|
|
|
|
conv_unit = 0.0001; /* unites = INCHES */
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// if(IF_DRILL_METRIC) conv_unit = 0.000254; /* unites = mm */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
File_Place_Offset = wxPoint( 0, 0 );
|
|
|
|
|
2011-02-27 23:25:07 +00:00
|
|
|
wxString boardFilePath = ( (wxFileName) GetScreen()->GetFileName()).GetPath();
|
|
|
|
wxDirDialog dirDialog( this, _( "Select Output Directory" ), boardFilePath );
|
|
|
|
|
|
|
|
if( dirDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
fn = GetScreen()->GetFileName();
|
2011-02-27 23:25:07 +00:00
|
|
|
fn.SetPath( dirDialog.GetPath() );
|
2009-04-05 20:49:15 +00:00
|
|
|
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" ) );
|
2011-02-27 23:25:07 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point
|
|
|
|
// numbers like 1.3)
|
2011-09-07 19:41:04 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Generate header file comments.) */
|
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();
|
2011-02-28 18:36:19 +00:00
|
|
|
sprintf( line, "## Created by PcbNew version %s\n", TO_UTF8( Title ) );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( "## Unit = inches, Angle = deg.\n", rptfile );
|
|
|
|
|
|
|
|
fputs( "##\n", rptfile );
|
|
|
|
fputs( "\n$BeginDESCRIPTION\n", rptfile );
|
|
|
|
|
2011-02-25 16:23:24 +00:00
|
|
|
GetBoard()->ComputeBoundingBox();
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
|
|
|
{
|
2011-03-25 20:07:27 +00:00
|
|
|
sprintf( line, "$MODULE %s\n", EscapedUTF8( Module->m_Reference->m_Text ).c_str() );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-25 20:07:27 +00:00
|
|
|
sprintf( line, "reference %s\n", EscapedUTF8( Module->m_Reference->m_Text ).c_str() );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, rptfile );
|
2011-03-25 20:07:27 +00:00
|
|
|
sprintf( line, "value %s\n", EscapedUTF8( Module->m_Value->m_Text ).c_str() );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, rptfile );
|
2011-03-25 20:07:27 +00:00
|
|
|
sprintf( line, "footprint %s\n", EscapedUTF8( Module->m_LibRef ).c_str() );
|
2008-10-01 16:00:35 +00:00
|
|
|
fputs( line, rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
msg = wxT( "attribut" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Module->m_Attributs & MOD_VIRTUAL )
|
|
|
|
msg += wxT( " virtual" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Module->m_Attributs & MOD_CMS )
|
|
|
|
msg += wxT( " smd" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( ( Module->m_Attributs & (MOD_VIRTUAL | MOD_CMS) ) == 0 )
|
|
|
|
msg += wxT( " none" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
msg += wxT( "\n" );
|
2011-02-28 18:36:19 +00:00
|
|
|
fputs( TO_UTF8( msg ), rptfile );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
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 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_FRONT )
|
2008-10-01 16:00:35 +00:00
|
|
|
strcat( line, "layer component\n" );
|
2009-12-07 03:46:13 +00:00
|
|
|
else if( Module->GetLayer() == LAYER_N_BACK )
|
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" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-10-01 16:00:35 +00:00
|
|
|
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-11-14 22:15:22 +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 );
|
2011-09-07 19:41:04 +00:00
|
|
|
const char* shape_name[6] = { "??? ", "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;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( pad->m_layerMask & LAYER_BACK )
|
2007-08-23 04:28:46 +00:00
|
|
|
layer = 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( pad->m_layerMask & LAYER_FRONT )
|
2007-08-23 04:28:46 +00:00
|
|
|
layer |= 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8(Module->m_Reference->m_Text ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write board Edges */
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* 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;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( ( (DRAWSEGMENT*) PtStruct )->GetLayer() != EDGE_N )
|
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
WriteDrawSegmentPcb( (DRAWSEGMENT*) PtStruct, rptfile );
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Generate EOF. */
|
2007-08-23 04:28:46 +00:00
|
|
|
fputs( "$EndDESCRIPTION\n", rptfile );
|
|
|
|
fclose( rptfile );
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default( ); // revert to the current locale
|
2011-02-27 23:25:07 +00:00
|
|
|
|
|
|
|
msg = _( "Module report file created:" );
|
|
|
|
msg.Append( wxT( "\n" ) + fn.GetFullPath() );
|
|
|
|
|
|
|
|
wxMessageBox( msg, _( "Module Report" ), wxICON_INFORMATION );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Output to rpt file a segment type from the PCB drawing.
|
|
|
|
* The contours are of different types:
|
|
|
|
* Segment
|
|
|
|
* Circle
|
|
|
|
* Arc
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
double conv_unit, ux0, uy0, dx, dy;
|
2011-09-07 19:41:04 +00:00
|
|
|
double radius, width;
|
2008-10-01 16:00:35 +00:00
|
|
|
char line[1024];
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
conv_unit = 0.0001; /* units = INCHES */
|
2008-10-01 16:00:35 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
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
|
|
|
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:
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = 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 );
|
2011-09-07 19:41:04 +00:00
|
|
|
fprintf( rptfile, "radius %.6lf\n", radius );
|
2009-01-18 15:51:06 +00:00
|
|
|
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;
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = hypot( dx - ux0, dy - uy0 );
|
2008-10-01 16:00:35 +00:00
|
|
|
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 );
|
2009-11-14 22:15:22 +00:00
|
|
|
fprintf( rptfile, "start %.6lf %.6lf\n",
|
|
|
|
endx * conv_unit, endy * conv_unit );
|
2009-01-18 15:51:06 +00:00
|
|
|
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
|
|
|
}
|