2009-09-10 13:04:04 +00:00
|
|
|
/* file debug_kbool_key_file_fct.cpp
|
|
|
|
*/
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-11-14 19:47:52 +00:00
|
|
|
#include "kicad_string.h"
|
2009-09-10 13:04:04 +00:00
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "wxPcbStruct.h"
|
|
|
|
#include "zones.h"
|
|
|
|
#include "PolyLine.h"
|
|
|
|
|
|
|
|
#include "debug_kbool_key_file_fct.h"
|
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
#if defined (CREATE_KBOOL_KEY_FILES) || (CREATE_KBOOL_KEY_FILES_FIRST_PASS)
|
2009-09-10 13:04:04 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
// Helper class to handle a coordinate
|
|
|
|
struct kfcoord
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
static FILE* kdebugFile;
|
2009-11-14 19:47:52 +00:00
|
|
|
static char sDate_Time[256];
|
2009-11-16 08:13:40 +00:00
|
|
|
static vector <kfcoord> s_EntityCoordinates;
|
2009-09-10 13:04:04 +00:00
|
|
|
|
|
|
|
void CreateKeyFile()
|
|
|
|
{
|
2009-11-14 19:47:52 +00:00
|
|
|
wxString datetimestr;
|
|
|
|
wxDateTime datetime = wxDateTime::Now();
|
|
|
|
datetime.SetCountry( wxDateTime::Country_Default );
|
|
|
|
datetimestr = datetime.FormatISODate( )
|
|
|
|
+ wxT(" ")
|
|
|
|
+ datetime.FormatISOTime( );
|
2011-02-28 18:36:19 +00:00
|
|
|
strcpy(sDate_Time, TO_UTF8(datetimestr) );
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2009-09-10 13:04:04 +00:00
|
|
|
kdebugFile = fopen( KEYFILE_FILENAME, "wt" );
|
|
|
|
if( kdebugFile )
|
|
|
|
{
|
|
|
|
fprintf( kdebugFile, "# KEY file for GDS-II postprocessing tool\n" );
|
|
|
|
fprintf( kdebugFile, "# File = %s\n", KEYFILE_FILENAME );
|
|
|
|
fprintf( kdebugFile, "# ====================================================================\n");
|
|
|
|
fprintf( kdebugFile, "\nHEADER 5; # version\n");
|
|
|
|
fprintf( kdebugFile, "BGNLIB;\n");
|
|
|
|
|
|
|
|
fprintf( kdebugFile, "LASTMOD {%s}; # last modification time\n",sDate_Time );
|
|
|
|
fprintf( kdebugFile, "LASTACC {%s}; # last access time\n",sDate_Time );
|
|
|
|
|
|
|
|
fprintf( kdebugFile, "LIBNAME trial;\n" );
|
2009-11-16 12:10:37 +00:00
|
|
|
fprintf( kdebugFile, "UNITS;\n# Internal pcbnew units are in 0.0001 inch\n" );
|
|
|
|
fprintf( kdebugFile, "USERUNITS 1; PHYSUNITS 1;\n\n" );
|
2009-09-10 13:04:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "CreateKeyFile() cannot create output file" ) );
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
|
|
|
s_EntityCoordinates.clear();
|
2009-09-10 13:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CloseKeyFile()
|
|
|
|
{
|
|
|
|
if( kdebugFile )
|
|
|
|
{
|
|
|
|
fprintf( kdebugFile, "\nENDLIB;\n" );
|
|
|
|
fclose( kdebugFile );
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
s_EntityCoordinates.clear();
|
2009-09-10 13:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* sCurrEntityName = NULL;
|
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
void OpenKeyFileEntity( const char* aName )
|
2009-09-10 13:04:04 +00:00
|
|
|
{
|
|
|
|
if( kdebugFile )
|
|
|
|
{
|
|
|
|
fprintf( kdebugFile, "\nBGNSTR; # Begin of structure\n" );
|
|
|
|
fprintf( kdebugFile, "CREATION {%s}; # creation time\n",sDate_Time);
|
|
|
|
fprintf( kdebugFile, "LASTMOD {%s}; # last modification time\n",sDate_Time);
|
|
|
|
fprintf( kdebugFile, "STRNAME %s;\n", aName );
|
|
|
|
}
|
|
|
|
sCurrEntityName = aName;
|
2009-11-16 08:13:40 +00:00
|
|
|
s_EntityCoordinates.clear();
|
2009-09-10 13:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
void CloseKeyFileEntity()
|
2009-09-10 13:04:04 +00:00
|
|
|
{
|
|
|
|
if( kdebugFile )
|
|
|
|
fprintf( kdebugFile, "\nENDSTR %s;\n", sCurrEntityName );
|
|
|
|
}
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
/* start a polygon entity in key file
|
|
|
|
*/
|
|
|
|
void StartKeyFilePolygon( int aLayer)
|
2009-09-10 13:04:04 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
s_EntityCoordinates.clear();
|
2009-09-10 13:04:04 +00:00
|
|
|
fprintf( kdebugFile, "\nBOUNDARY; LAYER %d; DATATYPE 0;\n", aLayer );
|
|
|
|
}
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
/* add a polygon corner to the current polygon entity in key file
|
|
|
|
*/
|
|
|
|
void AddKeyFilePointXY( int aXcoord, int aYcoord)
|
2009-09-10 13:04:04 +00:00
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
kfcoord coord;
|
|
|
|
coord.x = aXcoord;
|
|
|
|
coord.y = aYcoord;
|
|
|
|
s_EntityCoordinates.push_back( coord );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Close a polygon entity in key file
|
|
|
|
* write the entire polygon data to the file
|
|
|
|
*/
|
|
|
|
void EndKeyFilePolygon()
|
|
|
|
{
|
|
|
|
// Polygon must be closed: test for that and close it if needed
|
|
|
|
if( s_EntityCoordinates.size() )
|
|
|
|
{
|
|
|
|
if( s_EntityCoordinates.back().x != s_EntityCoordinates[0].x
|
|
|
|
|| s_EntityCoordinates.back().y != s_EntityCoordinates[0].y )
|
|
|
|
s_EntityCoordinates.push_back( s_EntityCoordinates[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( kdebugFile, " XY %d;\n", s_EntityCoordinates.size() );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < s_EntityCoordinates.size(); ii ++ )
|
|
|
|
fprintf( kdebugFile, " X %d; Y %d;\n",
|
|
|
|
s_EntityCoordinates[ii].x, s_EntityCoordinates[ii].y );
|
|
|
|
fprintf( kdebugFile, "ENDEL;\n" );
|
|
|
|
s_EntityCoordinates.clear();
|
2009-09-10 13:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CopyPolygonsFromFilledPolysListToKeyFile( ZONE_CONTAINER* aZone, int aLayer )
|
|
|
|
{
|
|
|
|
if( !kdebugFile )
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned corners_count = aZone->m_FilledPolysList.size();
|
|
|
|
unsigned ic = 0;
|
|
|
|
while( ic < corners_count )
|
|
|
|
{
|
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
// write polygon:
|
|
|
|
StartKeyFilePolygon( aLayer );
|
2009-09-10 13:04:04 +00:00
|
|
|
for( ; ic < corners_count; ic++ )
|
|
|
|
{
|
2009-11-16 08:13:40 +00:00
|
|
|
CPolyPt* corner = &aZone->m_FilledPolysList[ic];
|
2009-11-14 19:47:52 +00:00
|
|
|
AddKeyFilePointXY( corner->x, corner->y );
|
2009-09-10 13:04:04 +00:00
|
|
|
if( corner->end_contour )
|
|
|
|
{
|
|
|
|
ic++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
EndKeyFilePolygon();
|
2009-09-10 13:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|