fix export_gencad.cpp

This commit is contained in:
Dick Hollenbeck 2014-06-30 10:03:20 -05:00
parent 516c386a51
commit e460b4a524
7 changed files with 141 additions and 153 deletions

View File

@ -1,6 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
*
@ -106,7 +107,7 @@ enum LAYER_ID
Edge_Cuts,
Margin,
F_CrtYd, // CrtYd & Body are footprint only
F_CrtYd, // CrtYd & Fab are footprint only
B_CrtYd,
F_Fab,
B_Fab,

View File

@ -323,11 +323,8 @@ bool BOARD::SetLayer( LAYER_ID aIndex, const LAYER& aLayer )
}
wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
const wxString BOARD::GetLayerName( LAYER_ID aLayer ) const
{
if( !IsPcbLayer( aLayer ) )
return wxEmptyString;
// All layer names are stored in the BOARD.
if( IsLayerEnabled( aLayer ) )
{

View File

@ -644,7 +644,7 @@ public:
* @return wxString - the layer name, which for copper layers may
* be custom, else standard.
*/
wxString GetLayerName( LAYER_ID aLayer ) const;
const wxString GetLayerName( LAYER_ID aLayer ) const;
/**
* Function SetLayerName

View File

@ -262,7 +262,9 @@ void DIALOG_COPPER_ZONE::initDialog()
m_LayerId.push_back( layer );
msg = board->GetLayerName( layer ).Trim();
msg = board->GetLayerName( layer );
msg.Trim();
EDA_COLOR_T layerColor = board->GetLayerColor( layer );

View File

@ -99,24 +99,20 @@ static const wxString GenCADLayerNameFlipped[32] =
static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
{
char tmp[60];
if( IsCopperLayer( aId ) )
{
if( aId == F_Cu )
return "TOP";
else if( aId == B_Cu )
return "BOTTON";
return "BOTTOM";
else if( aId <= 14 )
{
int len = sprintf( tmp, "INNER%d", aCuCount - aId );
return std::string( tmp, len );
return StrPrintf( "INNER%d", aCuCount - aId - 1 );
}
else
{
int len = sprintf( tmp, "LAYER%d", aId );
return std::string( tmp, len );
return StrPrintf( "LAYER%d", aId );
}
}
@ -161,73 +157,65 @@ static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
};
static const LAYER_ID gc_seq[] = {
B_Cu,
In30_Cu,
In29_Cu,
In28_Cu,
In27_Cu,
In26_Cu,
In25_Cu,
In24_Cu,
In23_Cu,
In22_Cu,
In21_Cu,
In20_Cu,
In19_Cu,
In18_Cu,
In17_Cu,
In16_Cu,
In15_Cu,
In14_Cu,
In13_Cu,
In12_Cu,
In11_Cu,
In10_Cu,
In9_Cu,
In8_Cu,
In7_Cu,
In6_Cu,
In5_Cu,
In4_Cu,
In3_Cu,
In2_Cu,
In1_Cu,
F_Cu,
};
// flipped layer name for Gencad export (to make CAM350 imports correct)
static std::string GenCADLayerNameFlipped( int aCuCount, LAYER_ID aId )
{
char tmp[60];
if( IsCopperLayer( aId ) )
if( 1<= aId && aId <= 14 )
{
if( aId == F_Cu )
return "BOTTOM";
else if( aId == B_Cu )
return "TOP";
else if( aId <= 14 )
{
int len = sprintf( tmp, "INNER%d", aId );
return std::string( tmp, len );
}
else
{
int len = sprintf( tmp, "LAYER%d", aId ); // this is probably wrong, need help.
return std::string( tmp, len );
}
return StrPrintf( "INNER%d", 14 - aId );
}
else
{
const char* txt;
// using a switch to clearly show mapping & catch out of bounds index.
switch( aId )
{
// Technicals
case F_Adhes: txt = "B.Adhes"; break;
case B_Adhes: txt = "F.Adhes"; break;
case F_Paste: txt = "SOLDERPASTE_BOTTOM"; break;
case B_Paste: txt = "SOLDERPASTE_TOP"; break;
case F_SilkS: txt = "SILKSCREEN_BOTTOM"; break;
case B_SilkS: txt = "SILKSCREEN_TOP"; break;
case F_Mask: txt = "SOLDERMASK_BOTTOM"; break;
case B_Mask: txt = "SOLDERMASK_TOP"; break;
// Users
case Dwgs_User: txt = "Dwgs.User"; break;
case Cmts_User: txt = "Cmts.User"; break;
case Eco1_User: txt = "Eco1.User"; break;
case Eco2_User: txt = "Eco2.User"; break;
case Edge_Cuts: txt = "Edge.Cuts"; break;
case Margin: txt = "Margin"; break;
// Footprint
case B_CrtYd: txt = "F_CrtYd"; break;
case F_CrtYd: txt = "B_CrtYd"; break;
case B_Fab: txt = "F_Fab"; break;
case F_Fab: txt = "B_Fab"; break;
default:
wxASSERT_MSG( 0, wxT( "aId UNEXPECTED" ) );
txt = "BAD-INDEX!"; break;
}
return txt;
}
return GenCADLayerName( aCuCount, aId );
};
#endif
static std::string fmt_mask( LSET aSet )
{
#if 0
return aSet.FmtHex();
#else
return StrPrintf( "%08x", (unsigned) ( aSet & LSET::AllCuMask() ).to_ulong() );
#endif
}
// These are the export origin (the auxiliary axis)
static int GencadOffsetX, GencadOffsetY;
@ -255,9 +243,6 @@ static double MapYTo( int aY )
/* Driver function: processing starts here */
void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
{
#if 0 // working on this 30-Jun-14, not ready yet, failed the initial testing.
wxFileName fn = GetBoard()->GetFileName();
FILE* file;
@ -347,8 +332,6 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
module->SetFlag( 0 );
}
}
#endif
}
@ -426,9 +409,11 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
// Emit vias pads
TRACK* old_via = 0;
for( unsigned i = 0; i < vias.size(); i++ )
{
VIA* via = vias[i];
if( old_via && 0 == ViaSort( &old_via, &via ) )
continue;
@ -436,7 +421,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
viastacks.push_back( via );
fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
via->GetWidth(), via->GetDrillValue(),
via->GetLayerSet().FmtHex().c_str(),
fmt_mask( via->GetLayerSet() ).c_str(),
via->GetDrillValue() / SCALE_FACTOR,
via->GetWidth() / (SCALE_FACTOR * 2) );
}
@ -557,8 +542,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
pad->GetOffset().x / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR );
}
break;
}
break;
case PAD_TRAPEZOID:
fprintf( aFile, " POLYGON %g\n",
@ -583,16 +568,16 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n",
via->GetWidth(), via->GetDrillValue(),
mask.FmtHex().c_str(),
fmt_mask( mask ).c_str(),
via->GetDrillValue() / SCALE_FACTOR );
for( LSEQ seq = mask.Seq(); seq; ++seq )
for( LSEQ seq = mask.Seq( gc_seq, DIM( gc_seq ) ); seq; ++seq )
{
LAYER_ID layer = *seq;
fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
via->GetWidth(), via->GetDrillValue(),
mask.FmtHex().c_str(),
fmt_mask( mask ).c_str(),
GenCADLayerName( cu_count, layer ).c_str()
);
}
@ -612,7 +597,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
LSET pad_set = pad->GetLayerSet() & master_layermask;
for( LSEQ seq = pad_set.Seq(); seq; ++seq )
// the special gc_seq
for( LSEQ seq = pad_set.Seq( gc_seq, DIM( gc_seq ) ); seq; ++seq )
{
LAYER_ID layer = *seq;
@ -622,6 +608,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
// Flipped padstack
fprintf( aFile, "PADSTACK PAD%dF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR );
// the normal LAYER_ID sequence is inverted from gc_seq[]
for( LSEQ seq = pad_set.Seq(); seq; ++seq )
{
LAYER_ID layer = *seq;
@ -990,7 +977,7 @@ static void CreateRoutesSection( FILE* aFile, BOARD* aPcb )
fprintf( aFile, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
via->GetWidth(), via->GetDrillValue(),
vset.FmtHex().c_str(),
fmt_mask( vset ).c_str(),
MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
via->GetDrillValue() / SCALE_FACTOR, vianum++ );
}

View File

@ -132,9 +132,6 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberextensions ),
m_useGerberExtensions ? trueStr : falseStr );
aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberextensions ),
m_useGerberExtensions ? trueStr : falseStr );
if( m_useGerberAttributes ) // save this option only if active,
// to avoid incompatibility with older Pcbnew version
aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberattributes ), trueStr );
@ -153,10 +150,12 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
m_useAuxOrigin ? trueStr : falseStr );
aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpennumber ),
m_HPGLPenNum );
// Obsolete parameter, pen speed is no more managed, because hpgl format
// is now an export format, and for this, pen speed has no meaning
// aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ),
// m_HPGLPenSpeed );
aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ),
m_HPGLPenSpeed );
aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpendiameter ),

View File

@ -105,7 +105,9 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::Init()
{
LAYER_ID layer = *seq;
wxString msg = m_Parent->GetBoard()->GetLayerName( layer ).Trim();
wxString msg = m_Parent->GetBoard()->GetLayerName( layer );
msg.Trim();
m_LayerSelectionCtrl->InsertItems( 1, &msg, ii );