Commit e460b4a5 authored by Dick Hollenbeck's avatar Dick Hollenbeck

fix export_gencad.cpp

parent 516c386a
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
* *
...@@ -106,7 +107,7 @@ enum LAYER_ID ...@@ -106,7 +107,7 @@ enum LAYER_ID
Edge_Cuts, Edge_Cuts,
Margin, Margin,
F_CrtYd, // CrtYd & Body are footprint only F_CrtYd, // CrtYd & Fab are footprint only
B_CrtYd, B_CrtYd,
F_Fab, F_Fab,
B_Fab, B_Fab,
......
...@@ -323,11 +323,8 @@ bool BOARD::SetLayer( LAYER_ID aIndex, const LAYER& aLayer ) ...@@ -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. // All layer names are stored in the BOARD.
if( IsLayerEnabled( aLayer ) ) if( IsLayerEnabled( aLayer ) )
{ {
......
...@@ -644,7 +644,7 @@ public: ...@@ -644,7 +644,7 @@ public:
* @return wxString - the layer name, which for copper layers may * @return wxString - the layer name, which for copper layers may
* be custom, else standard. * be custom, else standard.
*/ */
wxString GetLayerName( LAYER_ID aLayer ) const; const wxString GetLayerName( LAYER_ID aLayer ) const;
/** /**
* Function SetLayerName * Function SetLayerName
......
...@@ -262,7 +262,9 @@ void DIALOG_COPPER_ZONE::initDialog() ...@@ -262,7 +262,9 @@ void DIALOG_COPPER_ZONE::initDialog()
m_LayerId.push_back( layer ); m_LayerId.push_back( layer );
msg = board->GetLayerName( layer ).Trim(); msg = board->GetLayerName( layer );
msg.Trim();
EDA_COLOR_T layerColor = board->GetLayerColor( layer ); EDA_COLOR_T layerColor = board->GetLayerColor( layer );
......
...@@ -99,24 +99,20 @@ static const wxString GenCADLayerNameFlipped[32] = ...@@ -99,24 +99,20 @@ static const wxString GenCADLayerNameFlipped[32] =
static std::string GenCADLayerName( int aCuCount, LAYER_ID aId ) static std::string GenCADLayerName( int aCuCount, LAYER_ID aId )
{ {
char tmp[60];
if( IsCopperLayer( aId ) ) if( IsCopperLayer( aId ) )
{ {
if( aId == F_Cu ) if( aId == F_Cu )
return "TOP"; return "TOP";
else if( aId == B_Cu ) else if( aId == B_Cu )
return "BOTTON"; return "BOTTOM";
else if( aId <= 14 ) else if( aId <= 14 )
{ {
int len = sprintf( tmp, "INNER%d", aCuCount - aId ); return StrPrintf( "INNER%d", aCuCount - aId - 1 );
return std::string( tmp, len );
} }
else else
{ {
int len = sprintf( tmp, "LAYER%d", aId ); return StrPrintf( "LAYER%d", aId );
return std::string( tmp, len );
} }
} }
...@@ -161,73 +157,65 @@ static std::string GenCADLayerName( int aCuCount, LAYER_ID 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) // flipped layer name for Gencad export (to make CAM350 imports correct)
static std::string GenCADLayerNameFlipped( int aCuCount, LAYER_ID aId ) static std::string GenCADLayerNameFlipped( int aCuCount, LAYER_ID aId )
{ {
char tmp[60]; if( 1<= aId && aId <= 14 )
if( IsCopperLayer( aId ) )
{ {
if( aId == F_Cu ) return StrPrintf( "INNER%d", 14 - aId );
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 );
}
}
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 #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) // These are the export origin (the auxiliary axis)
static int GencadOffsetX, GencadOffsetY; static int GencadOffsetX, GencadOffsetY;
...@@ -255,9 +243,6 @@ static double MapYTo( int aY ) ...@@ -255,9 +243,6 @@ static double MapYTo( int aY )
/* Driver function: processing starts here */ /* Driver function: processing starts here */
void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent ) 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(); wxFileName fn = GetBoard()->GetFileName();
FILE* file; FILE* file;
...@@ -347,8 +332,6 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent ) ...@@ -347,8 +332,6 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent )
module->SetFlag( 0 ); module->SetFlag( 0 );
} }
} }
#endif
} }
...@@ -426,9 +409,11 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb ) ...@@ -426,9 +409,11 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
// Emit vias pads // Emit vias pads
TRACK* old_via = 0; TRACK* old_via = 0;
for( unsigned i = 0; i < vias.size(); i++ ) for( unsigned i = 0; i < vias.size(); i++ )
{ {
VIA* via = vias[i]; VIA* via = vias[i];
if( old_via && 0 == ViaSort( &old_via, &via ) ) if( old_via && 0 == ViaSort( &old_via, &via ) )
continue; continue;
...@@ -436,7 +421,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb ) ...@@ -436,7 +421,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
viastacks.push_back( via ); viastacks.push_back( via );
fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n", fprintf( aFile, "PAD V%d.%d.%s ROUND %g\nCIRCLE 0 0 %g\n",
via->GetWidth(), via->GetDrillValue(), via->GetWidth(), via->GetDrillValue(),
via->GetLayerSet().FmtHex().c_str(), fmt_mask( via->GetLayerSet() ).c_str(),
via->GetDrillValue() / SCALE_FACTOR, via->GetDrillValue() / SCALE_FACTOR,
via->GetWidth() / (SCALE_FACTOR * 2) ); via->GetWidth() / (SCALE_FACTOR * 2) );
} }
...@@ -557,8 +542,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb ) ...@@ -557,8 +542,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
pad->GetOffset().x / SCALE_FACTOR, pad->GetOffset().x / SCALE_FACTOR,
(-pad->GetOffset().y - dr) / SCALE_FACTOR ); (-pad->GetOffset().y - dr) / SCALE_FACTOR );
} }
break;
} }
break;
case PAD_TRAPEZOID: case PAD_TRAPEZOID:
fprintf( aFile, " POLYGON %g\n", fprintf( aFile, " POLYGON %g\n",
...@@ -583,16 +568,16 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb ) ...@@ -583,16 +568,16 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n", fprintf( aFile, "PADSTACK VIA%d.%d.%s %g\n",
via->GetWidth(), via->GetDrillValue(), via->GetWidth(), via->GetDrillValue(),
mask.FmtHex().c_str(), fmt_mask( mask ).c_str(),
via->GetDrillValue() / SCALE_FACTOR ); 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; LAYER_ID layer = *seq;
fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n", fprintf( aFile, "PAD V%d.%d.%s %s 0 0\n",
via->GetWidth(), via->GetDrillValue(), via->GetWidth(), via->GetDrillValue(),
mask.FmtHex().c_str(), fmt_mask( mask ).c_str(),
GenCADLayerName( cu_count, layer ).c_str() GenCADLayerName( cu_count, layer ).c_str()
); );
} }
...@@ -612,7 +597,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb ) ...@@ -612,7 +597,8 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
LSET pad_set = pad->GetLayerSet() & master_layermask; 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; LAYER_ID layer = *seq;
...@@ -622,6 +608,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb ) ...@@ -622,6 +608,7 @@ static void CreatePadsShapesSection( FILE* aFile, BOARD* aPcb )
// Flipped padstack // Flipped padstack
fprintf( aFile, "PADSTACK PAD%dF %g\n", i, pad->GetDrillSize().x / SCALE_FACTOR ); 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 ) for( LSEQ seq = pad_set.Seq(); seq; ++seq )
{ {
LAYER_ID layer = *seq; LAYER_ID layer = *seq;
...@@ -990,7 +977,7 @@ static void CreateRoutesSection( FILE* aFile, BOARD* aPcb ) ...@@ -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", fprintf( aFile, "VIA VIA%d.%d.%s %g %g ALL %g via%d\n",
via->GetWidth(), via->GetDrillValue(), via->GetWidth(), via->GetDrillValue(),
vset.FmtHex().c_str(), fmt_mask( vset ).c_str(),
MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ), MapXTo( via->GetStart().x ), MapYTo( via->GetStart().y ),
via->GetDrillValue() / SCALE_FACTOR, vianum++ ); via->GetDrillValue() / SCALE_FACTOR, vianum++ );
} }
......
...@@ -132,9 +132,6 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter, ...@@ -132,9 +132,6 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberextensions ), aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberextensions ),
m_useGerberExtensions ? trueStr : falseStr ); 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, if( m_useGerberAttributes ) // save this option only if active,
// to avoid incompatibility with older Pcbnew version // to avoid incompatibility with older Pcbnew version
aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberattributes ), trueStr ); aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_usegerberattributes ), trueStr );
...@@ -153,10 +150,12 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter, ...@@ -153,10 +150,12 @@ void PCB_PLOT_PARAMS::Format( OUTPUTFORMATTER* aFormatter,
m_useAuxOrigin ? trueStr : falseStr ); m_useAuxOrigin ? trueStr : falseStr );
aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpennumber ), aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpennumber ),
m_HPGLPenNum ); 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 // Obsolete parameter, pen speed is no more managed, because hpgl format
// aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ), // is now an export format, and for this, pen speed has no meaning
// m_HPGLPenSpeed ); // aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ),
// m_HPGLPenSpeed );
aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ), aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpenspeed ),
m_HPGLPenSpeed ); m_HPGLPenSpeed );
aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpendiameter ), aFormatter->Print( aNestLevel+1, "(%s %d)\n", getTokenName( T_hpglpendiameter ),
......
...@@ -105,7 +105,9 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::Init() ...@@ -105,7 +105,9 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::Init()
{ {
LAYER_ID layer = *seq; 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 ); m_LayerSelectionCtrl->InsertItems( 1, &msg, ii );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment